public function formAction()
 {
     $id = $this->getRequest()->getParam('id');
     try {
         if (empty($id)) {
             throw new ProductAntidumpingDutyException($this->i18n->_('The product id was not defined'));
         }
         $product = ProductQuery::create()->findByPK($id);
         if (!$product instanceof Product) {
             throw new ProductAntidumpingDutyException($this->i18n->_('The Product was not found'));
         }
         $productAntidumpingDuty = ProductAntidumpingDutyQuery::create()->findByParentKey($product->getKeyMother());
         if (!$productAntidumpingDuty instanceof ProductAntidumpingDuty) {
             $productAntidumpingDuty = new ProductAntidumpingDuty();
         }
         $productAntidumpingDuty->setParentKey($product->getKeyMother());
         $comboHeader = $this->i18n->_('Select One');
         $header = array('' => $comboHeader);
         $this->view->currencies = CurrencyQuery::create()->find()->toCombo($comboHeader);
         $this->view->types = $header + array_flip(ProductAntidumpingDuty::$Type);
         $this->view->rules = $header + array_flip(ProductAntidumpingDuty::$Rule);
         $this->view->contentTitle = $this->i18n->_('Compensatory Fee');
         $this->view->productAntidumpingDuty = $productAntidumpingDuty;
     } catch (ProductAntidumpingDutyException $e) {
         $this->setFlash('error', $e->getMessage());
         $this->_redirect('product/list');
     }
 }
Exemplo n.º 2
0
 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 array
  */
 public function listAction()
 {
     $this->view->page = $page = $this->getRequest()->getParam('page') ?: 1;
     if ($this->getRequest()->isPost()) {
         $this->view->post = $post = $this->getRequest()->getParams();
     }
     $total = PurchaseOrderEntryQuery::create()->filter($post)->count();
     $this->view->purchaseOrderEntries = $purchaseOrderEntries = PurchaseOrderEntryQuery::create()->filter($post)->page($page, $this->getMaxPerPage())->find();
     $this->view->paginator = $this->createPaginator($total, $page);
     $this->view->purchaseOrders = \Application\Query\PurchaseOrderQuery::create()->find()->toCombo();
     $this->view->products = \Application\Query\ProductQuery::create()->find()->toCombo();
     $this->view->warehouses = \Application\Query\WarehouseQuery::create()->find()->toCombo();
 }
Exemplo n.º 4
0
 /**
  * 
  * Product Collection and user for logs
  * @param ProductCollection $products
  * @param User $user
  * @return mixed
  */
 public function save(ProductCollection $products, User $user)
 {
     $this->setUser($user);
     $existProducts = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $products->getPrimaryKeys())->find();
     while ($products->valid()) {
         $product = $products->read();
         if ($existProducts->containsIndex($product->getIndex())) {
             $SAPProducts["Product"][] = $product->toSAPArray() + array("Movement" => 2);
             $this->newLogForUpdate($product);
         } else {
             $SAPProducts["Product"][] = $product->toSAPArray() + array("Movement" => 1);
             $this->newLogForCreate($product);
         }
     }
     $SAPConnectionClient = new SAPConnectorClient();
     $response = $SAPConnectionClient->saveProducts($SAPProducts);
     return json_decode($response->productResult->message);
 }
Exemplo n.º 5
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));
 }
Exemplo n.º 6
0
 /**
  *
  * @param PurchaseOrderEntry $purchaseOrderEntry
  * @return CustomsTariffCode $tariffCode
  */
 private function getPurchaseOrderEntryTariffCode(PurchaseOrderEntry $purchaseOrderEntry)
 {
     $idProduct = $purchaseOrderEntry->getIdProduct();
     $idTariffCode = ProductQuery::create()->findByPK($idProduct)->getIdCustomsTariffCode();
     $tariffCode = CustomsTariffCodeQuery::create()->findByPK($idTariffCode);
     return $tariffCode;
 }
