public function newPurchaseOrderAction()
 {
     $this->view->contentTitle = $this->i18n->_("New Purchase Order");
     $this->view->proformasInvoiceEntries = $proformaInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::LINE_STATUS, ProformaInvoiceEntry::$LineStatus["Open"])->whereAdd(ProformaInvoiceEntry::STATUS, ProformaInvoiceEntry::$Status["End Production"])->find();
     if (!$proformaInvoiceEntries->count()) {
         $this->setFlash('warning', $this->i18n->_('There are no Proforma Invoice Lines to be consolidated.'));
         $this->_redirect('purchase-order/list');
     }
     if (!$proformaInvoiceEntries->isEmpty()) {
         $this->view->inspections = InspectionQuery::create()->whereAdd(Inspection::ID_INSPECTION_TYPE, Inspection::$inspectionsArray["Pre-shipment"])->whereAdd(Inspection::ID_PROFORMA_INVOICE, $proformaInvoiceEntries->getIdProformasInvoice(), InspectionQuery::IN)->find();
         $this->view->proformasInvoice = $proformasInvoice = ProformaInvoiceQuery::create()->whereAdd(ProformaInvoice::ID_PROFORMA_INVOICE, $proformaInvoiceEntries->getIdProformasInvoice(), ProformaInvoiceQuery::IN)->find();
         $this->view->products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $proformaInvoiceEntries->getIdProducts(), ProductQuery::IN)->find();
         $this->view->suppliers = $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDCODE, $proformasInvoice->getDistinctSuppliers(), SapSupplierQuery::IN)->find();
         $this->view->courtyards = CourtyardQuery::create()->whereAdd(Courtyard::ID_COURTYARD, $proformasInvoice->getDistinctCourtyards(), CourtyardQuery::IN)->find();
     }
     $this->view->currencies = CurrencyQuery::create()->find();
     $this->view->setTpl("Purchase");
 }
