Example #1
0
 public function salesByProductAction()
 {
     $this->view->months = $this->getMonthsArray();
     $parentKey = $this->getRequest()->getParam('parent-key');
     $abcLimits = RestockPurchaseAbcClassQuery::create()->find();
     $inventory = InventoryRotationQuery::create()->find()->generateRotation($abcLimits);
     $products = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $parentKey, BaseQuery::LIKE)->find();
     $rotationGenerator = new RotationGeneratorManager();
     $rotationByKeyMother = $rotationGenerator->generateRotationByKeyMother($inventory, $products)->getByIndex($parentKey);
     $targetPrices = $products->map(function (Product $product) {
         return array($product->getItemCode() => $product->getCost());
     });
     $statusNames = Product::$StatusFullName;
     $this->view->abc = $abc = RestockAbcClassQuery::create()->find();
     $items = $inventory->filterByKeysMother($parentKey);
     $this->view->items = $items->generateRotation($abcLimits);
     $priceHistory = array();
     $products->rewind();
     while ($product = $products->read()) {
         $productCostLogs = ProductCostLogQuery::create()->whereAdd(ProductCostLog::ID_PRODUCT, $product->getItemCode())->orderBy(ProductCostLog::ID_PRODUCT_COST_LOG, ProductCostLogQuery::DESC)->setLimit(10)->find();
         $i = 0;
         $priceHistory[$product->getItemCode()] = array();
         while ($productCostLog = $productCostLogs->read()) {
             $priceHistory[$product->getItemCode()][$i]['date'] = $productCostLog->getDate();
             $priceHistory[$product->getItemCode()][$i]['currency'] = $productCostLog->getIdCurrencyTo();
             $priceHistory[$product->getItemCode()][$i]['price'] = $productCostLog->getPriceTo();
             $priceHistory[$product->getItemCode()][$i]['notes'] = $productCostLog->getNotes();
             $priceHistory[$product->getItemCode()][$i]['user'] = UserQuery::create()->findByPK($productCostLog->getIdUser())->getFullName();
             $i++;
         }
     }
     $this->view->priceHistory = $priceHistory;
     $this->view->data = $this->getEditInformation($parentKey);
     $this->view->parentKey = $rotationByKeyMother;
     $this->view->targetPrices = $targetPrices;
     $this->view->products = $products->toArray();
     $this->view->statusNames = $statusNames;
     $this->view->customsTariffCodes = array("" => $this->i18n->_("Select a Customs Tariff Code")) + CustomsTariffCodeQuery::create()->actives()->find()->toCombo();
     $this->view->defaultShippings = $this->getDefaultShipping();
     $this->view->setTpl('Sales');
 }
 /**
  * 
  * @return json
  */
 public function getListResultsAction()
 {
     $params = $this->getRequest()->getParams();
     $customsTariffCodes = CustomsTariffCodeQuery::create()->filter($params)->findByPage($params['page'], $this->getMaxPerPage());
     die(json_encode($customsTariffCodes->toArray()));
 }
Example #3
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));
 }
Example #4
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;
 }
 /**
  *
  * @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;
 }
Example #6
0
 /**
  *
  * Gets all Tax Codes from SAP, searches the DB for the CstGrpCode, then updates or creates
  */
 public function syncTaxCodesAction()
 {
     $r = SapTaxCodeQuery::create()->find();
     echo "<pre>";
     $errors = 0;
     $new = 0;
     $updated = 0;
     while ($r->valid()) {
         $save = 0;
         $sapTaxCode = $r->read();
         echo "Name: " . $sapTaxCode->getCstGrpName() . " Code: " . $sapTaxCode->getCstGrpCode() . "Tax %: " . $sapTaxCode->getTotalTax() . "\n";
         $customsTariffCode = CustomsTariffCodeQuery::create()->whereAdd(CustomsTariffCode::CODE, $sapTaxCode->getCstGrpCode())->findOne();
         if (!$customsTariffCode instanceof CustomsTariffCode) {
             $customsTariffCode = new CustomsTariffCode();
             $save = 1;
         }
         $customsTariffCode->setCode($sapTaxCode->getCstGrpCode());
         $customsTariffCode->setName($sapTaxCode->getCstGrpName());
         $customsTariffCode->setPercent($sapTaxCode->getTotalTax());
         $customsTariffCode->setStatus(1);
         try {
             $this->getCustomsTariffCodeCatalog()->beginTransaction();
             if ($save) {
                 $this->getCustomsTariffCodeCatalog()->create($customsTariffCode);
                 $new++;
             } else {
                 $this->getCustomsTariffCodeCatalog()->update($customsTariffCode);
                 $updated++;
             }
             $this->getCustomsTariffCodeCatalog()->commit();
         } catch (Exception $e) {
             $this->getCustomsTariffCodeCatalog()->rollBack();
             echo "\nError al intentar guardar la Fraccion Arancelaria: " . $e->getMessage();
         }
     }
     echo "\n\nTotals:\nErrors: " . $errors . "\nNew: " . $new . "\nUpdated: " . $updated;
     die;
 }