/** * This function return limits to abc class by purchase * * @author Erick Guevara Mart�nez * @return RestockPurchaseAbcClassCollection */ protected function getABCPurchaseClass() { if ($this->ABCBySales == null) { $this->ABCBySales = RestockPurchaseAbcClassQuery::create()->find(); } return $this->ABCBySales; }
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'); }