/**
  * This function generates and return the rotation by key mother
  * (This function generates all math of Rot x Cve Madre workset Excel Document)
  *
  * @author Erick Guevara Mart�nez
  * @param InventoryRotationCollection $inventory
  * @param ProductCollection $products
  * @return \Application\Managers\RotationsManager\Stocks\KeyMotherStock
  */
 public function generateRotationByKeyMother(InventoryRotationCollection $inventory, ProductCollection $products)
 {
     // Init a new stock
     $stockByKeyMother = new KeyMotherStock();
     // Read all inventory lines to get the family stock rotation
     $inventory->rewind();
     //$inventoryParentKey = $inventory->copy();
     $productCostsQuery = ProductCostLogQuery::create()->whereAdd(ProductCostLog::ID_PRODUCT, $products->getPrimaryKeys())->addAscendingOrderBy(ProductCostLog::ID_PRODUCT)->addDescendingOrderBy(ProductCostLog::DATE);
     $productCosts = ProductCostLogQuery::create()->addColumn("*")->removeFrom()->from($productCostsQuery, "myGroup")->addGroupBy(ProductCostLog::ID_PRODUCT)->find()->getUpdates();
     //die("<pre>".print_r($productCosts, true));
     while ($inventory->valid()) {
         $productInventory = $inventory->read();
         $product = $products->getByPK($productInventory->getItemCode());
         // Verify if exist product in our database
         if ($product instanceof Product) {
             // Verify If key mother is into stock
             if ($stockByKeyMother->existIndex($productInventory->getCMADRE())) {
                 // If key mother is into stock then get key mother line
                 $keyMotherLine = $stockByKeyMother->getByIndex($productInventory->getCMADRE());
                 // sum the properties
                 $keyMotherLine->setMonth00($keyMotherLine->getMonth00() + $productInventory->getMes00P())->setMonth01($keyMotherLine->getMonth01() + $productInventory->getMes01P())->setMonth02($keyMotherLine->getMonth02() + $productInventory->getMes02P())->setMonth03($keyMotherLine->getMonth03() + $productInventory->getMes03P())->setMonth04($keyMotherLine->getMonth04() + $productInventory->getMes04P())->setMonth05($keyMotherLine->getMonth05() + $productInventory->getMes05P())->setMonth06($keyMotherLine->getMonth06() + $productInventory->getMes06P())->setMonth07($keyMotherLine->getMonth07() + $productInventory->getMes07P())->setMonth08($keyMotherLine->getMonth08() + $productInventory->getMes08P())->setMonth09($keyMotherLine->getMonth09() + $productInventory->getMes09P())->setMonth10($keyMotherLine->getMonth10() + $productInventory->getMes10P())->setMonth11($keyMotherLine->getMonth11() + $productInventory->getMes11P())->setMonth12($keyMotherLine->getMonth12() + $productInventory->getMes12P())->setAccumSalesUnits($keyMotherLine->getAccumSalesUnits() + $productInventory->getVTAACUM())->setOnHand($keyMotherLine->getOnHand() + $productInventory->getOH())->setTotalSale($keyMotherLine->getTotalSale() + $productInventory->getTVTA())->setProductByCMADRE($keyMotherLine->getProductByCMADRE() + 1)->setLineProducts($product->isLine() ? $keyMotherLine->getLineProducts() + 1 : $keyMotherLine->getLineProducts())->setManualVIM($keyMotherLine->getManualVIM() + $product->getIndividualVim())->setDescription($product->getItemName());
                 // Check if the product is rescue then set key mother in rescue
                 if ($product->isRescue()) {
                     $keyMotherLine->setRescue(1);
                 }
             } else {
                 // If key mother isn't into stock then create it
                 $keyMotherLine = new KeyMotherLine();
                 $keyMotherLine->setKeyMother($productInventory->getCMADRE())->setMonth00($productInventory->getMes00P())->setMonth01($productInventory->getMes01P())->setMonth02($productInventory->getMes02P())->setMonth03($productInventory->getMes03P())->setMonth04($productInventory->getMes04P())->setMonth05($productInventory->getMes05P())->setMonth06($productInventory->getMes06P())->setMonth07($productInventory->getMes07P())->setMonth08($productInventory->getMes08P())->setMonth09($productInventory->getMes09P())->setMonth10($productInventory->getMes10P())->setMonth11($productInventory->getMes11P())->setMonth12($productInventory->getMes12P())->setAccumSalesUnits($productInventory->getVTAACUM())->setOnHand($productInventory->getOH())->setPrice7($productInventory->getPRC7())->setManualVIM($product->getIndividualVim())->setRescue($product->isRescue() ? 1 : 0)->setTotalSale($productInventory->getTVTA())->setProductByCMADRE(1)->setDateLastLogin($productCosts[$product->getItemCode()] ? $productCosts[$product->getItemCode()] : "--")->setLineProducts($product->isLine() ? 1 : 0)->setDescription($product->getItemName());
                 if ($product->isRescue()) {
                     $keyMotherLine->setRescue(1);
                 }
             }
             // Add the kye mother changes into stock
             $stockByKeyMother->addStockable($keyMotherLine);
         }
     }
     // return the stock by key mother
     return $stockByKeyMother->ABCClassmentBySale();
 }
