You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use Knp\Component\Pager\PaginatorInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
  6. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  7. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class ProductRepositoryQuery extends AbstractRepositoryQuery
  10. {
  11. protected bool $isJoinProductFamily =false;
  12. protected bool $isJoinProductFamilySectionProperties =false;
  13. public function __construct(ProductRepository $repository, PaginatorInterface $paginator)
  14. {
  15. parent::__construct($repository, 'r', $paginator);
  16. }
  17. public function orderByDefault(): \Lc\SovBundle\Repository\AbstractRepositoryQuery
  18. {
  19. return $this->orderBy('position', 'ASC');
  20. }
  21. public function joinProductFamily():self
  22. {
  23. if (!$this->isJoinProductFamily) {
  24. $this->isJoinProductFamily = true;
  25. return $this
  26. ->innerJoin('.productFamily', 'pf')
  27. ->addSelect('pf');
  28. }
  29. return $this;
  30. }
  31. public function filterBySection(SectionInterface $section):self
  32. {
  33. $this->joinProductFamilySectionProperties(false);
  34. $this->andWhereSection('pfsp', $section);
  35. $this->andWhere('pfsp.status = 1');
  36. return $this;
  37. }
  38. public function joinProductFamilySectionProperties(bool $addSelect = true): self
  39. {
  40. $this->joinProductFamily();
  41. if (!$this->isJoinProductFamilySectionProperties) {
  42. $this->isJoinProductFamilySectionProperties = true;
  43. $this->leftJoin('pf.productFamilySectionProperties', 'pfsp');
  44. if ($addSelect) {
  45. $this->addSelect('pfsp');
  46. }
  47. }
  48. return $this;
  49. }
  50. public function filterIsOnline():self
  51. {
  52. $this->joinProductFamily();
  53. $this->andWhereStatus('pf', 1);
  54. $this->andWhereStatus($this->id, 1);
  55. return $this;
  56. }
  57. public function filterAvailableQuantityNegative() :self
  58. {
  59. $this->andWhere(
  60. $this->query->expr()->orX(
  61. $this->query->expr()->andX(
  62. $this->query->expr()->orX(
  63. 'pf.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  64. 'pf.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  65. ),
  66. 'pf.availableQuantity < 0 '
  67. ),
  68. $this->query->expr()->andX(
  69. 'pf.behaviorCountStock LIKE :behaviorCountStockByProduct',
  70. 'r.availableQuantity < 0 '
  71. )
  72. )
  73. );
  74. $this->setParameter(
  75. 'behaviorCountStockByProductFamily',
  76. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  77. );
  78. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  79. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  80. return $this;
  81. }
  82. public function filterAvailableQuantitySupplierNegative() :self
  83. {
  84. $this->andWhere(
  85. $this->query->expr()->orX(
  86. $this->query->expr()->andX(
  87. $this->query->expr()->orX(
  88. 'pf.behaviorCountStock LIKE :behaviorCountStockByProductFamily',
  89. 'pf.behaviorCountStock LIKE :behaviorCountStockByMeasure'
  90. ),
  91. 'pf.availableQuantitySupplier < 0 '
  92. ),
  93. $this->query->expr()->andX(
  94. 'pf.behaviorCountStock LIKE :behaviorCountStockByProduct',
  95. 'r.availableQuantitySupplier < 0 '
  96. )
  97. )
  98. );
  99. $this->setParameter(
  100. 'behaviorCountStockByProductFamily',
  101. ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
  102. );
  103. $this->setParameter('behaviorCountStockByMeasure', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE);
  104. $this->setParameter('behaviorCountStockByProduct', ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT);
  105. return $this;
  106. }
  107. }