public function updateColdChainStatus()
 {
     date_default_timezone_set('Asia/karachi');
     $cc_id = $this->form_values['ccm_id'];
     $created_by = $this->_em->find('Users', $this->_user_id);
     foreach ($cc_id as $index => $ccm_id) {
         $working_status = $this->form_values['working_status'];
         $temperature = $this->form_values['temperature'];
         $ccmAssetId = $this->form_values['asset_id'];
         $reason = $this->form_values['reason'];
         $utilization = $this->form_values['utilization'];
         $wh_id = $this->form_values['wh_id'];
         $ccm_status_history = new CcmStatusHistory();
         $ccm_status_history->setTemperatureAlarm($temperature[$index]);
         $cold_chain_id = $this->_em->getRepository('ColdChain')->find($ccm_id);
         $ccm_status_history->setCcm($cold_chain_id);
         $ccm_status_history->setStatusDate(new \DateTime(date("Y-m-d h:i")));
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
         $ccm_status_history->setWarehouse($warehouse_id);
         $work_status = $this->_em->getRepository('CcmStatusList')->find($working_status[$index]);
         $ccm_status_history->setCcmStatusList($work_status);
         $ccm_asset_type = $this->_em->getRepository('CcmAssetTypes')->find($ccmAssetId[$index]);
         $ccm_status_history->setCcmAssetType($ccm_asset_type);
         if (empty($reason[$index])) {
             $reason_id = $this->_em->getRepository('CcmStatusList')->find(1);
             $ccm_status_history->setReason($reason_id);
         } else {
             $reason_id = $this->_em->getRepository('CcmStatusList')->find($reason[$index]);
             $ccm_status_history->setReason($reason_id);
         }
         if (empty($utilization[$index])) {
             $utilization_id = $this->_em->getRepository('CcmStatusList')->find(1);
             $ccm_status_history->setUtilization($utilization_id);
         } else {
             $utilization_id = $this->_em->getRepository('CcmStatusList')->find($utilization[$index]);
             $ccm_status_history->setUtilization($utilization_id);
         }
         $ccm_status_history->setCreatedBy($created_by);
         $ccm_status_history->setModifiedBy($created_by);
         $ccm_status_history->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($ccm_status_history);
         $this->_em->flush();
         $ccm_history_id = $ccm_status_history->getPkId();
         $cold_chain = new Model_ColdChain();
         $cold_chain->updateCcmStatusHistory($ccm_id, $ccm_history_id);
     }
     $ccm_id_q = $this->form_values['ccm_id_q'];
     foreach ($ccm_id_q as $index => $ccm_id_quantity) {
         $work_quantity = $this->form_values['work_quantity'];
         $comments = $this->form_values['comments'];
         $asset_id_q = $this->form_values['asset_id_q'];
         $wh_id = $this->form_values['wh_id'];
         $ccm_status = new CcmStatusHistory();
         $cold_chain_id_q = $this->_em->getRepository('ColdChain')->find($ccm_id_quantity);
         $ccm_status->setCcm($cold_chain_id_q);
         $ccm_status->setWorkingQuantity($work_quantity[$index]);
         $ccm_status->setComments($comments[$index]);
         $ccm_status->setStatusDate(new \DateTime(date("Y-m-d h:i")));
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
         $ccm_status->setWarehouse($warehouse_id);
         $ccm_asset_type_q = $this->_em->getRepository('CcmAssetTypes')->find($asset_id_q[$index]);
         $ccm_status->setCcmAssetType($ccm_asset_type_q);
         $ccm_status->setCreatedBy($created_by);
         $ccm_status->setModifiedBy($created_by);
         $ccm_status->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($ccm_status);
         $this->_em->flush();
         $history_id = $ccm_status->getPkId();
         $cold_chain = new Model_ColdChain();
         $cold_chain->updateCcmStatusHistory($ccm_id_quantity, $history_id);
     }
     $ccm_id_histroy = $this->form_values['ccm_id_q'];
     foreach ($ccm_id_histroy as $index => $ccm_id_quantity) {
         $work_quantity = $this->form_values['work_quantity'];
         $total_quantity = $this->form_values['total_quantity'];
         $wh_id = $this->form_values['wh_id'];
         $ccm_history = new CcmHistory();
         $quantity = $total_quantity[$index] - $work_quantity[$index];
         $ccm_history->setQuantity($quantity);
         $ccm_history->setCreatedDate(new \DateTime(date("Y-m-d")));
         $action_id = $this->_em->getRepository('ListDetail')->find(26);
         $ccm_history->setAction($action_id);
         $ccm_id = $this->_em->getRepository('ColdChain')->find($ccm_id_quantity);
         $ccm_history->setCcm($ccm_id);
         $user_id = $this->_em->getRepository('Users')->find($this->_user_id);
         $ccm_history->setCreatedBy($user_id);
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
         $ccm_history->setWarehouse($warehouse_id);
         $ccm_history->setCreatedBy($created_by);
         $ccm_history->setModifiedBy($created_by);
         $ccm_history->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($ccm_history);
     }
     $this->_em->flush();
 }
