/**
  * 
  * @author Erick Guevara Martíne<
  * @param PurchaseOrderEntryCollection $entries
  * @return array
  */
 public function getCondensedPayments(PurchaseOrder $purchaseOrder)
 {
     $purchaseOrderPaymentTerms = PurchaseOrderPaymentTermQuery::create()->whereAdd(PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find();
     $purchaseOrderProgrammedPayments = PurchaseOrderProgrammedPaymentQuery::create()->whereAdd(PurchaseOrderProgrammedPayment::ID_PURCHASE_ORDER_PAYMENT_TERM, $purchaseOrderPaymentTerms->getPrimaryKeys())->find();
     $events = EventQuery::create()->whereAdd(Event::ID_EVENT, $purchaseOrderPaymentTerms->getEventIds())->find();
     $payments = array();
     while ($purchaseOrderPaymentTerms->valid()) {
         $purchaseOrderPaymentTerm = $purchaseOrderPaymentTerms->read();
         $event = $events->getByPK($purchaseOrderPaymentTerm->getIdEvent());
         $purchaseOrderProgrammedPayments->filterByPurchaseOrderPaymentTerm($purchaseOrderPaymentTerm);
         $payments[$event->getIdEvent()]["event"] = $event->getName();
         $payments[$event->getIdEvent()]["idEvent"] = $event->getIdEvent();
         $payments[$event->getIdEvent()]["payment"] += $purchaseOrderPaymentTerm->getAmount();
         $payments[$event->getIdEvent()]["currency"] = $purchaseOrderPaymentTerm->getCurrency();
         if (!$purchaseOrderProgrammedPayments->isEmpty()) {
             $payments[$event->getIdEvent()]["noEdit"] = true;
         }
     }
     return $payments;
 }
 /**
  *
  * @return array
  */
 public function updateAction()
 {
     $params = $this->getRequest()->getParams();
     if ($this->getRequest()->isPost()) {
         $idProformaInvoice = $this->getRequest()->getParam('id_proforma_invoice');
         $proformaInvoiceParams['date'] = $this->getRequest()->getParam('date', null);
         $proformaInvoiceParams['folio'] = $this->getRequest()->getParam('folio', null);
         $proformaInvoiceParams['id_courtyard'] = $this->getRequest()->getParam('id_courtyard', null);
         $proformaInvoiceParams['id_currency'] = $this->getRequest()->getParam('id_currency');
         $proformaInvoiceParams['comments'] = $this->getRequest()->getParam('comments', null);
         $proformaInvoiceEntriesParams['warehouseStore'] = $this->getRequest()->getParam('warehouse_store', '');
         $proformaInvoiceEntriesParams['entries'] = $this->getRequest()->getParam('entries', array());
         $proformaInvoicePaymentTermIds = ProformaInvoiceProgrammedPaymentQuery::create()->addColumn(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE_PAYMENT_TERM)->whereAdd(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE, $idProformaInvoice)->fetchCol();
         $proformaInvoiceNotErasableEvents = ProformaInvoicePaymentTermQuery::create()->addColumn(ProformaInvoicePaymentTerm::ID_EVENT)->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_PAYMENT, $proformaInvoicePaymentTermIds, ProformaInvoicePaymentTermQuery::IN)->distinct()->fetchCol();
         $erasableEvents = EventQuery::create()->addColumn(Event::ID_EVENT)->whereAdd(Event::ID_EVENT, $proformaInvoiceNotErasableEvents, EventQuery::NOT_IN)->distinct()->fetchCol();
         $proformaInvoicePaymentTermsParams["events"] = $this->getRequest()->getParam('events', array());
         $totalAmmount = $this->getRequest()->getParam('quantityMatch');
         $totalProformaInvoiceEntries = count($proformaInvoiceEntriesParams['entries']);
         try {
             $proformaInvoice = ProformaInvoiceQuery::create()->findByPKOrThrow($idProformaInvoice, $this->i18n->_("Proforma Invoice with id {$idProformaInvoice} not found"));
             $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find();
             foreach ($proformaInvoiceEntriesParams['entries'] as $index => $values) {
                 $proformaInvoiceEntry = $proformaInvoiceEntries->getByPK($index);
                 $values["id_warehouse_store"] = $proformaInvoiceEntriesParams['warehouseStore'];
                 ProformaInvoiceEntryFactory::populate($proformaInvoiceEntry, $values);
             }
             ProformaInvoiceFactory::populate($proformaInvoice, $proformaInvoiceParams);
             $sapConnectionClient = new SAPConnectorClient();
             $result = $sapConnectionClient->purchaseQuotation($proformaInvoice, $proformaInvoiceEntries);
             if ($result->purchaseQuotationResult->code == 200) {
                 $proformaInvoiceFiles = ProformaInvoiceFileQuery::create()->whereAdd(ProformaInvoiceFile::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find();
                 $uploadPath = 'public/' . ($filePath = "files/proformas/" . $result->purchaseQuotationResult->id);
                 if ($_FILES["proforma_invoice_file"]["name"] != "") {
                     $fileUploader = new FileUploader("proforma_invoice_file");
                     $fileUploader->saveFile($uploadPath, false);
                     $newFile = FileFactory::createFromArray(array(File::CONTENT => $filePath . $fileUploader->getFileName(), File::TYPE => file::$typeFile["typeFile"]));
                     $this->getFileCatalog()->create($newFile);
                     $newProformaInvoiceFile = ProformaInvoiceFileFactory::createFromArray(array(ProformaInvoiceFile::ID_PROFORMA_INVOICE => $proformaInvoice->getIdProformaInvoice(), ProformaInvoiceFile::ID_FILE => $newFile->getIdFile(), ProformaInvoiceFile::TYPE => ProformaInvoiceFile::$Types["PINew"]));
                     $this->getProformaInvoiceFileCatalog()->create($newProformaInvoiceFile);
                     $proformaInvoiceFile = $proformaInvoiceFiles->getByType(ProformaInvoiceFile::$Types["PINew"]);
                     if ($proformaInvoiceFile->getIdProformaInvoiceFile() > 0) {
                         $this->getProformaInvoiceFileCatalog()->deleteById($proformaInvoiceFile->getIdProformaInvoiceFile());
                         $this->getFileCatalog()->deleteById($proformaInvoiceFile->getIdFile());
                     }
                 }
                 if ($_FILES["proforma_invoice_file_authorized"]["name"] != "") {
                     $fileUploader = new FileUploader("proforma_invoice_file_authorized");
                     $fileUploader->saveFile($uploadPath, false);
                     $newFile = FileFactory::createFromArray(array(File::CONTENT => $filePath . $fileUploader->getFileName(), File::TYPE => file::$typeFile["typeFile"]));
                     $this->getFileCatalog()->create($newFile);
                     $newProformaInvoiceFile = ProformaInvoiceFileFactory::createFromArray(array(ProformaInvoiceFile::ID_PROFORMA_INVOICE => $proformaInvoice->getIdProformaInvoice(), ProformaInvoiceFile::ID_FILE => $newFile->getIdFile(), ProformaInvoiceFile::TYPE => ProformaInvoiceFile::$Types["PIAuthorized"]));
                     $this->getProformaInvoiceFileCatalog()->create($newProformaInvoiceFile);
                     $proformaInvoiceFile = $proformaInvoiceFiles->getByType(ProformaInvoiceFile::$Types["PIAuthorized"]);
                     if ($proformaInvoiceFile->getIdProformaInvoiceFile() > 0) {
                         $this->getProformaInvoiceFileCatalog()->deleteById($proformaInvoiceFile->getIdProformaInvoiceFile());
                         $this->getFileCatalog()->deleteById($proformaInvoiceFile->getIdFile());
                     }
                 }
                 $allPaymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE, $proformaInvoice->getIdProformaInvoice())->find();
                 try {
                     $this->getProformaInvoicePaymentTermCatalog()->beginTransaction();
                     $paymentTerms = $allPaymentTerms->filterByEventId($erasableEvents);
                     while ($paymentTerms->valid()) {
                         $paymentTerm = $paymentTerms->read();
                         $this->getProformaInvoicePaymentTermCatalog()->deleteById($paymentTerm->getIdProformaInvoicePayment());
                     }
                     $notErasabledPaymentTerms = $allPaymentTerms->filterByEventId($proformaInvoiceNotErasableEvents, $line);
                     $programmedPayments = ProformaInvoiceProgrammedPaymentQuery::create()->whereAdd(ProformaInvoiceProgrammedPayment::ID_PROFORMA_INVOICE_PAYMENT_TERM, $notErasabledPaymentTerms->getPrimaryKeys())->find();
                     while ($proformaInvoiceEntries->valid()) {
                         $proformaInvoiceEntry = $proformaInvoiceEntries->read();
                         $totalPayment = 0;
                         foreach ($proformaInvoicePaymentTermsParams["events"] as $key => $payment) {
                             $amount = str_replace(",", "", $payment['payment']);
                             $proformaInvoicePaymentTermsParams["events"][$key]['percentage'] = $amount / $totalAmmount * 100;
                         }
                         foreach ($proformaInvoicePaymentTermsParams["events"] as $event) {
                             $newPaymentTerm = ProformaInvoicePaymentTermFactory::createFromArray(array(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE => $proformaInvoice->getIdProformaInvoice(), ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY => $proformaInvoiceEntry->getIdProformaInvoiceEntry(), ProformaInvoicePaymentTerm::LINE => $proformaInvoiceEntry->getVisOrder(), ProformaInvoicePaymentTerm::ID_EVENT => $event["id"], ProformaInvoicePaymentTerm::PIECES => $proformaInvoiceEntry->getQuantity(), ProformaInvoicePaymentTerm::PAYMENT => $proformaInvoiceEntry->getTotalImport() * $event["percentage"] / 100, ProformaInvoicePaymentTerm::CURRENCY => $proformaInvoice->getIdCurrency()));
                             $this->getProformaInvoicePaymentTermCatalog()->create($newPaymentTerm);
                         }
                         $entryPaymentTerms = $notErasabledPaymentTerms->filterByProformaInvoiceEntry($proformaInvoiceEntry);
                         while ($entryPaymentTerms->valid()) {
                             $paymentTerm = $entryPaymentTerms->read();
                             $entryProgrammedPayments = $programmedPayments->filterByPaymentTerm($paymentTerm);
                             while ($entryProgrammedPayments->valid()) {
                                 $payment = $entryProgrammedPayments->read();
                                 $payment->setIdCurrency($proformaInvoice->getIdCurrency());
                                 $payment->setLine($proformaInvoiceEntry->getVisOrder());
                                 $this->getProformaInvoiceProgrammedPaymentCatalog()->update($payment);
                             }
                             $paymentTerm->setCurrency($proformaInvoice->getIdCurrency());
                             $paymentTerm->setIdProformaInvoiceEntry($proformaInvoiceEntry->getIdProformaInvoiceEntry());
                             $paymentTerm->setLine($proformaInvoiceEntry->getVisOrder());
                             $this->getProformaInvoicePaymentTermCatalog()->update($paymentTerm);
                         }
                     }
                     $this->newLogForUpdate($proformaInvoice);
                     $this->getProformaInvoicePaymentTermCatalog()->commit();
                     $this->setFlash('ok', $this->i18n->_("Proforma Invoice with id {$result->purchaseQuotationResult->id} was updated."));
                 } catch (Exception $e) {
                     $this->getProformaInvoicePaymentTermCatalog()->rollBack();
                     $this->setFlash('error', $this->i18n->_($e->getMessage()));
                 }
             } else {
                 $this->setFlash('error', $result->purchaseQuotationResult->code . " - " . $result->purchaseQuotationResult->message);
             }
         } catch (Exception $e) {
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('proforma-invoice/list');
 }
示例#3
0
 /**
  *
  */
 public function reactivateAction()
 {
     $id = $this->getRequest()->getParam('id');
     $event = EventQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the Event with id {$id}"));
     try {
         $this->getEventCatalog()->beginTransaction();
         $event->setStatus(Event::$Status['Active']);
         $this->getEventCatalog()->update($event);
         $this->getEventCatalog()->commit();
         $this->setFlash('ok', $this->i18n->_("Se reactivo correctamente el Event"));
     } catch (Exception $e) {
         $this->getEventCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->_redirect('event/list');
 }
示例#4
0
 private function getEvents()
 {
     $events = array();
     $events[""] = $this->i18n->_("Select an event");
     $eventsQuery = Application\Query\EventQuery::create()->actives()->find();
     $total = Application\Query\EventQuery::create()->actives()->count();
     foreach ($eventsQuery as $event) {
         $events[$event->getIdEvent()] = $event->getName();
     }
     return $events;
 }
 /**
  *
  * @param int $idPurchaseOrder
  * @param int $idEvent
  */
 private function getMissingPurchaseInformation($idPurchaseOrder, $idEvent)
 {
     $purchaseOrder = PurchaseOrderQuery::create()->findByPKOrThrow($idPurchaseOrder, $this->i18n->_("PurchaseOrder with id {$idPurchaseOrder} not found."));
     $supplier = SapSupplierQuery::create()->findByPKOrThrow($purchaseOrder->getIdSupplier(), $this->i18n->_("SapSupplier with id {$purchaseOrder->getIdSupplier()} not found."));
     $event = EventQuery::create()->findByPKOrThrow($idEvent, $this->i18n->_("Event with id {$idEvent} not found."));
     $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find();
     $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $purchaseOrderEntries->getDisctinctProformaInvoiceIds())->find();
     $paymentTerms = PurchaseOrderPaymentTermQuery::create()->whereAdd(PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(ProformaInvoicePaymentTerm::ID_EVENT, $event->getIdEvent())->find();
     $purchasePayments = new PurchaseOrderProgrammedPaymentCollection();
     while ($purchaseOrderPaymentTerm = $paymentTerms->read()) {
         $purchaseOrderMissingProgrammedPayment = PurchaseOrderProgrammedPaymentFactory::createFromArray(array('id_purchase_order_programmed_payment' => 'VPOPP' . $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'id_proforma_invoice_payment_term' => $purchaseOrderPaymentTerm->getIdProformaInvoicePaymentTerm(), 'id_purchase_order_payment_term' => $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'pieces' => $purchaseOrderPaymentTerm->getPieces(), 'id_purchase_order' => $purchaseOrderPaymentTerm->getIdPurchaseOrder(), 'line' => $purchaseOrderPaymentTerm->getLine(), 'id_purchase_order_entry' => $purchaseOrderPaymentTerm->getIdPurchaseOrderEntry(), 'id_programmed_payment' => 'VPP' . $purchaseOrderPaymentTerm->getIdPurchaseOrderPaymentTerm(), 'id_currency' => $purchaseOrderPaymentTerm->getCurrency(), 'id_company' => $purchaseOrder->getIdSupplier(), 'type' => ProgrammedPayment::$TypePayment['PurchaseOrder'], 'ammount' => $purchaseOrderPaymentTerm->getAmount(), 'folio' => 'Not Available', 'due_date' => 'Not Available', 'status' => ProgrammedPayment::$TypeStatus['Virtual']));
         $purchasePayments->append($purchaseOrderMissingProgrammedPayment);
     }
     $response = array("docNum" => $purchaseOrder->getSapDocumentNumber(), "docEntry" => $purchaseOrder->getIdPurchaseOrder(), "createDate" => $purchaseOrder->getDeliveryEstimateDate(), "supplier" => $supplier->getCardCode(), "supplierName" => $supplier->getCardname(), "event" => $event->getName());
     while ($purchaseOrderEntries->valid()) {
         $purchaseOrderEntry = $purchaseOrderEntries->read();
         $proformaInvoiceEntry = $proformaInvoiceEntries->getByIdProformaInvoiceAndLine($purchaseOrderEntry->getBaseEntry(), $purchaseOrderEntry->getBaseLine());
         $programmedPayment = $purchasePayments->filterByPurchaseOrderEntry($purchaseOrderEntry)->getOne();
         $response["entries"][] = array("line" => $purchaseOrderEntry->getLine(), "product" => $purchaseOrderEntry->getIdProduct(), "quantity" => $purchaseOrderEntry->getQuantity(), "price" => $purchaseOrderEntry->getPrice(), "currency" => $purchaseOrderEntry->getCurrency(), "requisitions" => implode($proformaInvoiceEntry->getRequisitionIdsToArray()), "PI_Line" => $purchaseOrderEntry->getBaseEntry() . "/" . $purchaseOrderEntry->getBaseLine(), "ammount" => $programmedPayment->getAmmount(), "credits" => 0, "pendingBalance" => $programmedPayment->getAmmount());
     }
     return $response;
 }