public function ajaxUpdatePhysicalCurrentQuantityAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $wh_id = $this->_identity->getWarehouseId();
     $data = explode("|", substr($this->_request->data, 0, -1));
     $count = count($data);
     $physical_quantity = 0;
     $current_quantity = 0;
     $em = Zend_Registry::get('doctrine');
     $em->getConnection()->beginTransaction();
     try {
         for ($i = 0; $i < $count; $i++) {
             $flag = 0;
             $placement_physical_summary = $this->_em->getRepository("PhysicalStockTakingDetail")->find($data[$i]);
             if ($placement_physical_summary->getStockBatch() != "") {
                 //$physical_quantity = $placement_physical_summary->getQuantity();
                 $current_quantity = $placement_physical_summary->getStockBatch()->getQuantity();
                 $batch_id = $placement_physical_summary->getStockBatch()->getPkId();
                 $stk_master = new Model_StockMaster();
                 $physical_quantity = $stk_master->getPhysicalBatchQuantity($batch_id);
                 /* $already_exists = $this->_em->getRepository("PhysicalStockTakingDetail")->findBy(array("stockBatch" => $batch_id, "warehouse" => $this->_identity->getWarehouseId()));
                    if (count($already_exists) > 0) {
                    foreach ($already_exists as $physical_stk) {
                    if ($physical_stk->getPkId() != $placement_physical_summary->getPkId()) {
                    $physical_quantity = $physical_quantity + $physical_stk->getQuantity();
                    }
                    }
                    } */
                 if ($current_quantity > $physical_quantity) {
                     $quantity = $current_quantity - $physical_quantity;
                     $type = 13;
                     $placement_physical_summary->setCurrentQuantity($current_quantity);
                     $this->_em->persist($placement_physical_summary);
                     $this->_em->flush();
                 } else {
                     if ($current_quantity < $physical_quantity) {
                         $quantity = $physical_quantity - $current_quantity;
                         $type = 12;
                         $placement_physical_summary->setCurrentQuantity($current_quantity);
                         $this->_em->persist($placement_physical_summary);
                         $this->_em->flush();
                     } else {
                         if ($current_quantity == $physical_quantity) {
                             $flag = 1;
                             $stock_detail = null;
                         }
                     }
                 }
             } else {
                 $stock_batch_model = new Model_StockBatch();
                 $batch_number = $placement_physical_summary->getBatchNumber();
                 $item_pack_size_id = $placement_physical_summary->getItemPackSize()->getPkId();
                 //$production_date = ($placement_physical_summary->getProductionDate() != null) ? $placement_physical_summary->getProductionDate()->format("d/m/Y") : '';
                 $expiry_date = $placement_physical_summary->getExpiryDate()->format("d/m/Y");
                 $vvm_type_id = 2;
                 //$manufacturer_id = $this->_em->getRepository("StakeholderItemPackSizes")->findBy(array('itemPackSize' => $placement_physical_summary->getItemPackSize()->getPkId()));
                 $array = array('number' => $batch_number, 'quantity' => $placement_physical_summary->getQuantity(), 'item_id' => $item_pack_size_id, 'production_date' => '', 'expiry_date' => $expiry_date, 'unit_price' => '0', 'vvm_type_id' => $vvm_type_id, 'manufacturer_id' => $placement_physical_summary->getStakeholderItemPackSize());
                 $batch_id = $stock_batch_model->createBatch($array);
                 $type = 12;
                 $quantity = 0;
                 $multi_batches = $this->_em->getRepository("PhysicalStockTakingDetail")->findBy(array("batchNumber" => $batch_number, "warehouse" => $this->_identity->getWarehouseId(), "physicalStockTaking" => Model_PhysicalStockTakingDetail::STOCKID));
                 if (count($multi_batches) > 0) {
                     foreach ($multi_batches as $add_batch_id) {
                         $add_batch_id->setCurrentQuantity($current_quantity);
                         $ba_id01 = $this->_em->getRepository('StockBatch')->find($batch_id);
                         $add_batch_id->setStockBatch($ba_id01);
                         $this->_em->persist($add_batch_id);
                         $this->_em->flush();
                         $quantity += $add_batch_id->getQuantity();
                     }
                 }
             }
             if ($flag == 0) {
                 $tranaction_type = new Model_TransactionTypes();
                 $type_nature = $tranaction_type->findById($type);
                 $stock_batch_vvm = new StockBatchVvm();
                 $stock_batch_vvm->setQuantity($type_nature['0']['nature'] . $quantity);
                 $stock_batch_vvm->setVvmStage($placement_physical_summary->getVvmStage());
                 $ba_id1 = $this->_em->getRepository('StockBatch')->find($batch_id);
                 $stock_batch_vvm->setStockBatch($ba_id1);
                 $this->_em->persist($stock_batch_vvm);
                 $this->_em->flush();
                 $stock_batch_vvm_id = $stock_batch_vvm->getPkId();
                 $stock_batch_vvm_history = new StockBatchVvmHistory();
                 $stock_batch_vvm_ID = $this->_em->getRepository('StockBatchVvm')->find($stock_batch_vvm_id);
                 $stock_batch_vvm_history->setStockBatchVvm($stock_batch_vvm_ID);
                 $stock_batch_vvm_history->setQuantity($type_nature['0']['nature'] . $quantity);
                 $stock_batch_vvm_history->setVvmStage($placement_physical_summary->getVvmStage());
                 $ba_id2 = $this->_em->getRepository('StockBatch')->find($batch_id);
                 $stock_batch_vvm_history->setStockBatch($ba_id2);
                 $this->_em->persist($stock_batch_vvm_history);
                 $this->_em->flush();
                 $stock_master = new StockMaster();
                 $stock_master->setTransactionDate(new \DateTime(date('Y-m-d')));
                 $tran_type = $this->_em->getRepository('TransactionTypes')->find($type);
                 $stock_master->setTransactionType($tran_type);
                 $warehouse_id = $this->_em->getRepository('Warehouses')->find($wh_id);
                 $stock_master->setFromWarehouse($warehouse_id);
                 $stock_master->setToWarehouse($warehouse_id);
                 $created_by = $this->_em->getRepository('Users')->find($this->_userid);
                 $stock_master->setCreatedBy($created_by);
                 $stock_master->setCreatedDate(new \DateTime(date("Y-m-d")));
                 $adjustment_date = date('d/m/Y');
                 $sm = new Model_StockMaster();
                 $trans = $sm->getTransactionNumber($type, $adjustment_date);
                 $stock_master->setTransactionNumber($trans['trans_no']);
                 $stock_master->setDraft(0);
                 $stock_master->setTransactionCounter($trans['id']);
                 $stock_master->setParentId(0);
                 $this->_em->persist($stock_master);
                 $this->_em->flush();
                 $stock_detail = new StockDetail();
                 $stock_detail->setStockMaster($stock_master);
                 $b_id = $this->_em->getRepository('StockBatch')->find($batch_id);
                 $stock_detail->setStockBatch($b_id);
                 $stock_detail->setQuantity($type_nature[0]['nature'] . $quantity);
                 $stock_detail->setAdjustmentType($type);
                 $stock_detail->setVvmStage($placement_physical_summary->getVvmStage());
                 $stock_detail->setTemporary(0);
                 $stock_detail->setItemUnit($placement_physical_summary->getItemPackSize()->getItemUnit());
                 $this->_em->persist($stock_detail);
                 $this->_em->flush();
                 $stock_ID = $stock_master->getPkId();
                 $stock_batch = new Model_StockBatch();
                 $warehouse_data = new Model_WarehousesData();
                 $stock_batch->adjustQuantityBywarehouse($batch_id);
                 $warehouse_data->addReport($stock_ID, $type);
                 $placement_physical_summary->setStockMaster($stock_master);
                 $this->_em->persist($placement_physical_summary);
                 $this->_em->flush();
             }
             $already_exists = $this->_em->getRepository("PhysicalStockTakingDetail")->findBy(array("stockBatch" => $batch_id, "warehouse" => $this->_identity->getWarehouseId(), "physicalStockTaking" => Model_PhysicalStockTakingDetail::STOCKID));
             if (count($already_exists) > 0) {
                 foreach ($already_exists as $physical_stk) {
                     if ($physical_stk->getPlacementLocation() != null && $physical_stk->getQuantity() > 0) {
                         $placement = new Placements();
                         $placement->setQuantity($physical_stk->getQuantity());
                         $placement->setPlacementLocation($physical_stk->getPlacementLocation());
                         $placement->setStockBatch($physical_stk->getStockBatch());
                         if ($stock_detail != null) {
                             $placement->setStockDetail($stock_detail);
                         }
                         $type_id = $this->_em->getRepository("ListDetail")->find(114);
                         $placement->setPlacementTransactionType($type_id);
                         $created_by = $this->_em->getRepository("Users")->find($this->_userid);
                         $placement->setCreatedBy($created_by);
                         $placement->setIsPlaced(1);
                         $placement->setCreatedDate(new \DateTime(date("Y-m-d")));
                         $vvm = $physical_stk->getVvmStage();
                         $placement->setVvmStage($vvm);
                         $this->_em->persist($placement);
                         $this->_em->flush();
                     }
                 }
             }
         }
         $em->getConnection()->commit();
         echo 1;
     } catch (Exception $e) {
         $em->getConnection()->rollback();
         $em->close();
         echo 0;
     }
 }
 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());
 }
