예제 #1
0
 public function authorizeAction()
 {
     $idProformaInvoice = $this->getRequest()->getParam("id", "");
     $proformaInvoice = ProformaInvoiceQuery::create()->findByPKOrThrow($idProformaInvoice, $this->i18n->_("The Proforma Invoice with id {$idProformaInvoice} does not exist."));
     $proformaInvoice->setStatus(ProformaInvoice::$Status["Authorized"]);
     $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $idProformaInvoice)->find();
     $sapConnectionClient = new SAPConnectorClient();
     $result = $sapConnectionClient->authorizePurchaseQuotation($proformaInvoice->getIdProformaInvoice(), $proformaInvoice->getStatus());
     if ($result->authorizePurchaseQuotationResult->code == 200) {
         foreach ($_FILES as $name => $value) {
             $inputName = $name;
         }
         $fileUploader = new FileUploader($inputName);
         $uploadPath = 'public/' . ($filePath = "files/proformas/" . $proformaInvoice->getIdProformaInvoice());
         $fileUploader->saveFile($uploadPath, false);
         try {
             $this->getProformaInvoiceFileCatalog()->beginTransaction();
             $file = FileFactory::createFromArray(array(File::TYPE => File::$typeFile["typeFile"], File::CONTENT => $filePath . $fileUploader->getFileName()));
             $this->getFileCatalog()->create($file);
             $proformaInvoiceFile = ProformaInvoiceFileFactory::createFromArray(array(ProformaInvoiceFile::ID_FILE => $file->getIdFile(), ProformaInvoiceFile::ID_PROFORMA_INVOICE => $proformaInvoice->getIdProformaInvoice(), ProformaInvoiceFile::TYPE => ProformaInvoiceFile::$Types["PIAuthorized"]));
             $this->getProformaInvoiceFileCatalog()->create($proformaInvoiceFile);
             $log = $this->newLogForAutorized($proformaInvoice);
             $this->getProformaInvoiceFileCatalog()->commit();
             $this->getEventDispatcherService()->dispatchProformaInvoiceEvent($proformaInvoice, ProformaInvoiceEvent::PROFORMAINVOICE_AUTHORIZED, $proformaInvoiceEntries);
             $this->setFlash('ok', $this->i18n->_("The Proforma Invoice with id {$result->authorizePurchaseQuotationResult->id} was autorized."));
         } catch (Exception $e) {
             $this->getProformaInvoiceFileCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     } else {
         $this->setFlash('error', $result->purchaseQuotationResult->code . " - " . $result->purchaseQuotationResult->message);
     }
     $this->_redirect('proforma-invoice/list');
 }