Пример #1
0
 function editLedgerTranscationDate()
 {
     $id = $this->form_values['id'];
     $date = $this->form_values['date'];
     $stockMaster = $this->_em->getRepository("StockMaster")->find($id);
     $previous_month = $stockMaster->getTransactionDate()->format("m");
     $previous_year = $stockMaster->getTransactionDate()->format("Y");
     if (count($stockMaster) > 0) {
         $trans_type = $stockMaster->getTransactionType()->getPkId();
         if ($trans_type == 1) {
             $wh_id = $stockMaster->getToWarehouse()->getPkId();
         } else {
             $wh_id = $stockMaster->getFromWarehouse()->getPkId();
         }
         $trans = $this->getTransactionNumber($trans_type, $date, $wh_id, $stockMaster->getPkId());
         $stockMaster->setTransactionDate(new DateTime(date(App_Controller_Functions::dateToDbFormat($date))));
         $stockMaster->setTransactionNumber($trans['trans_no']);
         $stockMaster->setTransactionCounter($trans['id']);
         $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
         $stockMaster->setModifiedBy($created_by);
         $stockMaster->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($stockMaster);
         $this->_em->flush();
         // REP Update data for updating warehouse_data table
         $wh_data = new Model_HfDataMaster();
         $stock_detail = $this->_em->getRepository("StockDetail")->findBy(array("stockMaster" => $id));
         if (count($stock_detail) > 0) {
             // For Updated Date
             foreach ($stock_detail as $row1) {
                 $wh_data->form_values = array('report_month' => $row1->getStockMaster()->getTransactionDate()->format("m"), 'report_year' => $row1->getStockMaster()->getTransactionDate()->format("Y"), 'item_id' => $row1->getStockBatchWarehouse()->getStockBatch()->getPackInfo()->getStakeholderItemPackSize()->getItemPackSize()->getPkId(), 'warehouse_id' => $wh_id, 'created_by' => $row1->getStockMaster()->getCreatedBy()->getPkId());
                 $wh_data->adjustStockReport();
             }
             // For Previous Date
             foreach ($stock_detail as $row2) {
                 $wh_data->form_values = array('report_month' => $previous_month, 'report_year' => $previous_year, 'item_id' => $row2->getStockBatchWarehouse()->getStockBatch()->getPackInfo()->getStakeholderItemPackSize()->getItemPackSize()->getPkId(), 'warehouse_id' => $wh_id, 'created_by' => $row2->getStockMaster()->getCreatedBy()->getPkId());
                 $wh_data->adjustStockReport();
             }
         }
     }
     return true;
 }
 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);
     $created_by = $this->_em->find('Users', $this->_user_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")));
         $stock_master->setModifiedBy($pipeline_consignments->getCreatedBy());
         $stock_master->setModifiedDate(App_Tools_Time::now());
         $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->setUnitPrice(0);
         $stock_batch->setProductionDate($pipeline_consignments->getProductionDate());
         $vvm_type = $this->_em->getRepository("VvmTypes")->find(2);
         $stock_batch->setVvmType($vvm_type);
         $stock_batch->setPackInfo($pipeline_consignments->getManufacturer());
         $stock_batch->setCreatedBy($pipeline_consignments->getCreatedBy());
         $stock_batch->setCreatedDate(App_Tools_Time::now());
         $stock_batch->setModifiedBy($pipeline_consignments->getCreatedBy());
         $stock_batch->setModifiedDate(App_Tools_Time::now());
         $this->_em->persist($stock_batch);
         $this->_em->flush();
         $stock_batch_warehouses = new StockBatchWarehouses();
         $stock_batch_warehouses->setQuantity($qty);
         $stock_batch_warehouses->setStatus('Stacked');
         $stock_batch_warehouses->setStockBatch($stock_batch);
         $stock_batch_warehouses->setWarehouse($pipeline_consignments->getToWarehouse());
         $this->_em->persist($stock_batch_warehouses);
         $this->_em->flush();
         $batch_id = $stock_batch_warehouses->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("StockBatchWarehouses")->find($batch_id);
     $stock_detail->setStockBatchWarehouse($stock_batch);
     $stock_detail->setItemUnit($pipeline_consignments->getItemPackSize()->getItemUnit());
     $stock_detail->setCreatedBy($pipeline_consignments->getCreatedBy());
     $stock_detail->setCreatedDate(App_Tools_Time::now());
     $stock_detail->setModifiedBy($pipeline_consignments->getCreatedBy());
     $stock_detail->setModifiedDate(App_Tools_Time::now());
     $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->setStockBatchWarehouse($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->setModifiedBy($pipeline_consignments->getCreatedBy());
             $placements->setCreatedDate(new DateTime(date("Y-m-d H:i:s")));
             $placements->setModifiedDate(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);
     $pipeline_consignments->setCreatedBy($created_by);
     $pipeline_consignments->setCreatedDate(App_Tools_Time::now());
     $pipeline_consignments->setModifiedBy($created_by);
     $pipeline_consignments->setModifiedDate(App_Tools_Time::now());
     $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_HfDataMaster();
     $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());
 }