nbCycle = $nbCycle; $this->productFamily = $productFamily; $this->productSolver = $productSolver; $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, DistributionBuilder $distributionBuilder) { $this->distributionList = $distributionBuilder->getDistributionListFromCurrentOrder($section, $this->nbCycle); // if ($openingResolver->isOpenSale($section, null,OpeningResolver::OPENING_CONTEXT_BACKEND) == false && date('w') > 2) { // $currentCycleNumber = $currentCycleNumber - 1; // } foreach ($this->distributionList as $distribution){ $this->labels[$this->getKey($distribution->getCycleNumber(),$distribution->getYear())] = $distribution->getCycleNumber(); foreach ($this->getProperties() as $propertyName => $property) { $this->properties[$propertyName]['data'][$this->getKey($distribution->getCycleNumber(),$distribution->getYear())] = 0; } foreach ($this->getAverageProperties() as $propertyName => $property) { $this->averageProperties[$propertyName]['data'][$this->getKey($distribution->getCycleNumber(),$distribution->getYear())] = 0; } } } public function populateProperties(OrderShopStore $orderShopStore) { $countsOrderedByCyclesAndProducts = $orderShopStore->countValidOrderProductsOfDistributionsByProducts( $this->distributionList, $this->productIds ); foreach ($countsOrderedByCyclesAndProducts as $result) { $this->setData($result['productId'], $this->getKey($result['cycleNumber'],$result['year']), $result['quantity']); $product = $this->productIds[$result['productId']]; if ($this->productFamily->getBehaviorDisplaySale() == ProductFamilyModel::BEHAVIOR_DISPLAY_SALE_BY_MEASURE) { $ratioByMeasure = $this->productSolver->getQuantityInherited($product) / $this->productSolver->getUnitInherited($product)->getCoefficient(); $this->setData('total_sales', $this->getKey($result['cycleNumber'],$result['year']), intval($result['quantity']) * $ratioByMeasure); } else { $this->setData('total_sales', $this->getKey($result['cycleNumber'],$result['year']), intval($result['quantity'])); } } $this->setAveragePropertiesData(); } protected function getKey($cycleNumber, $year){ return $cycleNumber.'/'.substr($year,2); } }