src/Repository/Idempiere/CPaymentRepository.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Idempiere;
  3. use App\Entity\Idempiere\CPayment;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\ORM\OptimisticLockException;
  6. use Doctrine\ORM\ORMException;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. /**
  9.  * @extends ServiceEntityRepository<CPayment>
  10.  *
  11.  * @method CPayment|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method CPayment|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method CPayment[]    findAll()
  14.  * @method CPayment[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class CPaymentRepository extends ServiceEntityRepository
  17. {
  18.     public $sequence;
  19.     
  20.     public function __construct(ManagerRegistry $registry)
  21.     {
  22.         parent::__construct($registryCPayment::class);
  23.         /** Table Sequence */
  24.         $RSequence = new AdSequenceRepository($registry);
  25.         $this->sequence $RSequence->findBy(['name' => $this->getClassMetadata()->getTableName()]);
  26.         $this->sequence $this->sequence[0];
  27.     }
  28.     /**
  29.      * @throws ORMException
  30.      * @throws OptimisticLockException
  31.      */
  32.     public function add(CPayment $entitybool $flush true): void
  33.     {
  34.         $this->_em->persist($entity);
  35.         if ($flush) {
  36.             $this->_em->flush();
  37.         }
  38.     }
  39.     /**
  40.      * @throws ORMException
  41.      * @throws OptimisticLockException
  42.      */
  43.     public function remove(CPayment $entitybool $flush true): void
  44.     {
  45.         $this->_em->remove($entity);
  46.         if ($flush) {
  47.             $this->_em->flush();
  48.         }
  49.     }
  50.     /**
  51.      * Obtener pagos filtrando las 
  52.      * 
  53.      * @param array $BP_Items Rubros de Organizacion
  54.      * @param mixed $DocStatus Estatus de documento
  55.      * @param string $Date Fecha
  56.      * 
  57.      * @return CPayment[] Pagos
  58.      */
  59.     public function findPaymentsByBPItem(Array $BP_Items$DocStatus nullString $Date null)
  60.     {
  61.         $qb $this->createQueryBuilder('cp');
  62.         $qb
  63.             ->join('cp.sm_marca''sm')
  64.             ->where(
  65.                 $qb->expr()->andX(
  66.                     $qb->expr()->eq('cp.isreceipt'"'N'"),
  67.                     $qb->expr()->in('sm.sm_bp_item_id'':bp_items')
  68.                 )
  69.             )
  70.             ->setParameter('bp_items'$BP_Items);
  71.         if ( is_array($DocStatus) && count($DocStatus) > 0) {
  72.             $qb->andWhere(
  73.                 $qb->expr()->in('cp.docstatus'':status')
  74.             )->setParameter('status'$DocStatus);
  75.         } else if ( !is_null($DocStatus) && !empty($DocStatus) ) {
  76.             $qb->andWhere(
  77.                 $qb->expr()->eq('cp.docstatus'':status')
  78.             )->setParameter('status'$DocStatus);
  79.         }
  80.         if ( !is_null($Date) && !empty($Date) ) {
  81.             $qb->andWhere(
  82.                 $qb->expr()->eq('cp.dateacct'':date')
  83.             )->setParameter('date'$Date);
  84.         }
  85.         $query $qb
  86.             ->orderBy(
  87.                 $qb->expr()->desc('cp.c_doctype_id'),
  88.                 $qb->expr()->desc('cp.ad_org_id')
  89.             )
  90.             ->getQuery();
  91.         return $query->getResult();
  92.     }
  93.     public function convertAmt(CPayment $Payamt)
  94.     {
  95.         $conn $this->getEntityManager()->getConnection();
  96.         $sql    'SELECT CURRENCYCONVERT(:payamt, :currency_id, :currencytarget_id, :dateacct, :conversiontype_id, :client_id, :org_id)';
  97.         $stmt   $conn->prepare($sql);
  98.         $rs     $stmt->executeQuery([
  99.             'payamt' => $Payamt->getPayamt(),
  100.             'currency_id' => $Payamt->getCCurrencyId(),
  101.             'currencytarget_id' => 100,
  102.             'dateacct' => $Payamt->getDateacct(),
  103.             'conversiontype_id' => $Payamt->getCConversiontypeId(),
  104.             'client_id' => $Payamt->getAdClientId(),
  105.             'org_id' => $Payamt->getAdOrgId()
  106.         ]);
  107.         return $rs->fetchOne();
  108.     }
  109. }