Example #1
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);
 }
 /**
  * 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();
 }
 public function getTotalByIdFreigthFare($idFreightFare)
 {
     $idFreightFare = (array) $idFreightFare;
     $totalByIdFreightFare = 0;
     if (count($idFreightFare) > 0) {
         $products = $this->products->filterByIdFreightFare($idFreightFare);
         $restockEntries = $this->restockEntries->filterByArrayIdProduct($products->getPrimaryKeys());
         while ($restockEntries->valid()) {
             $restockEntry = $restockEntries->read();
             $totalByIdFreightFare += $this->getPurchaseSettedByIdRestockEntry($restockEntry->getIdRestockEntry());
         }
     }
     return $totalByIdFreightFare;
 }
Example #4
0
 /**
  *
  * @return array
  */
 public function createAction()
 {
     $params = $this->getRequest()->getParams();
     $products = new ProductCollection();
     // 		die("<pre>".print_r($params,true)."</pre>");
     $productGroup = ProductGroupQuery::create()->findByPKOrThrow($params["idProductGroup"], $this->i18n->_("The ProductGroup with id {$params["idProductGroup"]} does not exist."));
     $family = FamilyQuery::create()->findByPKOrThrow($params["IdCategory"], $this->i18n->_("The Family with id {$params["idFamily"]} does not exist."));
     $subfamily = SubfamilyQuery::create()->findByPKOrThrow($params["idSubfamily"], $this->i18n->_("The Subfamily with id {$params["idSubfamily"]} does not exist."));
     $brand = BrandQuery::create()->findByPKOrThrow($params["idBrand"], $this->i18n->_("The Brand with id {$params["idBrand"]} does not exist."));
     if ($params["supplier_id"] != '') {
         $supplier = SapSupplierQuery::create()->findByPKOrThrow($params["supplier_id"], $this->i18n->_("The Supplier with id {$params["supplier_id"]} does not exist."));
     } else {
         $supplier = new SapSupplier();
     }
     $path = 'product/' . $params["keyMother"] . '/';
     $savedFile = $this->saveFile('importationPermission', $path);
     if ($savedFile instanceof File) {
         $this->getFileCatalog()->beginTransaction();
         try {
             $this->getFileCatalog()->create($savedFile);
             $this->getFileCatalog()->commit();
         } catch (Exception $e) {
             $this->getFileCatalog()->rollBack();
             throw new \InvalidArgumentException($this->i18n->_("The Import Permit File can't be saved."));
         }
     }
     //die("<pre>".print_r($params, true)."</pre>");
     foreach ($params["colors"] as $item) {
         $color = ColorQuery::create()->findByPKOrThrow($item["idColor"], $this->i18n->_("The Color with id {$item["idColor"]} does not exist."));
         $itemcode = ($codPro = $params["keyMother"] . $brand->getName()) . $color->getCode();
         $product = ProductFactory::createFromArray(array('CstGrpCode' => $params["idCustomsTariffCode"], 'FirmCode' => $brand->getCode(), 'U_Color' => $color->getCode(), 'U_Categoria' => $family->getName(), 'U_PCS_Id_Categoria' => $family->getIndex(), 'U_PCS_Impor_per_id' => $savedFile ? $savedFile->getIdFile() : -1, 'ItmsGrpCod' => $productGroup->getIdProductGroup(), 'U_Id_Familia' => $productGroup->getCode(), 'U_Familia' => $productGroup->getName(), 'U_id_subcategoria' => $subfamily->getCode(), 'CardCode' => $supplier->getCardCode(), 'U_PCSid_npd_sheet' => $params["idNpd"] > 0 ? $params["idNpd"] : -1, 'ItemCode' => $itemcode, 'ItemName' => $item["itemName"], 'SWW' => $item["status"], 'Invntitem' => 1, 'PrchseItem' => 1, 'U_id_marca' => $brand->getName(), 'U_Marca' => $brand->getName(), 'SellItem' => 1, 'U_Madre_09' => $params["keyMother"], 'U_CODPRO' => $codPro, 'BuyUnitMsr' => "PZA", 'NumInBuy' => 1, 'SalUnitMsr' => "PZA", 'NumInSale' => 1, 'InvntryUom' => "PZA", 'U_MCFrente' => $params["mcFront"], 'U_MCAltura' => $params["mcHeight"], 'U_MCProfundida' => $params["mcDepth"], 'U_MCPeso' => $params["mcWeight"], 'U_PzasXCaja' => $params["mcParts"], 'U_PCS_Pieces_per_inn' => $params["piecesPerInner"], 'U_pzafrente' => $params["pzaFront"], 'U_pzaaltura' => $params["pzaHeight"], 'U_pzaprofu' => $params["pzaDepth"], 'U_PesoxPza' => $params["pzaWeight"], 'U_pzadiametro' => $params["pzaDiameter"], 'U_PCS_Individual_Pac' => $params["individualPackage"], 'U_PCS_Packing_Front' => $params["packingFront"], 'U_PCS_Packing_Height' => $params["packingHeight"], 'U_PCS_Packing_Depth' => $params["packingDepth"], 'U_PCS_Packing_Weight' => $params["packingWeight"], 'U_PCS_Packing_Diamet' => $params["packingDiameter"], 'U_PCS_Def_Freight_Fa' => $params["defaultFreightFare"], 'U_PCS_Important' => $params["important"] ? 1 : 0, 'U_PCS_Rescue' => 1, 'U_PCS_VIM' => $params["vim"], 'U_PCS_Individual_VIM' => $item["vim"], 'U_PCS_import_permit' => $params["remarks"], 'U_PCS_Put_trougth' => $params["goodTrough"], 'U_PCS_Catalog_Year' => $params["catalogYear"], 'LeadTime' => $params["lead_time"], 'U_PCS_id_incoterm' => $params["incoterm"], 'U_PCS_manual_restock' => $params["manual_restock"] ? 1 : 0, 'Price' => $params["price"], 'Currency' => $params["currency"], 'U_ShortName' => $params['U_ShortName']));
         $products->append($product);
     }
     //die(print_r($products));
     $saveProducts = new SapProductSaveManager();
     $responses = $saveProducts->save($products, $this->getUser()->getBean());
     $productCostLog = new ProductCostLog();
     foreach ($responses as $response) {
         $productCostLog->setIdCurrencyFrom($params["currency"]);
         $productCostLog->setIdCurrencyTo($params["currency"]);
         $productCostLog->setPriceFrom($params["price"]);
         $productCostLog->setPriceTo($params["price"]);
         $productCostLog->setIdProduct($response[1]);
         if ($response[0] == 200) {
             $this->newLogForCreateProductCost($productCostLog);
             $success .= "<br>" . $this->i18n->_("The Product with ItemCode {$response[1]} was saved correctly.");
         } else {
             $error .= "<br>" . $this->i18n->_("The Product with ItemCode {$response[1]} can't be saved.");
         }
     }
     if (strlen($success) > 0) {
         if ($params["idNpd"] > 0) {
             $npdSheet = NpdSheetQuery::create()->findByPKOrThrow($params["idNpd"], "The NPDSheet with id {$params["idNpd"]} does not exist.");
             $this->getCatalog('NpdSheetCatalog')->beginTransaction();
             try {
                 $npdSheet->setStatus(NpdSheet::$Status["Closed"]);
                 $this->getCatalog('NpdSheetCatalog')->update($npdSheet);
                 $this->getCatalog('NpdSheetCatalog')->commit();
                 $success .= "<br>" . $this->i18n->_("The NPD Sheet with id {$params["idNpd"]} was closed.");
             } catch (Exception $e) {
                 $error .= $this->i18n->_("The NPD Sheet with id {$params["idNpd"]} can't be closed.");
                 $this->getCatalog('NpdSheetCatalog')->rollBack();
             }
         }
         $this->setFlash('ok', $success);
     }
     if (strlen($error) > 0) {
         $this->setFlash('error', $error);
     }
     $this->_redirect('product/list');
     if (!empty($idNpdSheet)) {
         $this->getEventDispatcherService()->createProductNotification($product, ProductEvent::COMPRAS_ITEM_CODES_REQUEST, $colors);
     }
 }
 public function getSettedImportUSDByIdRestockEntry($idRestockEntry)
 {
     $restockEntry = $this->restockEntries->getByPK($idRestockEntry);
     $totalCartonParts = $this->totalCartons[$idRestockEntry];
     $product = $this->products->getByPK($restockEntry->getIdProduct());
     $minTargetPrice = $this->getMinTargetPriceUSDByIdProduct($restockEntry->getIdProduct());
     return $totalCartonParts * $minTargetPrice;
 }
 /**
  *
  * @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;
 }