From 02e022ebfa06e11bba29316abebad0242ba23f62 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Jun 2020 19:59:06 +0200 Subject: [PATCH] Fix class not found for supplier credit. Class must be into commoninvoice --- htdocs/compta/bank/class/account.class.php | 2 + htdocs/compta/facture/class/facture.class.php | 155 ------------------ htdocs/compta/facture/prelevement.php | 20 ++- htdocs/core/class/commoninvoice.class.php | 154 +++++++++++++++++ htdocs/langs/en_US/bills.lang | 2 + htdocs/langs/en_US/withdrawals.lang | 2 +- 6 files changed, 173 insertions(+), 162 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index ca6a2e8d589..07e4abb0197 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1389,6 +1389,8 @@ class Account extends CommonObject $label = ''.$langs->trans("BankAccount").''; $label .= '
'.$langs->trans('Label').': '.$this->label; $label .= '
'.$langs->trans('AccountNumber').': '.$this->number; + $label .= '
'.$langs->trans('IBAN').': '.$this->iban; + $label .= '
'.$langs->trans('BIC').': '.$this->bic; $label .= '
'.$langs->trans("AccountCurrency").': '.$this->currency_code; if (empty($user->rights->banque->lire) || !empty($user->socid)) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 9a80ad91d24..8957da7b9db 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4078,161 +4078,6 @@ class Facture extends CommonInvoice } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Create a withdrawal request for a direct debit order or a credit transfer order. - * Use the remain to pay excluding all existing open direct debit requests. - * - * @param User $fuser User asking the direct debit transfer - * @param float $amount Amount we request direct debit for - * @param string $type 'direct-debit' or 'bank-transfer' - * @param string $sourcetype Source ('facture' or 'supplier_invoice') - * @return int <0 if KO, >0 if OK - */ - public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'facture') - { - // phpcs:enable - global $conf; - - $error = 0; - - dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); - - if ($this->statut > self::STATUS_DRAFT && $this->paye == 0) - { - require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; - $bac = new CompanyBankAccount($this->db); - $bac->fetch(0, $this->socid); - - $sql = 'SELECT count(*)'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; - if ($type == 'bank-transfer') { - $sql .= ' WHERE fk_facture_fourn = '.$this->id; - } else { - $sql .= ' WHERE fk_facture = '.$this->id; - } - $sql .= ' AND ext_payment_id IS NULL'; // To exclude record done for some online payments - $sql .= ' AND traite = 0'; - - dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - if ($row[0] == 0) - { - $now = dol_now(); - - $totalpaye = $this->getSommePaiement(); - $totalcreditnotes = $this->getSumCreditNotesUsed(); - $totaldeposits = $this->getSumDepositsUsed(); - //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits; - - // We can also use bcadd to avoid pb with floating points - // For example print 239.2 - 229.3 - 9.9; does not return 0. - //$resteapayer=bcadd($this->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); - //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); - if (empty($amount)) $amount = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); - - if (is_numeric($amount) && $amount != 0) - { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande('; - if ($type == 'bank-transfer') { - $sql .= 'fk_facture_fourn, '; - } else { - $sql .= 'fk_facture, '; - } - $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)'; - $sql .= ' VALUES ('.$this->id; - $sql .= ",'".price2num($amount)."'"; - $sql .= ",'".$this->db->idate($now)."'"; - $sql .= ",".$fuser->id; - $sql .= ",'".$this->db->escape($bac->code_banque)."'"; - $sql .= ",'".$this->db->escape($bac->code_guichet)."'"; - $sql .= ",'".$this->db->escape($bac->number)."'"; - $sql .= ",'".$this->db->escape($bac->cle_rib)."'"; - $sql .= ",'".$this->db->escape($sourcetype)."'"; - $sql .= ",".$conf->entity; - $sql .= ")"; - - dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) - { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this).'::demandeprelevement Erreur'); - $error++; - } - } - else - { - $this->error = 'WithdrawRequestErrorNilAmount'; - dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount'); - $error++; - } - - if (!$error) - { - // Force payment mode of invoice to withdraw - $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', 1); - if ($payment_mode_id > 0) - { - $result = $this->setPaymentMethods($payment_mode_id); - } - } - - if ($error) return -1; - return 1; - } - else - { - $this->error = "A request already exists"; - dol_syslog(get_class($this).'::demandeprelevement Impossible de creer une demande, demande deja en cours'); - return 0; - } - } - else - { - $this->error = $this->db->error(); - dol_syslog(get_class($this).'::demandeprelevement Erreur -2'); - return -2; - } - } - else - { - $this->error = "Status of invoice does not allow this"; - dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->statut, $this->paye, $this->mode_reglement_id"); - return -3; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Supprime une demande de prelevement - * - * @param User $fuser User making delete - * @param int $did id de la demande a supprimer - * @return int <0 if OK, >0 if KO - */ - public function demande_prelevement_delete($fuser, $did) - { - // phpcs:enable - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; - $sql .= ' WHERE rowid = '.$did; - $sql .= ' AND traite = 0'; - if ($this->db->query($sql)) - { - return 0; - } - else - { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error); - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 2b181e52078..dd9c1394563 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -114,12 +114,12 @@ if (empty($reshook)) if ($action == "delete") { - if ($object->id > 0) + if ($object->id > 0) { $result = $object->demande_prelevement_delete($user, GETPOST('did', 'int')); if ($result == 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id.'&mode='.$mode); exit; } } @@ -487,13 +487,21 @@ if ($object->id > 0) print ""; print ''; - print ''.$langs->trans("RIB").''; + $title = 'CustomerIBAN'; + if ($mode == 'bank-transfer') { + $title = 'SupplierIBAN'; + } + print ''.$langs->trans($title).''; $bac = new CompanyBankAccount($db); $bac->fetch(0, $object->thirdparty->id); print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic; - if ($bac->verif() <= 0) print img_warning('Error on default bank number for IBAN : '.$bac->error_message); + if (!empty($bac->iban)) { + if ($bac->verif() <= 0) print img_warning('Error on default bank number for IBAN : '.$bac->error_message); + } else { + print img_warning($langs->trans("NoDefaultIBANFound")); + } print ''; @@ -741,7 +749,7 @@ if ($object->id > 0) $obj = $db->fetch_object($result_sql); print ''; - print ''.dol_print_date($db->jdate($obj->date_demande), 'day')."\n"; + print ''.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."\n"; print ''.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.''; print ''.price($obj->amount).''; print '-'; @@ -750,7 +758,7 @@ if ($object->id > 0) print ''.$langs->trans("OrderWaiting").''; print ''; - print ''; + print ''; print img_delete(); print ''; diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index c37ece437d4..cb7ce67d923 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -687,6 +687,160 @@ abstract class CommonInvoice extends CommonObject return $datelim; } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Create a withdrawal request for a direct debit order or a credit transfer order. + * Use the remain to pay excluding all existing open direct debit requests. + * + * @param User $fuser User asking the direct debit transfer + * @param float $amount Amount we request direct debit for + * @param string $type 'direct-debit' or 'bank-transfer' + * @param string $sourcetype Source ('facture' or 'supplier_invoice') + * @return int <0 if KO, >0 if OK + */ + public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'facture') + { + // phpcs:enable + global $conf; + + $error = 0; + + dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); + + if ($this->statut > self::STATUS_DRAFT && $this->paye == 0) + { + require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; + $bac = new CompanyBankAccount($this->db); + $bac->fetch(0, $this->socid); + + $sql = 'SELECT count(*)'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + if ($type == 'bank-transfer') { + $sql .= ' WHERE fk_facture_fourn = '.$this->id; + } else { + $sql .= ' WHERE fk_facture = '.$this->id; + } + $sql .= ' AND ext_payment_id IS NULL'; // To exclude record done for some online payments + $sql .= ' AND traite = 0'; + + dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $row = $this->db->fetch_row($resql); + if ($row[0] == 0) + { + $now = dol_now(); + + $totalpaye = $this->getSommePaiement(); + $totalcreditnotes = $this->getSumCreditNotesUsed(); + $totaldeposits = $this->getSumDepositsUsed(); + //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits; + + // We can also use bcadd to avoid pb with floating points + // For example print 239.2 - 229.3 - 9.9; does not return 0. + //$resteapayer=bcadd($this->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); + //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); + if (empty($amount)) $amount = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); + + if (is_numeric($amount) && $amount != 0) + { + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande('; + if ($type == 'bank-transfer') { + $sql .= 'fk_facture_fourn, '; + } else { + $sql .= 'fk_facture, '; + } + $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, entity)'; + $sql .= ' VALUES ('.$this->id; + $sql .= ",'".price2num($amount)."'"; + $sql .= ",'".$this->db->idate($now)."'"; + $sql .= ",".$fuser->id; + $sql .= ",'".$this->db->escape($bac->code_banque)."'"; + $sql .= ",'".$this->db->escape($bac->code_guichet)."'"; + $sql .= ",'".$this->db->escape($bac->number)."'"; + $sql .= ",'".$this->db->escape($bac->cle_rib)."'"; + $sql .= ",'".$this->db->escape($sourcetype)."'"; + $sql .= ",".$conf->entity; + $sql .= ")"; + + dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) + { + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this).'::demandeprelevement Erreur'); + $error++; + } + } + else + { + $this->error = 'WithdrawRequestErrorNilAmount'; + dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount'); + $error++; + } + + if (!$error) + { + // Force payment mode of invoice to withdraw + $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement', 'code', 'id', 1); + if ($payment_mode_id > 0) + { + $result = $this->setPaymentMethods($payment_mode_id); + } + } + + if ($error) return -1; + return 1; + } + else + { + $this->error = "A request already exists"; + dol_syslog(get_class($this).'::demandeprelevement Impossible de creer une demande, demande deja en cours'); + return 0; + } + } + else + { + $this->error = $this->db->error(); + dol_syslog(get_class($this).'::demandeprelevement Erreur -2'); + return -2; + } + } + else + { + $this->error = "Status of invoice does not allow this"; + dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->statut, $this->paye, $this->mode_reglement_id"); + return -3; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Remove a direct debit request or a credit transfer request + * + * @param User $fuser User making delete + * @param int $did ID of request to delete + * @return int <0 if OK, >0 if KO + */ + public function demande_prelevement_delete($fuser, $did) + { + // phpcs:enable + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + $sql .= ' WHERE rowid = '.$did; + $sql .= ' AND traite = 0'; + if ($this->db->query($sql)) + { + return 0; + } + else + { + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error); + return -1; + } + } } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 1e562909360..dccc80b1918 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -440,6 +440,8 @@ BankAccountNumberKey=Checksum Residence=Address IBANNumber=IBAN account number IBAN=IBAN +CustomerIBAN=IBAN of customer +SupplierIBAN=IBAN of vendor BIC=BIC/SWIFT BICNumber=BIC/SWIFT code ExtraInfos=Extra infos diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index bea89f1d5d0..49c9f8b5921 100644 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -131,7 +131,7 @@ ICS=Creditor Identifier CI END_TO_END="EndToEndId" SEPA XML tag - Unique id assigned per transaction USTRD="Unstructured" SEPA XML tag ADDDAYS=Add days to Execution Date - +NoDefaultIBANFound=No default IBAN found for this third party ### Notifications InfoCreditSubject=Payment of direct debit payment order %s by the bank InfoCreditMessage=The direct debit payment order %s has been paid by the bank
Data of payment: %s