public function getEntriesToCompleteInfoArray(PurchaseOrderEntryCollection $entries)
 {
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $entries->getProducts())->find();
     $arrayEntries = array();
     while ($entries->valid()) {
         $entry = $entries->read();
         $product = $products->getByPK($entry->getIdProduct());
         $arrayEntries[] = array("line" => $entry->getLine(), "itemCode" => $product->getItemCode(), "description" => $product->getItemName(), "unitPrice" => $entry->getPrice(), "quantity" => $entry->getQuantity(), "currency" => $entry->getCurrency());
     }
     return $arrayEntries;
 }
 /**
  * 
  * @return \Application\Model\Collection\InspectionCollection
  */
 public function getInspectionCollection()
 {
     if (!$this->inspectionCollection instanceof InspectionCollection) {
         $this->inspectionCollection = InspectionQuery::create()->whereAdd(Inspection::ID_PROFORMA_INVOICE, $this->purchaseOrderEntryCollection->getDisctinctProformaInvoiceIds())->find();
     }
     return $this->inspectionCollection;
 }
 /**
  * 
  * 
  * @author Erick Guevara Martínez
  * @param PurchaseOrderEntryCollection $purchaseOrderEntries
  * @param PurchaseOrderPaymentTermCatalog $paymentTermCatalog
  * @return \Application\Model\Collection\PurchaseOrderPaymentTermCollection
  */
 public function createPaymentTerms(PurchaseOrderEntryCollection $purchaseOrderEntries)
 {
     $proformaInvoiceEntriesQuery = ProformaInvoiceEntryQuery::create();
     $proformaInvoiceEntriesQuery->where()->setOR();
     while ($purchaseOrderEntries->valid()) {
         $purchaseOrderEntry = $purchaseOrderEntries->read();
         $where = "(" . ProformaInvoiceEntry::ID_PROFORMA_INVOICE . " = " . $purchaseOrderEntry->getBaseEntry() . " AND " . ProformaInvoiceEntry::LINE . " = " . $purchaseOrderEntry->getBaseLine() . ")";
         $proformaInvoiceEntriesQuery->whereAdd("", null, null, $where, BaseQuery::AS_FIELD);
     }
     $purchaseOrderEntries->rewind();
     $proformaInvoiceEntries = $proformaInvoiceEntriesQuery->find();
     $PIPaymentTerms = ProformaInvoicePaymentTermQuery::create()->whereAdd(ProformaInvoicePaymentTerm::ID_PROFORMA_INVOICE_ENTRY, $proformaInvoiceEntries->getPrimaryKeys())->find();
     $POPaymentTerms = new PurchaseOrderPaymentTermCollection();
     while ($purchaseOrderEntries->valid()) {
         $purchaseOrderEntry = $purchaseOrderEntries->read();
         $proformaInvoiceEntry = $proformaInvoiceEntries->getByIdProformaInvoiceAndLine($purchaseOrderEntry->getBaseEntry(), $purchaseOrderEntry->getBaseLine());
         $paymentTerms = $PIPaymentTerms->filterByProformaInvoiceEntry($proformaInvoiceEntry);
         while ($paymentTerms->valid()) {
             $paymentTerm = $paymentTerms->read();
             $payment = $purchaseOrderEntry->getQuantity() * $paymentTerm->getPayment() / $paymentTerm->getPieces();
             $POPaymentTerm = PurchaseOrderPaymentTermFactory::createFromArray(array(PurchaseOrderPaymentTerm::AMOUNT => $payment, PurchaseOrderPaymentTerm::CURRENCY => $purchaseOrderEntry->getCurrency(), PurchaseOrderPaymentTerm::ID_EVENT => $paymentTerm->getIdEvent(), PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER => $purchaseOrderEntry->getIdPurchaseOrder(), PurchaseOrderPaymentTerm::ID_PURCHASE_ORDER_ENTRY => $purchaseOrderEntry->getIdPurchaseOrderEntry(), PurchaseOrderPaymentTerm::ID_PROFORMA_INVOICE_PAYMENT_TERM => $paymentTerm->getIdProformaInvoicePayment(), PurchaseOrderPaymentTerm::LINE => $purchaseOrderEntry->getLine(), PurchaseOrderPaymentTerm::PIECES => $purchaseOrderEntry->getQuantity(), PurchaseOrderPaymentTerm::STATUS => PurchaseOrderPaymentTerm::$Status["Active"]));
             $this->getPurchaseOrderPaymentTermsCatalog()->create($POPaymentTerm);
             $POPaymentTerms->append($POPaymentTerm);
         }
     }
     return $POPaymentTerms;
 }
