2
0
forked from Wavyzz/dolibarr

Debug v19 - Support of bank payment rejection on SEPA.

This commit is contained in:
Laurent Destailleur
2023-12-09 20:28:28 +01:00
parent 02735fab0a
commit 100a657633
6 changed files with 48 additions and 27 deletions

View File

@@ -1919,7 +1919,7 @@ if ($resql) {
$colspan++;
}
}
print '<tr><td colspan="'.($colspan + 1).'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
print '<tr><td colspan="'.($colspan + 1).'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
}
print "</table>";

View File

@@ -97,27 +97,28 @@ class RejetPrelevement
}
/**
* Create
* Create a reject
*
* @param User $user User object
* @param int $id Id
* @param string $motif Motif
* @param int $date_rejet Date rejet
* @param int $date_rejet Date reject
* @param int $bonid Bon id
* @param int $facturation Facturation
* @return void
* @param int $facturation 1=Bill the reject
* @return int Return >=0 if OK, <0 if KO
*/
public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
{
global $langs, $conf;
global $langs;
$error = 0;
$this->id = $id;
$this->bon_id = $bonid;
$now = dol_now();
dol_syslog("RejetPrelevement::Create id $id");
$bankaccount = ($this->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
dol_syslog("RejetPrelevement::Create id ".$id);
$bankaccount = ($this->type == 'bank-transfer' ? getDolGlobalString('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalString('PRELEVEMENT_ID_BANKACCOUNT'));
$facs = $this->getListInvoices(1);
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
@@ -172,30 +173,34 @@ class RejetPrelevement
$fac->fetch($facs[$i][0]);
// Make a negative payment
//$pai = new Paiement($this->db);
$amountrejected = $facs[$i][1];
// Make a negative payment
// Amount must be an array (id of invoice -> amount)
$pai->amounts = array();
/*
* We replace the comma with a point otherwise some
* PHP installs sends only the part integer negative
*/
//var_dump($this->type);exit;
$pai->amounts[$facs[$i][0]] = price2num($amountrejected * -1); // The payment must be negative because it is a refund
$pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * ($this->type == 'bank-transfer' ? 1 : -1));
$pai->datepaye = $date_rejet;
$pai->paiementid = 3; // type of payment: withdrawal
$pai->num_paiement = $fac->ref;
$pai->num_payment = $fac->ref;
$pai->num_paiement = $langs->trans('Rejection').' '.$fac->ref;
$pai->num_payment = $langs->trans('Rejection').' '.$fac->ref;
$pai->id_prelevement = $this->bon_id;
$pai->num_prelevement = $lipre->bon_ref;
if ($pai->create($this->user) < 0) {
// we call with no_commit
$error++;
dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
} else {
$result = $pai->addPaymentToBank($user, 'payment', '(InvoiceRefused)', $bankaccount, '', '');
// We record entry into bank
$mode = 'payment';
if ($this->type == 'bank-transfer') {
$mode = 'payment_supplier';
}
$result = $pai->addPaymentToBank($user, $mode, '(InvoiceRefused)', $bankaccount, '', '');
if ($result < 0) {
dol_syslog("RejetPrelevement::Create AddPaymentToBan Error");
$error++;
@@ -220,9 +225,13 @@ class RejetPrelevement
if ($error == 0) {
dol_syslog("RejetPrelevement::Create Commit");
$this->db->commit();
return 1;
} else {
dol_syslog("RejetPrelevement::Create Rollback");
$this->db->rollback();
return -1;
}
}

View File

@@ -96,6 +96,7 @@ llxHeader('', $langs->trans("WithdrawalsReceipts"));
if ($id > 0 || $ref) {
if ($object->fetch($id, $ref) >= 0) {
$head = prelevement_prepare_head($object);
print dol_get_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
@@ -293,8 +294,9 @@ if ($resql) {
print '<input type="hidden" name="id" value="'.$id.'">';
$massactionbutton = '';
$title = ($salaryBonPl ? $langs->trans("Salaries") : ($object->type == 'bank-transfer' ? $langs->trans("SupplierInvoices") : $langs->trans("Invoices")));
print_barre_liste(($salaryBonPl ? $langs->trans("Salaries") : $langs->trans("Invoices")), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
print"\n<!-- debut table -->\n";
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
@@ -339,7 +341,6 @@ if ($resql) {
print '<tr class="oddeven">';
print '<td class="nowraponall">';
print($salaryBonPl ? $salarytmp->getNomUrl(1) : $invoicetmp->getNomUrl(1));
print "</td>\n";

View File

@@ -85,7 +85,7 @@ $error = 0;
if ($action == 'confirm_rejet' && $permissiontoadd) {
if (GETPOST("confirm") == 'yes') {
if (GETPOST('remonth', 'int')) {
$daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
$daterej = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
}
if (empty($daterej)) {

View File

@@ -33,9 +33,11 @@
*/
function prelevement_prepare_head(BonPrelevement $object)
{
global $langs, $conf, $user;
global $langs, $conf;
$salary = $object->checkIfSalaryBonPrelevement();
$langs->load("withdrawals");
$langs->loadLangs(array("bills", "withdrawals"));
$h = 0;
$head = array();
@@ -50,8 +52,16 @@ function prelevement_prepare_head(BonPrelevement $object)
$head[$h][2] = 'prelevement';
$h++;
$titleoftab = $langs->trans("Bills");
if ($object->type == 'bank-transfer') {
$titleoftab = $langs->trans("SupplierBills");
}
if ($salary > 0) {
$titleoftab = $langs->trans("Salaries");
}
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$object->id;
$head[$h][1] = ($salary <= 0 ? $langs->trans("Bills") : $langs->trans("Salaries"));
$head[$h][1] = $titleoftab;
$head[$h][2] = 'invoices';
$h++;

View File

@@ -66,8 +66,9 @@ WithdrawalRefusedConfirm=Are you sure you want to enter a withdrawal rejection f
RefusedData=Date of rejection
RefusedReason=Reason for rejection
RefusedInvoicing=Billing the rejection
NoInvoiceRefused=Do not charge the rejection
InvoiceRefused=Invoice refused (Charge the rejection to customer)
NoInvoiceRefused=Do not charge the customer for the refusal
InvoiceRefused=Charge the customer for the refusal
DirectDebitRefusedInvoicingDesc=Set a flag to say this refusal must be charged to the customer
StatusDebitCredit=Status debit/credit
StatusWaiting=Waiting
StatusTrans=Sent