Exemplo n.º 7
0
 /**
  *
  * @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;
 }
 /**
  * 
  * 
  */
 public function getQuarantineListResultsAction()
 {
     $page = $this->getRequest()->getParam('page') ?: 1;
     $warehouseEntries = WarehouseEntranceQuery::create()->whereAdd(WarehouseEntrance::ID_FOLIO_IMPORT, null, WarehouseEntranceQuery::NOT_EQUAL)->whereAdd(WarehouseEntrance::ID_FOLIO_IMPORT, '0', WarehouseEntranceQuery::NOT_EQUAL)->find();
     $params = $this->getRequest()->getParams();
     $params['id_purchase_order'] = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::SAP_DOCUMENT_NUMBER, $params['sap_document_number'])->fetchOne();
     if (empty($params['id_purchase_order']) && !empty($params['sap_document_number'])) {
         $params['id_purchase_order'] = -1;
     }
     $warehouseEntryProductQuery = WarehouseEntranceProductQuery::create()->whereAdd(WarehouseEntranceProduct::ID_PURCHASE_ORDER, null, WarehouseEntranceProductQuery::NOT_EQUAL)->whereAdd(WarehouseEntranceProduct::STATUS, WarehouseEntranceProduct::$Status['Quarantine'], WarehouseEntranceProductQuery::EQUAL)->whereAdd(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE, $warehouseEntries->getPrimaryKeys(), WarehouseEntranceProductQuery::IN)->filter($params)->orderBy(WarehouseEntranceProduct::ID_WAREHOUSE_ENTRANCE, 'DESC')->findByPage($page, $this->getMaxPerPage());
     $purchaseOrderCollection = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $warehouseEntryProductQuery->getPurchaseOrderIds(), PurchaseOrderQuery::IN)->find();
     $purchaseOrderEntryCollection = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrderCollection->getPrimaryKeys(), PurchaseOrderEntryQuery::IN)->find();
     $i = 0;
     $this->getCatalog('QuarantineCatalog')->beginTransaction();
     while ($warehouseEntryLine = $warehouseEntryProductQuery->read()) {
         $warehouseEntry = WarehouseEntranceQuery::create()->whereAdd(WarehouseEntrance::ID_WAREHOUSE_ENTRANCE, $warehouseEntryLine->getIdWarehouseEntrance())->findOne();
         if (TransferLineLogQuery::create()->whereAdd(TransferLineLog::BASEENTRY, $warehouseEntryLine->getIdWarehouseEntrance())->whereAdd(TransferLineLog::BASELINE, $warehouseEntryLine->getIdWarehouseEntranceProduct())->count()) {
             $transferLine = TransferLineLogQuery::create()->whereAdd(TransferLineLog::BASEENTRY, $warehouseEntryLine->getIdWarehouseEntrance())->whereAdd(TransferLineLog::BASELINE, $warehouseEntryLine->getIdWarehouseEntranceProduct())->findOne();
             $warehouseEntryLines[$i]['warehouse'] = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::CODE, $transferLine->getWhsCode())->findOne()->getName();
         } else {
             $warehouseEntryLines[$i]['warehouse'] = $this->i18n->_('Not Available');
         }
         $claimReport = $this->getClaimReport($warehouseEntryLine->getIdWarehouseEntrance(), $warehouseEntryLine->getIdWarehouseEntranceProduct());
         $folioImport = $this->getWarehouseEntryFolioImport($warehouseEntry->getIdFolioImport());
         $quarantine = $this->getQuarantine($warehouseEntryLine->getIdWarehouseEntrance(), $warehouseEntryLine->getIdWarehouseEntranceProduct());
         $product = ProductQuery::create()->findByPK($warehouseEntryLine->getIdProduct());
         $warehouseEntryLines[$i]['id_warehouse_entrance_product'] = $warehouseEntryLine->getIdWarehouseEntranceProduct();
         $warehouseEntryLines[$i]['id_warehouse_entrance'] = $warehouseEntry->getIdWarehouseEntrance();
         $warehouseEntryLines[$i]['id_folio_import'] = $folioImport->getIdFolioImport();
         $warehouseEntryLines[$i]['folio_import'] = $folioImport->getFolio();
         if (PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $warehouseEntryLine->getIdPurchaseOrder())->find()->count()) {
             $purchaseOrder = PurchaseOrderQuery::create()->findByPK($warehouseEntryLine->getIdPurchaseOrder());
         } else {
             $purchaseOrder = new PurchaseOrder();
         }
         $purchaseOrderEntry = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $purchaseOrder->getIdPurchaseOrder())->whereAdd(PurchaseOrderEntry::LINE, (string) $warehouseEntryLine->getBaseLine())->findOneOrElse(new PurchaseOrderEntry());
         $proformaInvoice = ProformaInvoiceQuery::create()->whereAdd(ProformaInvoice::ID_PROFORMA_INVOICE, $purchaseOrderEntry->getBaseEntry())->findOneOrElse(new ProformaInvoice());
         $warehouseEntryLines[$i]['proforma_invoice'] = $proformaInvoice->getSapDocumentNumber();
         $warehouseEntryLines[$i]['purchase_order'] = $purchaseOrder->getSapDocumentNumber();
         $warehouseEntryLines[$i]['item_code'] = $product->getItemCode();
         $warehouseEntryLines[$i]['item_name'] = $product->getItemName();
         $warehouseEntryLines[$i]['original_quantity'] = $warehouseEntryLine->getQuantity();
         $warehouseEntryLines[$i]['current_quantity'] = $currentQuantity = $quarantine->getQuantity();
         if ($warehouseEntryLine->getLineStatus() == 'C') {
             // 				$warehouseEntryLines[$i]['cancelled'] = true;
             // 				$warehouseEntryLines[$i]['status'] = 'Cancelled';
             // 				$warehouseEntryLines[$i]['statusRow'] = ' ';
         } else {
             $warehouseEntryLines[$i]['cancelled'] = false;
             if (!$currentQuantity) {
                 $warehouseEntryLines[$i]['status'] = 'Debugged';
                 $warehouseEntryLines[$i]['statusRow'] = 'success';
             } else {
                 $warehouseEntryLines[$i]['status'] = $warehouseEntryLine->getStatusName();
                 $warehouseEntryLines[$i]['statusRow'] = 'warning';
             }
         }
         $warehouseEntryLines[$i]['quarantine'] = $warehouseEntryLine->getStatusName();
         $warehouseEntryLines[$i]['claimed_amount'] = $claimReport->getClaimedAmount();
         $warehouseEntryLines[$i]['final_amount'] = $claimReport->getFinalAmount();
         $warehouseEntryLines[$i]['claim_report_status'] = $claimReport->getStatusName();
         $warehouseEntryLines[$i]['allow_debug'] = TransferLineLogQuery::create()->whereAdd(TransferLineLog::BASEENTRY, $warehouseEntryLine->getIdWarehouseEntrance())->whereAdd(TransferLineLog::BASELINE, $warehouseEntryLine->getIdWarehouseEntranceProduct())->count();
         if ($warehouseEntryLine->getStatus() == WarehouseEntranceProduct::$Status['Quarantine']) {
             $quarantineProduct = $this->getQuarantine($warehouseEntryLine->getIdWarehouseEntrance(), $warehouseEntryLine->getIdWarehouseEntranceProduct());
             $warehouseEntryLines[$i]['initial_quantity'] = $quarantineProduct->getQuantity();
         }
         $i++;
     }
     $this->getCatalog('QuarantineCatalog')->commit();
     die(json_encode($warehouseEntryLines));
 }
 /**
  * 
  * @param int $idFolioImport
  */
 public function __construct($idFolioImport, $USDToMXN, $EURtoUSD)
 {
     $this->folioImport = FolioImportQuery::create()->findByPK($idFolioImport);
     if ($USDToMXN) {
         $this->USDToMXN = $USDToMXN;
     }
     if ($EURtoUSD) {
         $this->EURtoUSD = $EURtoUSD;
     }
     $this->purchaseOrders = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::ID_FOLIO_IMPORT, $idFolioImport)->find();
     $this->purchaseOrdersEntries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $this->getPurchaseOrders()->getPrimaryKeys())->find();
     $this->products = $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $this->getPurchaseOrdersEntries()->getProducts())->find();
     $this->productAntidumpingDuties = ProductAntidumpingDutyQuery::create()->whereAdd(ProductAntidumpingDuty::PARENT_KEY, $products->getKeyMother())->find();
 }
 public function getPurchaseOrderEntriesForNewClaimReportAction()
 {
     $docNum = $this->getRequest()->getParam('docNum');
     $values = array();
     $query = PurchaseOrderQuery::create()->whereAdd(PurchaseOrder::SAP_DOCUMENT_NUMBER, $docNum)->findOne();
     $entries = PurchaseOrderEntryQuery::create()->whereAdd(PurchaseOrderEntry::ID_PURCHASE_ORDER, $query->getIdPurchaseOrder())->find();
     $i = 0;
     while ($entry = $entries->read()) {
         $product = ProductQuery::create()->findByPK($entry->getIdProduct());
         $values[$i]['itemName'] = $product->getItemName();
         $values[$i]['itemCode'] = $product->getItemCode();
         $i++;
     }
     die(json_encode($values));
 }
