Fix class not found for supplier credit. Class must be into

commoninvoice
This commit is contained in:
Laurent Destailleur 2020-06-24 19:59:06 +02:00
parent 2865d6bd15
commit 02e022ebfa
6 changed files with 173 additions and 162 deletions

View File

@ -1389,6 +1389,8 @@ class Account extends CommonObject
$label = '<u>'.$langs->trans("BankAccount").'</u>';
$label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
$label .= '<br><b>'.$langs->trans('AccountNumber').':</b> '.$this->number;
$label .= '<br><b>'.$langs->trans('IBAN').':</b> '.$this->iban;
$label .= '<br><b>'.$langs->trans('BIC').':</b> '.$this->bic;
$label .= '<br><b>'.$langs->trans("AccountCurrency").':</b> '.$this->currency_code;
if (empty($user->rights->banque->lire) || !empty($user->socid))

View File

@ -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)

View File

@ -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 "</td>";
print '</tr>';
print '<tr><td>'.$langs->trans("RIB").'</td><td colspan="3">';
$title = 'CustomerIBAN';
if ($mode == 'bank-transfer') {
$title = 'SupplierIBAN';
}
print '<tr><td>'.$langs->trans($title).'</td><td colspan="3">';
$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 '</td></tr>';
@ -741,7 +749,7 @@ if ($object->id > 0)
$obj = $db->fetch_object($result_sql);
print '<tr class="oddeven">';
print '<td class="left">'.dol_print_date($db->jdate($obj->date_demande), 'day')."</td>\n";
print '<td class="left">'.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."</td>\n";
print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'</a></td>';
print '<td class="center">'.price($obj->amount).'</td>';
print '<td align="center">-</td>';
@ -750,7 +758,7 @@ if ($object->id > 0)
print '<td class="center">'.$langs->trans("OrderWaiting").'</td>';
print '<td class="right">';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete&amp;did='.$obj->rowid.'">';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&did='.$obj->rowid.'&mode='.$mode.'">';
print img_delete();
print '</a></td>';

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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<br>Data of payment: %s