Esempio n. 2
0
 /**
  *
  * @param \Application\Model\Bean\Collection\PurchaseOrderCollection $purchaseOrderCollection
  * @param Boolean $ajax
  * @return array $purchaseOrders
  */
 private function getPurchaseOrdersWithEntries(PurchaseOrderCollection $purchaseOrderQuery, $ajax = false)
 {
     $i = 0;
     while ($purchaseOrder = $purchaseOrderQuery->read()) {
         $purchaseOrders[$i]['edit_products'] = false;
         $purchaseOrders[$i]['individual_packs'] = $this->i18n->_('Not Available');
         $purchaseOrders[$i]['weight'] = $this->i18n->_('Not Available');
         $purchaseOrders[$i]['cbm'] = $this->i18n->_('Not Available');
         $purchaseOrders[$i]['price'] = $this->i18n->_('Not Available');
         $purchaseOrders[$i]['id_purchase_order'] = $this->i18n->_('Not Available');
         $purchaseOrders[$i]['currency'] = $purchaseOrder->getIdCurrency();
         $idCourtyard = $purchaseOrder->getIdCourtyard();
         if (CourtyardQuery::create()->whereAdd(Courtyard::ID_COURTYARD, $purchaseOrder->getIdCourtyard())->count()) {
             $purchaseOrders[$i]['id_forwarder'] = CourtyardQuery::create()->findByPK($purchaseOrder->getIdCourtyard())->getIdForwarder();
             $purchaseOrders[$i]['id_departure_port'] = CourtyardQuery::create()->findByPK($purchaseOrder->getIdCourtyard())->getIdPortCustom();
             $courtyard = CourtyardQuery::create()->findByPK($purchaseOrder->getIdCourtyard());
             $purchaseOrders[$i]['departure_port'] = PortCustomQuery::create()->findByPK($courtyard->getIdPortCustom())->getName();
             if (ForwarderQuery::create()->whereAdd(Forwarder::ID_FORWARDER, $courtyard->getIdForwarder())->count()) {
                 $purchaseOrders[$i]['forwarder'] = ForwarderQuery::create()->findByPK($courtyard->getIdForwarder())->getName();
             } else {
                 $purchaseOrders[$i]['forwarder'] = 'Not available';
             }
         }
         if ($ajax) {
             $purchaseOrders[$i]['country'] = utf8_encode($country);
         } else {
             $country;
         }
         if (CountryQuery::create()->whereAdd(Country::CODE, $purchaseOrder->getIdDestinationCountry())->count()) {
             $purchaseOrders[$i]['id_destination_country'] = $purchaseOrder->getIdDestinationCountry();
             $purchaseOrders[$i]['country'] = CountryQuery::create()->findByPK($purchaseOrder->getIdDestinationCountry())->getName();
         }
         $purchaseOrders[$i]['courtyard_arrival_date'] = $purchaseOrder->getCourtyardArrivalDate();
         $purchaseOrders[$i]['invoice_number'] = $this->getPurchaseOrderCommercialInvoice($purchaseOrder->getIdPurchaseOrder())->getCommercialInvoiceNumber();
         $purchaseOrderEntryQuery = null;
         $purchaseOrderEntryQuery = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->find();
         $price = 0;
         $cbm = 0;
         $individual_packs = 0;
         $cartons = 0;
         $quantity = 0;
         $weight = 0;
         $valuable = array();
         $j = 0;
         $packingList = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['PackingList'])->count();
         $commercialInvoice = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['CommercialInvoice'])->count();
         if ($packingList) {
             $purchaseOrders[$i]['packing_list'] = true;
         } else {
             $purchaseOrders[$i]['packing_list'] = false;
         }
         if ($commercialInvoice) {
             $purchaseOrders[$i]['commercial_invoice'] = true;
         } else {
             $purchaseOrders[$i]['commercial_invoice'] = false;
         }
         $entries = null;
         while ($purchaseOrderEntry = $purchaseOrderEntryQuery->read()) {
             if (ProductQuery::create()->whereAdd(Product::ITEM_CODE, $purchaseOrderEntry->getIdProduct())->count()) {
                 $product = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $purchaseOrderEntry->getIdProduct())->findOne();
             }
             if ($product->getMcParts()) {
                 $cartonsEntry = ceil(floatval($purchaseOrderEntry->getQuantity()) / $product->getMcParts());
             } else {
             }
             $volume = $product->getMcFront() * $product->getMcHeight() * $product->getMcDepth() / 1000000;
             $cbm += $cartonsEntry * $volume;
             $weight += $cartonsEntry * $product->getMcWeight();
             $price += $purchaseOrderEntry->getAmount();
             $cartons += $cartonsEntry;
             $quantity += floatval($purchaseOrderEntry->getQuantity());
             if ($product->getMcWeight() * $cartonsEntry == 0 || ($volume = $product->getMcFront() * $product->getMcHeight() * $product->getMcDepth() / 1000000) == 0) {
                 $purchaseOrders[$i]['edit_products'] = true;
             }
             $entries[$j]['id_product'] = $product->getItemCode();
             $entries[$j]['important'] = $product->getImportant();
             $entries[$j]['item_code'] = $product->getItemCode();
             $entries[$j]['product'] = $product->getItemName();
             $entries[$j]['price'] = $purchaseOrderEntry->getPrice();
             $entries[$j]['amount'] = $purchaseOrderEntry->getAmount();
             $entries[$j]['cartons'] = $cartonsEntry;
             $entries[$j]['quantity'] = floatval($purchaseOrderEntry->getQuantity());
             $entries[$j]['weight'] = $product->getMcWeight() * $cartonsEntry;
             $entries[$j]['volume'] = $volume * $cartonsEntry;
             if (FreightFareQuery::create()->whereAdd(FreightFare::ID_FREIGHT_FARE, $product->getDefaultFreightFare())->count()) {
                 $idFreightType = FreightFareQuery::create()->findByPK($product->getDefaultFreightFare())->getIdFreightType();
                 $entries[$j]['default_shipping'] = FreightTypeQuery::create()->findByPK($idFreightType)->getName();
             } else {
                 $entries[$j]['default_shipping'] = $this->i18n->_('Not Available');
             }
             //
             if ($product->getImportPermit()) {
                 $importPermit = FileQuery::create()->findByPK($product->getImportPermit());
                 if ($importPermit) {
                     $entries[$j]['import_permit'] = true;
                 } else {
                     $entries[$j]['import_permit'] = false;
                 }
             } else {
                 $entries[$j]['import_permit'] = false;
             }
             $entries[$j]['row_status'] = 'success';
             $purchaseOrders[$i]['row_status'] = 'success';
             if (!$entries[$j]['import_permit']) {
                 $entries[$j]['row_status'] = 'error';
                 $purchaseOrders[$i]['row_status'] = 'error';
                 $entries[$j]['label'] = $this->i18n->_('This product, does not have an Import Clearance Document.');
                 $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order has entries without Import Clearance.');
             } else {
                 if (!$purchaseOrders[$i]['commercial_invoice']) {
                     $purchaseOrders[$i]['row_status'] = 'error';
                     $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order, does not have a Commercial Invoice Document.');
                 } else {
                     if (!$purchaseOrders[$i]['packing_list']) {
                         $purchaseOrders[$i]['row_status'] = 'error';
                         $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order, does not have a Packing List Document.');
                     }
                 }
             }
             if ($product->getImportant()) {
                 $entries[$j]['row_status'] = 'warning';
                 $purchaseOrders[$i]['row_status'] = 'warning';
                 $entries[$j]['label'] = $this->i18n->_('This product is small and valuable.');
                 $purchaseOrders[$i]['label'] = $this->i18n->_('This Purchase Order has small and valuable stuff.');
             }
             $j++;
         }
         if (count($valuable) == 1) {
             $purchaseOrders[$i]['importance'] = $valuable[1];
         } else {
             $flag = 0;
             $value = $valuable[1];
             for ($j = 2; $j <= count($valuable); $j++) {
                 if ($valuable[$j] != $value) {
                     $value = 2;
                     break;
                 }
             }
             $purchaseOrders[$i]['importance'] = $value;
         }
         switch ($purchaseOrders[$i]['importance']) {
             case '1':
                 $purchaseOrders[$i]['importance'] = $this->i18n->_('Yes');
                 break;
             case '2':
                 $purchaseOrders[$i]['importance'] = $this->i18n->_('Mixed');
                 break;
             default:
                 $purchaseOrders[$i]['importance'] = $this->i18n->_('No');
         }
         $packingList = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['PackingList'])->count();
         $commercialInvoice = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['CommercialInvoice'])->count();
         if ($packingList) {
             $purchaseOrders[$i]['packing_list'] = true;
         } else {
             $purchaseOrders[$i]['packing_list'] = false;
         }
         if ($commercialInvoice) {
             $purchaseOrders[$i]['commercial_invoice'] = true;
         } else {
             $purchaseOrders[$i]['commercial_invoice'] = false;
         }
         $cartons = 0;
         $quantity = 0;
         $weight = 0;
         $cbm = 0;
         $price = 0;
         foreach ($entries as $entry) {
             $cartons += intval($entry['cartons']);
             $quantity += intval($entry['quantity']);
             $weight += $entry['weight'];
             $cbm += $entry['volume'];
             $price += $entry['price'] * $entry['quantity'];
         }
         $purchaseOrders[$i]['entries'] = $entries;
         $purchaseOrders[$i]['cartons'] = $cartons;
         $purchaseOrders[$i]['quantity'] = $quantity;
         $purchaseOrders[$i]['weight'] = $weight;
         $purchaseOrders[$i]['cbm'] = $cbm;
         $purchaseOrders[$i]['price'] = $price;
         $purchaseOrders[$i]['id_purchase_order'] = $purchaseOrder->getIdPurchaseOrder();
         $purchaseOrders[$i]['doc_num'] = $purchaseOrder->getSapDocumentNumber();
         if ($purchaseOrder->getCourtyardArrivalDate() != null) {
             $purchaseOrders[$i]['courtyard_arrival_date'] = $purchaseOrder->getCourtyardArrivalDate();
         }
         $i++;
     }
     return $purchaseOrders;
 }
