Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public function multipleAdjustmentAction()
 {
     $stock_master = new Model_StockMaster();
     $stock_batch = new Model_StockBatch();
     $stock_detail = new Model_StockDetail();
     $warehouse_data = new Model_HfDataMaster();
     $form = new Form_MultipleAdjustment();
     $form_values = array();
     $temp = array();
     $arr_data = array('transaction_number' => "", 'stock_id' => "", 'transaction_date' => date("d/m/Y"), 'warehouse_name' => "", 'success' => $this->_request->success);
     $form_values['transaction_type_id'] = 2;
     $form_values['adjustment_type'] = 2;
     $stock_id = "";
     $master_id = "";
     if (!empty($this->_request->hdn_stock_id)) {
         $stock_id = $this->_request->hdn_stock_id;
     }
     if (!empty($this->_request->hdn_master_id)) {
         $master_id = $this->_request->hdn_master_id;
     }
     if (!empty($this->_request->warehouse)) {
         $warehouse_id = $this->_request->warehouse;
     }
     if ($this->_request->isPost()) {
         $created_by = $this->_em->find('Users', $this->_user_id);
         if (!empty($master_id)) {
             $em = Zend_Registry::get('doctrine');
             $em->getConnection()->beginTransaction();
             try {
                 //Start update issue period
                 $array = $this->_request->getParams();
                 $stock_master->updateStockPeriod($master_id, $array);
                 //End update issue period
                 $transaction_number = $stock_master->updateStockMasterTemp($master_id, $this->_request->comments);
                 $stock_detail->updateStockDetailTemp($master_id);
                 //Save Data in warehouse_data table
                 $warehouse_data->addReport($master_id, 2);
                 /*
                  * Auto Receive for 6th level
                  * $stock_master->autoReceiveData($master_id);
                  */
                 $this->view->msg = 'Stock has been issued successfully. Your voucher number is ';
                 $this->view->voucher = $transaction_number;
                 $this->view->master_id = $master_id;
                 $em->getConnection()->commit();
             } catch (Exception $e) {
                 $em->getConnection()->rollback();
                 $em->close();
                 App_FileLogger::info($e);
             }
         } elseif ($form->isValid($this->_request->getPost())) {
             $em = Zend_Registry::get('doctrine');
             $em->getConnection()->beginTransaction();
             try {
                 $editissue = $this->_request->getPost('issueedit');
                 if ($editissue == "Yes") {
                     $d_id = $this->_request->getPost('detailid');
                     $obj_stock_detail = $em->getRepository("StockDetail")->find($d_id);
                     $old_batch_id = $obj_stock_detail->getStockBatch()->getPkId();
                     $data = $form->getValues();
                     $obj_stock_master = $obj_stock_detail->getStockMaster();
                     $master_update = false;
                     $arr_date = explode("/", $data['transaction_date']);
                     if (intval($arr_date[1]) . "-" . intval($arr_date[2]) != intval($obj_stock_detail->getStockMaster()->getTransactionDate()->format("m")) . "-" . intval($obj_stock_detail->getStockMaster()->getTransactionDate()->format("Y"))) {
                         $trans = $stock_master->getTransactionNumber(2, $data['transaction_date']);
                         $obj_stock_master->setTransactionNumber($trans['trans_no']);
                         $obj_stock_master->setTransactionCounter($trans['id']);
                         $master_update = true;
                     }
                     $obj_stock_master->setTransactionDate(new \DateTime(App_Controller_Functions::dateToDbFormat($data['transaction_date'])));
                     if (!empty($warehouse_id)) {
                         $to_wh = $em->getRepository("Warehouses")->find($warehouse_id);
                         $obj_stock_master->setToWarehouse($to_wh);
                         $master_update = true;
                     }
                     if ($master_update) {
                         $obj_stock_master->setModifiedBy($created_by);
                         $obj_stock_master->setModifiedDate(App_Tools_Time::now());
                         $em->persist($obj_stock_master);
                         $em->flush();
                     }
                     $qunty = str_replace(",", "", $data['quantity']);
                     $obj_stock_detail->setQuantity("-" . $qunty);
                     $vvms = $this->_em->getRepository("VvmStages")->find($data['vvm_stage']);
                     $obj_stock_detail->setVvmStage($vvms);
                     $stock_b = $em->getRepository("StockBatch")->find($data['number']);
                     $obj_stock_detail->setStockBatch($stock_b);
                     if (!empty($data['item_unit_id'])) {
                         $item_unit = $em->getRepository("ItemUnits")->find($data['item_unit_id']);
                         $obj_stock_detail->setItemUnit($item_unit);
                     }
                     $obj_stock_detail->setModifiedBy($created_by);
                     $obj_stock_detail->setModifiedDate(App_Tools_Time::now());
                     $em->persist($obj_stock_detail);
                     $em->flush();
                     list($dd, $mm, $yy) = explode("/", $data['transaction_date']);
                     $item_id = $data['item_id'];
                     $wh_id = $this->_identity->getWarehouseId();
                     $user_id = $this->_userid;
                     $query = "SELECT AdjustQty(" . $data['number'] . "," . $wh_id . ") FROM DUAL";
                     $str_sql = $em->getConnection()->prepare($query);
                     $str_sql->execute();
                     $query = "SELECT AdjustQty(" . $old_batch_id . "," . $wh_id . ") FROM DUAL";
                     $str_sql = $em->getConnection()->prepare($query);
                     $str_sql->execute();
                     $query = "SELECT REPUpdateData({$mm},{$yy},{$item_id},{$wh_id},{$user_id}) FROM DUAL";
                     $str_sql = $em->getConnection()->prepare($query);
                     $str_sql->execute();
                 } else {
                     $temp = $form->getValues();
                     $data = array_merge($temp, $form_values);
                     $data['warehouse'] = $warehouse_id;
                     if (empty($this->_request->transaction_number)) {
                         $stock_id = $stock_master->addStockMaster($data);
                     }
                     if (isset($data['quantity']) && !empty($data['quantity'])) {
                         $qty = str_replace(",", "", $data['quantity']);
                     }
                     if (isset($data['available_quantity']) && !empty($data['available_quantity'])) {
                         $ava_qty = str_replace(",", "", $data['available_quantity']);
                     }
                     if ((int) $qty > (int) $ava_qty || (int) $qty == (int) $ava_qty) {
                         $data['quantity'] = $ava_qty;
                         $autorun = true;
                     }
                     list($batch_id, $priority) = explode("|", $this->_request->number);
                     $form_values['item_unit_id'] = $this->_request->item_unit_id;
                     $form_values['stock_master_id'] = $stock_id;
                     $form_values['stock_batch_id'] = $batch_id;
                     $data = array_merge($temp, $form_values);
                     $detail_id = $stock_detail->addStockDetail($data);
                     $stock_batch->adjustQuantityByWarehouse($batch_id);
                     if ($autorun == true) {
                         $stock_batch->autoRunningLEFOBatch($form->getValue('item_id'));
                         $stock_batch->form_values['pk_id'] = $batch_id;
                         $stock_batch->form_values['status'] = Model_StockBatch::FINISHED;
                         $stock_batch->changeStatus();
                     }
                     /* $placement = new Model_Placements();
                        $placement->form_values['stock_batch_id'] = $batch_id;
                        $placement->form_values['quantity'] = $data['quantity'];
                        $placement->form_values['placement_location_id'] = $data['pick_from'];
                        $placement->form_values['stock_detail_id'] = $detail_id;
                        $placement->addPlacement(); */
                 }
                 $em->getConnection()->commit();
                 $this->redirect("/stock/multiple-adjustment");
                 // For Data Show
                 $temp_stock_list = $stock_master->getTempStocksList();
                 if ($temp_stock_list != false) {
                     //  $form->transaction_number->setValue($temp_stock_list[0]['transaction_number']);
                     $form->transaction_date->setValue(date("d/m/Y h:i A", strtotime($temp_stock_list[0]['transaction_date'])));
                     $form->warehouse_name->setValue($temp_stock_list[0]['to_warehouse']);
                     $form->transaction_reference->setValue($temp_stock_list[0]['transaction_reference']);
                     $form->hdn_to_warehouse_id->setValue($temp_stock_list[0]['to_warehouse_id']);
                     $form->product->setValue($temp_stock_list[0]['to_warehouse_id']);
                     $arr_data['warehouse_name'] = $temp_stock_list[0]['to_warehouse'];
                     // $arr_data['warehouse_name'] = $temp_stock_list[0]['to_warehouse'];
                     $form->activity_id->setValue($temp_stock_list[0]['activity_id']);
                     $arr_data['tempstocks'] = $temp_stock_list;
                     $form->makeFieldReadonly();
                 } else {
                     $form->transaction_date->setValue(date("d/m/Y h:i A"));
                 }
             } catch (Exception $e) {
                 $em->getConnection()->rollback();
                 $em->close();
                 App_FileLogger::info($e);
                 switch ($e->getMessage()) {
                     case 'PLCD_QTY_GREATER_THAN_ISSUE_QTY':
                         $this->view->status = false;
                         $this->view->msg = "Issue quantity should not greater than placed quantity!";
                         break;
                 }
             }
         }
         $this->view->form = $form;
         $this->view->arr_data = $arr_data;
         if ($this->_request->type == 's') {
             $this->redirect("/stock/issue-search");
         }
     }
     $stock_master->form_values = $form_values;
     $temp_stock = $stock_master->getTempStock();
     if ($temp_stock != false) {
         $arr_data = array_merge($arr_data, $temp_stock);
     }
     if (!empty($temp_stock['stock_id'])) {
         $form->hdn_stock_id->setValue($temp_stock['stock_id']);
         $form->hdn_master_id->setValue($temp_stock['stock_id']);
     } elseif (!empty($stockid)) {
         $form->hdn_stock_id->setValue($stock_id);
         $form->hdn_master_id->setValue($stock_id);
     }
     $this->view->form = $form;
     $base_url = Zend_Registry::get('baseurl');
     switch ($this->_user_level) {
         case 1:
         case 2:
         case 3:
             $this->view->menu_type = 1;
             $this->view->inlineScript()->appendFile($base_url . '/js/all_level_combos.js');
             break;
         case 4:
         case 5:
         case 6:
             $this->view->menu_type = 2;
             $this->view->inlineScript()->appendFile($base_url . '/js/level_combos.js');
             break;
     }
     // Edit Issue Start
     if (!empty($this->_request->id)) {
         $detail_id = $this->_request->id;
         $issue = $this->_em->getRepository("StockDetail")->find($detail_id);
         $form->transaction_number->setValue($issue->getStockMaster()->getTransactionNumber());
         $form->transaction_date->setValue($issue->getStockMaster()->getTransactionDate()->format("d/m/Y h:i A"));
         $form->warehouse_name->setValue($issue->getStockMaster()->getToWarehouse()->getWarehouseName());
         $form->transaction_reference->setValue($issue->getStockMaster()->getTransactionReference());
         //$form->activity_id->setValue($issue->getStockMaster()->getStakeholderActivity()->getPkId());
         $arr_data['warehouse_name'] = $issue->getStockMaster()->getToWarehouse()->getWarehouseName();
         $form->item_id->setValue($issue->getStockBatchWarehouse()->getStockBatch()->getPackInfo()->getStakeholderItemPackSize()->getItemPackSize()->getPkId());
         $form->fillBatchCombo($issue->getStockBatchWarehouse()->getStockBatch()->getPackInfo()->getStakeholderItemPackSize()->getItemPackSize()->getPkId());
         $form->number->setValue($issue->getStockBatch()->getPkId());
         $form->vvm_stage->setValue($issue->getVvmStage());
         $form->quantity->setValue($issue->getQuantity());
         $av_qty = $issue->getStockBatch()->getQuantity() + ABS($issue->getQuantity());
         $form->available_quantity->setValue($av_qty);
         $form->expiry_date->setValue($issue->getStockBatch()->getExpiryDate()->format("d/m/Y"));
         $this->view->issueedit = true;
         $this->view->detail_id = $this->_request->id;
     }
     // Edit Issue End
     $this->view->arr_data = $arr_data;
     $this->view->type = $this->_request->getParam("t", "issue");
     $this->view->wh_id = $this->_identity->getWarehouseId();
     $this->view->params = array("province" => $this->_identity->getProvinceId(), "district" => $this->_identity->getDistrictId());
     $this->view->role = $this->_identity->getRoleId();
 }