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. public function __construct(ManagerRegistry $registry)
  20. {
  21. parent::__construct($registry, CPayment::class);
  22. /** Table Sequence */
  23. $RSequence = new AdSequenceRepository($registry);
  24. $this->sequence = $RSequence->findBy(['name' => $this->getClassMetadata()->getTableName()]);
  25. $this->sequence = $this->sequence[0];
  26. }
  27. /**
  28. * @throws ORMException
  29. * @throws OptimisticLockException
  30. */
  31. public function add(CPayment $entity, bool $flush = true): void
  32. {
  33. $this->_em->persist($entity);
  34. if ($flush) {
  35. $this->_em->flush();
  36. }
  37. }
  38. /**
  39. * @throws ORMException
  40. * @throws OptimisticLockException
  41. */
  42. public function remove(CPayment $entity, bool $flush = true): void
  43. {
  44. $this->_em->remove($entity);
  45. if ($flush) {
  46. $this->_em->flush();
  47. }
  48. }
  49. /**
  50. * Obtener pagos filtrando las
  51. *
  52. * @param array $BP_Items Rubros de Organizacion
  53. * @param mixed $DocStatus Estatus de documento
  54. * @param string $Date Fecha
  55. *
  56. * @return CPayment[] Pagos
  57. */
  58. public function findPaymentsByBPItem(Array $BP_Items, $DocStatus = null, String $Date = null)
  59. {
  60. $qb = $this->createQueryBuilder('cp');
  61. $qb
  62. ->join('cp.sm_marca', 'sm')
  63. ->where(
  64. $qb->expr()->andX(
  65. $qb->expr()->eq('cp.isreceipt', "'N'"),
  66. $qb->expr()->in('sm.sm_bp_item_id', ':bp_items')
  67. )
  68. )
  69. ->setParameter('bp_items', $BP_Items);
  70. if ( is_array($DocStatus) && count($DocStatus) > 0) {
  71. $qb->andWhere(
  72. $qb->expr()->in('cp.docstatus', ':status')
  73. )->setParameter('status', $DocStatus);
  74. } else if ( !is_null($DocStatus) && !empty($DocStatus) ) {
  75. $qb->andWhere(
  76. $qb->expr()->eq('cp.docstatus', ':status')
  77. )->setParameter('status', $DocStatus);
  78. }
  79. if ( !is_null($Date) && !empty($Date) ) {
  80. $qb->andWhere(
  81. $qb->expr()->eq('cp.dateacct', ':date')
  82. )->setParameter('date', $Date);
  83. }
  84. $query = $qb
  85. ->orderBy(
  86. $qb->expr()->desc('cp.c_doctype_id'),
  87. $qb->expr()->desc('cp.ad_org_id')
  88. )
  89. ->getQuery();
  90. return $query->getResult();
  91. }
  92. public function convertAmt(CPayment $Payamt)
  93. {
  94. $conn = $this->getEntityManager()->getConnection();
  95. $sql = 'SELECT CURRENCYCONVERT(:payamt, :currency_id, :currencytarget_id, :dateacct, :conversiontype_id, :client_id, :org_id)';
  96. $stmt = $conn->prepare($sql);
  97. $rs = $stmt->executeQuery([
  98. 'payamt' => $Payamt->getPayamt(),
  99. 'currency_id' => $Payamt->getCCurrencyId(),
  100. 'currencytarget_id' => 100,
  101. 'dateacct' => $Payamt->getDateacct(),
  102. 'conversiontype_id' => $Payamt->getCConversiontypeId(),
  103. 'client_id' => $Payamt->getAdClientId(),
  104. 'org_id' => $Payamt->getAdOrgId()
  105. ]);
  106. return $rs->fetchOne();
  107. }
  108. }