Esempio n. 3
0
 /**
  *
  * @return array
  */
 public function editAction()
 {
     try {
         $this->view->contentTitle = $this->i18n->_("Purchase Order Edit");
         $idPurchaseOrder = $this->getRequest()->getParam('id');
         $this->view->purchaseOrder = $purchaseOrder = PurchaseOrderQuery::create()->findByPKOrThrow($idPurchaseOrder, $this->i18n->_("The Purchase Order width id {$idPurchaseOrder} does not exist"));
         $accessRole = $this->getUser()->getAccessRole();
         $accessRoleManager = new AccessRoleManager();
         $availableSuppliers = $accessRoleManager->getAssociateSuppliers($accessRole);
         if (!$availableSuppliers->containsIndex($purchaseOrder->getIdSupplier())) {
             throw new PurchaseOrderException($this->i18n->_("You don't have permission to edit this Purchase Order."));
         }
         $this->view->supplier = $supplier = $availableSuppliers->getByPK($purchaseOrder->getIdSupplier());
         // Search Purchase Order Entries by id purchase order
         $purchaseOrderEntryManager = new PurchaseOrderEntryManager();
         $purchaseOrderEntries = $purchaseOrderEntryManager->getPurchaseOrderEntries($purchaseOrder);
         $this->view->entries = Zend_Json::encode($purchaseOrderEntryManager->getEntriesToCompleteInfoArray($purchaseOrderEntries));
         // Search the courtyards by id
         if ($purchaseOrder->getIdCourtyard()) {
             $courtyard = CourtyardQuery::create()->findByPKOrElse($purchaseOrder->getIdCourtyard(), new Courtyard());
             if ($courtyard->getIdForwarder()) {
                 $ports = PortCustomQuery::create()->innerJoinForwarder()->whereAdd("Forwarder." . Forwarder::ID_FORWARDER, $courtyard->getIdForwarder())->find()->toCombo();
                 $portCombo = array("" => "Select a Port") + $ports;
                 $courtyards = CourtyardQuery::create()->whereAdd(Courtyard::ID_PORT_CUSTOM, $courtyard->getIdPortCustom())->whereAdd(Courtyard::ID_FORWARDER, $courtyard->getIdForwarder())->find()->toCombo();
                 $courtyardCombo = array("" => "Select Courtyard") + $courtyards;
             } else {
                 $portCombo = array("" => "Select a Port");
                 $courtyardCombo = array("" => "Select Courtyard");
             }
         } else {
             $courtyard = new Courtyard();
             $portCombo = array("" => "Select a Port");
             $courtyardCombo = array("" => "Select a Courtyard");
         }
         $this->view->forwarders = array("" => "Select Forwarder") + ForwarderQuery::create()->find()->toCombo();
         $this->view->portsCustom = $portCombo;
         $this->view->courtyards = $courtyardCombo;
         $this->view->courtyard = $courtyard;
         $this->view->currencies = CurrencyQuery::create()->find();
         $this->view->warehouses = WarehouseQuery::create()->find()->toCombo($this->i18n->_("Select a Warehouse"));
         $this->view->warehouseStore = $warehouseStore = WarehouseStoreQuery::create()->findByPKOrThrow($purchaseOrderEntries->getOne()->getIdWarehouseStore(), $this->i18n->_("The Warehouse Store with Code {$purchaseOrderEntries->current()->getIdWarehouseStore()} does not exist."));
         $this->view->warehouseStores = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::LOCATION, $warehouseStore->getLocation())->whereAdd(WarehouseStore::TYPE, WarehouseStore::$Type["ppv"])->find()->toCombo($this->i18n->_("Select a Warehouse Store"));
         $this->view->status = array("" => $this->i18n->_("Select a Status"), PurchaseOrder::$Status["New"] => PurchaseOrder::$StatusNames[PurchaseOrder::$Status["New"]], PurchaseOrder::$Status["Ready"] => PurchaseOrder::$StatusNames[PurchaseOrder::$Status["Ready"]]);
         $this->view->uploadBLHouseStatus = PurchaseOrder::$Status["Ready"];
         $this->view->purchaseOrderCommercialInvoice = PurchaseOrderCommercialInvoiceQuery::create()->whereAdd(PurchaseOrderCommercialInvoice::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->findOneOrElse(new PurchaseOrderCommercialInvoice());
         $purchaseOrderPaymentsManager = new PurchaseOrderPaymentsManager();
         $this->view->payments = Zend_Json::encode($purchaseOrderPaymentsManager->getCondensedPayments($purchaseOrder));
     } catch (Exception $e) {
         $this->setFlash('error', $e->getMessage());
         $this->_redirect('purchase-order/list');
     }
 }
