public function getWarehouse()
 {
     $this->__load();
     return parent::getWarehouse();
 }
 public function uploadReceiveConsignments()
 {
     $params = $this->form_values;
     $wh_id = $params['wh_id'];
     $rec_id = $params['rec_id'];
     $batch_no = $params['batch_no'];
     $qty = str_replace(",", "", $params['qty']);
     $voucher = $params['voucher'];
     $consignments_location = $this->_em->getRepository("PipelineConsignmentsPlacements")->findBy(array("pipelineConsignment" => $rec_id));
     if (count($consignments_location) > 0) {
         foreach ($consignments_location as $cl) {
             $location_id[] = $cl->getPlacementLocation()->getPkId();
         }
     }
     $str_qry = $this->_em->createQueryBuilder()->select("pc.masterId")->from("PipelineConsignments", "pc")->where("pc.voucherNumber = '" . $voucher . "'")->andWhere("pc.masterId > 0")->andWhere("pc.toWarehouse = " . $wh_id);
     $stock_master_id = $str_qry->getQuery()->getResult();
     if (count($stock_master_id) > 0) {
         $master_id = $stock_master_id[0]['masterId'];
     } else {
         $master_id = 0;
     }
     $pipeline_consignments = $this->_em->getRepository("PipelineConsignments")->find($rec_id);
     /**
      * Record must exists
      */
     if (count($pipeline_consignments) == 0) {
         $result_msg = array("message" => "Selected record id {$rec_id} does not exist in pipeline consignments. Please update your data.");
         App_FileLogger::info($result_msg['message']);
         return $result_msg;
     }
     /**
      * Check if we need to create new voucher or add detail entry in existing voucher
      * If 0 then New Voucher
      * If greater then 0 then Add in Existing voucher 
      */
     if ($master_id == 0) {
         $tr_date = date("d/m/Y");
         $obj_master = new Model_StockMaster();
         $trans = $obj_master->getTransactionNumber(1, $tr_date, $wh_id);
         $stock_master = new StockMaster();
         $stock_master->setTransactionDate(new DateTime());
         $stock_master->setTransactionNumber($trans['trans_no']);
         $stock_master->setTransactionCounter($trans['id']);
         $stock_master->setTransactionReference($pipeline_consignments->getReferenceNumber());
         $stock_master->setDraft(0);
         $stock_master->setComments($pipeline_consignments->getDescription());
         $type = $this->_em->getRepository("TransactionTypes")->find(1);
         $stock_master->setTransactionType($type);
         $stock_master->setFromWarehouse($pipeline_consignments->getFromWarehouse());
         $stock_master->setToWarehouse($pipeline_consignments->getToWarehouse());
         $stock_master->setParentId(0);
         $stock_master->setStakeholderActivity($pipeline_consignments->getStakeholderActivity());
         $stock_master->setCreatedBy($pipeline_consignments->getCreatedBy());
         $stock_master->setCreatedDate(new DateTime(date("Y-m-d H:i:s")));
         $this->_em->persist($stock_master);
         $this->_em->flush();
         $master_id = $stock_master->getPkId();
     }
     $array = array("item_id" => $pipeline_consignments->getItemPackSize()->getPkId(), "number" => $batch_no, "wh_id" => $pipeline_consignments->getToWarehouse()->getPkId());
     $batch_id = $this->checkBatch($array);
     /**
      * Check if Batch exists or not
      * If 0 then create new batch
      * If greater then 0 then add quantity in existing batch
      */
     if ($batch_id === 0) {
         $stock_batch = new StockBatch();
         $stock_batch->setNumber(strtoupper($batch_no));
         $stock_batch->setExpiryDate($pipeline_consignments->getExpiryDate());
         $stock_batch->setQuantity($qty);
         $stock_batch->setStatus('Stacked');
         $stock_batch->setUnitPrice(0);
         $stock_batch->setProductionDate($pipeline_consignments->getProductionDate());
         $stock_batch->setLastUpdate(new DateTime(date("Y-m-d")));
         $stock_batch->setItemPackSize($pipeline_consignments->getItemPackSize());
         $vvm_type = $this->_em->getRepository("VvmTypes")->find(2);
         $stock_batch->setVvmType($vvm_type);
         $stock_batch->setWarehouse($pipeline_consignments->getToWarehouse());
         $stock_batch->setStakeholderItemPackSize($pipeline_consignments->getManufacturer());
         $this->_em->persist($stock_batch);
         $this->_em->flush();
         $batch_id = $stock_batch->getPkId();
     }
     /*
      * Add Entry in stock detail against selected master voucher
      */
     $stock_detail = new StockDetail();
     $stock_detail->setQuantity($qty);
     $stock_detail->setTemporary(0);
     $vvms = $this->_em->getRepository("VvmStages")->find(1);
     $stock_detail->setVvmStage($vvms);
     $stock_detail->setIsReceived(1);
     $stock_detail->setAdjustmentType(1);
     $stock_master = $this->_em->getRepository("StockMaster")->find($master_id);
     $stock_detail->setStockMaster($stock_master);
     $stock_batch = $this->_em->getRepository("StockBatch")->find($batch_id);
     $stock_detail->setStockBatch($stock_batch);
     $stock_detail->setItemUnit($pipeline_consignments->getItemPackSize()->getItemUnit());
     $this->_em->persist($stock_detail);
     $this->_em->flush();
     if (count($location_id) > 0) {
         foreach ($location_id as $plac_id) {
             $plac_loc_id = $this->_em->getRepository("PlacementLocations")->find($plac_id);
             /*
              * Add entry in Placement table
              */
             $placements = new Placements();
             $placements->setQuantity($qty);
             $vvms = $this->_em->getRepository("VvmStages")->find(1);
             $placements->setVvmStage($vvms);
             $placements->setIsPlaced(1);
             $placements->setPlacementLocation($plac_loc_id);
             $placements->setStockBatch($stock_batch);
             $placements->setStockDetail($stock_detail);
             $trans_type = $this->_em->getRepository("ListDetail")->find(Model_ListDetail::STOCK_PLACEMENT);
             $placements->setPlacementTransactionType($trans_type);
             $placements->setCreatedBy($pipeline_consignments->getCreatedBy());
             $placements->setCreatedDate(new DateTime(date("Y-m-d H:i:s")));
             $this->_em->persist($placements);
             $this->_em->flush();
         }
     }
     /*
      * Update Received Qty in Future Arrivals table
      */
     //$update_qty = $pipeline_consignments->getReceivedQuantity() + $qty;
     //if ($update_qty <= $pipeline_consignments->getQuantity()) {
     $pipeline_consignments->setReceivedQuantity($qty);
     $pipeline_consignments->setMasterId($master_id);
     $this->_em->persist($pipeline_consignments);
     $this->_em->flush();
     //}
     /*
      * Adjust Batch Quantity By Warehouse
      */
     $this->adjustQuantityByWarehouse($batch_id, $pipeline_consignments->getToWarehouse()->getPkId());
     /*
      * Adjust Warehouse data for selected month and item
      */
     $warehouse_data = new Model_WarehousesData();
     $warehouse_data->form_values = array('report_month' => date("m"), 'report_year' => date("Y"), 'item_id' => $pipeline_consignments->getItemPackSize()->getPkId(), 'warehouse_id' => $pipeline_consignments->getToWarehouse()->getPkId(), 'created_by' => $pipeline_consignments->getCreatedBy()->getPkId());
     $warehouse_data->adjustStockReport();
     $stock_master = $this->_em->getRepository("StockMaster")->find($master_id);
     return "V" . base64_encode($stock_master->getTransactionNumber() . "|" . $stock_master->getPkId());
 }
 public function addStockWarehouseByIssue()
 {
     if (!empty($this->form_values['wh_id'])) {
         $wh_id = $this->form_values['wh_id'];
     } else {
         $wh_id = $this->_identity->getWarehouseId();
     }
     $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
     $tranaction_type = new Model_TransactionTypes();
     $arr_types = $tranaction_type->getAll();
     $array_types = array();
     foreach ($arr_types as $arrtype) {
         $array_types[$arrtype['pkId']] = $arrtype['nature'];
     }
     if (isset($this->form_values['stock_id']) && !empty($this->form_values['stock_id'])) {
         $stock_id = $this->form_values['stock_id'];
         $stock_detail = new Model_StockDetail();
         $stock_detail->pkId = $stock_id;
         $stock_detail_result = $stock_detail->findbyStockId();
         $type_id = 1;
         if (isset($this->form_values['remarks']) && !empty($this->form_values['remarks'])) {
             $remarks = $this->form_values['remarks'];
         }
         if (isset($this->form_values['issue_no']) && !empty($this->form_values['issue_no'])) {
             $issue_no = $this->form_values['issue_no'];
         }
         if (isset($this->form_values['count']) && !empty($this->form_values['count'])) {
             $count_o = $this->form_values['count'];
         }
         if (isset($this->form_values['rec_date']) && !empty($this->form_values['rec_date'])) {
             $rec_date = $this->form_values['rec_date'];
         }
         if (isset($this->form_values['rec_ref']) && !empty($this->form_values['rec_ref'])) {
             $rec_ref = $this->form_values['rec_ref'];
         }
         if (isset($this->form_values['vvmstage']) && !empty($this->form_values['vvmstage'])) {
             $vvmstage = $this->form_values['vvmstage'];
         }
         if (isset($this->form_values['locations']) && !empty($this->form_values['locations'])) {
             $locations = $this->form_values['locations'];
         }
         if (count($stock_detail_result) > 0) {
             $stock_master = new StockMaster();
             $time_arr = explode(' ', $rec_date);
             $time = date('H:i:s', strtotime($time_arr[1] . $time_arr[2]));
             $stock_master->setTransactionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($time_arr[0]) . ' ' . $time));
             $tran_type = $this->_em->getRepository('TransactionTypes')->find($type_id);
             $stock_master->setTransactionType($tran_type);
             $stock_master->setTransactionReference($rec_ref);
             $from_warehouse_id = $this->_em->getRepository('Warehouses')->find($stock_detail_result[0]['fromWarehouse']);
             $stock_master->setFromWarehouse($from_warehouse_id);
             $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
             $stock_master->setToWarehouse($warehouse_id);
             $stock_master->setCreatedBy($created_by);
             $stock_master->setModifiedBy($created_by);
             $stock_master->setCreatedDate(App_Tools_Time::now());
             $stock_master->setModifiedDate(App_Tools_Time::now());
             $stock_master->setComments($remarks);
             $trans_no = $this->getTransactionNumber(1, $rec_date);
             $stock_master->setTransactionNumber($trans_no['trans_no']);
             if (!empty($stock_detail_result[0]['stakeholderActivity'])) {
                 $stakeholder_activity = $this->_em->getRepository('StakeholderActivities')->find($stock_detail_result[0]['stakeholderActivity']);
                 $stock_master->setStakeholderActivity($stakeholder_activity);
             }
             $stock_master->setDraft(0);
             $stock_master->setTransactionCounter($trans_no['id']);
             $stock_master->setParentId(0);
             $this->_em->persist($stock_master);
             $this->_em->flush();
             $fk_stock_ID = $stock_master->getPkId();
         }
     }
     if (isset($this->form_values['stockid']) && !empty($this->form_values['stockid'])) {
         $stock_ids = $this->form_values['stockid'];
         $count_stock_ids = count($stock_ids);
         foreach ($stock_ids as $index => $detail_id) {
             $stock_detail = new Model_StockDetail();
             $stock_detail->stockReceived($detail_id);
             $stockBatch = $stock_detail->GetBatchDetail($detail_id);
             $stockDetail = $stock_detail->findByDetailId($detail_id);
             $array_missing = $this->form_values['missing'];
             $quantity = ABS($stockBatch['0']['quantity']);
             $obj_stock_batch = new Model_StockBatch();
             $product_id = $stockBatch['0']['itemPackSize'];
             $array = array('number' => $stockBatch['0']['number'], 'item_id' => $product_id);
             $batch_id1 = $obj_stock_batch->checkBatch($array);
             if ($batch_id1 === 0) {
                 $stock_batch = new StockBatch();
                 $stock_batch->setNumber(strtoupper($stockBatch['0']['number']));
                 $stock_batch->setExpiryDate(new \DateTime($stockBatch[0]['expiryDate']));
                 $stock_batch->setUnitPrice($stockBatch['0']['unitPrice']);
                 $stock_batch->setProductionDate(new \DateTime($stockBatch[0]['productionDate']));
                 if (!empty($stockBatch['0']['stakeholderItemPackSize'])) {
                     $pack_info_id = $this->_em->getRepository('PackInfo')->findOneBy(array("stakeholderItemPackSize" => $stockBatch['0']['stakeholderItemPackSize']));
                     $stock_batch->setPackInfo($pack_info_id);
                 }
                 if (!empty($stockBatch['0']['vvmType'])) {
                     $vvm_id = $this->_em->getRepository('VvmTypes')->find($stockBatch['0']['vvmType']);
                     $stock_batch->setVvmType($vvm_id);
                 }
                 $stock_batch->setModifiedBy($created_by);
                 $stock_batch->setModifiedDate(App_Tools_Time::now());
                 $stock_batch->setCreatedBy($created_by);
                 $stock_batch->setCreatedDate(App_Tools_Time::now());
                 $this->_em->persist($stock_batch);
                 $this->_em->flush();
                 $batch_id2 = $stock_batch->getPkId();
                 $stock_batch_warehouses = new StockBatchWarehouses();
                 $stock_batch_warehouses->setQuantity($quantity);
                 $stock_batch_warehouses->setStatus(Model_StockBatch::STACKED);
                 $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
                 $stock_batch_warehouses->setWarehouse($warehouse_id);
                 $stock_batch_id = $this->_em->getRepository('StockBatch')->find($batch_id2);
                 $stock_batch_warehouses->setStockBatch($stock_batch_id);
                 $stock_batch_warehouses->setModifiedBy($created_by);
                 $stock_batch_warehouses->setModifiedDate(App_Tools_Time::now());
                 $stock_batch_warehouses->setCreatedBy($created_by);
                 $stock_batch_warehouses->setCreatedDate(App_Tools_Time::now());
                 $this->_em->persist($stock_batch_warehouses);
                 $this->_em->flush();
                 $batch_id1 = $stock_batch_warehouses->getPkId();
             }
             $stock_detail = new StockDetail();
             $sm_id = $this->_em->getRepository('StockMaster')->find($fk_stock_ID);
             $stock_detail->setStockMaster($sm_id);
             $sb_id = $this->_em->getRepository('StockBatchWarehouses')->find($batch_id1);
             $stock_detail->setStockBatchWarehouse($sb_id);
             $iu_id = $this->_em->getRepository('ItemUnits')->find($stockDetail['0']['itemUnit']);
             $stock_detail->setItemUnit($iu_id);
             $stock_detail->setQuantity($array_types[$type_id] . $quantity);
             $stock_detail->setTemporary(0);
             $vvms = $this->_em->getRepository("VvmStages")->find($vvmstage[$index]);
             $stock_detail->setVvmStage($vvms);
             $stock_detail->setIsReceived($detail_id);
             $stock_detail->setAdjustmentType($type_id);
             $stock_detail->setModifiedBy($created_by);
             $stock_detail->setModifiedDate(App_Tools_Time::now());
             $stock_detail->setCreatedBy($created_by);
             $stock_detail->setCreatedDate(App_Tools_Time::now());
             $this->_em->persist($stock_detail);
             $this->_em->flush();
             $adj_stock_detail_id = $stock_detail->getPkId();
             if (!empty($locations[$index])) {
                 $placement = new Model_Placements();
                 $placement->form_values = array('vvmstage' => $vvmstage[$index], 'is_placed' => 1, 'quantity' => $array_types[$type_id] . $quantity, 'placement_loc_type_id' => 114, 'placement_loc_id' => $locations[$index], 'batch_id' => $batch_id1, 'detail_id' => $stock_detail->getPkId(), 'user_id' => $this->_user_id, 'created_date' => date("Y-m-d"));
                 $placement->add();
             }
             if (isset($array_missing[$index]) && !empty($array_missing[$index])) {
                 $type = $this->form_values['types'];
                 $stock_detail = new Model_StockDetail();
                 $stockDetail = $stock_detail->findByDetailId($detail_id);
                 if (count($stockDetail) > 0) {
                     $stock_master = new StockMaster();
                     $stock_master->setTransactionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($rec_date)));
                     $tran_type1 = $this->_em->getRepository('TransactionTypes')->find($type[$index]);
                     $stock_master->setTransactionType($tran_type1);
                     //$type_id;
                     $stock_master->setTransactionReference($rec_ref);
                     $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
                     $stock_master->setFromWarehouse($warehouse_id);
                     $stock_master->setToWarehouse($warehouse_id);
                     $stock_master->setCreatedBy($created_by);
                     $stock_master->setModifiedBy($created_by);
                     $stock_master->setCreatedDate(App_Tools_Time::now());
                     $stock_master->setModifiedDate(App_Tools_Time::now());
                     $stock_master->setComments($remarks);
                     $trans_no = $this->getTransactionNumber($type[$index], $rec_date);
                     $stock_master->setTransactionNumber($trans_no['trans_no']);
                     $stock_master->setDraft(0);
                     $stock_master->setTransactionCounter($trans_no['id']);
                     $stock_master->setParentId($fk_stock_ID);
                     $this->_em->persist($stock_master);
                     $this->_em->flush();
                     $stock_id = $stock_master->getPkId();
                 }
                 $stock_detail_a = new StockDetail();
                 $s_id = $this->_em->getRepository('StockMaster')->find($stock_id);
                 $stock_detail_a->setStockMaster($s_id);
                 $sb_id = $this->_em->getRepository('StockBatchWarehouses')->find($batch_id1);
                 $stock_detail_a->setStockBatchWarehouse($sb_id);
                 $iu_id = $this->_em->getRepository('ItemUnits')->find($stockDetail['0']['itemUnit']);
                 $stock_detail_a->setItemUnit($iu_id);
                 $stock_detail_a->setQuantity($array_types[$type[$index]] . $array_missing[$index]);
                 $stock_detail_a->setAdjustmentType($type[$index]);
                 $stock_detail_a->setTemporary(0);
                 $stock_detail_a->setIsReceived($adj_stock_detail_id);
                 $vvms = $this->_em->getRepository("VvmStages")->find($vvmstage[$index]);
                 $stock_detail_a->setVvmStage($vvms);
                 $stock_detail_a->setCreatedBy($created_by);
                 $stock_detail_a->setModifiedBy($created_by);
                 $stock_detail_a->setCreatedDate(App_Tools_Time::now());
                 $stock_detail_a->setModifiedDate(App_Tools_Time::now());
                 $this->_em->persist($stock_detail_a);
                 $this->_em->flush();
                 if (!empty($locations[$index])) {
                     $placement2 = new Model_Placements();
                     $placement2->form_values = array('vvmstage' => $vvmstage[$index], 'is_placed' => 0, 'quantity' => $array_types[$type[$index]] . $array_missing[$index], 'placement_loc_type_id' => 115, 'placement_loc_id' => $locations[$index], 'batch_id' => $batch_id1, 'detail_id' => $stock_detail_a->getPkId(), 'user_id' => $this->_user_id, 'created_date' => date("Y-m-d"));
                     $placement2->add();
                 }
             }
             $obj_stock_batch->adjustQuantityByWarehouse($batch_id1);
             $obj_stock_batch->autoRunningLEFOBatch($product_id);
         }
     }
     $warehouse_data = new Model_HfDataMaster();
     $warehouse_data->addReport($stock_id, 1, 'wh');
     return true;
 }
