public function addStockIssueAction()
 {
     $stock_master = new Model_StockMaster();
     $stock_batch = new Model_StockBatch();
     $placements = new Model_Placements();
     $stock_detail = new Model_StockDetail();
     $warehouse_data = new Model_WarehousesData();
     $form_values = array();
     $temp = array();
     $batch = array();
     $arr_data = array('transaction_number' => "", 'stock_id' => "", 'transaction_date' => date("d/m/Y"), 'warehouse_name' => "", 'success' => $this->_request->success);
     $date_em = '01' . "-" . $this->_request->month . "-" . $this->_request->year;
     $date_in = date('d/m/Y', strtotime($date_em));
     $this->view->month = $this->_request->month;
     $this->view->year = $this->_request->year;
     $this->view->data_in = $date_in;
     $form_values['transaction_type_id'] = 2;
     $form_values['adjustment_type'] = 2;
     //need to be dynamic
     $form_values['transaction_reference'] = $this->_request->transaction_reference;
     $form_values['activity_id'] = $this->_request->activity_id;
     $warehouse_id = $this->_request->r_wh_id;
     $form_values['comments'] = $this->_request->comments;
     // end
     $stock_id = "";
     $master_id = "";
     $start = 0;
     $end = $this->_request->getParam('counter', 10);
     $activity_id = 1;
     $type_d = $this->_request->type_d;
     $r_wh_id = $this->_request->r_wh_id;
     $form_values['type_d'] = $type_d;
     $form = new Form_AddStockIssue();
     $form->addRows($start, $end);
     $form->transaction_date->setValue(date("{$date_in} h:i A"));
     if (!empty($this->_request->stock_master_id)) {
         $master_id = $this->_request->stock_master_id;
     }
     $form->hdn_activity_id->setValue($activity_id);
     $form->hdn_receive_warehouse_id->setValue($r_wh_id);
     $form->hdn_stock_master_id->setValue($master_id);
     $rows = $this->_em->getRepository('Warehouses')->find($warehouse_id);
     $this->view->warehouse_name = $rows->getWarehouseName();
     $em = Zend_Registry::get('doctrine');
     $em->getConnection()->beginTransaction();
     try {
         if ($type_d == 'd' && !$this->_request->isPost()) {
             $s_master = new Model_StockMaster();
             $s_master->form_values['sender_warehouse_id'] = $this->_identity->getWarehouseId();
             $s_master->form_values['receive_warehouse_id'] = $r_wh_id;
             $result = $s_master->getIssueTemp();
             $form->transaction_date->setValue($result[0]['transaction_date']);
             $form->transaction_reference->setValue($result[0]['transaction_reference']);
             $form->comments->setValue($result[0]['comments']);
             $i = 0;
             foreach ($result as $row) {
                 $rows = "rows" . $i;
                 $form->{$rows}->item_pack_size_id->setValue($row['item_pack_size_id']);
                 $stock_batch->form_values['item_pack_size_id'] = $row['item_pack_size_id'];
                 $stock_batch->form_values['transaction_date'] = $row['transaction_date'];
                 $associated = $stock_batch->getRunningBatches();
                 if ($associated) {
                     foreach ($associated as $row_batch) {
                         $batch[$row_batch['pkId']] = $row_batch['number'] . '|' . number_format($row_batch['quantity']) . '|' . $row_batch['priority'];
                     }
                 }
                 $stock_batch->form_values['pk_id'] = $row['stock_batch_id'];
                 $stock_batch->form_values['trans_date'] = App_Controller_Functions::dateToDbFormat($row['transaction_date']);
                 $placements->form_values['batch_id'] = $row['stock_batch_id'];
                 $placements->form_values['trans_date'] = App_Controller_Functions::dateToDbFormat($row['transaction_date']);
                 $vvmstages = $placements->getIssueAvailableVvmStages();
                 if (!empty($batch)) {
                     $form->{$rows}->number->setMultiOptions($batch);
                     if (!empty($vvmstages[0]['qty'])) {
                         $form->{$rows}->hdn_available_quantity->setValue($vvmstages[0]['qty']);
                         $form->{$rows}->hdn_vvm_stage->setValue($vvmstages[0]['placement_location_id'] . "|" . $vvmstages[0]['vvm_stage_id'] . "|" . $vvmstages[0]['qty']);
                     }
                 }
                 unset($batch);
                 $form->{$rows}->number->setValue($row['stock_batch_id']);
                 $form->{$rows}->expiry_date->setValue($row['expiry_date']);
                 $form->{$rows}->quantity->setValue(abs($row['quantity']));
                 $i++;
             }
         } else {
             if ($this->_request->isPost()) {
                 $temp = $this->_request->getPost();
                 //  App_Controller_Functions::pr($temp);
                 $data = array_merge($temp, $form_values);
                 $data['warehouse'] = $warehouse_id;
                 // Stock Master
                 $stock_id = $stock_master->addStockMaster1($data);
                 $form_values['type'] = 'd';
                 // end
                 $form_values['stock_master_id'] = $stock_id;
                 $form_values['counter'] = $end;
                 $form_values['transaction_type_id'] = 2;
                 $data = array_merge($temp, $form_values);
                 $detail_id = $stock_detail->addStockDetail1Validation($data);
                 if (empty($detail_id)) {
                     for ($i = 0; $i < $end; $i++) {
                         $form_values = $data;
                         $row = $form_values["rows" . $i];
                         if ($row['quantity'] > 0) {
                             $stock_batch->adjustQuantityByWarehouse($row['number']);
                             $stock_batch->autoRunningLEFOBatch($row['item_pack_size_id']);
                             $stock_batch->form_values['pk_id'] = $row['number'];
                             $stock_batch->form_values['status'] = Model_StockBatch::FINISHED;
                             $stock_batch->changeStatus();
                         }
                     }
                     $stock_m = $this->_em->getRepository('StockMaster')->find($stock_id);
                     $this->view->msg = 'Stock has been issued successfully. Your voucher number is ';
                     $this->view->voucher = $stock_m->getTransactionNumber();
                     $this->view->master_id = $stock_id;
                     $this->view->error = "B";
                 } else {
                     // Open report in edit form after save
                     //  App_Controller_Functions::pr($result);
                     $this->view->error = "P";
                     $this->view->msg = $detail_id;
                 }
             }
         }
         $em->getConnection()->commit();
     } catch (Exception $e) {
         $em->getConnection()->rollback();
         $em->close();
     }
     if ($type_d == 'n' && !$this->_request->isPost()) {
         $sips = new Model_StakeholderItemPackSizes();
         $sips->form_values['stakeholder_id'] = '1';
         $result = $sips->getAllProductsByStakeholderTypeVaccines();
         $i = 0;
         $batch11 = array();
         foreach ($result as $row) {
             $rows = "rows" . $i;
             $form->{$rows}->item_pack_size_id->setValue($row['item_pack_size_id']);
             $stock_batch->form_values['item_pack_size_id'] = $row['item_pack_size_id'];
             $stock_batch->form_values['transaction_date'] = date("{$date_in} h:i A");
             $associated = $stock_batch->getRunningBatches();
             $batch11[''] = "Select";
             if ($associated) {
                 foreach ($associated as $row_batch) {
                     $batch11[$row_batch['pkId']] = $row_batch['number'] . '|' . number_format($row_batch['quantity']) . '|' . $row_batch['priority'];
                 }
             }
             if (!empty($batch11)) {
                 $form->{$rows}->number->setMultiOptions($batch11);
             }
             unset($batch11);
             $i++;
         }
     }
     $this->view->form = $form;
     $this->view->start = $start;
     $this->view->end = $end;
 }
 public function updateVvmStageAction()
 {
     $data = array();
     $data['batch_id'] = $this->_request->getParam('batch_id');
     $data['placement_id'] = $this->_request->getParam('placement_id');
     $data['vvm_stage'] = $this->_request->getParam('vvm_stage');
     $data['qty'] = $this->_request->getParam('qty');
     $placements = new Model_Placements();
     $placements->form_values = $data;
     $result = $placements->updateVvmStage();
     echo Zend_Json::encode(array($result));
 }
 public function ajaxIssueAvailableVvmStagesAction()
 {
     $this->_helper->layout->disableLayout();
     $wh_id = $this->_identity->getWarehouseId();
     $placements = new Model_Placements();
     $batch_id = $this->_request->getParam('batch');
     $priority = $this->_request->getParam('priority');
     $batch = $this->_em->getRepository("StockBatch")->find($batch_id);
     $item_cat = $batch->getItemPackSize()->getItemCategory()->getPkId();
     $placements->form_values['priority'] = $priority;
     $this->view->vvmstages = $placements->getAvailableVvmStages($batch_id, $item_cat);
     $this->view->role = $this->_identity->getRoleId();
     $this->view->item_cat = $item_cat;
     $wh = $this->_em->getRepository("Warehouses")->find($wh_id);
     $this->view->is_placement_enable = 1;
     //$wh->getIsPlacementEnable();
 }
 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;
 }
 public function addStockDetail1($array)
 {
     $em = Zend_Registry::get('doctrine');
     $action = Zend_Registry::get("action");
     $form_values = $array;
     $end = $form_values['counter'];
     for ($i = 0; $i < $end; $i++) {
         $row = $form_values["rows" . $i];
         if ($row['quantity'] > 0) {
             $stock_detail = new StockDetail();
             $type = $array['transaction_type_id'];
             $type1 = $type;
             $quantity = str_replace(",", "", $row['quantity']);
             if ($type == Model_TransactionTypes::TRANSACTION_ISSUE) {
                 $quantity = "-" . $quantity;
             }
             $stock_id = $array['stock_master_id'];
             $stock_master_id = $this->_em->getRepository('StockMaster')->find($stock_id);
             $stock_detail->setStockMaster($stock_master_id);
             $row_item = $this->_em->getRepository('ItemPackSizes')->find($row['item_pack_size_id']);
             $item_unit = $row_item->getItemUnit()->getPkId();
             if (!empty($item_unit)) {
                 $item_unit_id = $this->_em->getRepository('ItemUnits')->find($item_unit);
                 $stock_detail->setItemUnit($item_unit_id);
             }
             $stock_detail->setQuantity($quantity);
             $stock_detail->setTemporary(0);
             if ($action == 'add-stock-issue') {
                 list($location, $vvm) = explode("|", trim($row['hdn_vvm_stage']));
                 if ($vvm == 0) {
                     $row['hdn_vvm_stage'] = 0;
                 } else {
                     if (!empty($vvm)) {
                         $row['hdn_vvm_stage'] = $vvm;
                     } else {
                         $row['hdn_vvm_stage'] = $location;
                     }
                 }
             }
             $vvms = $this->_em->getRepository("VvmStages")->find($row['hdn_vvm_stage']);
             $stock_detail->setVvmStage($vvms);
             $stock_detail->setAdjustmentType("{$type}");
             if ($type == 1) {
                 $str_sql = $this->_em->createQueryBuilder()->select("sbw.pkId")->from('StockBatchWarehouses', 'sbw')->join('sbw.stockBatch', 'sb')->join('sb.packInfo', 'pi')->join('pi.stakeholderItemPackSize', 'sip')->where("sip.itemPackSize = '" . $row['item_id'] . "' ")->andWhere("sb.number = '" . $row['number'] . "'  ")->andWhere("sbw.warehouse =  '" . $this->_identity->getWarehouseId() . "' ");
                 //this IF is for stock receive
                 $row_q = $str_sql->getQuery()->getResult();
                 $stock_batch_id = $this->_em->getRepository('StockBatchWarehouses')->find($row_q['0']['pkId']);
                 $stock_detail->setStockBatchWarehouse($stock_batch_id);
                 $stock_detail->setIsReceived(1);
             } else {
                 if ($type == 2) {
                     //this ELSE IF is for stock issue
                     $stock_batch_id = $this->_em->getRepository('StockBatchWarehouses')->find($row['number']);
                     $stock_detail->setStockBatchWarehouse($stock_batch_id);
                     $stock_detail->setIsReceived(0);
                 }
             }
             $created_by = $this->_em->getRepository('Users')->find($this->_user_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();
             //  echo $row['number'];
             //  exit;
             //  echo   $stock_batch_id->getPkId();
             //  exit;
             $query = "SELECT AdjustQty(" . $stock_batch_id->getPkId() . "," . $this->_identity->getWarehouseId() . ") FROM DUAL";
             $str_sql = $em->getConnection()->prepare($query);
             $str_sql->execute();
             if ($action == 'add-stock-issue' && !empty($location)) {
                 $placements = new Model_Placements();
                 $placements->form_values['placement_loc_id'] = $location;
                 $placements->form_values['batch_id'] = $row['number'];
                 $placements->form_values['vvmstage'] = $vvm;
                 $placements->form_values['is_placed'] = 1;
                 $placements->form_values['quantity'] = $quantity;
                 $placements->form_values['placement_loc_type_id'] = 115;
                 $placements->form_values['detail_id'] = $stock_detail->getPkId();
                 $placements->form_values['user_id'] = $this->_user_id;
                 $placements->form_values['created_date'] = date("Y-m-d");
                 $placements->addIssuePlacement();
             }
         }
     }
     return $stock_detail->getPkId();
 }
 public function deleteStockIssueAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     if ($this->_request->isPost()) {
         $batch_id = $this->_request->b_id;
         $loc_id = $this->_request->loc_id;
         $vvm_stage_id = $this->_request->vvm_id;
         $qty_issued = $this->_request->qty_issued;
         $item_cat_id = $this->_request->item_cat_id;
         if ($item_cat_id == 1) {
             $loc_type = Model_PlacementLocations::LOCATIONTYPE_CCM;
         } else {
             $loc_type = Model_PlacementLocations::LOCATIONTYPE_NONCCM;
         }
         $placement_locations = $this->_em->getRepository("PlacementLocations")->findBy(array("locationId" => $loc_id, "locationType" => $loc_type));
         $placement_loc_id = $placement_locations[0]->getPkId();
         $placement_details = $batch_id . "|" . $placement_loc_id . "|" . $vvm_stage_id . "|" . $qty_issued;
         $placement_type = Model_PlacementLocations::PLACEMENT_TRANSACTION_TYPE_P;
         $placement = new Model_Placements();
         $flag = $placement->updateStockPlacement($placement_details, $placement_type);
         if ($flag) {
             $this->redirect("/stock/issue-search");
             exit;
         }
     }
 }