Esempio n. 1
0
 /**
  * 
  */
 public function getListResultsAction()
 {
     $params = $this->getRequest()->getParams();
     $freightType = FreightTypeQuery::create()->filter($params)->page($params['page'], $this->getMaxPerPage())->find();
     die(json_encode($freightType->toArray()));
 }
Esempio n. 2
0
 /**
  *
  */
 public function exportToExcelAction()
 {
     $post = $this->getRequest()->getParams();
     $post['id_transit'] = "%" . $post['id_transit'] . "%";
     $freightFares = FreightFareQuery::create()->filter($post)->find();
     $i = 1;
     while ($freightFare = $freightFares->read()) {
         $port = \Application\Query\PortCustomQuery::create()->whereAdd(PortCustom::ID_PORT_CUSTOM, $freightFare->getFobPort())->findOne();
         $destination = \Application\Query\PortCustomQuery::create()->whereAdd(PortCustom::ID_PORT_CUSTOM, $freightFare->getDestinationPort())->findOne();
         $freightTYpe = FreightTypeQuery::create()->whereAdd(FreightType::ID_FREIGHT_TYPE, $freightFare->getIdFreightType())->findOne();
         $forwarder = ForwarderQuery::create()->whereAdd(Forwarder::ID_FORWARDER, $freightFare->getIdForwarder())->findOne();
         $currency = \Application\Query\CurrencyQuery::create()->whereAdd(\Application\Model\Bean\Currency::CURRCODE, $freightFare->getIdCurrency())->findOne();
         $data[$i] = array($freightFare->getIdFreightFare(), $freightFare->getIdTransit(), $port->getName(), $destination->getName(), $freightTYpe->getName(), $freightFare->getNotes(), $freightFare->getTt(), $freightFare->getFrecuency(), $forwarder->getName(), $freightFare->getGoodThrough(), $freightFare->getUnitName(), $freightFare->getUNitCost(), $freightFare->getPeak(), $freightFare->getStatusName());
         $i++;
     }
     $header = array($this->i18n->_('ID'), $this->i18n->_('ID-Transit'), $this->i18n->_('FOB Port'), $this->i18n->_('Destination Port'), $this->i18n->_('Freight Type'), $this->i18n->_('Notes'), $this->i18n->_('Transit Time'), $this->i18n->_('Frecuency'), $this->i18n->_('Forwarder'), $this->i18n->_('Good Through'), $this->i18n->_('Unit'), $this->i18n->_('Unit Cost'), $this->i18n->_('Peak/Unit'), $this->i18n->_('Status'));
     $title = $this->i18n->_('Freight Fares Report');
     $fileName = $this->i18n->_('Freight_fares_report');
     $tableColumnsWidth = array('mini', 'medium', 'medium', 'medium', 'medium', 'medium', 'medium', 'medium', 'medium', 'medium', 'mini', 'mini', 'mini');
     $report = new SimpleListReport();
     $report->setTableTitle($title);
     $report->setTableHeaders($header);
     $report->setTableContent($data);
     $report->setFilename($fileName);
     $report->setTableColumnsWidth($tableColumnsWidth);
     $report->createSpreadsheet();
 }
