No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

ProductsSalesStatistic.php 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Lc\CaracoleBundle\Statistic\Product;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
  5. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  6. use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
  7. use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
  8. use Lc\CaracoleBundle\Resolver\OpeningResolver;
  9. use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
  10. use Lc\CaracoleBundle\Statistic\Statistic;
  11. class ProductsSalesStatistic extends Statistic
  12. {
  13. protected int $nbCycle;
  14. protected $productFamily;
  15. protected $cycleNumbers = array();
  16. protected $productIds = array();
  17. public function __construct(EntityManagerInterface $entityManager, $productFamily, $nbCycle)
  18. {
  19. parent::__construct($entityManager);
  20. $this->nbCycle = $nbCycle;
  21. $this->productFamily = $productFamily;
  22. $this->createProperties();
  23. }
  24. public function createProperties()
  25. {
  26. $this->addProperty(
  27. 'total_sales',
  28. [
  29. 'label' => 'Total ventes'
  30. ]
  31. );
  32. foreach ($this->productFamily->getProducts() as $product) {
  33. $this->productIds[$product->getId()] = $product;
  34. $this->addProperty(
  35. $product->getId(),
  36. [
  37. 'label' => $product->getTitle()
  38. ]
  39. );
  40. }
  41. }
  42. // Initialise les valeurs des données pour chaque Interval de date
  43. public function init(SectionInterface $section, OrderShopSolver $orderShopSolver, OpeningResolver $openingResolver)
  44. {
  45. $currentCycleNumber = $orderShopSolver->getCycleNumberCurrentOrder($section);
  46. if ($openingResolver->isOpenSale($section, null,OpeningResolver::OPENING_CONTEXT_BACKEND) == false && date('w') > 2) {
  47. $currentCycleNumber = $currentCycleNumber - 1;
  48. }
  49. $this->cycleNumbers = array();
  50. for ($w = $currentCycleNumber - $this->nbCycle + 1; $w <= $currentCycleNumber; $w++) {
  51. $this->cycleNumbers[] = $w;
  52. $this->labels[$w] = 'S ' . $w;
  53. foreach ($this->getProperties() as $propertyName => $property) {
  54. $this->properties[$propertyName]['data'][$w] = 0;
  55. }
  56. foreach ($this->getAverageProperties() as $propertyName => $property) {
  57. $this->averageProperties[$propertyName]['data'][$w] = 0;
  58. }
  59. }
  60. }
  61. public function populateProperties(OrderShopStore $orderShopStore)
  62. {
  63. $countsOrderedByCyclesAndProducts = $orderShopStore->countValidOrderProductsOfCyclesByProducts(
  64. $this->cycleNumbers,
  65. $this->productIds
  66. );
  67. foreach ($countsOrderedByCyclesAndProducts as $result) {
  68. $this->setData($result['productId'], $result['cycleNumber'], $result['quantity']);
  69. $product = $this->productIds[$result['productId']];
  70. if ($this->productFamily->getBehaviorDisplaySale() == ProductFamilyModel::BEHAVIOR_DISPLAY_SALE_BY_MEASURE) {
  71. $ratioByMeasure = $product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient();
  72. $this->setData('total_sales', $result['cycleNumber'], intval($result['quantity']) * $ratioByMeasure);
  73. } else {
  74. $this->setData('total_sales', $result['cycleNumber'], intval($result['quantity']));
  75. }
  76. }
  77. $this->setAveragePropertiesData();
  78. }
  79. }