src/Repository/Idempiere/MProductRepository.php line 101

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Idempiere;
  3. use App\Entity\Idempiere\MProduct;
  4. use App\Entity\Idempiere\MProductprice;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Query\Parameter;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use Monolog\Logger;
  10. /**
  11.  * @method MProduct|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method MProduct|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method MProduct[]    findAll()
  14.  * @method MProduct[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class MProductRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registryMProduct::class);
  21.     }
  22.     public function findBy(array $criteria, array $orderBy null$limit null$offset null)
  23.     {
  24.         $logger = new Logger("Repositorio de Producto");
  25.         $ad_ord_id 0;
  26.         if (key_exists('ad_org_id'$criteria)) {
  27.             $ad_ord_id $criteria['ad_org_id'];
  28.             $logger->log(Logger::DEBUG"Org = " $ad_ord_id);
  29.             unset($criteria['ad_org_id']);
  30.         }
  31.         $m_pricelist_id 0;
  32.         if (key_exists('m_pricelist_id'$criteria)) {
  33.             $m_pricelist_id $criteria['m_pricelist_id'];
  34.             $logger->log(Logger::DEBUG"Price List = " $m_pricelist_id);
  35.             unset($criteria['m_pricelist_id']);
  36.         }
  37.         /** @var MProductPriceRepository */
  38.         $RPrice $this->_em->getRepository(MProductprice::class);
  39.         /** @var MProduct[] */
  40.         $Products parent::findBy($criteria$orderBy$limit$offset);
  41.         foreach ($Products as $p) {
  42.             $productPrice $RPrice->findPrice($ad_ord_id$m_pricelist_id$p->getId());
  43.             if ($productPrice != null
  44.                 $p->setPrice($productPrice->getPricelist());
  45.             
  46.             $logger->log(Logger::DEBUG"Product Price = [" $p->getSku() . ", " $p->getPrice() . "]");
  47.         }
  48.         return $Products;
  49.     }
  50.     /**
  51.      * Buscar productos con imagenes para el catalogo
  52.      * 
  53.      * @param int $sm_marca_id Identificador de la marca
  54.      * @param int $m_product_category_id Identificador de la Categoria
  55.      * @return array
  56.      */
  57.     public function findToCatalog(Int $sm_marca_idInt $m_product_category_id 0): array
  58.     {
  59.         $qb $this->createQueryBuilder('mp');
  60.         $qb
  61.             ->join('mp.m_productdownload''mpd')
  62.             ->where(
  63.                 $qb->expr()->andX(
  64.                     $qb->expr()->eq('mp.isactive'"'Y'"),
  65.                     $qb->expr()->eq('mp.issold'"'Y'"),
  66.                     $qb->expr()->eq('mp.sm_marca_id'':marca_id'),
  67.                     $qb->expr()->eq('mpd.isactive'"'Y'"),
  68.                     $qb->expr()->like('mpd.downloadurl'':format')
  69.                 )
  70.             );
  71.             
  72.         if ($m_product_category_id 0)
  73.             $qb->andWhere$qb->expr()->eq('mp.m_product_category_id'':category_id') );
  74.         $qb->setParameters(
  75.             new ArrayCollection([
  76.                 new Parameter('marca_id'$sm_marca_id),
  77.                 new Parameter('format''%.png')
  78.             ])
  79.         );
  80.             
  81.         if ($m_product_category_id 0)
  82.             $qb->setParameter('category_id'$m_product_category_id);
  83.         
  84.         $query $qb
  85.             ->orderBy('mp.m_product_category_id''DESC')
  86.             ->addOrderBy('mp.m_product_id''DESC')
  87.             ->getQuery();
  88.         return $query->getResult();
  89.     }
  90.     public function findToOrder(Int $sm_marca_id, Array $categoriesString $value null)
  91.     {
  92.         $qb $this->createQueryBuilder('mp');
  93.         $qb
  94.             ->where(
  95.                 $qb->expr()->andX(
  96.                     $qb->expr()->eq('mp.issold'"'Y'"),
  97.                     $qb->expr()->eq('mp.isactive'"'Y'"),
  98.                     $qb->expr()->eq('mp.sm_marca_id'':marca_id'),
  99.                     $qb->expr()->in('mp.m_product_category_id'':categories'
  100.                 )
  101.             )
  102.             ->setParameters(
  103.                 new ArrayCollection([
  104.                     new Parameter('marca_id'$sm_marca_id),
  105.                     new Parameter('categories'$categories)
  106.                 ])
  107.             );
  108.         
  109.         if ( !is_null($value) ) {
  110.             $qb->andWhere(
  111.                 $qb->expr()->orX(
  112.                     $qb->expr()->like('mp.value'':value'),
  113.                     $qb->expr()->like('mp.sku'':value'),
  114.                     $qb->expr()->like('mp.name'':value')
  115.                 )
  116.             )->setParameter('value''%'$value .'%');
  117.         }
  118.         $query $qb
  119.             ->orderBy('mp.m_product_category_id''DESC')
  120.             ->addOrderBy('mp.m_product_id''DESC')
  121.             ->getQuery();
  122.         return $query->getResult();
  123.     }
  124.     /**
  125.      * Busca los productos con sus cantidades 
  126.      * disponibles segun su almacen o ubicacion
  127.      * 
  128.      * @param int $m_product_id Identificador del producto
  129.      * @param int $m_warehouse_id Identificador del almacen
  130.      * @param int $m_locator_id Identificador de la ubicacion
  131.      * 
  132.      * @return float Productos
  133.      */
  134.     public function getQtyOnHandToOrder(Int $m_product_idInt $m_warehouse_idInt $m_locator_id 0): Float
  135.     {
  136.         $connection $this->getEntityManager()->getConnection();
  137.         $stmt $connection->prepare("SELECT BOMQtyOnHandToOrder(:product_id, :warehouse_id, :locator_id) AS QtyToOrder");
  138.         $resulSet $stmt->executeQuery([
  139.             'product_id' => $m_product_id,
  140.             'warehouse_id' => $m_warehouse_id,
  141.             'locator_id' => $m_locator_id
  142.         ]);
  143.         return $resulSet->fetchOne();
  144.     }
  145.     /**
  146.      * Busca los productos con sus cantidades 
  147.      * disponibles segun su almacen o ubicacion
  148.      * 
  149.      * @param int $m_product_id Identificador del producto
  150.      * @param int $m_warehouse_id Identificador del almacen
  151.      * @param int $m_locator_id Identificador de la ubicacion
  152.      * 
  153.      * @return float Productos
  154.      */
  155.     public function findStorage(Int $m_product_idInt $m_warehouse_idInt $m_locator_id 0): Float
  156.     {
  157.         $connection $this->getEntityManager()->getConnection();
  158.         $stmt $connection->prepare("SELECT bomqtyonhand(:product_id, :warehouse_id, :locator_id) AS QtyToOrder");
  159.         $resulSet $stmt->executeQuery([
  160.             'product_id' => $m_product_id,
  161.             'warehouse_id' => $m_warehouse_id,
  162.             'locator_id' => $m_locator_id
  163.         ]);
  164.         return $resulSet->fetchOne();
  165.     }
  166. }