Esempio n. 3
0
 private function getPurchaseOrderEntries($idPurchaseOrder)
 {
     $purchaseOrderQuery = PurchaseOrderQuery::create()->findByPK($idPurchaseOrder);
     if ($purchaseOrderQuery) {
         $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $idPurchaseOrder)->find();
         while ($purchaseOrder = $purchaseOrderQuery->read()) {
             $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;
             while ($purchaseOrderEntry = $purchaseOrderEntryQuery->read()) {
                 $product = ProductQuery::create()->findByPK($purchaseOrderEntry->getIdProduct());
                 $mcParts = $product->getMcParts();
                 if (!empty($mcParts)) {
                     $cartonsEntry = floor($purchaseOrderEntry->getQuantity() / $product->getMcParts());
                 } else {
                     $this->setFlash('warning', $this->i18n->_("You must edit MC Parts, it cannot be cero."));
                     $this->_redirect('product/edit/id/' . $product->getItemCode());
                 }
                 $volume = $product->getMcFront() * $product->getMcHeight() * $product->getMcDepth() / 1000000;
                 $cbm += $cartonsEntry * $volume;
                 $weight += $cartonsEntry * $product->getMcWeight();
                 $price += $purchaseOrderEntry->getQuantity() * $purchaseOrderEntry->getPrice();
                 $cartons += $cartonsEntry;
                 $quantity += $purchaseOrderEntry->getQuantity();
                 $entry[$j]['id_product'] = $product->getItemCode();
                 $supplier = SapSupplierQuery::create()->findByPK($purchaseOrder->getIdSupplier());
                 if ($supplier) {
                     $entry[$j]['supplier'] = $supplier->getCardCode();
                     $entry[$j]['id_currency'] = $purchaseOrder->getIdCurrency();
                     // 						echo $purchaseOrder->getIdCurrency();die;
                     $entry[$j]['currency_code'] = CurrencyQuery::create()->findByPK($purchaseOrder->getIdCurrency())->getCurrCode();
                     $entry[$j]['currency_name'] = CurrencyQuery::create()->findByPK($purchaseOrder->getIdCurrency())->getCurrName();
                     // 						$entry[$j]['currency_symbol'] = CurrencyQuery::create()->findByPK($supplier->getIdCurrency())->getSymbol();
                 } else {
                     $entry[$j]['supplier'] = $this->i18n->_('Not Available');
                 }
                 $entry[$j]['line'] = $purchaseOrderEntry->getLine();
                 $tariff = CustomsTariffCodeQuery::create()->findByPK($product->getIdCustomsTariffCode());
                 $entry[$j]['tariff_code'] = $tariff->getName();
                 $entry[$j]['tariff_percentage'] = $tariff->getPercent();
                 $entry[$j]['id_purchase_order_entry'] = $purchaseOrderEntry->getIdPurchaseOrderEntry();
                 $entry[$j]['id_purchase_order'] = $purchaseOrder->getIdPurchaseOrder();
                 $entry[$j]['doc_num'] = $purchaseOrder->getSapDocumentNumber();
                 $entry[$j]['num_purchase_order'] = $purchaseOrder->getIdPurchaseOrder();
                 $entry[$j]['invoice_number'] = $purchaseOrder->getInvoiceNumber();
                 $entry[$j]['cartons'] = $purchaseOrderEntry->getCartons();
                 $entry[$j]['carton_parts'] = $purchaseOrderEntry->getCartonParts();
                 $entry[$j]['loose_pieces'] = $purchaseOrderEntry->getLoosePieces();
                 $entry[$j]['total'] = $purchaseOrderEntry->getTotal();
                 $entry[$j]['invoice_total'] = $purchaseOrderEntry->getInvoiceTotal();
                 $entry[$j]['diference'] = $purchaseOrderEntry->getDiference();
                 $entry[$j]['quantity_by_warehouse'] = $purchaseOrderEntry->getQuantityByWarehouse();
                 $entry[$j]['document_number'] = $purchaseOrderEntry->getDocumentNumber();
                 $entry[$j]['item_code'] = $product->getItemCode();
                 $entry[$j]['item_name'] = $product->getItemName();
                 $entry[$j]['price'] = $purchaseOrderEntry->getPrice();
                 $entry[$j]['amount'] = $purchaseOrderEntry->getQuantity() * $purchaseOrderEntry->getPrice();
                 $entry[$j]['cartons'] = $purchaseOrderEntry->getCartons();
                 $entry[$j]['quantity'] = $purchaseOrderEntry->getQuantity();
                 $entry[$j]['weight'] = $product->getMcWeight() * $cartonsEntry;
                 $entry[$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();
                 }
                 $j++;
             }
         }
         return $entry;
     } else {
         return null;
     }
 }