Exemplo n.º 11
0
 public function getProductPriceInUsd()
 {
     $product = ProductQuery::create()->findByPK($this->getIdProduct());
     switch ($product->getCurrency()) {
         case 'USD':
             return $product->getCost();
             break;
         case 'EUR':
             return $product->getCost() * $this->getExchangeRateEurToUsd();
             break;
         case 'MXP':
             return $product->getCost() / $this->getExchangeRateUsdToPesos();
         default:
             return $product->getCost();
     }
 }
Exemplo n.º 12
0
 public function exportToExcelAction()
 {
     $params = $this->getRequest()->getParams();
     $allPurchaseOrderEntries = PurchaseOrderEntryQuery::create()->find();
     $purchaseOrders = PurchaseOrderQuery::create()->filter($params)->addDescendingOrderBy(PurchaseOrder::PURCHASE_ORDER_DATE)->whereAdd("PurchaseOrder.DocType", "I")->whereAdd("PurchaseOrderEntry.ItemCode", "TR%", 'NOT LIKE')->whereAdd("PurchaseOrderEntry.WhsCode", "9999", PurchaseOrderQuery::NOT_LIKE)->whereAdd(PurchaseOrder::ID_PURCHASE_ORDER, $allPurchaseOrderEntries->getDistinctPurchaseOrder(), PurchaseOrderQuery::IN)->find();
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $allPurchaseOrderEntries->getProducts(), ProductQuery::IN)->find();
     $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $purchaseOrders->getDistinctSuppliers(), SapSupplierQuery::IN)->find();
     $warehousesStores = WarehouseStoreQuery::create()->whereAdd(WarehouseStore::CODE, $allPurchaseOrderEntries->getDistinctIdWarehouseStore(), WarehouseStoreQuery::IN)->find();
     $warehouses = WarehouseQuery::create()->whereAdd(Warehouse::CODE, $warehousesStores->getDistinctWarehouses(), WarehouseQuery::IN)->find();
     $currencies = CurrencyQuery::create()->find();
     $countries = CountryQuery::create()->find();
     require_once 'PHPExcel.php';
     $objPHPExcel = new PHPExcel();
     $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet->setCellValue('A1', $this->i18n->_('Purchase Order Folio'))->setCellValue('B1', $this->i18n->_('Destination Country'))->setCellValue('C1', $this->i18n->_('Supplier Code'))->setCellValue('D1', $this->i18n->_('Supplier Name'))->setCellValue('E1', $this->i18n->_('Creation Date'))->setCellValue('F1', $this->i18n->_('Status'))->setCellValue('G1', $this->i18n->_('Entry Line'))->setCellValue('H1', $this->i18n->_('Product Code'))->setCellValue('I1', $this->i18n->_('Product Description'))->setCellValue('J1', $this->i18n->_('Amount'))->setCellValue('K1', $this->i18n->_('Price'))->setCellValue('L1', $this->i18n->_('Import'))->setCellValue('M1', $this->i18n->_('Currency'))->setCellValue('N1', $this->i18n->_('Location'))->setCellValue('O1', $this->i18n->_('Warehouse'));
     $activeSheet->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
     $i = 2;
     while ($purchaseOrders->valid()) {
         $purchaseOrder = $purchaseOrders->read();
         $currency = $currencies->getByPkOrEmpty($purchaseOrder->getIdCurrency());
         $supplier = $suppliers->getByPkOrElse($purchaseOrder->getIdSupplier(), new SapSupplier());
         $country = $countries->getByPK($purchaseOrder->getIdDestinationCountry());
         $purchaseOrderEntries = $allPurchaseOrderEntries->filterByPurchaseOrderPk($purchaseOrder->getIdPurchaseOrder());
         $entriesCount = $i;
         while ($purchaseOrderEntries->valid()) {
             $purchaseOrderEntry = $purchaseOrderEntries->read();
             $product = $products->getByPK($purchaseOrderEntry->getIdProduct()) ? $products->getByPK($purchaseOrderEntry->getIdProduct()) : new Product();
             $warehouseStore = $warehousesStores->getByPkOrElse($purchaseOrderEntry->getIdWarehouseStore(), new WarehouseStore());
             $warehouse = $warehouseStore->getLocation() > 0 ? $warehouses->getByPK($warehouseStore->getLocation()) : new WarehouseStore();
             $activeSheet->setCellValue('A' . $entriesCount, $purchaseOrder->getSapDocumentNumber())->setCellValue('B' . $entriesCount, utf8_encode($country->getName()))->setCellValue('C' . $entriesCount, $supplier->getCardCode())->setCellValue('D' . $entriesCount, $supplier->getCardname())->setCellValue('E' . $entriesCount, $purchaseOrder->getPurchaseOrderDate())->setCellValue('F' . $entriesCount, $purchaseOrder->getStatusName())->setCellValue("G" . $entriesCount, $purchaseOrderEntry->getLine())->setCellValue("H" . $entriesCount, $product->getItemCode())->setCellValue("I" . $entriesCount, $product->getItemName())->setCellValue("J" . $entriesCount, $purchaseOrderEntry->getAmount())->setCellValue("K" . $entriesCount, $purchaseOrderEntry->getPrice())->setCellValue("L" . $entriesCount, $purchaseOrderEntry->getImport())->setCellValue("M" . $entriesCount, $currency->getCurrCode())->setCellValue("N" . $entriesCount, $warehouse->getName())->setCellValue("O" . $entriesCount, $warehouseStore->getName());
             $entriesCount++;
         }
         $i = $entriesCount;
     }
     $columns = range('A', 'O');
     foreach ($columns as $column) {
         $activeSheet->getColumnDimension($column)->setAutoSize(true);
     }
     header("Content-Type: application/vnd.ms-excel");
     $date = \Zend_Date::now();
     $fileName = $this->i18n->_("Purchase_orders_report") . $date->get("ddMMyyyy");
     header("Content-Disposition: attachment; filename=\"{$fileName}.xlsx\"");
     header("Cache-Control: max-age=0");
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save("php://output");
     exit;
 }
 public function exportToExcelAction()
 {
     $report = new SimpleListReport();
     $params = $this->getRequest()->getParams();
     $productPrintingAreas = ProductPrintingAreaQuery::create()->filter($params)->find();
     $i = 0;
     $tableContent = array();
     while ($productPrintingArea = $productPrintingAreas->read()) {
         $productionTimePrintingTechniqueQuery = ProductionTimePrintingTechniqueQuery::create()->whereAdd(ProductionTimePrintingTechnique::ID_PRODUCT_PRINTING_AREA, $productPrintingArea->getIdProductPrintingArea())->find();
         $j = 1;
         while ($productionTimePrintingTechnique = $productionTimePrintingTechniqueQuery->read()) {
             switch ($j) {
                 case 1:
                     $id_printing_technique = $productionTimePrintingTechnique->getIdPrintingTechnique();
                     $max_area = $productionTimePrintingTechnique->getMaxArea();
                     $max_inks = $productionTimePrintingTechnique->getMaxInks();
                     break;
                 case 2:
                     $id_printing_technique_alternative = $productionTimePrintingTechnique->getIdPrintingTechnique();
                     $max_area_alternative = $productionTimePrintingTechnique->getMaxArea();
                     $max_inks_alternative = $productionTimePrintingTechnique->getMaxInks();
                     break;
             }
             if ($j == 2) {
                 break;
             }
             $j++;
         }
         $product = ProductQuery::create()->findByPK($productPrintingArea->getIdProduct());
         $tableContent[$i][] = $productPrintingArea->getIdProduct();
         $tableContent[$i][] = $product->getKeyMother();
         $tableContent[$i][] = $product->getItemName();
         $tableContent[$i][] = $productPrintingArea->getIdEShop();
         $tableContent[$i][] = $id_printing_technique;
         $tableContent[$i][] = $productPrintingArea->getIncludedLogos();
         $tableContent[$i][] = $productPrintingArea->getIdPrintingSize();
         $tableContent[$i][] = $max_inks;
         $tableContent[$i][] = $id_printing_technique_alternative;
         $tableContent[$i][] = $max_inks_alternative;
         $tableContent[$i][] = $max_area;
         $tableContent[$i][] = $max_area_alternative;
         $tableContent[$i][] = $productPrintingArea->getPrintingOrder();
         $i++;
     }
     $tableHeaders = array('SKU', 'Item', 'Item Name', 'Id E-Shop', 'Printing Technique', 'Included Logos', 'Surface', 'Max Inks', 'Printing Technique Alternative', 'Max Inks Alternative', 'Max Area', 'Max Area Alternative', 'Printing Order');
     $report->setTableTitle('Product Printing Area Report');
     $report->setTableHeaders($tableHeaders);
     $report->setTableContent($tableContent);
     $report->setFilename('product_printing_area_report');
     $report->createSpreadsheet();
     die;
 }
