/**
  *
  */
 public function payAction()
 {
     $params = $this->getRequest()->getParams();
     $returnAction = $this->getRequest()->getParam("returnAction", "list");
     $payment = Zend_Json::decode(stripslashes($params["sapPayment"]));
     $this->getActualPaymentCatalog()->beginTransaction();
     try {
         $fileUploader = new FileUploader('file');
         if (!$fileUploader->isUpload()) {
             throw new Exception("El archivo es invalido");
         }
         $uploadDir = 'public/files/payments/docnum' . $docnum;
         $fileUploader->saveFile($uploadDir, false);
         $file = new File();
         $file->setContent($uploadDir . $fileUploader->getFileName());
         $file->setType(File::$typeFile['typeImage']);
         $this->getFileCatalog()->create($file);
         foreach ($params["payment"] as $programmedPaymentParam) {
             if ($programmedPaymentParam["payment"] > 0) {
                 $programmedPayment = ProgrammedPaymentQuery::create()->findByPK($programmedPaymentParam["id"]);
                 $balance = $this->getPaymentBalance($programmedPayment);
                 if ($balance + $programmedPaymentParam["payment"] > $programmedPayment->getAmmount()) {
                     throw new Exception("Balance overloaded");
                 }
                 $actualPayment = ActualPaymentFactory::createFromArray(array(ActualPayment::ID_FILE => $file->getIdFile(), ActualPayment::DOCNUM => $payment["idPayment"], ActualPayment::ID_PROGRAMMED_PAYMENT => $programmedPayment->getIdProgrammedPayment(), ActualPayment::AMMOUNT => $programmedPaymentParam["payment"], ActualPayment::PAYMENT_DATE => $payment["paymentDate"], ActualPayment::TYPE => $payment["type"]));
                 $this->getActualPaymentCatalog()->create($actualPayment);
                 if ($balance + $programmedPaymentParam["payment"] == $programmedPayment->getAmmount()) {
                     $programmedPayment->setStatus(ProgrammedPayment::$TypeStatus['Paid']);
                     $event = ProgrammedPaymentEvent::TOTAL_PAYMENT;
                 } else {
                     $programmedPayment->setStatus(ProgrammedPayment::$TypeStatus['Partial']);
                     $event = ProgrammedPaymentEvent::PARTIAL_PAYMENT;
                 }
                 $this->getProgrammedPaymentCatalog()->update($programmedPayment);
                 $this->getEventDispatcherService()->createProgrammedPaymentNotification($event, $programmedPayment, $actualPayment);
                 //TODO Despachar el evento de Pago Realizado
             }
         }
         $this->getActualPaymentCatalog()->commit();
         $this->setFlash("ok", $this->i18n->_('The payments were successfully saved'));
     } catch (Exception $e) {
         $this->getActualPaymentCatalog()->rollBack();
         $this->setFlash("error", $this->i18n->_('The payments could not be saved: ' . $e->getMessage()));
     }
     $this->getHelper('redirector')->goto($returnAction);
 }
Example #2
0
 /**
  * Uploads the file and returns an \Application\Model\Bean\File
  * @author joseluis
  * @param String $fileField
  * @param String $path
  * @return \Application\Model\Bean\File if success false otherwise
  */
 private function saveFile($fileField, $path)
 {
     $type = $_FILES[$fileField]['type'];
     if ($type) {
         try {
             $uploadPath = 'public/files/' . $path;
             $fileUploader = new FileUploader($fileField);
             if (strstr($type, "image") != false) {
                 $folder = 'images';
                 $uploadPath .= $folder;
                 $fileUploader->saveFile($uploadPath, true);
                 $fileType = 1;
             } else {
                 $folder = 'files';
                 $uploadPath .= $folder;
                 $fileUploader->saveFile($uploadPath, false);
                 $fileType = 2;
             }
             $myFile = new File();
             $uploadPath = 'files/' . $path . $folder;
             $myFile->setContent($uploadPath . $fileUploader->getFileName());
             $myFile->setType($fileType);
             return $myFile;
         } catch (Exception $e) {
             //the file wasn't uploaded
             return false;
         }
     }
 }
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     $params = $this->getRequest()->getParams();
     $id = $params['id_customs_broker'];
     $customsBroker = CustomsBrokerQuery::create()->findByPKOrThrow($id, $this->i18n->_('It does not exist Customs Broker with id'));
     $this->getCustomsBrokerCatalog()->beginTransaction();
     try {
         $address = AddressFactory::createFromArray($params);
         $this->getCatalog('AddressCatalog')->update($address);
     } catch (Exception $e) {
         //Address couldn't be created
         $this->getCustomsBrokerCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     //updates the file and its register in the db and eliminates previous one
     $type = $_FILES['id_last_fee_file']['type'];
     if ($type) {
         try {
             $uploadPath = 'files/company/customs-broker/' . $params['id_company'];
             $fileUploader = new FileUploader("id_last_fee_file");
             if ($fileUploader->isUpload()) {
                 if ($customsBroker->getIdLastFeeFile()) {
                     $idFile = $customsBroker->getIdLastFeeFile();
                     $feeFile = \Application\Query\FileQuery::create()->findByPK($idFile);
                     //$this->getCatalog('FileCatalog')->deleteById($feeFile->getIdFile());
                     is_dir(unlink('public/' . $feeFile->getContent()));
                 }
                 if (strstr($type, "image") != false) {
                     $uploadPath .= '/images';
                     $fileUploader->saveFile('public/' . $uploadPath, true);
                 } else {
                     $uploadPath .= '/files';
                     $fileUploader->saveFile('public/' . $uploadPath, false);
                 }
                 $myFile = new File();
                 $myFile->setContent($uploadPath . $fileUploader->getFileName());
                 $myFile->setType(file::$typeFile['typeFile']);
                 $this->getCatalog('FileCatalog')->create($myFile);
                 $customsBroker->setIdLastFeeFile($myFile->getIdFile());
             }
         } catch (Exception $e) {
             //the images wasn't uploaded
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     try {
         $this->getCustomsBrokerCatalog()->unlinkAllPortCustom($id);
         $idsCustomsPort = $params['idsCustomsPort'];
         foreach ($idsCustomsPort as $idCustomsPort) {
             $this->getCustomsBrokerCatalog()->linkToPortCustom($customsBroker->getIdCustomsBroker(), $idCustomsPort);
         }
     } catch (Exception $e) {
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     //Inserts a customs broker register
     try {
         CustomsBrokerFactory::populate($customsBroker, $params);
         $this->getCustomsBrokerCatalog()->update($customsBroker);
     } catch (Exception $e) {
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->getCustomsBrokerCatalog()->commit();
     $this->setFlash('ok', $this->i18n->_("The Customs Brokers with id {$id} has been updated"));
     $this->_redirect("customs-broker/list");
 }