Esempio n. 4
0
 /**
  * 
  */
 public function getListResultsAction()
 {
     $storage = $this->getStorageService();
     $params = $this->getRequest()->getParams();
     $page = $params['page'];
     $productQuery = ProductQuery::create()->useFileCache()->filter($params);
     $colors = ColorQuery::create()->find();
     $brands = BrandQuery::create()->find();
     $productCollection = $productQuery->find();
     $freightFareCollection = FreightFareQuery::create()->find();
     $freightTypeCollection = FreightTypeQuery::create()->find();
     $customsTariffCodeCollection = CustomsTariffCodeQuery::create()->find();
     $incotermCollection = IncotermQuery::create()->useFileCache()->find();
     $products = $productQuery->findByPage($page, $this->getMaxPerPage());
     // 		if (!$productStorage)
     // 			$storage->saveValue($productQuery->find(), 'products');
     $productPrintingArea = ProductPrintingAreaQuery::create()->addColumn(ProductPrintingArea::ID_PRODUCT)->whereAdd(ProductPrintingArea::ID_PRODUCT, $products->getKeyMother(), ProductPrintingAreaQuery::IN)->fetchCol();
     //
     $arrayProducts = array();
     while ($products->valid()) {
         $product = $products->read();
         $hasPrintingArea = in_array($product->getKeyMother(), $productPrintingArea) ? 1 : 0;
         $arrayProducts[$product->getIndex()] = $product->toArrayForList() + array("has_printing_area" => $hasPrintingArea);
     }
     die(json_encode($arrayProducts));
 }
 /**
  *
  * @param unknown_type $idPurchaseOrder
  */
 private function getPurchaseOrderEntries($idPurchaseOrder)
 {
     $purchaseOrderQuery = PurchaseOrderQuery::create()->findByPK($idPurchaseOrder);
     if ($purchaseOrderQuery) {
         $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $idPurchaseOrder)->find();
         while ($purchaseOrder = $purchaseOrderQuery->read()) {
             $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;
             while ($purchaseOrderEntry = $purchaseOrderEntryQuery->read()) {
                 $product = ProductQuery::create()->findByPK($purchaseOrderEntry->getIdProduct());
                 $cartonsEntry = ceil($purchaseOrderEntry->getQuantity() / $product->getMcParts());
                 $volume = $product->getMcFront() * $product->getMcHeight() * $product->getMcDepth() / 1000000;
                 $cbm += $cartonsEntry * $volume;
                 $weight += $cartonsEntry * $product->getMcWeight();
                 $price += $purchaseOrderEntry->getQuantity() * $purchaseOrderEntry->getPrice();
                 $cartons += $cartonsEntry;
                 $quantity += $purchaseOrderEntry->getQuantity();
                 $entry[$j]['id_product'] = $product->getItemCode();
                 $entry[$j]['line'] = $purchaseOrderEntry->getLine();
                 $entry[$j]['id_purchase_order_entry'] = $purchaseOrderEntry->getLine();
                 $entry[$j]['id_purchase_order'] = $purchaseOrder->getIdPurchaseOrder();
                 $entry[$j]['doc_num'] = $purchaseOrder->getSapDocumentNumber();
                 $entry[$j]['cartons'] = $purchaseOrderEntry->getCartons();
                 $entry[$j]['carton_parts'] = $purchaseOrderEntry->getCartonParts();
                 $entry[$j]['loose_pieces'] = $purchaseOrderEntry->getLoosePieces();
                 $entry[$j]['total'] = $purchaseOrderEntry->getTotal();
                 $entry[$j]['invoice_total'] = $purchaseOrderEntry->getInvoiceTotal();
                 $entry[$j]['diference'] = $purchaseOrderEntry->getDiference();
                 $entry[$j]['quantity_by_warehouse'] = $purchaseOrderEntry->getQuantityByWarehouse();
                 $entry[$j]['document_number'] = $purchaseOrderEntry->getDocumentNumber();
                 $entry[$j]['item_code'] = $product->getItemCode();
                 $entry[$j]['item_name'] = $product->getItemName();
                 $entry[$j]['price'] = $purchaseOrderEntry->getPrice();
                 $entry[$j]['amount'] = $purchaseOrderEntry->getAmount();
                 $entry[$j]['cartons'] = $purchaseOrderEntry->getCartons();
                 $entry[$j]['quantity'] = $purchaseOrderEntry->getQuantity();
                 $entry[$j]['weight'] = $product->getMcWeight() * $cartonsEntry;
                 $entry[$j]['volume'] = number_format($volume * $cartonsEntry, 2);
                 if (FreightFareQuery::create()->whereAdd(FreightFare::ID_FREIGHT_FARE, $product->getDefaultFreightFare())->count()) {
                     $idFreightType = FreightFareQuery::create()->findByPK($product->getDefaultFreightFare())->getIdFreightType();
                     $entry[$j]['default_shipping'] = FreightTypeQuery::create()->findByPK($idFreightType)->getName();
                 }
                 $j++;
             }
         }
         return $entry;
     } else {
         return null;
     }
 }
 /**
  *
  * @param string $idProduct
  * @return array
  */
 private function getLandedCost($idProduct, Application\Model\Bean\ProductPriceList $productPriceList, $productPrice = null)
 {
     $product = ProductQuery::create()->findByPK($idProduct);
     if (FreightFareQuery::create()->whereAdd(FreightFare::ID_FREIGHT_FARE, $product->getDefaultFreightFare())->count()) {
         $freightFare = FreightFareQuery::create()->findByPK($product->getDefaultFreightFare());
         $freightType = FreightTypeQuery::create()->findByPK($freightFare->getIdFreightType());
     } else {
         $result['message'] = $this->i18n->_('You must edit the Freight Fare.');
         $result['result'] = false;
         return $result;
     }
     if (CustomsTariffCodeQuery::create()->whereAdd(CustomsTariffCode::CODE, $product->getIdCustomsTariffCode())->count()) {
         $customsTariffCode = CustomsTariffCodeQuery::create()->findByPK($product->getIdCustomsTariffCode());
     } else {
         $result['message'] = $this->i18n->_('You must edit the Customs Code.');
         $result['result'] = false;
         return $result;
     }
     $unit = $freightFare->getUnit();
     $unitCost = $freightFare->getUnitCost();
     $maxLoad = $freightType->getMaxLoad();
     $cbmByCarton = $product->getCbmByCarton();
     if (!$cbmByCarton) {
         $result['message'] = $this->i18n->_('You must edit the Cartons.');
         $result['result'] = false;
         return $result;
     }
     $containerCartons = ceil($maxLoad / $cbmByCarton);
     $containerWeight = $containerCartons * $product->getMcWeight();
     $containerTotalProducts = $containerCartons * $product->getMcParts();
     if (!$containerTotalProducts) {
         $result['message'] = $this->i18n->_('You must edit Master Carton Parts.');
         $result['result'] = false;
         return $result;
     }
     if (!$productPrice) {
         if (!$product->getCost()) {
             $result['message'] = $this->i18n->_('You must edit the Price.');
             $result['result'] = false;
             return $result;
         }
         $productCost = $productPriceList->getProductPriceInUsd() * $containerTotalProducts;
     } else {
         $productCost = $productPrice * $containerTotalProducts;
     }
     switch ($unit) {
         case FreightFare::$Units['CBM']:
             $freightCost = $unitCost * $maxLoad;
             break;
         case FreightFare::$Units['Container']:
             $freightCost = $unitCost;
             break;
         case FreightFare::$Units['KG']:
             $freightCost = $unitCost * $containerWeight;
             break;
     }
     $productCostAndFreightCost = $productCost + $freightCost;
     $igi = $productCostAndFreightCost * $customsTariffCode->getPercent() / 100;
     $dta = $productCostAndFreightCost * 0.8 / 100;
     $iva = ($productCostAndFreightCost + $dta + $igi) * 0.16;
     $totalCostProduct = $productCostAndFreightCost + $igi + $dta + $iva;
     $landedCost = $totalCostProduct / $containerTotalProducts;
     $result['message'] = $this->i18n->_('yep! everything goes well');
     $result['result'] = strval(round($landedCost, 2));
     return $result;
 }