Exemplo n.º 14
0
 public function npdKeyAction()
 {
     $this->view->setTpl('Npd-key');
     $this->view->contentTitle = 'NPD Key';
     $idNPDSheet = $this->getRequest()->getParam('id');
     $this->view->productNewKey = $this->getRequest()->getParam('product-new-key');
     if (!empty($idNPDSheet)) {
         $this->view->npdSheet = $npdSheet = NpdSheetQuery::create()->findByPK($idNPDSheet);
     }
     $params = $this->getRequest()->getParams();
     if ($this->getRequest()->isPost()) {
         $this->view->post = $post = $this->getRequest()->getParams();
         $this->view->subGroup = $subFamily = SubfamilyQuery::create()->findByPK($post['id_subfamily']);
         $this->view->family = $family = FamilyQuery::create()->findByPK($post['id_family']);
         $this->view->productGroup = $productGroup = ProductGroupQuery::create()->findByPK($post['id_product_group']);
         $this->view->idPg = $family->getIdFamily();
         $this->view->IdSd = $subFamily->getIdSubfamily();
     } else {
         if (!empty($npdSheet)) {
             if ($npdSheet->getIdSubfamily() > 0) {
                 $this->view->subGroup = $subFamily = SubfamilyQuery::create()->findByPK($npdSheet->getIdSubfamily());
             } else {
                 $this->view->subGroup = $subFamily = new Subfamily();
             }
             $this->view->family = $family = FamilyQuery::create()->findByPK($npdSheet->getIdFamily());
             $this->view->productGroup = $productGroup = ProductGroupQuery::create()->findByPK($family->getIdProductGroup());
             $this->view->idPg = $family->getIdFamily();
             /*if($subFamily > 0){
             		 $idSd = $subFamily->getIdSubfamily();
             		}
             		$this->view->IdSd = $idSd;*/
         }
     }
     // Get Product Groups
     $productGroupQuery = ProductGroupQuery::create();
     $productGroupQuery->where()->setOR();
     $productGroupQuery->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup(), ProductGroupQuery::EQUAL);
     $productGroupCombo = $productGroupQuery->actives()->find()->toCombo();
     $this->view->productGroups = $productGroupCombo;
     // Get Families
     $familyQuery = FamilyQuery::create();
     $familyQuery->where()->setOR();
     $familyQuery->whereAdd(Family::ID_PRODUCT_GROUP, $family->getIdProductGroup(), FamilyQuery::EQUAL);
     $familyQuery->where()->setAND();
     $familyQuery->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup());
     $familyCombo = $familyQuery->actives()->find()->toCombo();
     // Get subgfamilies
     $subfamiliesQuery = SubfamilyQuery::create();
     if ($subFamily->getIdSubfamily() > 0) {
         $subfamiliesQuery->where()->setOR();
         $subfamiliesQuery->whereAdd(Subfamily::ID_SUBFAMILY, $subFamily->getIdSubfamily(), SubfamilyQuery::EQUAL);
         $subfamiliesQuery->where()->setAND();
     }
     $subfamiliesQuery->whereAdd(Family::ID_FAMILY, $family->getIdFamily());
     $subGroupCombo = array("" => "Select Subfamily") + $subfamiliesQuery->actives()->find()->toCombo();
     // Get Colors NPD
     $colorsNpd = ColorQuery::create()->innerJoinNpdSheet()->whereAdd('NpdSheet.' . NpdSheet::ID_NPD_SHEET, $idNPDSheet)->find();
     $productColors = ColorQuery::create()->find()->toCombo();
     $select = array('' => $this->i18n->_('** Select **'));
     $this->view->colors = $select + $colorsNpd->toCombo();
     $this->view->brands = $brands = $select + \Application\Query\BrandQuery::create()->actives()->find()->toCombo();
     $this->view->productColors = $productColors;
     //search families for list products
     $idProductGroup = $this->getRequest()->getParam('id_product_group');
     $clvProductGroup = $this->getRequest()->getParam('clv_family');
     $idCategory = $this->getRequest()->getParam('clv_category');
     $clvSubcategory = $this->getRequest()->getParam('clv_subcategory');
     $clvcomposition = $this->getRequest()->getParam('clv_composition');
     $clvBrand = $this->getRequest()->getParam('clv_brand');
     $clvColor = $this->getRequest()->getParam('clv_color');
     $idColor = $this->getRequest()->getParam('id_color');
     if (isset($clvColor)) {
         $colorCode = $this->i18n->_("Not available");
     } else {
         $colorCode = $clvColor;
     }
     $productsFam = ProductQuery::create()->distinct()->addColumns(array('Product.' . Product::ID_PRODUCT_GROUP, 'ProductGroup.' . ProductGroup::CODE))->innerJoinProductGroup()->addAscendingOrderBy('Product.' . Product::ID_PRODUCT_GROUP)->fetchAll();
     foreach ($productsFam as $i => $productFam) {
         if ($productsFam[$i]["id_product_group"] == $idProductGroup) {
             $productGroupIds = array("prevFamily" => $productsFam[$i - 1]["id_product_group"], "productFamily" => $productsFam[$i]["id_product_group"], "nextFamily" => $productsFam[$i + 1]["id_product_group"]);
         }
     }
     $wantedProducts = ProductQuery::create();
     $wantedProducts->where()->setOR();
     $seachProducts = $wantedProducts->whereAdd('Product.' . Product::ID_PRODUCT_GROUP, $productGroupIds['productFamily'])->addColumns(array('Product.' . Product::ITEM_CODE, 'Product.' . Product::ITEM_NAME, 'Product.' . Product::STATUS, 'Product.' . Product::KEY_MOTHER, 'Product.' . Product::ID_COLOR))->whereAdd('Product.' . Product::ID_PRODUCT_GROUP, $productGroupIds['prevFamily'])->whereAdd('Product.' . Product::ID_PRODUCT_GROUP, $productGroupIds['nextFamily'])->fetchAll();
     $newProduct = array(array('item_code' => $clvProductGroup . $idCategory . $clvSubcategory . $clvcomposition . $clvBrand . $clvColor, 'item_name' => $npdSheet->getName(), 'status' => 'H', 'key_mother' => $clvProductGroup . $idCategory . $clvSubcategory . $clvcomposition, 'id_color' => $colorCode));
     //order total products
     $products = array_merge($seachProducts, $newProduct);
     array_multisort($products);
     //save index new product
     foreach ($products as $key => $val) {
         if ($newProduct[0]['item_code'] == $val['item_code']) {
             $index = $key;
         }
     }
     $parentKeys = ProductQuery::create()->whereAdd(Product::KEY_MOTHER, $newProduct[0]['key_mother'])->find()->count();
     $idSupplierAut = SupplierBudgetQuery::create()->innerJoinNpdSheetSupplier()->addColumn(NpdSheetSupplier::ID_SUPPLIER)->whereAdd('NpdSheetSupplier.' . NpdSheetSupplier::ID_NPD_SHEET, $idNPDSheet)->whereAdd('SupplierBudget.' . SupplierBudget::IS_AUTHORIZED, 1)->fetchAll();
     // die(print_r($idSupplierAut));
     if ($idSupplierAut) {
         $currency = CurrencyQuery::create()->whereAdd(Currency::ID_CURRENCY, SapSupplierQuery::create()->findByPK($idSupplierAut[0]['id_supplier'])->getIdCurrency())->findOne();
     } else {
         $this->setFlash('error', $this->i18n->_("there is no authorized supplier"));
         return $this->getHelper('redirector')->goto('list');
     }
     $this->view->new = $newProduct[0]['key_mother'];
     $this->view->families = $familyCombo;
     $this->view->subgroups = $subGroupCombo;
     $this->view->products = $products;
     $this->view->index = $index;
     $this->view->parentKeys = $parentKeys;
     $this->view->supplier = $idSupplierAut[0]['id_supplier'];
     $this->view->currency = $currency->getName();
 }