Example #2
0
 public function addVaccineCarrier()
 {
     //$ccm_model = new CcmModels();
     $form_values = $this->form_values;
     $ccm_model = $this->_em->getRepository('CcmModels')->find($form_values['catalogue_id']);
     /*  $ccm_model->setCatalogueId($form_values['catalogue_id']);
          $ccm_model->setAssetDimensionLength($form_values['asset_dimension_length']);
          $ccm_model->setAssetDimensionWidth($form_values['asset_dimension_width']);
          $ccm_model->setAssetDimensionHeight($form_values['asset_dimension_height']);
         * 
         */
     $asset_id_m = $this->_em->getRepository('CcmAssetTypes')->find(Model_CcmAssetTypes::VACCINECARRIER);
     $ccm_model->setCcmAssetType($asset_id_m);
     $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
     $ccm_model->setCreatedBy($created_by);
     $ccm_model->setModifiedBy($created_by);
     $ccm_model->setCreatedDate(new \DateTime(date("Y-m-d")));
     $ccm_model->setModifiedDate(new \DateTime(date("Y-m-d")));
     $this->_em->persist($ccm_model);
     $this->_em->flush();
     $model_id = $ccm_model->getPkId();
     $cold_chain = new ColdChain();
     $cold_chain->setAutoAssetId(App_Controller_Functions::generateCcemUniqueAssetId(Model_CcmAssetTypes::VACCINECARRIER));
     $cold_chain->setQuantity($form_values['quantity']);
     $asset_id = $this->_em->getRepository('CcmAssetTypes')->find(Model_CcmAssetTypes::VACCINECARRIER);
     $cold_chain->setCcmAssetType($asset_id);
     $m_id = $this->_em->getRepository('CcmModels')->find($model_id);
     $cold_chain->setCcmModel($m_id);
     $created_by1 = $this->_em->getRepository('Users')->find($this->_user_id);
     $cold_chain->setCreatedBy($created_by1);
     if (!empty($this->form_values['warehouse'])) {
         $w_id = $this->form_values['warehouse'];
         $warehouse = $this->_em->getRepository('Warehouses')->find($w_id);
         $cold_chain->setWarehouse($warehouse);
     }
     $cold_chain->setCreatedDate(new \DateTime(date("Y-m-d")));
     $this->_em->persist($cold_chain);
     $this->_em->flush();
     $cold_chain_id = $cold_chain->getPkId();
     $ccm_status_history = new CcmStatusHistory();
     $ccm_status_history->setStatusDate(new \DateTime(date("Y-m-d h:i")));
     $cold_chian_id = $this->_em->getRepository('ColdChain')->find($cold_chain_id);
     $ccm_status_history->setCcm($cold_chian_id);
     if (!empty($form_values['warehouse']) && $form_values['placed_at'] == 1) {
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($form_values['warehouse']);
         $ccm_status_history->setWarehouse($warehouse_id);
     } else {
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($this->_identity->getWarehouseId());
         $ccm_status_history->setWarehouse($warehouse_id);
     }
     $asset1_id = $this->_em->getRepository('CcmAssetTypes')->find(Model_CcmAssetTypes::VACCINECARRIER);
     $ccm_status_history->setCcmAssetType($asset1_id);
     $ccm_status_history->setWorkingQuantity($form_values['quantity']);
     $this->_em->persist($ccm_status_history);
     $this->_em->flush();
     $cold_chain_model = new Model_ColdChain();
     $ccm_history_id = $ccm_status_history->getPkId();
     $cold_chain_model->updateCcmStatusHistory($cold_chain_id, $ccm_history_id);
     if (!empty($form_values['warehouse'])) {
         $ccm_history = new CcmHistory();
         $w_id = $this->form_values['warehouse'];
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($w_id);
         $ccm_history->setWarehouse($warehouse_id);
         $ccm_id = $this->_em->getRepository('ColdChain')->find($cold_chain_id);
         $ccm_history->setCcm($ccm_id);
         $action_id = $this->_em->getRepository('ListDetail')->find('10');
         $ccm_history->setAction($action_id);
         $created_by12 = $this->_em->getRepository('Users')->find($this->_user_id);
         $ccm_history->setCreatedBy($created_by12);
         $ccm_history->setCreatedDate(new \DateTime(date("Y-m-d")));
         $this->_em->persist($ccm_history);
         $this->_em->flush();
     }
 }