Esempio n. 7
0
 /**
  *
  * @param unknown_type $idPurchaseOrder
  */
 private function getPurchaseOrderEntries($idPurchaseOrder)
 {
     $purchaseOrderQuery = PurchaseOrderQuery::create()->findByPK($idPurchaseOrder);
     if ($purchaseOrderQuery) {
         $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $idPurchaseOrder)->fetchAll();
         foreach ($purchaseOrderQuery as $purchaseOrder) {
             $purchaseOrderEntryQuery = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->notCancelled()->fetchAll();
             $price = 0;
             $cbm = 0;
             $individual_packs = 0;
             $cartons = 0;
             $quantity = 0;
             $weight = 0;
             $valuable = array();
             $j = 0;
             foreach ($purchaseOrderEntryQuery as $purchaseOrderEntry) {
                 $product = ProductQuery::create()->findByPK($purchaseOrderEntry['id_product'])->toArray();
                 if (!empty($product['mc_parts'])) {
                     $cartonsEntry = intval($purchaseOrderEntry['quantity'] / $product['mc_parts']);
                     $loosePieces = $purchaseOrderEntry['quantity'] % $product['mc_parts'];
                 } else {
                     $this->setFlash('warning', $this->i18n->_("You must edit MC Parts, it cannot be cero."));
                     $this->_redirect('product/edit/id/' . $product['id_product']);
                 }
                 $volume = $product['mc_front'] * $product['mc_height'] * $product['mc_depth'] / 1000000;
                 $cbm += $cartonsEntry * $volume;
                 $weight += $cartonsEntry * $product['mc_weight'];
                 $price += $purchaseOrderEntry['quantity'] * $purchaseOrderEntry['price'];
                 $cartons += $cartonsEntry;
                 $quantity += $purchaseOrderEntry['quantity'];
                 $entry[$j]['id_product'] = $product['id_product'];
                 $entry[$j]['line'] = $purchaseOrderEntry['line'];
                 $entry[$j]['id_purchase_order_entry'] = $purchaseOrderEntry['id_purchase_order_entry'];
                 $entry[$j]['id_purchase_order'] = $purchaseOrderEntry['id_purchase_order'];
                 $entry[$j]['cartons'] = $cartonsEntry;
                 $entry[$j]['carton_parts'] = $product['mc_parts'];
                 $entry[$j]['loose_pieces'] = $loosePieces;
                 $entry[$j]['invoice_total'] = $purchaseOrderEntry['quantity'];
                 $entry[$j]['diference'] = $purchaseOrderEntry['diference'];
                 $entry[$j]['quantity_by_warehouse'] = $purchaseOrderEntry['quantity_by_warehouse'];
                 $entry[$j]['document_number'] = $purchaseOrderEntry['document_number'];
                 $entry[$j]['item_code'] = $product['item_code'];
                 $entry[$j]['item_name'] = $product['item_name'];
                 $entry[$j]['price'] = $purchaseOrderEntry['price'];
                 $entry[$j]['amount'] = $purchaseOrderEntry['quantity'] * $purchaseOrderEntry['price'];
                 $entry[$j]['cartons'] = $purchaseOrderEntry['cartons'];
                 $entry[$j]['quantity'] = $purchaseOrderEntry['quantity'];
                 $entry[$j]['weight'] = $product['mc_weight'] * $cartonsEntry;
                 $entry[$j]['volume'] = number_format($volume * $cartonsEntry, 2);
                 $entry[$j]['default_shipping'] = FreightTypeQuery::create()->findByPK($product['default_shipping'])->getName();
                 $j++;
             }
         }
         return $entry;
     } else {
         return null;
     }
 }
