Ejemplo n.º 1
0
 public static function getInstance()
 {
     if (self::$fileLogger === null) {
         self::$fileLogger = new self();
     }
     return self::$fileLogger;
 }
Ejemplo n.º 2
0
 public function errorAction()
 {
     $this->_helper->layout->setLayout('error');
     $errors = $this->_getParam('error_handler');
     if (!$errors || !$errors instanceof ArrayObject) {
         $this->view->message = 'You have reached the error page';
         return;
     }
     switch ($errors->type) {
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
             // 404 error -- controller or action not found
             $this->getResponse()->setHttpResponseCode(404);
             $priority = Zend_Log::NOTICE;
             $this->view->message = 'Page not found';
             break;
         default:
             // application error
             $this->getResponse()->setHttpResponseCode(500);
             $priority = Zend_Log::CRIT;
             $this->view->message = 'Application error';
             break;
     }
     // Log exception, if logger available
     if ($log = $this->getLog()) {
         $log->log($this->view->message . " : " . $errors->exception, $priority);
         $log->log('Request Parameters' . " : " . implode("/", array_reverse($errors->request->getParams())) . "\n", $priority);
     } else {
         App_FileLogger::info($this->view->message . " : " . $errors->exception);
     }
     // conditionally display exceptions
     if ($this->getInvokeArg('displayExceptions') == true) {
         $this->view->exception = $errors->exception;
     }
     $this->view->request = $errors->request;
 }
Ejemplo n.º 3
0
 public function multipleAdjustmentAction()
 {
     $stock_master = new Model_StockMaster();
     $stock_batch = new Model_StockBatch();
     $stock_detail = new Model_StockDetail();
     $warehouse_data = new Model_WarehousesData();
     $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()) {
         $em = Zend_Registry::get('doctrine');
         $em->getConnection()->beginTransaction();
         try {
             if (!empty($master_id)) {
                 //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();
             } elseif ($form->isValid($this->_request->getPost())) {
                 $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) {
                         $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);
                     }
                     $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->getStockBatch()->getItemPackSize()->getPkId());
         $form->fillBatchCombo($issue->getStockBatch()->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();
 }
 public function transferAssetAction()
 {
     $form_values = array();
     $temp = array();
     $arr_data = array('success' => $this->_request->success, 'tempassets' => '');
     $arr_coldchain_ids = $this->_request->hdn_coldchain_id;
     if (count($arr_coldchain_ids) > 0) {
         $cold_chain = new Model_ColdChain();
         //$em = Zend_Registry::get('doctrine');
         //$em->getConnection()->beginTransaction();
         try {
             foreach ($arr_coldchain_ids as $coldchain_id) {
                 $cold_chain->form_values['coldchain_id'] = $coldchain_id;
                 $str_quantity_issue = "quantity_issue_" . $coldchain_id;
                 $str_quantity_available = "quantity_available_" . $coldchain_id;
                 $str_transfer = "transfer_" . $coldchain_id;
                 $cold_chain->form_values['quantity_issue'] = $this->_request->{$str_quantity_issue};
                 $cold_chain->form_values['quantity_available'] = $this->_request->{$str_quantity_available};
                 $cold_chain->form_values['transfer'] = $this->_request->{$str_transfer};
                 $cold_chain->form_values['from_warehouse'] = $this->_request->warehouse;
                 $cold_chain->form_values['to_warehouse'] = $this->_request->warehouse2;
                 $cold_chain->transferColdChainAsset();
             }
             //$em->getConnection()->commit();
         } catch (Exception $e) {
             //$em->getConnection()->rollback();
             //$em->close();
             App_FileLogger::info($e);
         }
     } else {
     }
     $this->view->user_level = $this->_identity->getUserLevel($this->_userid);
     $this->view->arr_data = $arr_data;
     $base_url = Zend_Registry::get('baseurl');
     $this->view->inlineScript()->appendFile($base_url . '/js/all_level_combos.js');
     $this->view->inlineScript()->appendFile($base_url . '/js/all_level_combos2.js');
 }