示例#4
0
 public function saveProgrammedPaymentAction()
 {
     $id = $this->getRequest()->getParam('id');
     $paymentStatus = $this->getRequest()->getParam('payment_status');
     $folioImport = FolioImportQuery::create()->findByPK($id);
     $sapConnector = new SAPConnectorClient();
     $redir = $this->getBaseUrl() . '/' . $this->getRequest()->getParam('controller') . '/list';
     $programmedPayments = $this->getRequest()->getParam('payment-term');
     $date = \Zend_Date::now();
     $results = array();
     $this->getCatalog('ProgrammedPaymentCatalog')->beginTransaction();
     foreach ($programmedPayments as $programmedPayment) {
         if (empty($programmedPayment['id_folios_import_programmed_payment'])) {
             $supplier = SapSupplierQuery::create()->findByPK($programmedPayment['id_company']);
             $servicePurchaseOrder = PurchaseOrderFactory::createFromArray(array('id_purchase_order' => "0", 'id_supplier' => $supplier->getCardCode(), 'purchase_order_date' => $date->get("yyyy-MM-dd"), 'delivery_estimate_date' => $date->get("yyyy-MM-dd"), 'invoice_number' => 'Pending', 'id_currency' => $programmedPayment['id_currency'], 'comments' => "Folio Import Service Purchase Order", 'groupnum' => $supplier->getGroupnum(), 'status' => PurchaseOrder::$Status["NewService"], 'id_courtyard' => -1, 'id_folio_import' => $programmedPayment['id_folio_import']));
             $purchaseOrderEntries = new PurchaseOrderEntryCollection();
             $linesCount = 0;
             $purchaseOrderEntry = PurchaseOrderEntryFactory::createFromArray(array('line' => $linesCount, "vis_order" => $linesCount, "id_product" => $programmedPayment['concept'], "quantity" => 1, "price" => $programmedPayment['ammount'], "id_warehouse_store" => '9999', "tax_code" => 'W3', 'lead_time' => -1, 'status' => PurchaseOrderEntry::$Status["ServiceEntry"], 'base_line' => -1, 'base_entry' => -1));
             $purchaseOrderEntries->append($purchaseOrderEntry);
             $result = $sapConnector->servicePurchaseOrder($servicePurchaseOrder, $purchaseOrderEntries);
             $results[] = array('success' => $result->purchaseOrderResult->success, 'id_purchase_order' => $result->purchaseOrderResult->id, 'id_folio_import' => $id, 'message' => $result->purchaseOrderResult->message);
             if ($result->purchaseOrderResult->success) {
                 $programmedPayment['doc_entry'] = $result->purchaseOrderResult->id;
                 $idFolioImportProgrammedPayment = $programmedPayment['id_folios_import_programmed_payment'];
                 if ($idFolioImportProgrammedPayment) {
                     if ($programmedPayment['status']) {
                         unset($programmedPayment['status']);
                         $folioImportProgrammedPayment = FolioImportProgrammedPaymentFactory::createFromArray($programmedPayment);
                         $folioImportProgrammedPayment->setType(ProgrammedPayment::$TypePayment['Folio']);
                         $this->getCatalog('FolioImportProgrammedPaymentCatalog')->update($folioImportProgrammedPayment);
                     }
                 } else {
                     $folioImportProgrammedPayment = FolioImportProgrammedPaymentFactory::createFromArray($programmedPayment);
                     $folioImportProgrammedPayment->setType(ProgrammedPayment::$TypePayment['Folio']);
                     $folioImportProgrammedPayment->setStatus(ProgrammedPayment::$TypeStatus['Pending']);
                     $folioImportProgrammedPayment->setIdFolioImport($id);
                     $folioImportProgrammedPayment->setFolio($folioImport->getFolio());
                     $this->getCatalog('FolioImportProgrammedPaymentCatalog')->create($folioImportProgrammedPayment);
                 }
             }
         }
     }
     try {
         if ($this->setResponseMessage($results) && $paymentStatus == FolioImport::$PaymentStatus['Inactive']) {
             $this->setFlash('warning', 'The payments were closed');
             $purchaseOrderQuery = PurchaseOrderQuery::create();
             $purchaseOrders = $purchaseOrderQuery->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $id)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status['NewService'], PurchaseOrderQuery::NOT_EQUAL)->find();
             $result = $sapConnector->createLandedCost($purchaseOrders);
         } else {
             $this->setFlash('warning', 'The payments were NOT closed');
         }
     } catch (Exception $e) {
         $this->getCatalog("ProgrammedPaymentCatalog")->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->newLogForPaymentAdded($folioImport);
     $this->getCatalog('ProgrammedPaymentCatalog')->commit();
     $this->_redirect('folio-import/list');
 }
