| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/facturestatcommon.class.php';
- class FactureStorno extends FactureStatCommon
- {
- /**
- * Get HUF, CARD factures to be storno
- *
- * @param int $entity Entity ID (optional, default=0)
- *
- * @return array Arrays of records or empty
- */
- public function facturesToBeStornoHufCard(string $fromDate, string $toDate, int $entity): array
- {
- return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::HUF, FactureStatCommon::CARD);
- }
- /**
- * Get HUF, CARD factures to be storno
- *
- * @param int $entity Entity ID (optional, default=0)
- *
- * @return array Arrays of records or empty
- */
- public function facturesToBeStornoEurCard(string $fromDate, string $toDate, int $entity): array
- {
- return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::EUR, FactureStatCommon::CARD);
- }
- /**
- * Get EUR, CASH factures to be storno
- *
- * @param int $entity Entity ID (optional, default=0)
- *
- * @return array Arrays of records or empty
- */
- public function facturesToBeStornoEurCash(string $fromDate, string $toDate, int $entity): array
- {
- return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::EUR, FactureStatCommon::CASH);
- }
- /**
- * Get HUF, CASH factures to be storno
- *
- * @param int $entity Entity ID (optional, default=0)
- *
- * @return array Arrays of records or empty
- */
- public function facturesToBeStornoHufCash(string $fromDate, string $toDate, int $entity): array
- {
- return $this->facturesToBeStorno($fromDate, $toDate, $entity, FactureStatCommon::HUF, FactureStatCommon::CASH);
- }
- /**
- * Get all factures to be storno
- *
- * @param int $entity Entity ID
- *
- * @return array Arrays of records or empty
- */
- public function allFacturesToBeStorno(int $entity): array
- {
- $result = [];
- $sqlEntity = $this->getEntitySql($entity);
- $sql = "
- SELECT f.*
- FROM ".MAIN_DB_PREFIX."facture AS f
- {$sqlEntity}
- ORDER BY f.rowid ASC
- ";
- $rows = $this->db->query($sql);
- if ($rows) {
- while ($row = $this->db->fetch_object($rows)) {
- $result[] = (array) $row;
- }
- }
- return $result;
- }
- /**
- * Get rows from DB
- *
- * @param int $entity Entity ID (optional, default=0)
- * @param string $currency Currency (EUR or HUF)
- * @param string $paymentCode Payment code (optional, possible values LIQ or CB, default='')
- *
- * @return array Arrays of records or empty
- */
- private function facturesToBeStorno(string $fromDate, string $toDate, int $entity, string $currency, string $paymentCode): array
- {
- $result = [];
- // entity condition
- $sqlEntity = $this->getEntitySql($entity);
- // payment code condition
- $sqlPaymentCode = (empty($paymentCode)) ? '' : $this->getPaymentCodeSql($paymentCode);
- $sql = "
- SELECT f.*
- FROM ".MAIN_DB_PREFIX."facture AS f
- LEFT JOIN ".MAIN_DB_PREFIX."facture_extrafields AS fe ON fe.fk_object=f.rowid
- WHERE fe.marked_for_storno=1
- AND f.date_closing BETWEEN '{$fromDate}' AND '{$toDate}'
- AND f.multicurrency_code ILIKE '{$currency}'
- AND NOT EXISTS (
- SELECT 1
- FROM llx_facture AS sf
- WHERE sf.fk_facture_source=f.rowid
- )
- {$sqlEntity}
- {$sqlPaymentCode}
- ORDER BY f.rowid ASC
- ";
- $rows = $this->db->query($sql);
- if ($rows) {
- while ($row = $this->db->fetch_object($rows)) {
- $result[] = (array) $row;
- }
- }
- return $result;
- }
- }
|