Esempio n. 8
0
 public function getSuggestedFreightAction()
 {
     $volume = $this->getRequest()->getParam("volume");
     $freightTypes = FreightTypeQuery::create()->actives()->find();
     $name = implode(" / ", $freightTypes->getSuggestedFreights($totalVolume)->toCombo());
     die(Zend_Json::encode(array("name" => $name)));
 }
Esempio n. 9
0
 /**
  * @return string
  */
 public function getFreightTypeName()
 {
     $freightTypeName = null;
     if (FreightTypeQuery::create()->whereAdd(FreightType::ID_FREIGHT_TYPE, $this->idFreightType)->count()) {
         $freightTypeName = FreightTypeQuery::create()->findByPK($this->idFreightType)->getName();
     }
     return $freightTypeName;
 }
Esempio n. 10
0
 private function getPurchaseOrders($idFolioImport, $status = null, $in = true)
 {
     $id = $idFolioImport;
     $purchaseOrderFolioQuery = PurchaseOrderFolioQuery::create()->addColumn(PurchaseOrderFolio::ID_PURCHASE_ORDER)->whereAdd(PurchaseOrderFolio::ID_FOLIO_IMPORT, $id);
     if ($status == null) {
         $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->count();
         $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->fetchAll();
     } else {
         if ($in) {
             $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::IN)->count();
             $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::IN)->fetchAll();
         } else {
             $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::NOT_EQUAL)->count();
             $purchaseOrderQuery = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrderFolioQuery, PurchaseOrderQuery::IN)->whereAdd(PurchaseOrder::STATUS, PurchaseOrder::$Status[$status], PurchaseOrderQuery::NOT_EQUAL)->fetchAll();
         }
     }
     if ($query) {
         $i = 0;
         foreach ($purchaseOrderQuery as $purchaseOrder) {
             try {
                 $purchaseOrderEntryQuery = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->fetchAll();
                 $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['id_purchase_order'])->whereAdd(PurchaseOrderFile::DOCUMENT_TYPE, PurchaseOrderFile::$DocumentType['PackingList'])->count();
                 $commercialInvoice = PurchaseOrderFileQuery::create()->whereAdd(PurchaseOrderFile::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->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;
                 }
                 foreach ($purchaseOrderEntryQuery as $purchaseOrderEntry) {
                     $product = ProductQuery::create()->findByPK($purchaseOrderEntry['id_product'])->toArray();
                     if (!empty($product['mc_parts'])) {
                         $cartonsEntry = ceil($purchaseOrderEntry['quantity'] / $product['mc_parts']);
                     } else {
                         $this->setFlash('warning', $this->i18n->_("You must edit MC Parts, it cannot be cero."));
                         $this->_redirect('product/edit/id/' . $product['id_product']);
                     }
                     $volume = $product['mc_front'] * $product['mc_height'] * $product['mc_depth'] / 1000000;
                     $cbm += $cartonsEntry * $volume;
                     $weight += $cartonsEntry * $product['mc_weight'];
                     $price += $purchaseOrderEntry['quantity'] * $purchaseOrderEntry['price'];
                     $cartons += $cartonsEntry;
                     $quantity += $purchaseOrderEntry['quantity'];
                     $entries[$j]['id_product'] = $product['id_product'];
                     $entries[$j]['status'] = $this->getPurchaseOrderEntryStatus($purchaseOrderEntry['status']);
                     $entries[$j]['important'] = $product['important'];
                     $entries[$j]['item_code'] = $product['item_code'];
                     $entries[$j]['product'] = $product['item_name'];
                     $entries[$j]['price'] = $purchaseOrderEntry['price'];
                     $entries[$j]['amount'] = $purchaseOrderEntry['quantity'] * $purchaseOrderEntry['price'];
                     $entries[$j]['cartons'] = $cartonsEntry;
                     $entries[$j]['quantity'] = $purchaseOrderEntry['quantity'];
                     $entries[$j]['weight'] = $product['mc_weight'] * $cartonsEntry;
                     $entries[$j]['volume'] = number_format($volume * $cartonsEntry, 2);
                     $entries[$j]['default_shipping'] = FreightTypeQuery::create()->findByPK($product['default_freight_fare'])->getName();
                     if (!empty($product['import_permit'])) {
                         $importPermit = FileQuery::create()->findByPK($product['import_permit']);
                         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.');
                             } else {
                                 if ($product['important']) {
                                     $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.');
                                 } else {
                                     $entries[$j]['row_status'] = 'success';
                                     $purchaseOrders[$i]['row_status'] = 'success';
                                 }
                             }
                         }
                     }
                     $j++;
                 }
                 //Checks if the entry has important stuff
                 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');
                 }
             } catch (Exception $e) {
                 var_dump($e->getMessage());
             }
             $purchaseOrders[$i]['id_purchase_order_folio'] = PurchaseOrderFolioQuery::create()->whereAdd(PurchaseOrderFolio::ID_PURCHASE_ORDER, $purchaseOrder['id_purchase_order'])->whereAdd(PurchaseOrderFolio::ID_FOLIO_IMPORT, $idFolioImport)->findOne()->getIdPurchaseOrderFolio();
             $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'] = number_format($cbm, 2);
             $purchaseOrders[$i]['price'] = $price;
             $purchaseOrders[$i]['id_purchase_order'] = $purchaseOrder['id_purchase_order'];
             $purchaseOrders[$i]['courtyard_arrival_date'] = $purchaseOrder['courtyard_arrival_date'];
             $i++;
         }
         return $purchaseOrders;
     } else {
         return null;
     }
 }