示例#5
0
 public function servicePurchaseOrder(PurchaseOrder $purchaseOrder, PurchaseOrderEntryCollection $purchaseOrderEntries)
 {
     $purchaseOrder->setSeries(PurchaseOrder::$Series['Default']);
     $parameters["purchaseOrderSachi"] = $purchaseOrder->toSAPArray();
     $parameters["purchaseOrderSachi"]["Lines"] = $purchaseOrderEntries->toSAPArray();
     $this->createLogrequest($parameters);
     return $this->soapClient->purchaseOrder($parameters);
 }
 /**
  * This action convert a requisition to purchase order
  *
  * @author Erick Guevara Mart�nez
  * @return array
  * Created October 15th, 2012
  */
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         //die("<pre>".print_r($this->getRequest()->getParams(), true));
         $folio = $this->getRequest()->getParam("folio");
         $comments = $this->getRequest()->getParam("comments");
         $lines = $this->getRequest()->getParam("line");
         foreach ($lines as $line) {
             if ($line["checked"]) {
                 $idProformaInvoice[] = $line["id_proforma_invoice"];
             }
         }
         $proformasInvoice = ProformaInvoiceQuery::create()->whereAdd(ProformaInvoice::ID_PROFORMA_INVOICE, $idProformaInvoice, ProformaInvoiceQuery::IN)->find();
         $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $proformasInvoice->getPrimaryKeys(), ProformaInvoiceEntryQuery::IN)->whereAdd(ProformaInvoiceEntry::STATUS, ProformaInvoiceEntry::$Status["End Production"])->find();
         $supplier = SapSupplierQuery::create()->findByPKOrThrow($proformasInvoice->current()->getIdSupplier(), $this->i18n->_("The Supplier with id {$proformasInvoice->current()->getIdSupplier()} does not exist"));
         $date = \Zend_Date::now();
         $purchaseOrder = PurchaseOrderFactory::createFromArray(array('id_purchase_order' => "0", 'id_supplier' => $supplier->getCardCode(), 'purchase_order_date' => $date->get("yyyy-MM-dd"), 'delivery_estimate_date' => $date->get("yyyy-MM-dd"), 'invoice_number' => $folio, 'id_currency' => $proformasInvoice->current()->getIdCurrency(), 'comments' => $comments, 'groupnum' => $supplier->getGroupnum(), 'status' => PurchaseOrder::$Status["New"], 'id_courtyard' => $proformasInvoice->current()->getIdCourtyard(), 'id_folio_import' => -1));
         $purchaseOrderEntries = new PurchaseOrderEntryCollection();
         $linesCount = 0;
         foreach ($lines as $line) {
             if ($line["checked"]) {
                 $proformaInvoiceEntry = $proformaInvoiceEntries->getByPK($line["line"]);
                 $purchaseOrderEntry = PurchaseOrderEntryFactory::createFromArray(array('id_purchase_order_entry' => "0", 'line' => $linesCount, "vis_order" => $linesCount, "id_product" => $proformaInvoiceEntry->getIdProduct(), "quantity" => $line["quantity"], "price" => $proformaInvoiceEntry->getPrice(), "id_warehouse_store" => $proformaInvoiceEntry->getIdWarehouseStore(), "tax_code" => $proformaInvoiceEntry->getTaxCode(), 'lead_time' => $proformaInvoiceEntry->getLeadTime(), 'status' => PurchaseOrderEntry::$Status["New"], 'base_line' => $proformaInvoiceEntry->getLine(), 'base_entry' => $proformaInvoiceEntry->getIdProformaInvoice()));
                 $purchaseOrderEntries->append($purchaseOrderEntry);
                 $linesCount++;
             }
         }
         $SAPConnectionClient = new SAPConnectorClient();
         $result = $SAPConnectionClient->purchaseOrder($purchaseOrder, $purchaseOrderEntries);
         if ($result->purchaseOrderResult->code == 200) {
             try {
                 $this->getPurchaseOrderCommercialInvoiceCatalog()->beginTransaction();
                 $filePath = "files/purchase-order/" . $result->purchaseOrderResult->id;
                 $uploadPath = 'public/' . $filePath;
                 $fileUploader = new FileUploader("commercial_invoice_file");
                 $fileUploader->saveFile($uploadPath, false);
                 $commercialInvoiceFile = PurchaseOrderFileFactory::createFromArray(array(PurchaseOrderFile::CONTENT => $filePath . $fileUploader->getFileName(), PurchaseOrderFile::TYPE => File::$typeFile["typeFile"], PurchaseOrderFile::DOCUMENT_TYPE => PurchaseOrderFile::$DocumentType["CommercialInvoice"], PurchaseOrderFile::ID_PURCHASE_ORDER => $result->purchaseOrderResult->id));
                 $this->getPurchaseOrderFileCatalog()->create($commercialInvoiceFile);
                 if ($_FILES["packing_list_file"]["name"] != "") {
                     $fileUploader = new FileUploader("packing_list_file");
                     $fileUploader->saveFile($uploadPath, false);
                     $packingListFile = PurchaseOrderFileFactory::createFromArray(array(PurchaseOrderFile::CONTENT => $filePath . $fileUploader->getFileName(), PurchaseOrderFile::TYPE => File::$typeFile["typeFile"], PurchaseOrderFile::DOCUMENT_TYPE => PurchaseOrderFile::$DocumentType["PackingList"], PurchaseOrderFile::ID_PURCHASE_ORDER => $result->purchaseOrderResult->id));
                     $this->getPurchaseOrderFileCatalog()->create($packingListFile);
                 }
                 $purchaseOrderCommercialInvoice = PurchaseOrderCommercialInvoiceFactory::createFromArray(array(PurchaseOrderCommercialInvoice::ID_PURCHASE_ORDER => $result->purchaseOrderResult->id, PurchaseOrderCommercialInvoice::COMMERCIAL_INVOICE_NUMBER => $folio));
                 $this->getPurchaseOrderCommercialInvoiceCatalog()->create($purchaseOrderCommercialInvoice);
                 $purchaseOrder = PurchaseOrderQuery::create()->findByPKOrThrow($purchaseOrderCommercialInvoice->getIdPurchaseOrder(), $this->i18n->_("The purchase order with id{$purchaseOrderEntry->getIdPurchaseOrder()} does not exist"));
                 $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrderCommercialInvoice->getIdPurchaseOrder())->find();
                 $purchaseOrderPaymentManager = new PurchaseOrderPaymentsManager();
                 $purchaseOrderPaymentManager->createPaymentTerms($purchaseOrderEntries);
                 $docNum = PurchaseOrderQuery::create()->findByPK($result->purchaseOrderResult->id)->getSapDocumentNumber();
                 $this->setFlash('ok', $this->i18n->_("The purchase Order with DocNum {$docNum} was saved correctly"));
                 $this->newLogForCreate($purchaseOrder);
                 $this->newLogForUploadCI($purchaseOrder);
                 $this->getEventDispatcherService()->dispatchPurchaseOrderEvent($purchaseOrder, PurchaseOrderEvent::PURCHASEORDER_INSPECTION_PASSED, $purchaseOrderEntries);
                 $this->getEventDispatcherService()->dispatchPurchaseOrderEvent($purchaseOrder, PurchaseOrderEvent::PURCHASEORDER_CREATED, $purchaseOrderEntries);
                 $this->getPurchaseOrderCommercialInvoiceCatalog()->commit();
             } catch (Exception $e) {
                 $this->getPurchaseOrderCommercialInvoiceCatalog()->rollBack();
                 $this->setFlash('error', $this->i18n->_($e->getMessage()));
             }
         } else {
             $this->setFlash('error', $result->purchaseOrderResult->code . " - " . $result->purchaseOrderResult->message);
         }
     }
     $this->_redirect('purchase-order/list');
 }