Esempio n. 4
0
 public function jsonForwarderCourtyardAction()
 {
     $idForwarder = $this->getRequest()->getParam("idForwarder");
     $courtyards = CourtyardQuery::create()->whereAdd(Courtyard::ID_FORWARDER, $idForwarder)->find();
     die(Zend_Json::encode(array("response" => $courtyards->toArray())));
 }
Esempio n. 5
0
 /**
  * This action get all forwarder's contacts without courtyard
  *
  * @author Erick Guevara Martínez
  * @return json
  */
 public function forwardercontactsAction()
 {
     // Get the forwarder and courtyard ids
     $idForwarder = $this->getRequest()->getParam("idForwarder");
     $idCourtyard = $this->getRequest()->getParam("idCourtyard");
     // Get the forwarder info
     $forwarder = ForwarderQuery::create()->findByPKOrThrow($idForwarder, $this->i18n->_("The forward with id {$idForwarder} does not exist"));
     if (!($idCourtyard > 0)) {
         $idCourtyard == null;
     }
     // Get all forwarder's contacts
     $contacts = ContactQuery::create()->whereAdd(Contact::ID_COMPANY, $forwarder->getIdCompany())->find()->toCombo();
     // Get all courtyards with forwarder's contact assign and exclude the courtyard param id
     $courtyards = CourtyardQuery::create()->whereAdd(Courtyard::ID_FORWARDER, $forwarder->getIdForwarder())->whereAdd(Courtyard::ID_COURTYARD, $idCourtyard, "<>")->find();
     // Unset the forwarder's contacts with courtyard assign
     foreach ($courtyards as $courtyard) {
         unset($contacts[$courtyard->getIdContact()]);
     }
     die(Zend_Json::encode(array("response" => $contacts)));
 }
Esempio n. 6
0
 /**
  * this function is used to ajax requests, return all courtyards with the recived id port and idForwarder
  *
  * @author Erick Guevara Martínez
  * @return Json
  */
 public function getCourtyardsByIdPortAction()
 {
     $idPort = $this->getRequest()->getParam("idPort");
     $idForwarder = $this->getRequest()->getParam("idForwarder");
     $courtyards = CourtyardQuery::create()->whereAdd(Courtyard::ID_PORT_CUSTOM, $idPort, BaseQuery::EQUAL)->whereAdd(Courtyard::ID_FORWARDER, $idForwarder, BaseQuery::EQUAL)->find()->toArray();
     die(Zend_Json::encode(array("response" => $courtyards)));
 }