Example #3
0
 public function updateStockPlacement($data, $placement_type)
 {
     // batch_id|placement_loc_id|vvm_stage_id|qty, batch_id|placement_loc_id|vvm_stage_id|qty,batch_id|placement_loc_id|vvm_stage_id|qty
     $placement_info = explode(",", $data);
     App_Controller_Functions::pr($data);
     // Get each placement batch, location,vvm stage and qty.
     foreach ($placement_info as $info) {
         $ids = explode("|", $info);
         // batch_id|placement_loc_id|vvm_stage_id|qty
         // get stock batch
         $stock_batch = $this->_em->getRepository("StockBatchWarehouses")->find($ids['0']);
         // get placement location
         $placement_location = $this->_em->getRepository("PlacementLocations")->find($ids['1']);
         // Get transaction type i.e stock picking.
         $plc_transaction_type = $this->_em->find("ListDetail", $placement_type);
         // Get user id.
         $user_id = $this->_em->find("Users", $this->_user_id);
         $placement = new Placements();
         $placement->setPlacementLocation($placement_location);
         $placement->setStockBatchWarehouse($stock_batch);
         $placement->setPlacementTransactionType($plc_transaction_type);
         $placement->setCreatedBy($user_id);
         $placement->setCreatedDate(App_Tools_Time::now());
         $placement->setModifiedBy($user_id);
         $placement->setModifiedDate(App_Tools_Time::now());
         $vvms = $this->_em->getRepository("VvmStages")->find($ids['2']);
         $placement->setVvmStage($vvms);
         // get qty
         if ($placement_type == Model_PlacementLocations::PLACEMENT_TRANSACTION_TYPE_P) {
             $qty = $ids['3'];
         } elseif ($placement_type == Model_PlacementLocations::PLACEMENT_TRANSACTION_TYPE_PICK) {
             $qty = -1 * $ids['3'];
         }
         $placement->setQuantity($qty);
         $this->_em->persist($placement);
     }
     $this->_em->flush();
     return true;
 }