示例#2
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');
 }
示例#3
0
 private function getProductPriceHistory($idProduct)
 {
     $product = ProductQuery::create()->findByPKOrThrow($idProduct, $this->i18n->_("The product with id {$idProduct} does not exist."));
     $historyQuery = ProductCostLogQuery::create()->addDescendingOrderBy(ProductCostLog::DATE);
     if ($allKeyMother) {
         $motherKeyProducts = ProductQuery::creat1304e()->whereAdd(Product::KEY_MOTHER, $product->getKeyMother(), BaseQuery::EQUAL)->find();
         $historyQuery->whereAdd(ProductCostLog::ID_PRODUCT, $motherKeyProducts->getPrimaryKeys(), BaseQuery::IN);
     }
     return $historyQuery->find();
 }
 /**
  * @return array
  * @param string $itemCode
  */
 private function getPriceHistoryAsCombo($itemCode)
 {
     $max = 10;
     $product = ProductQuery::create()->findByPK($itemCode);
     $productCostLog = ProductCostLogQuery::create()->whereAdd(ProductCostLog::ID_PRODUCT, $itemCode)->orderBy(ProductCostLog::ID_PRODUCT_COST_LOG, ProductCostLogQuery::DESC)->setLimit($max)->find();
     $response = $this->getLandedCost($itemCode, $product->getCost());
     $values = array($response['result'] => 'Current Price - ' . $product->getCost());
     $currentLandedCost = $response['result'];
     while ($productCost = $productCostLog->read()) {
         $response = $this->getLandedCost($itemCode, $productCost->getPriceTo());
         if ($currentLandedCost == $response['result']) {
             $values[$response['result']] = 'Current Price - ' . $productCost->getPriceTo() . ' ' . $productCost->getIdCurrencyTo();
         } else {
             $values[$response['result']] = $productCost->getDate() . ' - ' . $productCost->getPriceTo() . ' ' . $productCost->getIdCurrencyTo();
         }
         // 			$values[$response['result']] = $productCost->getDate() . ' - ' . $productCost->getPriceTo() .' '. $productCost->getIdCurrencyTo();
     }
     return $values;
 }
示例#5
0
 protected function getCostLogByIdProducts()
 {
     $productEntranceListQuery = WarehouseEntranceProductQuery::create()->addColumns(array('id_product' => "WarehouseEntranceProduct.ItemCode", 'price' => "WarehouseEntranceProduct.Price", 'currency' => "WarehouseEntranceProduct.Currency", 'line' => 'ROW_NUMBER()OVER( PARTITION BY ItemCode ORDER BY DocEntry DESC)'));
     $productCostHistory = WarehouseEntranceProductQuery::create()->addColumns(array('id_product', 'price', 'currency'))->removeFrom()->from("(" . $productEntranceListQuery->createSql() . ")", "entranceList")->whereAdd("line", 1, WarehouseEntranceProductQuery::EQUAL)->whereAdd("id_product", null, WarehouseEntranceProductQuery::IS_NOT_NULL)->find();
     $idsProducts = $productCostHistory->getIdsProducts();
     $productCostsQuery = ProductCostLogQuery::create()->whereAdd(ProductCostLog::ID_PRODUCT, $idsProducts, BaseQuery::NOT_IN)->addAscendingOrderBy(ProductCostLog::ID_PRODUCT)->addDescendingOrderBy(ProductCostLog::DATE);
     $productCosts = ProductCostLogQuery::create()->addColumn("*")->removeFrom()->from($productCostsQuery, "myGroup")->addGroupBy(ProductCostLog::ID_PRODUCT)->find();
     $costLogArray = array_merge($productCosts->toCostLogArray(), $productCostHistory->toCostLogArray());
     return $costLogArray;
 }