public function purposeTransferManagementAction() { $form = new Form_PurposeTransfer(); if ($this->_request->isPost()) { $product_id = $this->_request->getPost('product'); $batch_id = $this->_request->getPost('batch'); $msg = ''; $em = Zend_Registry::get('doctrine'); $em->getConnection()->beginTransaction(); try { $quantity = $this->_request->quantity; $newpurpose = $this->_request->newpurpose; $comments = $this->_request->comments; $toproducts = $this->_request->toproducts; foreach ($quantity as $key => $value) { if (!empty($value) && $value > 0) { $updatedqty = $value; list($batchid, $vvmid, $locationid, $activity_id) = explode("_", $key); $batch_detail = $this->_em->getRepository("StockBatch")->find($batchid); $stock_master = new Model_StockMaster(); $data = array('adjustment_date' => date("d/m/Y"), 'ref_no' => '', 'product' => $batch_detail->getItemPackSize()->getPkId(), 'batch_no' => $batchid, 'adjustment_type' => 17, 'quantity' => $updatedqty, 'comments' => $comments, 'item_unit_id' => $batch_detail->getItemPackSize()->getItemUnit()->getPkId(), 'vvm_stage' => $vvmid, 'location_id' => $locationid . "|" . $vvmid, 'purpose' => $activity_id); $stock_master->form_values = $data; $stock_master->addAjustment(); $stock_batch = new Model_StockBatch(); $array = array('wh_id' => $batch_detail->getWarehouse()->getPkId(), 'number' => $batch_detail->getNumber(), 'item_id' => $toproducts[$key], 'expiry_date' => $batch_detail->getExpiryDate()->format("d/m/Y"), 'quantity' => $updatedqty, 'production_date' => $batch_detail->getProductionDate() != null ? $batch_detail->getProductionDate()->format("d/m/Y") : '', 'vvm_type_id' => $batch_detail->getVvmType()->getPkId(), 'unit_price' => $batch_detail->getUnitPrice(), 'manufacturer_id' => $batch_detail->getStakeholderItemPackSize()->getPkId()); $transbatchid = $stock_batch->createBatch($array); $data2 = array('adjustment_type' => 16, 'batch_no' => $transbatchid, 'adjustment_date' => date("d/m/Y"), 'ref_no' => '', 'product' => $toproducts[$key], 'quantity' => $updatedqty, 'comments' => $comments, 'item_unit_id' => $batch_detail->getItemPackSize()->getItemUnit()->getPkId(), 'vvm_stage' => $vvmid, 'location_id' => $locationid . "|" . $vvmid, 'purpose' => $newpurpose[$key]); $stock_master->form_values = $data2; $stock_master->addAjustment(); //Log Entry START $history = new PurposeTransferHistory(); $from_batch = $this->_em->getRepository("StockBatch")->find($batchid); $history->setFromBatch($from_batch); $to_batch = $this->_em->getRepository("StockBatch")->find($transbatchid); $history->setToBatch($to_batch); $from_activity = $this->_em->getRepository("StakeholderActivities")->find($activity_id); $history->setFromActivity($from_activity); $to_activity = $this->_em->getRepository("StakeholderActivities")->find($newpurpose[$key]); $history->setToActivity($to_activity); $created_by = $this->_em->getRepository("Users")->find($this->_userid); $history->setCreatedBy($created_by); $history->setCreatedDate(new DateTime(date("Y-m-d"))); $history->setQuantity(ABS($updatedqty)); $transaction_type = $this->_em->getRepository("TransactionTypes")->find(Model_TransactionTypes::CHANGE_PURPOSE_POSITIVE); $history->setTransactionType($transaction_type); $this->_em->persist($history); $this->_em->flush(); //Log Entry END $stock_batch->adjustQuantityByWarehouse($transbatchid); $msg = 'Purpose has been changed successfully!'; $product_id = $batch_detail->getItemPackSize()->getPkId(); $batch_id = $batchid; } } $stock_detail = new Model_StockDetail(); $this->view->result = $stock_detail->purposeTransferManagement($batch_id); //$this->view->h_result = $stock_detail->getPurposeTransferHistory($product_id); //$this->view->history = $stock_detail->purposeTransferHistory($batch_id); $form->product->setValue($product_id); $this->view->batch = $batch_id; $em->getConnection()->commit(); } catch (Exception $e) { $em->getConnection()->rollback(); $em->close(); App_FileLogger::info($e); } $this->view->opening_balance_result = $stock_detail->getOpeningBalancePurpose($product_id, $batch_id); $this->view->closing_balance_result = $stock_detail->getClosingBalancePurpose($product_id, $batch_id); $this->view->h_result = $stock_detail->getPurposeTransferHistory($product_id); } $this->view->form = $form; $this->view->msg = $msg; }