Example #4
0
 public function createBatch($array)
 {
     $batchid = $this->checkBatch($array);
     $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
     if ($batchid === 0) {
         $wh_id = $this->_identity->getWarehouseId();
         $stock_batch = new StockBatch();
         $stock_batch->setNumber(strtoupper($array['number']));
         $stock_batch->setExpiryDate(new \DateTime(App_Controller_Functions::dateToDbFormat($array['expiry_date'])));
         if (!empty($array['production_date'])) {
             $stock_batch->setProductionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($array['production_date'])));
         }
         if (!empty($array['vvm_type_id'])) {
             $vvm_type_id = $this->_em->getRepository('VvmTypes')->find($array['vvm_type_id']);
             $stock_batch->setVvmType($vvm_type_id);
         }
         $stock_batch->setUnitPrice($array['unit_price']);
         if (!empty($array['manufacturer_id'])) {
             $stakeholder_item_pack_size = $this->_em->getRepository('StakeholderItemPackSizes')->find($array['manufacturer_id']);
             if ($stakeholder_item_pack_size->getItemPackSize()->getPkId() == $array['item_id']) {
                 $pack_info_id = $this->_em->getRepository('PackInfo')->findOneBy(array("stakeholderItemPackSize" => $stakeholder_item_pack_size->getPkId(), "packagingLevel" => '140'));
                 $stock_batch->setPackInfo($pack_info_id);
             } else {
                 $check_sips = $this->_em->getRepository('StakeholderItemPackSizes')->findOneBy(array("stakeholder" => $stakeholder_item_pack_size->getStakeholder()->getPkId(), "itemPackSize" => $array['item_id']));
                 if (count($check_sips) > 0) {
                     //                       echo $check_sips->getPkId();
                     //                       exit;
                     $pack_info_id = $this->_em->getRepository('PackInfo')->findOneBy(array("stakeholderItemPackSize" => $check_sips->getPkId(), "packagingLevel" => '140'));
                     $stock_batch->setPackInfo($pack_info_id);
                 } else {
                     $add_sips = new StakeholderItemPackSizes();
                     $add_sips->setStakeholder($stakeholder_item_pack_size->getStakeholder());
                     $item_pack_size_id = $this->_em->getRepository('ItemPackSizes')->find($array['item_id']);
                     $add_sips->setItemPackSize($item_pack_size_id);
                     $add_sips->setModifiedBy($created_by);
                     $add_sips->setModifiedDate(App_Tools_Time::now());
                     $add_sips->setCreatedBy($created_by);
                     $add_sips->setCreatedDate(App_Tools_Time::now());
                     $this->_em->persist($add_sips);
                     $this->_em->flush();
                     $sips_id = $add_sips->getPkId();
                     $pack_info_id_add = $this->_em->getRepository('PackInfo')->findOneBy(array("stakeholderItemPackSize" => $stakeholder_item_pack_size->getPkId(), "packagingLevel" => '140'));
                     $pack_info = new PackInfo();
                     $stakholder_item_pack_id = $this->_em->getRepository('StakeholderItemPackSizes')->find($sips_id);
                     $pack_info->setStakeholderItemPackSize($stakholder_item_pack_id);
                     $pack_info->setQuantityPerPack($pack_info_id_add->getQuantityPerPack());
                     $pack_info->setStatus($pack_info_id_add->getStatus());
                     $pack_info->setListRank($pack_info_id_add->getListRank());
                     $pack_info->setVolumPerVial($pack_info_id_add->getVolumPerVial());
                     $pack_info->setItemGtin($pack_info_id_add->getItemGtin());
                     $pack_info->setPackagingLevel($pack_info_id_add->getPackagingLevel());
                     $pack_info->setModifiedBy($created_by);
                     $pack_info->setModifiedDate(App_Tools_Time::now());
                     $pack_info->setCreatedBy($created_by);
                     $pack_info->setCreatedDate(App_Tools_Time::now());
                     $this->_em->persist($pack_info);
                     $this->_em->flush();
                     $stock_batch->setPackInfo($pack_info);
                 }
             }
         }
         $stock_batch->setModifiedBy($created_by);
         $stock_batch->setModifiedDate(App_Tools_Time::now());
         $stock_batch->setCreatedBy($created_by);
         $stock_batch->setCreatedDate(App_Tools_Time::now());
         $this->_em->persist($stock_batch);
         $this->_em->flush();
         $batchid = $stock_batch->getPkId();
         $stock_batch_warehouses = new StockBatchWarehouses();
         $stock_batch_warehouses->setQuantity(str_replace(",", "", $array['quantity']));
         $stock_batch_warehouses->setStatus(self::STACKED);
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
         $stock_batch_warehouses->setWarehouse($warehouse_id);
         $stock_batch_id = $this->_em->getRepository('StockBatch')->find($batchid);
         $stock_batch_warehouses->setStockBatch($stock_batch_id);
         $stock_batch_warehouses->setModifiedBy($created_by);
         $stock_batch_warehouses->setModifiedDate(App_Tools_Time::now());
         $stock_batch_warehouses->setCreatedBy($created_by);
         $stock_batch_warehouses->setCreatedDate(App_Tools_Time::now());
         $this->_em->persist($stock_batch_warehouses);
         $this->_em->flush();
         $stockBatchWarehousId = $stock_batch_warehouses->getPkId();
         if ($stockBatchWarehousId) {
             return $stockBatchWarehousId;
         } else {
             return false;
         }
     } else {
         return $batchid;
     }
 }
