public function saveClaimControlAction() { // echo '<pre>'; // print_r($this->getRequest()->getParams()); // die; $url = 'warehouse-entrance/list'; $id = $this->getRequest()->getParam('idWarehouseEntrance'); $line = $this->getRequest()->getParam('idWarehouseEntranceProduct'); $warehouseEntry = WarehouseEntranceQuery::create()->findByPK($id); $warehouseEntryLine = WarehouseEntranceProductQuery::create()->whereAdd(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE, $id)->whereAdd(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE_PRODUCT, $line)->findOne(); $path = 'warehouse-entrance/' . $warehouseEntryLine->getIndex() . '/'; $finalAmount = $this->getRequest()->getParam('finalAmount'); $status = $this->getRequest()->getParam('status'); $commentaries = $this->getRequest()->getParam('commentaries'); $comments = $this->getRequest()->getParam('comments'); $videoLink = $this->getRequest()->getParam('videoLink'); $reimbursementDocNum = $this->getRequest()->getParam('reimbursement_doc_num'); $this->getCatalog('WarehouseEntranceClaimReportCatalog')->beginTransaction(); $claimReport = $this->getClaimReport($warehouseEntryLine->getIdWarehouseEntrance(), $warehouseEntryLine->getIdWarehouseEntranceProduct()); $claimReport->setFinalAmount($finalAmount); $claimReport->setDebitMenoAmount($debitMemoAmount); $claimReport->setComments($commentaries); $claimReport->setVideoLink($videoLink); $claimReport->setReimbursementDocNum($reimbursementDocNum); $claimReport->setStatus($status); try { $this->getCatalog('WarehouseEntranceClaimReportCatalog')->update($claimReport); } catch (Exception $e) { $this->getCatalog('WarehouseEntranceClaimReportCatalog')->rollBack(); $this->setFlash('error', $e->getMessage()); $this->_redirect($url); } if (!empty($commentaries)) { $warehouseEntry->setComments($commentaries); } $file = $this->saveFile('document', $path, 'claimControlReport'); if ($file) { $warehouseEntryFile = WarehouseEntranceFileQuery::create()->whereAdd(WarehouseEntranceFile::ID_WAREHOUSE_ENTRANCE, $id)->count(); if ($warehouseEntryFile) { $warehouseEntryFile = WarehouseEntranceFileQuery::create()->whereAdd(WarehouseEntranceFile::ID_WAREHOUSE_ENTRANCE, $id)->findOne(); if (file_exists('public/' . $warehouseEntryFile->getContent())) { unlink('public/' . $warehouseEntryFile->getContent()); } $warehouseEntryFile->setContent($file->getContent()); $warehouseEntryFile->setType($file->getType()); try { $this->getCatalog('WarehouseEntranceFileCatalog')->update($warehouseEntryFile); } catch (Exception $e) { $this->setFlash('error', $e->getMessage()); $this->_redirect($url); } } else { $warehouseEntryFile = new WarehouseEntranceFile(); $warehouseEntryFile->setContent($file->getContent()); $warehouseEntryFile->setDocumentType(1); $warehouseEntryFile->setType($file->getType()); $warehouseEntryFile->setIdWarehouseEntrance($id); try { $this->getCatalog('WarehouseEntranceFileCatalog')->create($warehouseEntryFile); } catch (Exception $e) { $this->setFlash('error', $e->getMessage()); $this->_redirect($url); } } } $SapConnection = new SAPConnectorClient(); $result = $SapConnection->updateWarehouseEntry($warehouseEntry); if ($result->updateWarehouseEntryResult->success) { $this->setFlash('ok', $this->i18n->_('The Claim Report has been saved.')); $this->getCatalog('WarehouseEntranceClaimReportCatalog')->commit(); } else { $this->setFlash('error', $this->i18n->_($result->updateWarehouseEntryResult->message)); } $params = $this->getRequest()->getParams(); if ($reportStatus == WarehouseEntranceClaimReport::$ReportStatus['Closed']) { $this->getEventDispatcherService()->createClaimReportNotification($params, ClaimReportEvent::CLAIM_REPORT_NOTIFICATION); } $this->_redirect($url); }