Esempio n. 11
0
 /**
  * 
  * @throws \Exception
  */
 public function updateData()
 {
     $phpExcel = $this->getPhpExcel();
     $activeSheet = $phpExcel->getActiveSheet();
     $highestColumn = $activeSheet->getHighestColumn();
     $highestRow = $activeSheet->getHighestRow();
     $modifiedFreightFareCollection = new FreightFareCollection();
     $modifiedFreightFareArray = array();
     $originalFreightFaresArray = array();
     if ($highestRow > 1000) {
         throw new \Exception('The file is very big');
     }
     $headers = $activeSheet->rangeToArray('A3:' . $highestColumn . '3');
     if (!$this->validateFile($headers[2])) {
         throw new \Exception('This file does not contain valid content to update the data');
     }
     for ($row = 4; $row <= $highestRow; $row++) {
         $rowArray = $activeSheet->rangeToArray('A' . $row . ':' . $highestColumn . $row);
         $fields = $this->setRowArrayKeys($rowArray[$row - 1]);
         $modifiedFreightFaresArray[] = $fields;
         $originalFreightFaresArray[$fields['ID']] = $fields['ID'];
     }
     $forwarderCollection = ForwarderQuery::create()->find();
     $customPortCollection = PortCustomQuery::create()->find();
     $freightTypeCollection = FreightTypeQuery::create()->find();
     $originalFreightFareCollection = FreightFareQuery::create()->whereAdd(FreightFare::ID_FREIGHT_FARE, $originalFreightFaresArray)->find();
     $modified = 0;
     $created = 0;
     foreach ($modifiedFreightFaresArray as $modifiedFreightFare) {
         $destinationPort = $customPortCollection->getByName($modifiedFreightFare['Destination Port']);
         $fobPort = $customPortCollection->getByName($modifiedFreightFare['FOB Port']);
         $forwarder = $forwarderCollection->getByName($modifiedFreightFare['Forwarder']);
         $freightType = $freightTypeCollection->getByName($modifiedFreightFare['Freight Type']);
         $freightFare = $originalFreightFareCollection->getByPK($modifiedFreightFare['ID']);
         $freightFare->setIdFreightFare($modifiedFreightFare['ID']);
         if ($freightFare instanceof FreightFare) {
             if ($fobPort) {
                 $freightFare->setFobPort($fobPort->getIdPortCustom());
             }
             if ($destinationPort) {
                 $freightFare->setDestinationPort($destinationPort->getIdPortCustom());
             }
             if ($freightType) {
                 $freightFare->setIdFreightType($freightType->getIdFreightType());
             }
             if ($forwarder) {
                 $freightFare->setIdForwarder($forwarder->getIdForwarder());
             }
             $freightFare->setIdTransit($modifiedFreightFare['ID-Transit']);
             $freightFare->setNotes($modifiedFreightFare['Notes']);
             $freightFare->setTt($modifiedFreightFare['Transit Time']);
             $freightFare->setFrecuency($modifiedFreightFare['Frecuency']);
             $freightFare->setGoodThrough($modifiedFreightFare['Good Through']);
             $freightFare->setUnit(FreightFare::$Units[$modifiedFreightFare['Unit']]);
             $freightFare->setUnitCost($modifiedFreightFare['Fare']);
             $freightFare->setPeak($modifiedFreightFare['Peak/Unit']);
             $freightFare->setStatus(FreightFare::$Status[$modifiedFreightFare['Status']]);
             $this->getFreightFareCatalog()->beginTransaction();
             try {
                 $this->getFreightFareCatalog()->update($freightFare);
             } catch (\Exception $e) {
                 throw e;
                 $this->getFreightFareCatalog()->rollBack();
             }
             $this->getFreightFareCatalog()->commit();
             return true;
         } else {
         }
     }
 }