Ejemplo n.º 5
0
 public function loginAction()
 {
     $this->_helper->layout->setLayout('doc');
     $referrer = $this->_getParam('referrer', '');
     $form = new Form_LoginDoc();
     $error = false;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             try {
                 if (!$this->_identity->login($form->login_id->getValue(), base64_encode($form->password->getValue()))) {
                     $error = true;
                     throw new Exception();
                 }
                 $role = $this->_identity->getRoleId();
                 if ($role == 32) {
                     parent::_redirect('/docs/project-doc');
                 }
                 //$this->_populateSession();
                 if (isset($referrer) && !empty($referrer)) {
                     parent::_redirect(base64_decode($referrer));
                 } else {
                     parent::_redirect('/dashboard/index');
                 }
             } catch (Exception $e) {
                 App_FileLogger::info($e);
                 $form->populate($formData);
                 $error = "Email Or Password is incorrect!";
             }
         } else {
             $form->populate($formData);
         }
     }
     $this->view->headTitle('Log In');
     $this->view->form = $form;
     $this->view->error = $error;
 }
Ejemplo n.º 6
0
 public function uploadTransactionsAction()
 {
     try {
         $data = array();
         $data['quantity'] = $this->_request->getParam('qty');
         $data['placement_loc_id'] = $this->_request->getParam('placement_loc_id');
         $data['placement_loc_type_id'] = $this->_request->getParam('placement_loc_type_id');
         $data['batch_id'] = $this->_request->getParam('batch_id');
         $data['detail_id'] = $this->_request->getParam('detail_id');
         $data['created_date'] = $this->_request->getParam('created_date');
         $data['user_id'] = $this->_request->getParam('user_id');
         $data['vvmstage'] = $this->_request->getParam('vvmstage');
         $placement = new Model_Placements();
         $placement->form_values = $data;
         $result[]['id'] = $placement->add();
     } catch (OptimisticLockException $e) {
         App_FileLogger::info($e);
         $result[]['message'] = "Failed";
     }
     echo Zend_Json::encode($result);
 }
 public function uploadReceiveConsignments()
 {
     $params = $this->form_values;
     $wh_id = $params['wh_id'];
     $rec_id = $params['rec_id'];
     $batch_no = $params['batch_no'];
     $qty = str_replace(",", "", $params['qty']);
     $voucher = $params['voucher'];
     $consignments_location = $this->_em->getRepository("PipelineConsignmentsPlacements")->findBy(array("pipelineConsignment" => $rec_id));
     if (count($consignments_location) > 0) {
         foreach ($consignments_location as $cl) {
             $location_id[] = $cl->getPlacementLocation()->getPkId();
         }
     }
     $str_qry = $this->_em->createQueryBuilder()->select("pc.masterId")->from("PipelineConsignments", "pc")->where("pc.voucherNumber = '" . $voucher . "'")->andWhere("pc.masterId > 0")->andWhere("pc.toWarehouse = " . $wh_id);
     $stock_master_id = $str_qry->getQuery()->getResult();
     if (count($stock_master_id) > 0) {
         $master_id = $stock_master_id[0]['masterId'];
     } else {
         $master_id = 0;
     }
     $pipeline_consignments = $this->_em->getRepository("PipelineConsignments")->find($rec_id);
     /**
      * Record must exists
      */
     if (count($pipeline_consignments) == 0) {
         $result_msg = array("message" => "Selected record id {$rec_id} does not exist in pipeline consignments. Please update your data.");
         App_FileLogger::info($result_msg['message']);
         return $result_msg;
     }
     /**
      * Check if we need to create new voucher or add detail entry in existing voucher
      * If 0 then New Voucher
      * If greater then 0 then Add in Existing voucher 
      */
     if ($master_id == 0) {
         $tr_date = date("d/m/Y");
         $obj_master = new Model_StockMaster();
         $trans = $obj_master->getTransactionNumber(1, $tr_date, $wh_id);
         $stock_master = new StockMaster();
         $stock_master->setTransactionDate(new DateTime());
         $stock_master->setTransactionNumber($trans['trans_no']);
         $stock_master->setTransactionCounter($trans['id']);
         $stock_master->setTransactionReference($pipeline_consignments->getReferenceNumber());
         $stock_master->setDraft(0);
         $stock_master->setComments($pipeline_consignments->getDescription());
         $type = $this->_em->getRepository("TransactionTypes")->find(1);
         $stock_master->setTransactionType($type);
         $stock_master->setFromWarehouse($pipeline_consignments->getFromWarehouse());
         $stock_master->setToWarehouse($pipeline_consignments->getToWarehouse());
         $stock_master->setParentId(0);
         $stock_master->setStakeholderActivity($pipeline_consignments->getStakeholderActivity());
         $stock_master->setCreatedBy($pipeline_consignments->getCreatedBy());
         $stock_master->setCreatedDate(new DateTime(date("Y-m-d H:i:s")));
         $this->_em->persist($stock_master);
         $this->_em->flush();
         $master_id = $stock_master->getPkId();
     }
     $array = array("item_id" => $pipeline_consignments->getItemPackSize()->getPkId(), "number" => $batch_no, "wh_id" => $pipeline_consignments->getToWarehouse()->getPkId());
     $batch_id = $this->checkBatch($array);
     /**
      * Check if Batch exists or not
      * If 0 then create new batch
      * If greater then 0 then add quantity in existing batch
      */
     if ($batch_id === 0) {
         $stock_batch = new StockBatch();
         $stock_batch->setNumber(strtoupper($batch_no));
         $stock_batch->setExpiryDate($pipeline_consignments->getExpiryDate());
         $stock_batch->setQuantity($qty);
         $stock_batch->setStatus('Stacked');
         $stock_batch->setUnitPrice(0);
         $stock_batch->setProductionDate($pipeline_consignments->getProductionDate());
         $stock_batch->setLastUpdate(new DateTime(date("Y-m-d")));
         $stock_batch->setItemPackSize($pipeline_consignments->getItemPackSize());
         $vvm_type = $this->_em->getRepository("VvmTypes")->find(2);
         $stock_batch->setVvmType($vvm_type);
         $stock_batch->setWarehouse($pipeline_consignments->getToWarehouse());
         $stock_batch->setStakeholderItemPackSize($pipeline_consignments->getManufacturer());
         $this->_em->persist($stock_batch);
         $this->_em->flush();
         $batch_id = $stock_batch->getPkId();
     }
     /*
      * Add Entry in stock detail against selected master voucher
      */
     $stock_detail = new StockDetail();
     $stock_detail->setQuantity($qty);
     $stock_detail->setTemporary(0);
     $vvms = $this->_em->getRepository("VvmStages")->find(1);
     $stock_detail->setVvmStage($vvms);
     $stock_detail->setIsReceived(1);
     $stock_detail->setAdjustmentType(1);
     $stock_master = $this->_em->getRepository("StockMaster")->find($master_id);
     $stock_detail->setStockMaster($stock_master);
     $stock_batch = $this->_em->getRepository("StockBatch")->find($batch_id);
     $stock_detail->setStockBatch($stock_batch);
     $stock_detail->setItemUnit($pipeline_consignments->getItemPackSize()->getItemUnit());
     $this->_em->persist($stock_detail);
     $this->_em->flush();
     if (count($location_id) > 0) {
         foreach ($location_id as $plac_id) {
             $plac_loc_id = $this->_em->getRepository("PlacementLocations")->find($plac_id);
             /*
              * Add entry in Placement table
              */
             $placements = new Placements();
             $placements->setQuantity($qty);
             $vvms = $this->_em->getRepository("VvmStages")->find(1);
             $placements->setVvmStage($vvms);
             $placements->setIsPlaced(1);
             $placements->setPlacementLocation($plac_loc_id);
             $placements->setStockBatch($stock_batch);
             $placements->setStockDetail($stock_detail);
             $trans_type = $this->_em->getRepository("ListDetail")->find(Model_ListDetail::STOCK_PLACEMENT);
             $placements->setPlacementTransactionType($trans_type);
             $placements->setCreatedBy($pipeline_consignments->getCreatedBy());
             $placements->setCreatedDate(new DateTime(date("Y-m-d H:i:s")));
             $this->_em->persist($placements);
             $this->_em->flush();
         }
     }
     /*
      * Update Received Qty in Future Arrivals table
      */
     //$update_qty = $pipeline_consignments->getReceivedQuantity() + $qty;
     //if ($update_qty <= $pipeline_consignments->getQuantity()) {
     $pipeline_consignments->setReceivedQuantity($qty);
     $pipeline_consignments->setMasterId($master_id);
     $this->_em->persist($pipeline_consignments);
     $this->_em->flush();
     //}
     /*
      * Adjust Batch Quantity By Warehouse
      */
     $this->adjustQuantityByWarehouse($batch_id, $pipeline_consignments->getToWarehouse()->getPkId());
     /*
      * Adjust Warehouse data for selected month and item
      */
     $warehouse_data = new Model_WarehousesData();
     $warehouse_data->form_values = array('report_month' => date("m"), 'report_year' => date("Y"), 'item_id' => $pipeline_consignments->getItemPackSize()->getPkId(), 'warehouse_id' => $pipeline_consignments->getToWarehouse()->getPkId(), 'created_by' => $pipeline_consignments->getCreatedBy()->getPkId());
     $warehouse_data->adjustStockReport();
     $stock_master = $this->_em->getRepository("StockMaster")->find($master_id);
     return "V" . base64_encode($stock_master->getTransactionNumber() . "|" . $stock_master->getPkId());
 }
 public function ajaxMergeStakeholderItemPackSizeIdAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $em = Zend_Registry::get('doctrine');
     $em->getConnection()->beginTransaction();
     try {
         $data = explode("|", substr($this->_request->data, 0, -1));
         $count = count($data);
         $merge_into = $this->_request->merge;
         for ($i = 0; $i < $count; $i++) {
             $sips[] = $this->_em->getRepository("StakeholderItemPackSizes")->find($data[$i]);
         }
         $stakeholder_merge = $this->_em->getRepository("StakeholderItemPackSizes")->find($merge_into);
         for ($i = 0; $i < $count; $i++) {
             $sips_id = $sips[$i]->getPkId();
             $stk_id = $sips[$i]->getStakeholder()->getPkId();
             $stock_batch = $this->_em->getRepository("StockBatch")->findBy(array("stakeholderItemPackSize" => $sips_id));
             if (count($stock_batch) > 0) {
                 foreach ($stock_batch as $sd) {
                     $sd->setStakeholderItemPackSize($stakeholder_merge);
                     $this->_em->persist($sd);
                 }
             }
             $geo_location = $this->_em->getRepository("GeoLocations")->findBy(array("stakeholder" => $stk_id));
             if (count($geo_location) > 0) {
                 foreach ($geo_location as $gl) {
                     $gl->setStakeholder($stakeholder_merge->getStakeholder());
                     $this->_em->persist($gl);
                 }
             }
             $pipeline_consignements = $this->_em->getRepository("PipelineConsignments")->findBy(array("manufacturer" => $sips_id));
             if (count($pipeline_consignements) > 0) {
                 foreach ($pipeline_consignements as $pc) {
                     $pc->setManufacturer($stakeholder_merge);
                     $this->_em->persist($pc);
                 }
             }
             $pipeline_consignements_draft = $this->_em->getRepository("PipelineConsignmentsDraft")->findBy(array("manufacturer" => $sips_id));
             if (count($pipeline_consignements_draft) > 0) {
                 foreach ($pipeline_consignements_draft as $pcd) {
                     $pcd->setManufacturer($stakeholder_merge);
                     $this->_em->persist($pcd);
                 }
             }
             $users = $this->_em->getRepository("Users")->findBy(array("stakeholder" => $stk_id));
             if (count($users) > 0) {
                 foreach ($users as $usr) {
                     $usr->setStakeholder($stakeholder_merge->getStakeholder());
                     $this->_em->persist($usr);
                 }
             }
             $warehouses = $this->_em->getRepository("Warehouses")->findBy(array("stakeholder" => $stk_id));
             if (count($warehouses) > 0) {
                 foreach ($warehouses as $wh) {
                     $wh->setStakeholder($stakeholder_merge->getStakeholder());
                     $this->_em->persist($wh);
                 }
             }
             if ($sips[$i]->getStakeholder()->getPkId() != $stakeholder_merge->getStakeholder()->getPkId()) {
                 $this->_em->remove($sips[$i]->getStakeholder());
             }
             if ($merge_into != $sips_id) {
                 $this->_em->remove($sips[$i]);
             }
             $stk_item_pack = $this->_em->getRepository("StakeholderItemPackSizes")->findBy(array("stakeholder" => $stk_id));
             if (count($stk_item_pack) > 0) {
                 foreach ($stk_item_pack as $stkips) {
                     $stkips->setStakeholder($stakeholder_merge->getStakeholder());
                     $this->_em->persist($stkips);
                 }
             }
             $this->_em->flush();
         }
         $em->getConnection()->commit();
         echo 1;
     } catch (Exception $e) {
         $em->getConnection()->rollback();
         $em->close();
         App_FileLogger::info($e);
         echo 0;
     }
 }
