コード例 #1
0
 public function addStockWarehouseViaScanner()
 {
     $data = $this->form_values;
     $stock_id = $data['stockid'];
     $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
     $stocks = $this->_em->getRepository("StockDetail")->find($stock_id[0]);
     $stock_master = new StockMaster();
     $time_arr = explode(' ', $data['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(Model_TransactionTypes::TRANSACTION_RECIEVE);
     $stock_master->setTransactionType($tran_type);
     $stock_master->setTransactionReference($data['rec_ref']);
     $stock_master->setFromWarehouse($stocks->getStockMaster()->getFromWarehouse());
     $stock_master->setToWarehouse($stocks->getStockMaster()->getToWarehouse());
     $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($data['remarks']);
     $trans_no = $this->getTransactionNumber(1, $data['rec_date']);
     $stock_master->setTransactionNumber($trans_no['trans_no']);
     $stock_master->setDraft(0);
     $stock_master->setTransactionCounter($trans_no['id']);
     $stock_master->setParentId(0);
     $this->_em->persist($stock_master);
     $this->_em->flush();
     foreach ($stock_id as $index => $detail_id) {
         $stock_detail = $this->_em->getRepository("StockDetail")->find($detail_id);
         $received_location = $this->_em->getRepository("StockReceiveFromScanner")->findBy(array("stockDetail" => $detail_id));
         $obj_stock_batch = new Model_StockBatch();
         $array = array('number' => $stock_detail->getStockBatch()->getNumber(), 'item_id' => $stock_detail->getStockBatchWarehouse()->getStockBatch()->getPackInfo()->getStakeholderItemPackSize()->getItemPackSize()->getPkId());
         $batch_id = $obj_stock_batch->checkBatch($array);
         if ($batch_id === 0) {
             $stock_batch = new StockBatch();
             $stock_batch->setNumber(strtoupper($stock_detail->getStockBatch()->getNumber()));
             $stock_batch->setBatchMasterId($stock_detail->getStockBatch()->getBatchMasterId());
             $stock_batch->setExpiryDate($stock_detail->getStockBatch()->getExpiryDate());
             $stock_batch->setQuantity(ABS($stock_detail->getQuantity()));
             $stock_batch->setItemPackSize($stock_detail->getStockBatchWarehouse()->getStockBatch()->getPackInfo()->getStakeholderItemPackSize()->getItemPackSize());
             $stock_batch->setStatus('Stacked');
             $stock_batch->setUnitPrice($stock_detail->getStockBatch()->getUnitPrice());
             $stock_batch->setProductionDate($stock_detail->getStockBatch()->getProductionDate());
             $stock_batch->setVvmType($stock_detail->getStockBatch()->getVvmType());
             $stock_batch->setWarehouse($stock_detail->getStockMaster()->getToWarehouse());
             if ($stock_detail->getStockBatch()->getStakeholderItemPackSize() != null) {
                 $stock_batch->setStakeholderItemPackSize($stock_detail->getStockBatch()->getStakeholderItemPackSize());
             }
             $stock_batch->setCreatedBy($created_by);
             $stock_batch->setModifiedBy($created_by);
             $stock_batch->setCreatedDate(App_Tools_Time::now());
             $stock_batch->setModifiedDate(App_Tools_Time::now());
             $this->_em->persist($stock_batch);
             $this->_em->flush();
             $batch_id = $stock_batch->getPkId();
         }
         if (count($received_location) > 0) {
             foreach ($received_location as $placement) {
                 $stk_detail = new StockDetail();
                 $stk_detail->setStockMaster($stock_master);
                 $sb_id = $this->_em->getRepository('StockBatch')->find($batch_id);
                 $stk_detail->setStockBatch($sb_id);
                 $stk_detail->setItemUnit($stock_detail->getItemUnit());
                 $stk_detail->setQuantity(ABS($placement->getQuantity()));
                 $stk_detail->setTemporary(0);
                 $stk_detail->setVvmStage($placement->getVvmStage());
                 $stk_detail->setIsReceived($stock_detail->getPkId());
                 $stk_detail->setAdjustmentType(1);
                 $stk_detail->setCreatedBy($created_by);
                 $stk_detail->setModifiedBy($created_by);
                 $stk_detail->setCreatedDate(App_Tools_Time::now());
                 $stk_detail->setModifiedDate(App_Tools_Time::now());
                 $this->_em->persist($stk_detail);
                 $this->_em->flush();
                 /*
                  * Add entry in Placement table
                  */
                 $placements = new Placements();
                 $placements->setQuantity($placement->getQuantity());
                 $placements->setVvmStage($placement->getVvmStage());
                 $placements->setIsPlaced(1);
                 $placements->setPlacementLocation($placement->getPlacementLocation());
                 $placements->setStockBatch($sb_id);
                 //                    $placements->setStockDetail($stk_detail);
                 $trans_type = $this->_em->getRepository("ListDetail")->find(Model_ListDetail::STOCK_PLACEMENT);
                 $placements->setPlacementTransactionType($trans_type);
                 $placements->setCreatedBy($stk_detail->getStockMaster()->getCreatedBy());
                 $placements->setCreatedDate(App_Tools_Time::now());
                 $stock_master->setModifiedBy($created_by);
                 $stock_master->setModifiedDate(App_Tools_Time::now());
                 $this->_em->persist($placements);
                 $this->_em->flush();
             }
         } else {
             $stk_detail = new StockDetail();
             $stk_detail->setStockMaster($stock_master);
             $sb_id = $this->_em->getRepository('StockBatch')->find($batch_id);
             $stk_detail->setStockBatch($sb_id);
             $stk_detail->setItemUnit($stock_detail->getItemUnit());
             $stk_detail->setQuantity(ABS($stock_detail->getQuantity()));
             $stk_detail->setTemporary(0);
             $stk_detail->setVvmStage($stock_detail->getVvmStage());
             $stk_detail->setIsReceived($stock_detail->getPkId());
             $stk_detail->setAdjustmentType(1);
             $stk_detail->setModifiedBy($created_by);
             $stk_detail->setModifiedDate(App_Tools_Time::now());
             $stk_detail->setCreatedBy($created_by);
             $stk_detail->setCreatedDate(App_Tools_Time::now());
             $this->_em->persist($stk_detail);
             $this->_em->flush();
         }
         $details[$index] = $stk_detail;
         $stock_detail->setModifiedBy($created_by);
         $stock_detail->setModifiedDate(App_Tools_Time::now());
         $stock_detail->setIsReceived(1);
         $this->_em->persist($stock_detail);
         $this->_em->flush();
     }
     $missing = $this->form_values['missing'];
     $type = $this->form_values['types'];
     $tranaction_type = new Model_TransactionTypes();
     $arr_types = $tranaction_type->getAll();
     $array_types = array();
     foreach ($arr_types as $arrtype) {
         $array_types[$arrtype['pkId']] = $arrtype['nature'];
     }
     $count = 1;
     foreach ($missing as $index => $adjustment) {
         if ($adjustment > 0) {
             if ($count == 1) {
                 $stock_master = new StockMaster();
                 $stock_master->setTransactionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($data['rec_date'])));
                 $tran_type1 = $this->_em->getRepository('TransactionTypes')->find($type[$index]);
                 $stock_master->setTransactionType($tran_type1);
                 $stock_master->setTransactionReference($data['rec_ref']);
                 $stock_master->setFromWarehouse($stock_detail->getStockMaster()->getToWarehouse());
                 $stock_master->setToWarehouse($stock_detail->getStockMaster()->getToWarehouse());
                 $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($data['remarks']);
                 $trans_no = $this->getTransactionNumber($type[$index], $data['rec_date']);
                 $stock_master->setTransactionNumber($trans_no['trans_no']);
                 $stock_master->setDraft(0);
                 $stock_master->setTransactionCounter($trans_no['id']);
                 $stock_master->setParentId($stock_detail->getStockMaster()->getPkId());
                 $this->_em->persist($stock_master);
                 $this->_em->flush();
             }
             $stock_detail_a = new StockDetail();
             $stock_detail_a->setStockMaster($stock_master);
             $stock_detail_a->setStockBatch($details[$index]->getStockBatch());
             $stock_detail_a->setItemUnit($stock_detail->getItemUnit());
             $stock_detail_a->setQuantity($array_types[$type[$index]] . $missing[$index]);
             $stock_detail_a->setAdjustmentType($type[$index]);
             $stock_detail_a->setTemporary(0);
             $stock_detail_a->setIsReceived($details[$index]->getPkId());
             $vvms = $this->_em->getRepository("VvmStages")->find(1);
             $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();
             $count++;
         }
     }
     foreach ($details as $obj_stock_detail) {
         $obj_stock_batch->adjustQuantityByWarehouse($obj_stock_detail->getStockBatch()->getPkId());
         $obj_stock_batch->autoRunningLEFOBatch($obj_stock_detail->getStockBatchWarehouse()->getStockBatch()->getPackInfo()->getStakeholderItemPackSize()->getItemPackSize()->getPkId());
     }
     $warehouse_data = new Model_HfDataMaster();
     $warehouse_data->addReport($details[0]->getStockMaster()->getPkId(), 1, 'wh');
     return true;
 }
