src/Repository/Idempiere/MProductpriceRepository.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Idempiere;
  3. use App\Entity\Idempiere\MProductprice;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Query\Parameter;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. /**
  9. * @method MProductprice|null find($id, $lockMode = null, $lockVersion = null)
  10. * @method MProductprice|null findOneBy(array $criteria, array $orderBy = null)
  11. * @method MProductprice[] findAll()
  12. * @method MProductprice[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13. */
  14. class MProductpriceRepository extends ServiceEntityRepository
  15. {
  16. public function __construct(ManagerRegistry $registry)
  17. {
  18. parent::__construct($registry, MProductprice::class);
  19. }
  20. /**
  21. * Busca el ultimo precio de un producto
  22. *
  23. * @param int $ad_org_id Identificador de la organizacion
  24. * @param int $m_pricelist_id Identificador de la lista de precios
  25. * @param string $m_product_id Identificador del producto
  26. *
  27. * @return null|MProductprice Precio
  28. */
  29. public function findPrice(Int $ad_org_id = 0, Int $m_pricelist_id = 0, Int $m_product_id):? MProductprice
  30. {
  31. $qb = $this->createQueryBuilder('mpp');
  32. $qb
  33. ->join('mpp.m_pricelist_version', 'mpv')
  34. ->join('mpv.m_pricelist', 'mpl')
  35. ->join('mpp.m_product', 'mp')
  36. ->where(
  37. $qb->expr()->andX(
  38. $qb->expr()->eq('mpp.isactive', "'Y'"),
  39. $qb->expr()->eq('mpv.isactive', "'Y'"),
  40. $qb->expr()->eq('mpl.issopricelist', "'Y'"),
  41. $qb->expr()->eq('mp.m_product_id', ':product_id')
  42. )
  43. )
  44. ->setParameter('product_id', $m_product_id);
  45. if ($ad_org_id > 0) {
  46. $qb
  47. ->andWhere($qb->expr()->eq('mpp.ad_org_id', ':org_id'))
  48. ->setParameter('org_id', $ad_org_id);
  49. }
  50. if ($m_pricelist_id > 0) {
  51. $qb
  52. ->andWhere($qb->expr()->eq('mpv.m_pricelist_id', ':pricelist_id'))
  53. ->setParameter('pricelist_id', $m_pricelist_id);
  54. }
  55. return $qb
  56. ->orderBy(
  57. $qb->expr()->desc('mpv.updated')
  58. )
  59. ->setMaxResults(1)
  60. ->getQuery()
  61. ->getOneOrNullResult();
  62. }
  63. /**
  64. * Busca los precios de los productos
  65. *
  66. * @param int $ad_org_id Identificador de la organizacion
  67. * @param int $m_pricelist_id Identificador de la lista de precios
  68. * @param string $value Codigo o Nombre del producto
  69. *
  70. * @return null|MProductprice[] Productos con precios
  71. */
  72. public function findProductPrices(Int $m_pricelist_id, String $value = '')
  73. {
  74. $qb = $this->createQueryBuilder('mpp');
  75. $query = $qb
  76. ->distinct()
  77. ->join('mpp.m_product', 'mp')
  78. ->join('mp.sm_precios_estimadolines', 'spel')
  79. ->join('spel.sm_precio_estimado', 'spe')
  80. ->join('spe.m_pricelist_version', 'mpv', 'with', 'mpv.m_pricelist_version_id = mpp.m_pricelist_version_id')
  81. ->leftjoin('mp.m_productdownload', 'mpd', 'with', "mpd.iscover = 'Y'")
  82. ->where(
  83. $qb->expr()->andX(
  84. // Product Price
  85. $qb->expr()->eq('mpp.isactive', "'Y'"),
  86. // Product
  87. $qb->expr()->eq('mp.isactive', "'Y'"),
  88. $qb->expr()->eq('mp.issold', "'Y'"),
  89. $qb->expr()->eq('mp.issummary', "'N'"),
  90. $qb->expr()->orX(
  91. $qb->expr()->like('UPPER(mp.name)', 'UPPER(:value)'),
  92. $qb->expr()->like('UPPER(mp.sku)', 'UPPER(:value)'),
  93. $qb->expr()->like('UPPER(mp.value)','UPPER(:value)'),
  94. ),
  95. // Estimacion
  96. // $qb->expr()->eq('spel.isactive', "'Y'"),
  97. $qb->expr()->eq('spel.listo', "'Y'"),
  98. $qb->expr()->eq('spe.docstatus', "'Y'"),
  99. $qb->expr()->eq('spe.sm_isbreak', "'Y'"),
  100. // Version
  101. $qb->expr()->eq('mpv.m_pricelist_id', ':pricelist_id'),
  102. $qb->expr()->eq('mpv.isactive', "'Y'")
  103. )
  104. )
  105. ->setParameters(
  106. new ArrayCollection([
  107. new Parameter('value', $value ?: "%%"),
  108. new Parameter('pricelist_id', $m_pricelist_id)
  109. ])
  110. )
  111. ->getQuery();
  112. return $query->getResult();
  113. }
  114. }