Ejemplo n.º 9
0
 /**
  *
  * @param integer $wh_id
  * @return array $arr_data
  * @uses Barcode API
  */
 public function uploadReceivedQuantityViaScanner()
 {
     $params = $this->form_values;
     $rec_id = $params['rec_id'];
     $qty = $params['qty'];
     $location_id = $params['location_id'];
     $is_update = $params['update'];
     $vvmstage = $params['vvmstage'];
     $auth = $params['auth'];
     $stock_detail = $this->_em->getRepository("StockDetail")->find($rec_id);
     /**
      * Record must exists
      */
     if (count($stock_detail) == 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;
     }
     if ($is_update) {
         $detail_placements = $this->_em->getRepository("StockReceiveFromScanner")->findBy(array("stockDetail" => $rec_id));
         if (count($detail_placements) > 0) {
             foreach ($detail_placements as $row) {
                 $this->_em->remove($row);
             }
             $this->_em->flush();
         }
     }
     $plac_loc_id = $this->_em->getRepository("PlacementLocations")->find($location_id);
     /*
      * Add entry in Placement table
      */
     $stock_receive = new StockReceiveFromScanner();
     // $stock_receive->setStockDetail($stock_detail);
     $stock_receive->setPlacementLocation($plac_loc_id);
     $stock_receive->setQuantity($qty);
     $vvms = $this->_em->getRepository("VvmStages")->find($vvmstage);
     $stock_receive->setVvmStage($vvms);
     // $created_by = $this->_em->getRepository('Users')->find($this->_user_id);
     //$created_by = $this->_em->getRepository("Users")->find("159");//(array('auth' => $auth));
     $created_by = $this->_em->getRepository("Users")->findOneBy(array('auth' => $auth));
     //        echo 'users'.$created_by;
     //        exit;
     $stock_receive->setModifiedBy($created_by);
     $stock_receive->setModifiedDate(App_Tools_Time::now());
     $stock_receive->setCreatedBy($created_by);
     $stock_receive->setCreatedDate(App_Tools_Time::now());
     $this->_em->persist($stock_receive);
     $this->_em->flush();
     return array("message" => "success", "detail_id" => $stock_detail->getPkId());
 }