Exemplo n.º 15
0
 /**
  *
  * Gets all Products from SAP, searches the DB for the itemcode, then updates or creates
  */
 public function syncProductsAction()
 {
     $r = SapProductQuery::create()->whereAdd(SapProduct::INVNTITEM, "Y")->find();
     $errors = 0;
     $new = 0;
     $updated = 0;
     echo "<pre>";
     echo "Name, itemcode, clave madre, resultado, mensaje \n";
     while ($r->valid()) {
         $save = 0;
         $sapProduct = $r->read();
         echo "\"" . trim($sapProduct->getItemname()) . "\", " . $sapProduct->getItemcode() . ", " . $sapProduct->getUMadre9() . ", ";
         if (strlen($sapProduct->getItemcode()) != 11) {
             echo "1, Error! ItemCode invalido: len " . strlen($sapProduct->getItemcode()) . "\n";
             $errors++;
             continue;
         }
         $product = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $sapProduct->getItemcode(), ProductQuery::EQUAL)->findOne();
         if (!$product instanceof Product) {
             $product = new Product();
             $save = 1;
         }
         $brand = BrandQuery::create()->whereAdd(Brand::CODE, substr($sapProduct->getItemcode(), 7, 2))->findOne();
         if (!$brand instanceof Brand) {
             echo "2, Error! No Brand: " . substr($sapProduct->getItemcode(), 7, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdBrand($brand->getIdBrand());
         $color = ColorQuery::create()->whereAdd(Color::CODE, substr($sapProduct->getItemcode(), 9, 2))->findOne();
         if (!$color instanceof Color) {
             echo "3, Error! No Color: " . substr($sapProduct->getItemcode(), 9, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdColor($color->getIdColor());
         $customsTariffCode = CustomsTariffCodeQuery::create()->whereAdd(CustomsTariffCode::CODE, $sapProduct->getCstGrpCode())->findOne();
         if (!$customsTariffCode instanceof CustomsTariffCode) {
             echo "4, Error! No Tax Code: " . $sapProduct->getCstGrpCode() . "\n";
             $errors++;
             continue;
         }
         $product->setIdCustomsTariffCode($customsTariffCode->getIdCustomsTariffCode());
         $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::CODE, substr($sapProduct->getItemcode(), 0, 2))->findOne();
         if (!$productGroup instanceof ProductGroup) {
             echo "5, Error! No ProductGroup: " . substr($sapProduct->getItemcode(), 0, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdProductGroup($productGroup->getIdProductGroup());
         $family = FamilyQuery::create()->whereAdd(Family::CODE, substr($sapProduct->getItemcode(), 2, 1))->whereAdd(Family::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup())->findOne();
         if (!$family instanceof Family) {
             echo "6, Error! No Family: " . substr($sapProduct->getItemcode(), 2, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdFamily($family->getIdFamily());
         $subfamily = SubfamilyQuery::create()->whereAdd(Subfamily::CODE, substr($sapProduct->getItemcode(), 3, 1))->whereAdd(Subfamily::ID_FAMILY, $family->getIdFamily())->findOne();
         if (!$subfamily instanceof Subfamily) {
             echo "7, Error! No SubFamily: " . substr($sapProduct->getItemcode(), 3, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdSubfamily($subfamily->getIdSubfamily());
         $product->setBuyUnit($sapProduct->getBuyUnitMsr());
         $product->setCost(0);
         $product->setIdCurrency(1);
         $product->setIdIncoterm(1);
         $product->setImportant(0);
         $product->setInventaryItem($sapProduct->getInvntItem() == 'Y' ? 1 : 0);
         $product->setInventoryUnit($sapProduct->getInvntryUom());
         $product->setItemCode($sapProduct->getItemcode());
         $product->setItemName($sapProduct->getItemname());
         $product->setKeyMother(substr($sapProduct->getItemcode(), 0, 7));
         $product->setMcDepth($sapProduct->getUMCProfundida());
         $product->setMcFront($sapProduct->getUMCFrente());
         $product->setMcHeight($sapProduct->getUMCAltura());
         $product->setMcParts($sapProduct->getUPzasXCaja());
         $product->setMcWeight($sapProduct->getUMCPeso());
         $product->setNumBuy($sapProduct->getNumInBuy());
         $product->setNumSales($sapProduct->getNumInSales());
         $product->setPurchaseItem($sapProduct->getPrchseItem() == 'Y' ? 1 : 0);
         $product->setPzaDepth($sapProduct->getUPzaprofu());
         $product->setPzaDiameter($sapProduct->getUPzadiametro());
         $product->setPzaFront($sapProduct->getUPzafrente());
         $product->setPzaHeight($sapProduct->getUPpzaaltura());
         $product->setPzaWeight($sapProduct->getUPesoXPza());
         $product->setRescue(0);
         $product->setSaiUnit($sapProduct->getSAlUnitMsr());
         $product->setSellItem($sapProduct->getSellItem() == 'Y' ? 1 : 0);
         $product->setStatus($sapProduct->getSWW());
         if ($save) {
             $this->getProductCatalog()->create($product);
             $new++;
         } else {
             $this->getProductCatalog()->update($product);
             $updated++;
         }
         echo "0, Ok! \n";
     }
     echo "\n\nTotals:\nErrors: " . $errors . "\nNew: " . $new . "\nUpdated: " . $updated;
     die;
 }
 /**
  *
  * @return array
  */
 public function editAction()
 {
     $id = $this->getRequest()->getParam('id');
     $productionTimePrintingTechniques = ProductionTimePrintingTechniqueQuery::create()->findByPKOrThrow($id, $this->i18n->_("Not exists the ProductionTimePrintingTechnique with id {$id}"));
     $this->view->setTpl("Form");
     $this->view->productionTime = $productiontimeQuery = ProductionTimePrintingTechniqueQuery::create()->innerJoinProductPrintingArea()->findByPKOrThrow($id, $this->i18n->_("No exists Production Time Printing Technique"));
     $this->view->printingArea = $printingArea = ProductPrintingAreaQuery::create()->findByPKOrElse($productiontimeQuery->getIdProductPrintingArea(), new ProductPrintingArea());
     $this->view->product = ProductQuery::create()->findOneOrElse($printingArea->getIdProduct(), new Product());
     $this->view->technique = PrintingTechniqueQuery::create()->findByPKOrElse($productiontimeQuery->getIdPrintingTechnique(), new PrintingTechnique());
     $this->view->size = $size = PrintingSizeQuery::create()->findByPKOrElse($printingArea->getIdPrintingSize(), new \Application\Model\Bean\PrintingSize());
     // die(print_r($productiontimeQuery));
 }
Exemplo n.º 17
0
 /**
  * 
  * @param ProformaInvoiceEvent $proformaInvoiceEvent
  */
 public function createProformaInvoiceProductionEndNotification(ProformaInvoiceEvent $proformaInvoiceEvent)
 {
     $proformaInvoice = $proformaInvoiceEvent->getProformaInvoice();
     $proformaInvoiceEntries = $proformaInvoiceEvent->getProformaInvoiceEntries();
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $proformaInvoiceEntries->getIdProducts(), ProductQuery::IN)->find();
     $vars = array('subject' => 'A Proforma Invoice Entry has finished its production', 'proforma_invoice' => $proformaInvoice->toArray());
     $i = 0;
     $entries = array();
     while ($proformaInvoiceEntry = $proformaInvoiceEntries->read()) {
         $entries[$i] = $proformaInvoiceEntry->toArray();
         $entries[$i]['product'] = $products->getByPK($proformaInvoiceEntry->getIdProduct())->toArray();
         $i++;
     }
     $vars['proforma_invoice_entries'] = $entries;
     $this->createNotification(NotificationType::$id['PROFORMA_INVOICE_END_PRODUCTION'], $vars);
 }
Exemplo n.º 18
0
 /**
  *
  */
 public function exportToExcelAction()
 {
     $params = $this->getRequest()->getParams();
     $proformasInvoice = ProformaInvoiceQuery::create()->filter($params)->find();
     $proformasInvoiceEntries = ProformaInvoiceEntryQuery::create()->whereAdd(ProformaInvoiceEntry::ID_PROFORMA_INVOICE, $proformasInvoice->getPrimaryKeys(), ProformaInvoiceEntryQuery::IN)->find();
     $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDCODE, $proformasInvoice->getDistinctSuppliers(), SupplierQuery::IN)->find();
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $proformasInvoiceEntries->getIdProducts(), ProductQuery::IN)->find();
     $currencies = CurrencyQuery::create()->find();
     $countries = CountryQuery::create()->find();
     require_once 'PHPExcel.php';
     $objPHPExcel = new PHPExcel();
     $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet->setCellValue('A1', $this->i18n->_('Proforma Invoice Folio'))->setCellValue('B1', $this->i18n->_('Proforma Invoice Number'))->setCellValue('C1', $this->i18n->_('Proforma Invoice Status'))->setCellValue('D1', $this->i18n->_('Supplier Code'))->setCellValue('E1', $this->i18n->_('Supplier Name'))->setCellValue('F1', $this->i18n->_('Destination Country'))->setCellValue('G1', $this->i18n->_('Creation Date'))->setCellValue('H1', $this->i18n->_('Line Number'))->setCellValue('I1', $this->i18n->_('Line Status'))->setCellValue('J1', $this->i18n->_('Parent Key'))->setCellValue('K1', $this->i18n->_('Product Key'))->setCellValue('L1', $this->i18n->_('Description'))->setCellValue('M1', $this->i18n->_('Quantity'))->setCellValue('N1', $this->i18n->_('Open Price'))->setCellValue('O1', $this->i18n->_('Import'))->setCellValue('P1', $this->i18n->_('Currency'));
     $i = 2;
     while ($proformasInvoice->valid()) {
         $proformaInvoice = $proformasInvoice->read();
         $supplier = $suppliers->getByPK($proformaInvoice->getIdSupplier());
         $country = $countries->getByPK($proformaInvoice->getIdDestinationCountry());
         $proformaInvoiceEntries = $proformasInvoiceEntries->getByIdProformaInvoice($proformaInvoice->getIdProformaInvoice());
         $currency = $currencies->getByPkOrEmpty($proformaInvoice->getIdCurrency());
         $entriesCount = $i;
         while ($proformaInvoiceEntries->valid()) {
             $proformaInvoiceEntry = $proformaInvoiceEntries->read();
             $product = $products->getByPK($proformaInvoiceEntry->getIdProduct());
             $activeSheet->setCellValue('A' . $entriesCount, $proformaInvoice->getIdProformaInvoice())->setCellValue('B' . $entriesCount, $proformaInvoice->getFolio())->setCellValue('C' . $entriesCount, $proformaInvoice->getStatusName())->setCellValue('D' . $entriesCount, $supplier->getCardCode())->setCellValue('E' . $entriesCount, $supplier->getCardname())->setCellValue('F' . $entriesCount, utf8_encode($country->getName()))->setCellValue('G' . $entriesCount, $proformaInvoice->getDocDate())->setCellValue("H" . $entriesCount, $proformaInvoiceEntry->getLine())->setCellValue("I" . $entriesCount, $proformaInvoiceEntry->getStatusName())->setCellValue("J" . $entriesCount, $product->getKeyMother())->setCellValue("K" . $entriesCount, $product->getItemCode())->setCellValue("L" . $entriesCount, $product->getItemName())->setCellValue("M" . $entriesCount, $proformaInvoiceEntry->getQuantity())->setCellValue("N" . $entriesCount, $proformaInvoiceEntry->getPrice())->setCellValue("O" . $entriesCount, $proformaInvoiceEntry->getQuantity() * $proformaInvoiceEntry->getPrice())->setCellValue("P" . $entriesCount, $currency->getCurrCode());
             $entriesCount++;
         }
         $i = $entriesCount;
     }
     header("Content-Type: application/vnd.ms-excel");
     $date = \Zend_Date::now();
     $fileName = $this->i18n->_("Proforma_invoice_report") . $date->get("ddMMyyyy");
     header("Content-Disposition: attachment; filename=\"{$fileName}.xlsx\"");
     header("Cache-Control: max-age=0");
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save("php://output");
     exit;
 }
Exemplo n.º 19
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;
     }
 }
Exemplo n.º 20
0
 /**
  * 
  * Brings the products from a storage that are used in de VIM
  * @param \Application\Model\Collection\InventoryRotationCollection $inventory
  * @return \Application\Model\Collection\ProductCollection
  */
 private function getProducts($inventory)
 {
     $name = 'products';
     $storageService = $this->getStorageService();
     $products = $storageService->getValue($name);
     if (!$products) {
         $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $inventory->getDistinctItemCodes(), BaseQuery::IN)->addAscendingOrderBy(Product::ITEM_CODE)->find();
         $storageService->saveValue($products, $name);
     }
     return $products;
 }
Exemplo n.º 21
0
 public function dataAction()
 {
     $this->view->contentTitle = $this->i18n->_("Required Data");
     $inventory = InventoryRotationQuery::create()->find();
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $inventory->getDistinctItemCodes(), BaseQuery::IN)->whereAdd(Product::STATUS, array(Product::$Status["Hold"], Product::$Status["Line"]), ProductQuery::IN)->addAscendingOrderBy(Product::ITEM_CODE)->find();
     $this->view->products = $products->getProductsWithoutRestockRequiredData();
     $this->view->setTpl("Data");
 }
Exemplo n.º 22
0
 /**
  *
  * @param string $family
  * @return \Application\Managers\RotationsManager\Stocks\KeyMotherStock
  */
 public function filterByStatus($status)
 {
     $newStock = $this->newInstance();
     foreach ($this->stock as $stockLine) {
         $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $stockLine->getKeyMother(), ProductQuery::LIKE)->find();
         while ($product = $products->read()) {
             if ($product->getStatus() == $status) {
                 $newStock->addStockable($stockLine);
                 break;
             }
         }
     }
     return $newStock;
 }