Example #4
0
 public function addIssuePlacement()
 {
     $data = $this->form_values;
     $qty = $data['quantity'];
     $placement = new Placements();
     $placement->setQuantity($qty);
     $placement_loc_id = $this->_em->getRepository("PlacementLocations")->find($data['placement_loc_id']);
     $placement->setPlacementLocation($placement_loc_id);
     $batch_id = $this->_em->getRepository("StockBatch")->find($data['batch_id']);
     $placement->setStockBatch($batch_id);
     if ($data['detail_id'] != 0) {
         $detail_id = $this->_em->getRepository("StockDetail")->find($data['detail_id']);
         $placement->setStockDetail($detail_id);
     }
     $type_id = $this->_em->getRepository("ListDetail")->find($data['placement_loc_type_id']);
     $placement->setPlacementTransactionType($type_id);
     $created_by = $this->_em->getRepository("Users")->find($data['user_id']);
     $placement->setCreatedBy($created_by);
     $placement->setCreatedDate(new \DateTime($data['created_date']));
     $vvms = $this->_em->getRepository("VvmStages")->find($data['vvmstage']);
     $placement->setVvmStage($vvms);
     $placement->setIsPlaced($data['is_placed']);
     $this->_em->persist($placement);
     $this->_em->flush();
     return $placement->getPkId();
 }
 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;
 }