コード例 #2
0
 public function setBatchMasterId($batchMasterId)
 {
     $this->__load();
     return parent::setBatchMasterId($batchMasterId);
 }
コード例 #3
0
 public function addStockWarehouseByIssue()
 {
     if (!empty($this->form_values['wh_id'])) {
         $wh_id = $this->form_values['wh_id'];
     } else {
         $wh_id = $this->_identity->getWarehouseId();
     }
     $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);
             $u_id = $this->_em->getRepository('Users')->find($this->_user_id);
             $stock_master->setCreatedBy($u_id);
             $stock_master->setCreatedDate(new \DateTime(date("Y-m-d")));
             $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->setBatchMasterId($stockBatch['0']['batchMasterId']);
                 $stock_batch->setExpiryDate(new \DateTime($stockBatch[0]['expiryDate']));
                 $stock_batch->setQuantity($quantity);
                 $ips_id = $this->_em->getRepository('ItemPackSizes')->find($product_id);
                 $stock_batch->setItemPackSize($ips_id);
                 $stock_batch->setStatus('Stacked');
                 $stock_batch->setUnitPrice($stockBatch['0']['unitPrice']);
                 $stock_batch->setProductionDate(new \DateTime($stockBatch[0]['productionDate']));
                 if (!empty($stockBatch[0]['vvmType'])) {
                     $vvm_id = $this->_em->getRepository('VvmTypes')->find($stockBatch[0]['vvmType']);
                     $stock_batch->setVvmType($vvm_id);
                 }
                 $wb_id = $this->_em->getRepository('Warehouses')->find($wh_id);
                 $stock_batch->setWarehouse($wb_id);
                 if (!empty($stockBatch['0']['stakeholderItemPackSize'])) {
                     $stk_ips = $this->_em->getRepository('StakeholderItemPackSizes')->find($stockBatch['0']['stakeholderItemPackSize']);
                     $stock_batch->setStakeholderItemPackSize($stk_ips);
                 }
                 $this->_em->persist($stock_batch);
                 $this->_em->flush();
                 $batch_id1 = $stock_batch->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('StockBatch')->find($batch_id1);
             $stock_detail->setStockBatch($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);
             $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);
                     $u_id = $this->_em->getRepository('Users')->find($this->_user_id);
                     $stock_master->setCreatedBy($u_id);
                     $stock_master->setCreatedDate(new \DateTime(date("Y-m-d")));
                     $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('StockBatch')->find($batch_id1);
                 $stock_detail_a->setStockBatch($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);
                 $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_WarehousesData();
     $warehouse_data->addReport($stock_id, 1, 'wh');
     return true;
 }