nbCycle = $nbCycle; $this->productFamily = $productFamily; $this->createProperties(); } public function createProperties() { $this->addProperty( 'total_sales', [ 'label' => 'Total ventes' ] ); foreach ($this->productFamily->getProducts() as $product) { $this->productIds[$product->getId()] = $product; $this->addProperty( $product->getId(), [ 'label' => $product->getTitle() ] ); } } // Initialise les valeurs des données pour chaque Interval de date public function init(SectionInterface $section, OrderShopSolver $orderShopSolver, OpeningResolver $openingResolver) { $currentCycleNumber = $orderShopSolver->getCycleNumberCurrentOrder(); if ($openingResolver->isOpenSale($section, null,OpeningResolver::OPENING_CONTEXT_BACKEND) == false && date('w') > 2) { $currentCycleNumber = $currentCycleNumber - 1; } $this->cycleNumbers = array(); for ($w = $currentCycleNumber - $this->nbCycle + 1; $w <= $currentCycleNumber; $w++) { $this->cycleNumbers[] = $w; $this->labels[$w] = 'S ' . $w; foreach ($this->getProperties() as $propertyName => $property) { $this->properties[$propertyName]['data'][$w] = 0; } foreach ($this->getAverageProperties() as $propertyName => $property) { $this->averageProperties[$propertyName]['data'][$w] = 0; } } } public function populateProperties(OrderShopStore $orderShopStore) { $countsOrderedByCyclesAndProducts = $orderShopStore->countValidOrderProductsOfCyclesByProducts( $this->cycleNumbers, $this->productIds ); foreach ($countsOrderedByCyclesAndProducts as $result) { $this->setData($result['productId'], $result['cycleNumber'], $result['quantity']); $product = $this->productIds[$result['productId']]; if ($this->productFamily->getBehaviorDisplaySale() == ProductFamilyModel::BEHAVIOR_DISPLAY_SALE_BY_MEASURE) { $ratioByMeasure = $product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient(); $this->setData('total_sales', $result['cycleNumber'], intval($result['quantity']) * $ratioByMeasure); } else { $this->setData('total_sales', $result['cycleNumber'], intval($result['quantity'])); } } $this->setAveragePropertiesData(); } }