Exemplo n.º 1
0
 /**
  * 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();
 }
Exemplo n.º 2
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;
 }
 /**
  *
  * @param InventoryRotationCollection $inventory
  * @param KeyMotherStock $stockByKeyMother
  * @param FamilyStock $stockByFamily
  * @param unknown_type $products
  * @param FreightFareCollection $freightFares
  */
 public function generateMinMaxPurchase(InventoryRotationCollection $inventory, KeyMotherStock $stockByKeyMother, FamilyStock $stockByFamily, ProductCollection $products, FreightFareCollection $freightFares)
 {
     // Generates a new min/max purchase list
     $productMinMaxPurchaseList = new ProductMinMaxPurchaseList();
     // Process each products in the inventory
     $inventory->rewind();
     while ($inventory->valid()) {
         // Get the inventory line and product
         $inventoryLine = $inventory->read();
         $product = $products->getByPK($inventoryLine->getItemCode());
         // If the product exist in own catalog and your status is restockable then continue
         if ($product instanceof Product && ($product->isLine() || $product->isHold() && $product->hasRestockRequiredInformation())) {
             // Get the product default freight fare
             $freightFare = $freightFares->getByPkOrElse($product->getDefaultFreightFare(), new FreightFare());
             // Get the correcponging family rotation line
             $familyLine = $stockByFamily->getByIndex(substr($product->getItemCode(), 0, 3));
             // Get the correcesponging key mother rotation line
             $keyMotherLine = $stockByKeyMother->getByIndex($product->getKeyMother());
             // Get ABC Mix
             $abcMix = $this->getABCMix($familyLine, $keyMotherLine);
             // Get the percent min max inventory by abc
             // The min max percent inventory represent the extra inventory to keep (safely stock)
             $percentMinMax = $this->getMinMaxPercentPurchase()->getByPK($abcMix->getIdRestockAbcClass());
             // Generate the min max purchase line for each allowed product
             $productMinMaxPurchase = new ProductMinMaxPurchaseLine();
             // Set the basic data to generate all calcs of VIM excel worksheet ("recompra" document)
             $productMinMaxPurchase->setIdProduct($product->getItemCode())->setABCMix($abcMix->getIdRestockAbcClass())->setManualRestock($product->needManualRestock() ? 1 : 0)->setManualVIM($product->getIndividualVim())->setPercentMax($percentMinMax->getMaxPurchasePercent())->setPercentMin($percentMinMax->getMinPurchasePercent())->setPrice7($inventoryLine->getPRC7())->setReleaseTime(ceil(($product->getLeadTime() + $freightFare->getTt()) / 7));
             // Append the line into list
             $productMinMaxPurchaseList->appendLine($productMinMaxPurchase);
         }
     }
     // Return min max purchase list
     return $productMinMaxPurchaseList;
 }