Exemplo n.º 23
0
 public function exportToExcelAction()
 {
     $params = $this->getRequest()->getParams();
     $requisitions = RequisitionQuery::create()->filter($params)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->find();
     $requisitionIds = RequisitionQuery::create()->filter($params)->whereAdd(Requisition::STATUS, Requisition::$Status["Inactive"], BaseQuery::NOT_EQUAL)->fetchCol();
     $allRequisitionEntries = RequisitionEntryQuery::create()->whereAdd(RequisitionEntry::ID_REQUISITION, $requisitionIds, RequisitionEntryQuery::IN)->find();
     $currencies = CurrencyQuery::create()->find();
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $allRequisitionEntries->getDistinctProducts(), ProductQuery::IN)->find();
     $countries = CountryQuery::create()->find();
     $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::CARDCODE, $allRequisitionEntries->getDistinctSuppliers(), SupplierQuery::IN)->find();
     require_once 'PHPExcel.php';
     $objPHPExcel = new PHPExcel();
     $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet->setCellValue('A1', $this->i18n->_('Requisition Folio'))->setCellValue('B1', $this->i18n->_('Requisition Status'))->setCellValue('C1', $this->i18n->_('Reference'))->setCellValue('D1', $this->i18n->_('Creation Date'))->setCellValue('E1', $this->i18n->_('Destination'))->setCellValue('F1', $this->i18n->_('Parent Key'))->setCellValue('G1', $this->i18n->_('Product Status'))->setCellValue('H1', $this->i18n->_('Product Code'))->setCellValue('I1', $this->i18n->_('Product Description'))->setCellValue('J1', $this->i18n->_('Line Status'))->setCellValue('K1', $this->i18n->_('Supplier Default Code'))->setCellValue('L1', $this->i18n->_('Supplier Default Name'))->setCellValue('M1', $this->i18n->_('Ammount'))->setCellValue('N1', $this->i18n->_('Target Price'))->setCellValue('O1', $this->i18n->_('Price'))->setCellValue('P1', $this->i18n->_('Import'))->setCellValue('Q1', $this->i18n->_('currency'));
     $i = 2;
     while ($requisitions->valid()) {
         $requisition = $requisitions->read();
         $requisitionEntries = $allRequisitionEntries->filterByIdRequisition($requisition->getIdRequisition());
         $country = $countries->getByPK($requisition->getIdDestinationCountry());
         $entriesCount = $i;
         while ($requisitionEntries->valid()) {
             $requisitionEntry = $requisitionEntries->read();
             $product = $products->containsIndex($requisitionEntry->getIdProduct()) ? $products->getByPK($requisitionEntry->getIdProduct()) : new Product();
             $supplier = $requisitionEntry->getIdSupplierDefault() > 0 ? $suppliers->getByPkOrElse($requisitionEntry->getIdSupplierDefault(), new SapSupplier()) : new SapSupplier();
             $currency = $currencies->getByPK($requisitionEntry->getIdCurrency());
             $activeSheet->setCellValue("F" . $entriesCount, $product->getKeyMother())->setCellValue("G" . $entriesCount, $product->getStatus())->setCellValue("H" . $entriesCount, $product->getItemCode())->setCellValue("I" . $entriesCount, $product->getItemName())->setCellValue("J" . $entriesCount, $requisitionEntry->getStatusName())->setCellValue("K" . $entriesCount, $supplier->getCardCode())->setCellValue("L" . $entriesCount, $supplier->getCardname())->setCellValue("M" . $entriesCount, $requisitionEntry->getQuantity())->setCellValue("N" . $entriesCount, $product->getCost())->setCellValue("O" . $entriesCount, $requisitionEntry->getPrice())->setCellValue("P" . $entriesCount, $requisitionEntry->getImport())->setCellValue("Q" . $entriesCount, $currency->getCurrCode());
             $entriesCount++;
         }
         $activeSheet->mergeCells('A' . $i . ':A' . ($entriesCount - 1))->setCellValue('A' . $i, $requisition->getIdRequisition())->mergeCells('B' . $i . ':B' . ($entriesCount - 1))->setCellValue('B' . $i, $requisition->getStatusName())->mergeCells('C' . $i . ':C' . ($entriesCount - 1))->setCellValue('C' . $i, $requisition->getNumRequisition())->mergeCells('D' . $i . ':D' . ($entriesCount - 1))->setCellValue('D' . $i, $requisition->getDate())->mergeCells('E' . $i . ':E' . ($entriesCount - 1))->setCellValue('E' . $i, utf8_encode($country->getName()));
         $i = $entriesCount;
     }
     header("Content-Type: application/vnd.ms-excel");
     $date = \Zend_Date::now();
     $fileName = $this->i18n->_("Requisitions_report") . $date->get("ddMMyyyy");
     header("Content-Disposition: attachment; filename=\"{$fileName}.xlsx\"");
     header("Cache-Control: max-age=0");
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     $objWriter->save("php://output");
     exit;
 }