|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
-
- namespace Lc\CaracoleBundle\Statistic\Product;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
- use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
- use Lc\CaracoleBundle\Resolver\OpeningResolver;
- use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
- use Lc\CaracoleBundle\Statistic\Statistic;
-
- class ProductsSalesStatistic extends Statistic
- {
- protected int $nbCycle;
- protected $productFamily;
- protected $cycleNumbers = array();
- protected $productIds = array();
-
- public function __construct(EntityManagerInterface $entityManager, $productFamily, $nbCycle)
- {
- parent::__construct($entityManager);
- $this->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($section);
- 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();
- }
-
-
- }
|