Example #5
0
 public function createBatch($array)
 {
     $batchid = $this->checkBatch($array);
     if ($batchid === 0) {
         $wh_id = $this->_identity->getWarehouseId();
         $stock_batch = new StockBatch();
         $stock_batch->setNumber(strtoupper($array['number']));
         $stock_batch->setExpiryDate(new \DateTime(App_Controller_Functions::dateToDbFormat($array['expiry_date'])));
         $item_id = $this->_em->getRepository('ItemPackSizes')->find($array['item_id']);
         $stock_batch->setItemPackSize($item_id);
         $stock_batch->setQuantity(str_replace(",", "", $array['quantity']));
         $stock_batch->setStatus(self::STACKED);
         if (!empty($array['production_date'])) {
             $stock_batch->setProductionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($array['production_date'])));
         }
         if (!empty($array['vvm_type_id'])) {
             $vvm_type_id = $this->_em->getRepository('VvmTypes')->find($array['vvm_type_id']);
             $stock_batch->setVvmType($vvm_type_id);
         }
         $stock_batch->setUnitPrice($array['unit_price']);
         $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
         $stock_batch->setWarehouse($warehouse_id);
         if (!empty($array['manufacturer_id'])) {
             $stakeholder_item_pack_size = $this->_em->getRepository('StakeholderItemPackSizes')->find($array['manufacturer_id']);
             if ($stakeholder_item_pack_size->getItemPackSize()->getPkId() == $array['item_id']) {
                 $stock_batch->setStakeholderItemPackSize($stakeholder_item_pack_size);
             } else {
                 $check_sips = $this->_em->getRepository('StakeholderItemPackSizes')->findOneBy(array("stakeholder" => $stakeholder_item_pack_size->getStakeholder()->getPkId(), "itemPackSize" => $array['item_id']));
                 if (count($check_sips) > 0) {
                     $stock_batch->setStakeholderItemPackSize($check_sips);
                 } else {
                     $add_sips = new StakeholderItemPackSizes();
                     $add_sips->setQuantityPerPack($stakeholder_item_pack_size->getQuantityPerPack());
                     $add_sips->setStatus($stakeholder_item_pack_size->getStatus());
                     $add_sips->setListRank($stakeholder_item_pack_size->getListRank());
                     $add_sips->setVolumPerVial($stakeholder_item_pack_size->getVolumPerVial());
                     $add_sips->setGtin($stakeholder_item_pack_size->getGtin());
                     $add_sips->setItemGtin($stakeholder_item_pack_size->getItemGtin());
                     $add_sips->setPackagingLevel($stakeholder_item_pack_size->getPackagingLevel());
                     $add_sips->setStakeholder($stakeholder_item_pack_size->getStakeholder());
                     $add_sips->setItemPackSize($item_id);
                     $this->_em->persist($add_sips);
                     $this->_em->flush();
                     $stock_batch->setStakeholderItemPackSize($add_sips);
                 }
             }
         }
         $this->_em->persist($stock_batch);
         $this->_em->flush();
         $batchid = $stock_batch->getPkId();
         if ($wh_id == Model_Warehouses::FEDERAL_WHID) {
             $stock_batch->setBatchMasterId($batchid);
             $this->_em->persist($stock_batch);
             $this->_em->flush();
         }
         if ($batchid) {
             return $batchid;
         } else {
             return false;
         }
     } else {
         return $batchid;
     }
 }
 public function getPackInfo()
 {
     $this->__load();
     return parent::getPackInfo();
 }