public function transferColdChainAsset() { $form_values = $this->form_values; if ($form_values['transfer'] == 1) { $cold_chain_update = $this->_table->find($form_values['coldchain_id']); $to_warehouse = $this->_em->getRepository('Warehouses')->find($form_values['to_warehouse']); $cold_chain_update->setWarehouse($to_warehouse); $this->_em->persist($cold_chain_update); $this->_em->flush(); } elseif ($form_values['quantity_issue'] > 0) { if ($form_values['quantity_issue'] < $form_values['quantity_available']) { $sub_sql = $this->_em->createQueryBuilder()->select("" . "cc.assetId, cc.quantity, cc.autoAssetId, cc.serialNumber," . "cc.estimateLife, cc.workingSince, cc.manufactureYear, cc.status," . "cc.approvedBy, cc.approvedOn, cc.createdDate," . "csh.pkId AS ccmStatusHistoryId," . "cat.pkId AS ccmAssetTypeId," . "cmod.pkId AS ccmModelId," . "cu.pkId AS createdById," . "sh.pkId AS sourceId")->from("ColdChain", "cc")->leftJoin('cc.ccmStatusHistory', 'csh')->leftjoin('cc.ccmAssetType', 'cat')->leftjoin('cc.ccmModel', 'cmod')->leftjoin('cc.createdBy', 'cu')->leftJoin('cc.source', 'sh')->where("cc.pkId = " . $this->form_values['coldchain_id']); $one_row = $sub_sql->getQuery()->getResult(); $one_row = $one_row[0]; $cold_chain = new ColdChain(); $cold_chain->setAssetId($one_row['assetId']); $cold_chain->setQuantity($form_values['quantity_issue']); $cold_chain->setAutoAssetId($one_row['autoAssetId']); $cold_chain->setSerialNumber($one_row['serialNumber']); $cold_chain->setEstimateLife($one_row['estimateLife']); $cold_chain->setWorkingSince(new \DateTime(App_Controller_Functions::dateToDbFormat($one_row['workingSince']))); $cold_chain->setManufactureYear(new \DateTime(App_Controller_Functions::dateToDbFormat($one_row['manufactureYear']))); $cold_chain->setStatus($one_row['status']); $cold_chain->setApprovedBy($one_row['approvedBy']); $cold_chain->setApprovedOn(new \DateTime(App_Controller_Functions::dateToDbFormat($one_row['approvedOn']))); $cold_chain->setCreatedDate(new \DateTime(App_Controller_Functions::dateToDbFormat(date("d/m/Y")))); if ($one_row['ccmStatusHistoryId']) { $status_history_id = $this->_em->getRepository('CcmStatusHistory')->find($one_row['ccmStatusHistoryId']); $cold_chain->setCcmStatusHistory($status_history_id); } $asset_type = $this->_em->getRepository('CcmAssetTypes')->find($one_row['ccmAssetTypeId']); $cold_chain->setCcmAssetType($asset_type); $model_id = $this->_em->getRepository('CcmModels')->find($one_row['ccmModelId']); $cold_chain->setCcmModel($model_id); $created_by_id = $this->_em->getRepository('Users')->find($one_row['createdById']); $cold_chain->setCreatedBy($created_by_id); $cold_chain->setCreatedDate(new \DateTime(App_Controller_Functions::dateToDbFormat(date("d/m/Y")))); if ($one_row['sourceId']) { $source_id = $this->_em->getRepository('Stakeholders')->find($one_row['sourceId']); $cold_chain->setSource($source_id); } if ($form_values['to_warehouse']) { $frm_warehouse_id = $this->_em->getRepository('Warehouses')->find($form_values['to_warehouse']); $cold_chain->setWarehouse($frm_warehouse_id); } $this->_em->persist($cold_chain); $this->_em->flush(); /* * Adjust Quantity */ $adjusted_quantity = $form_values['quantity_available'] - $form_values['quantity_issue']; $cold_chain_adjust_quantity = $this->_table->find($form_values['coldchain_id']); $cold_chain_adjust_quantity->setQuantity($adjusted_quantity); $this->_em->persist($cold_chain_adjust_quantity); $this->_em->flush(); } /* elseif ($form_values['quantity_issue'] >= $form_values['quantity_available']) { $cold_chain_update = $this->_table->find($form_values['coldchain_id']); $cold_chain_update->setWarehouse($form_values['to_warehouse']); $this->_em->persist($cold_chain_update); $this->_em->flush(); } */ } //enter in clod chain history if ($form_values['transfer'] == 1 || $form_values['quantity_issue'] > 0) { $ccm_transfer = new CcmTransferHistory(); if ($form_values['quantity_issue']) { $ccm_transfer->setQuantity($form_values['quantity_issue']); } $ccm_transfer->setTransferDate(new \DateTime(App_Controller_Functions::dateToDbFormat(date("d/m/Y")))); $transferBy = $this->_em->getRepository('Users')->find($this->_user_id); $ccm_transfer->setTransferBy($transferBy); $ccm_id = $this->_em->getRepository('ColdChain')->find($form_values['coldchain_id']); $ccm_transfer->setCcm($ccm_id); $ccm_status_list_id = $this->_em->getRepository('CcmStatusList')->find('1'); //Temporarily hard code as this filed not found in coldchain table $ccm_transfer->setCcmStatusList($ccm_status_list_id); $from_warehouse = $this->_em->getRepository('Warehouses')->find($form_values['from_warehouse']); $ccm_transfer->setFromWarehouse($from_warehouse); $to_warehouse = $this->_em->getRepository('Warehouses')->find($form_values['to_warehouse']); $ccm_transfer->setToWarehouse($to_warehouse); $this->_em->persist($ccm_transfer); $this->_em->flush(); } if (!empty($form_values['to_warehouse'])) { $to_warehouse = $form_values['to_warehouse']; $qry = "SELECT REPUpdateCapacity({$to_warehouse}) from DUAL"; $row = $this->_em->getConnection()->prepare($qry); $row->execute(); $qry1 = "SELECT REPUpdateRequirement({$to_warehouse}) from DUAL"; $row1 = $this->_em->getConnection()->prepare($qry1); $row1->execute(); } if (!empty($form_values['from_warehouse'])) { $from_warehouse = $form_values['from_warehouse']; $qry = "SELECT REPUpdateCapacity({$from_warehouse}) from DUAL"; $row = $this->_em->getConnection()->prepare($qry); $row->execute(); $qry1 = "SELECT REPUpdateRequirement({$from_warehouse}) from DUAL"; $row1 = $this->_em->getConnection()->prepare($qry1); $row1->execute(); } }
public function setApprovedOn($approvedOn) { $this->__load(); return parent::setApprovedOn($approvedOn); }