facturestorno.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/facturestatcommon.class.php';
  3. class FactureStorno extends FactureStatCommon
  4. {
  5. /**
  6. * Get HUF, CARD factures to be storno
  7. *
  8. * @param int $entity Entity ID (optional, default=0)
  9. *
  10. * @return array Arrays of records or empty
  11. */
  12. public function facturesToBeStornoHufCard(string $fromDate, string $toDate, int $entity): array
  13. {
  14. return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::HUF, FactureStatCommon::CARD);
  15. }
  16. /**
  17. * Get HUF, CARD factures to be storno
  18. *
  19. * @param int $entity Entity ID (optional, default=0)
  20. *
  21. * @return array Arrays of records or empty
  22. */
  23. public function facturesToBeStornoEurCard(string $fromDate, string $toDate, int $entity): array
  24. {
  25. return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::EUR, FactureStatCommon::CARD);
  26. }
  27. /**
  28. * Get EUR, CASH factures to be storno
  29. *
  30. * @param int $entity Entity ID (optional, default=0)
  31. *
  32. * @return array Arrays of records or empty
  33. */
  34. public function facturesToBeStornoEurCash(string $fromDate, string $toDate, int $entity): array
  35. {
  36. return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::EUR, FactureStatCommon::CASH);
  37. }
  38. /**
  39. * Get HUF, CASH factures to be storno
  40. *
  41. * @param int $entity Entity ID (optional, default=0)
  42. *
  43. * @return array Arrays of records or empty
  44. */
  45. public function facturesToBeStornoHufCash(string $fromDate, string $toDate, int $entity): array
  46. {
  47. return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::HUF, FactureStatCommon::CASH);
  48. }
  49. /**
  50. * Get all factures to be storno
  51. *
  52. * @param int $entity Entity ID
  53. *
  54. * @return array Arrays of records or empty
  55. */
  56. public function allFacturesToBeStorno(int $entity): array
  57. {
  58. $result = [];
  59. $sqlEntity = $this->getEntitySql($entity);
  60. $sql = "
  61. SELECT f.*
  62. FROM ".MAIN_DB_PREFIX."facture AS f
  63. {$sqlEntity}
  64. ORDER BY f.rowid ASC
  65. ";
  66. $rows = $this->db->query($sql);
  67. if ($rows) {
  68. while ($row = $this->db->fetch_object($rows)) {
  69. $result[] = (array) $row;
  70. }
  71. }
  72. return $result;
  73. }
  74. /**
  75. * Get rows from DB
  76. *
  77. * @param int $entity Entity ID (optional, default=0)
  78. * @param string $currency Currency (EUR or HUF)
  79. * @param string $paymentCode Payment code (optional, possible values LIQ or CB, default='')
  80. *
  81. * @return array Arrays of records or empty
  82. */
  83. private function facturesToBeStorno(string $fromDate, string $toDate, int $entity, string $currency, string $paymentCode): array
  84. {
  85. $result = [];
  86. // entity condition
  87. $sqlEntity = $this->getEntitySql($entity);
  88. // payment code condition
  89. $sqlPaymentCode = (empty($paymentCode)) ? '' : $this->getPaymentCodeSql($paymentCode);
  90. $sql = "
  91. SELECT f.*
  92. FROM ".MAIN_DB_PREFIX."facture AS f
  93. LEFT JOIN ".MAIN_DB_PREFIX."facture_extrafields AS fe ON fe.fk_object=f.rowid
  94. WHERE fe.marked_for_storno=1
  95. AND f.date_closing BETWEEN '{$fromDate}' AND '{$toDate}'
  96. AND f.multicurrency_code ILIKE '{$currency}'
  97. AND NOT EXISTS (
  98. SELECT 1
  99. FROM llx_facture AS sf
  100. WHERE sf.fk_facture_source=f.rowid
  101. )
  102. {$sqlEntity}
  103. {$sqlPaymentCode}
  104. ORDER BY f.rowid ASC
  105. ";
  106. $rows = $this->db->query($sql);
  107. if ($rows) {
  108. while ($row = $this->db->fetch_object($rows)) {
  109. $result[] = (array) $row;
  110. }
  111. }
  112. return $result;
  113. }
  114. }