facturestat.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/facturestatcommon.class.php';
  3. class FactureStat extends FactureStatCommon
  4. {
  5. /**
  6. * Get total sale in HUF in CARD
  7. *
  8. * @param string $fromDate From date in YYYY-mm-dd H:i:s format
  9. * @param string $toDate To date in YYYY-mm-dd H:i:s format
  10. * @param int $entity Entity ID (optional, default=0)
  11. *
  12. * @return array Arrays of records or empty
  13. */
  14. public function sumSaleInHufCard(string $fromDate, string $toDate, int $entity=0): array
  15. {
  16. return $this->factureSummary($fromDate, $toDate, FactureStatCommon::HUF, $entity, FactureStatCommon::CARD);
  17. }
  18. /**
  19. * Get total sale in EUR in CARD
  20. *
  21. * @param string $fromDate From date in YYYY-mm-dd H:i:s format
  22. * @param string $toDate To date in YYYY-mm-dd H:i:s format
  23. * @param int $entity Entity ID (optional, default=0)
  24. *
  25. * @return array Arrays of records or empty
  26. */
  27. public function sumSaleInEurCard(string $fromDate, string $toDate, int $entity=0): array
  28. {
  29. return $this->factureSummary($fromDate, $toDate, FactureStatCommon::EUR, $entity, FactureStatCommon::CARD);
  30. }
  31. /**
  32. * Get total sale in EUR in CASH
  33. *
  34. * @param string $fromDate From date in YYYY-mm-dd H:i:s format
  35. * @param string $toDate To date in YYYY-mm-dd H:i:s format
  36. * @param int $entity Entity ID (optional, default=0)
  37. *
  38. * @return array Arrays of records or empty
  39. */
  40. public function sumSaleInEurCash(string $fromDate, string $toDate, int $entity=0): array
  41. {
  42. return $this->factureSummary($fromDate, $toDate, FactureStatCommon::EUR, $entity, FactureStatCommon::CASH);
  43. }
  44. /**
  45. * Get total sale in HUF in CASH
  46. *
  47. * @param string $fromDate From date in YYYY-mm-dd H:i:s format
  48. * @param string $toDate To date in YYYY-mm-dd H:i:s format
  49. * @param int $entity Entity ID (optional, default=0)
  50. *
  51. * @return array Arrays of records or empty
  52. */
  53. public function sumSaleInHufCash(string $fromDate, string $toDate, int $entity=0): array
  54. {
  55. return $this->factureSummary($fromDate, $toDate, FactureStatCommon::HUF, $entity, FactureStatCommon::CASH);
  56. }
  57. /**
  58. * Get total sale in HUF
  59. *
  60. * @param string $fromDate From date in YYYY-mm-dd H:i:s format
  61. * @param string $toDate To date in YYYY-mm-dd H:i:s format
  62. * @param int $entity Entity ID (optional, default=0)
  63. * @param string $paymentCode Payment code (optional, possible values LIQ or CB, default='')
  64. *
  65. * @return array Arrays of records or empty
  66. */
  67. public function sumSaleInEur(string $fromDate, string $toDate, int $entity=0, string $paymentCode=''): array
  68. {
  69. return $this->factureSummary($fromDate, $toDate, FactureStatCommon::EUR, $entity, $paymentCode);
  70. }
  71. /**
  72. * Get total sale in HUF
  73. *
  74. * @param string $fromDate From date in YYYY-mm-dd H:i:s format
  75. * @param string $toDate To date in YYYY-mm-dd H:i:s format
  76. * @param int $entity Entity ID (optional, default=0)
  77. * @param string $paymentCode Payment code (optional, possible values LIQ or CB, default='')
  78. *
  79. * @return array Arrays of records or empty
  80. */
  81. public function sumSaleInHuf(string $fromDate, string $toDate, int $entity=0, string $paymentCode=''): array
  82. {
  83. return $this->factureSummary($fromDate, $toDate, FactureStatCommon::HUF, $entity, $paymentCode);
  84. }
  85. /**
  86. * Get rows from DB
  87. *
  88. * @param string $fromDate From date in YYYY-mm-dd H:i:s format
  89. * @param string $toDate To date in YYYY-mm-dd H:i:s format
  90. * @param string $currency Currency (EUR or HUF)
  91. * @param int $entity Entity ID (optional, default=0)
  92. * @param string $paymentCode Payment code (optional, possible values LIQ or CB, default='')
  93. *
  94. * @return array Arrays of records or empty
  95. */
  96. private function factureSummary(string $fromDate, string $toDate, string $currency, int $entity=0, string $paymentCode=''): array
  97. {
  98. $result = [];
  99. // entity condition
  100. $sqlEntity = $this->getEntitySql($entity);
  101. // payment code condition
  102. $sqlPaymentCode = (empty($paymentCode)) ? '' : $this->getPaymentCodeSql($paymentCode);
  103. $sql = "
  104. SELECT f.entity, d.tva_tx, SUM(d.multicurrency_total_ht) AS multicurrency_total_ht,
  105. SUM(d.multicurrency_total_tva) AS multicurrency_total_tva,
  106. SUM(d.multicurrency_total_ttc) AS multicurrency_total_ttc
  107. FROM ".MAIN_DB_PREFIX."facture AS f
  108. JOIN ".MAIN_DB_PREFIX."facturedet AS d ON d.fk_facture=f.rowid
  109. WHERE f.date_closing BETWEEN '{$fromDate}' AND '{$toDate}'
  110. AND f.multicurrency_code ILIKE '{$currency}'
  111. {$sqlEntity}
  112. {$sqlPaymentCode}
  113. GROUP BY f.entity, d.tva_tx
  114. ORDER BY d.tva_tx ASC
  115. ";
  116. $rows = $this->db->query($sql);
  117. if ($rows) {
  118. while ($row = $this->db->fetch_object($rows)) {
  119. $result[] = (array) $row;
  120. }
  121. }
  122. return $result;
  123. }
  124. }