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($registryMProductprice::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 0Int $m_pricelist_id 0Int $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.         
  51.         if ($m_pricelist_id 0) {
  52.             $qb
  53.                 ->andWhere($qb->expr()->eq('mpv.m_pricelist_id'':pricelist_id'))
  54.                 ->setParameter('pricelist_id'$m_pricelist_id);
  55.         }
  56.         return $qb
  57.             ->orderBy(
  58.                 $qb->expr()->desc('mpv.updated')
  59.             )
  60.             ->setMaxResults(1)
  61.             ->getQuery()
  62.             ->getOneOrNullResult();
  63.     }
  64.     /**
  65.      * Busca los precios de los productos
  66.      * 
  67.      * @param int $ad_org_id Identificador de la organizacion
  68.      * @param int $m_pricelist_id Identificador de la lista de precios
  69.      * @param string $value Codigo o Nombre del producto
  70.      * 
  71.      * @return null|MProductprice[] Productos con precios
  72.      */
  73.     public function findProductPrices(Int $m_pricelist_idString $value '')
  74.     {
  75.         $qb $this->createQueryBuilder('mpp');
  76.         $query $qb
  77.             ->distinct()
  78.             ->join('mpp.m_product''mp')
  79.             ->join('mp.sm_precios_estimadolines''spel')
  80.             ->join('spel.sm_precio_estimado''spe')
  81.             ->join('spe.m_pricelist_version''mpv''with''mpv.m_pricelist_version_id = mpp.m_pricelist_version_id')
  82.             ->leftjoin('mp.m_productdownload''mpd''with'"mpd.iscover = 'Y'")
  83.             ->where(
  84.                 $qb->expr()->andX(
  85.                     // Product Price
  86.                     $qb->expr()->eq('mpp.isactive'"'Y'"),
  87.                     // Product
  88.                     $qb->expr()->eq('mp.isactive'"'Y'"),
  89.                     $qb->expr()->eq('mp.issold'"'Y'"),
  90.                     $qb->expr()->eq('mp.issummary'"'N'"),
  91.                     $qb->expr()->orX(
  92.                         $qb->expr()->like('UPPER(mp.name)''UPPER(:value)'),
  93.                         $qb->expr()->like('UPPER(mp.sku)',  'UPPER(:value)'),
  94.                         $qb->expr()->like('UPPER(mp.value)','UPPER(:value)'),
  95.                     ),
  96.                     // Estimacion
  97.                     // $qb->expr()->eq('spel.isactive', "'Y'"),
  98.                     $qb->expr()->eq('spel.listo'"'Y'"),
  99.                     $qb->expr()->eq('spe.docstatus'"'Y'"),
  100.                     $qb->expr()->eq('spe.sm_isbreak'"'Y'"),
  101.                     // Version
  102.                     $qb->expr()->eq('mpv.m_pricelist_id'':pricelist_id'),
  103.                     $qb->expr()->eq('mpv.isactive'"'Y'")
  104.                 )
  105.             )
  106.             ->setParameters(
  107.                 new ArrayCollection([
  108.                     new Parameter('value'$value ?: "%%"),
  109.                     new Parameter('pricelist_id'$m_pricelist_id)
  110.                 ])
  111.             )
  112.             ->getQuery();
  113.         return $query->getResult();
  114.     }
  115. }