creation of prelevement_bon only for 1 demande

This commit is contained in:
hystepik 2023-02-22 15:09:37 +01:00
parent 646c1b1502
commit be2ee21462
2 changed files with 15 additions and 10 deletions

View File

@ -747,9 +747,10 @@ class BonPrelevement extends CommonObject
* @param string $executiondate Date to execute the transfer
* @param int $notrigger Disable triggers
* @param string $type 'direct-debit' or 'bank-transfer'
* @param int $did ID of payment request
* @return int <0 if KO, No of invoice included into file if OK
*/
public function create($banque = 0, $agence = 0, $mode = 'real', $format = 'ALL', $executiondate = '', $notrigger = 0, $type = 'direct-debit')
public function create($banque = 0, $agence = 0, $mode = 'real', $format = 'ALL', $executiondate = '', $notrigger = 0, $type = 'direct-debit', $did = 0)
{
// phpcs:enable
global $conf, $langs, $user;
@ -811,7 +812,9 @@ class BonPrelevement extends CommonObject
$sql .= " AND pfd.traite = 0";
$sql .= " AND f.total_ttc > 0";
$sql .= " AND pfd.ext_payment_id IS NULL";
if ($did > 0) {
$sql .= " AND pfd.rowid = '".$this->db->escape($did)."'";
}
dol_syslog(__METHOD__."::Read invoices,", LOG_DEBUG);
$resql = $this->db->query($sql);

View File

@ -1442,8 +1442,8 @@ abstract class CommonInvoice extends CommonObject
}
// TODO Create a prelevement_bon and set its status to sent instead of this
$bon = new BonPrelevement($db);
$nbinvoices = $bon->create();
$bon = new BonPrelevement($this->db);
$nbinvoices = $bon->create(0, 0, 'real', 'ALL', '', 0, 'direct-debit', $did);
if ($nbinvoices <= 0) {
$error++;
$errorforinvoice++;
@ -1451,12 +1451,14 @@ abstract class CommonInvoice extends CommonObject
$this->errors[] = "Error on BonPrelevement creation";
}
$result = $bon->set_infotrans($user, $now, 'internet');
if ($result < 0) {
$error++;
$errorforinvoice++;
dol_syslog("Error on BonPrelevement creation", LOG_ERR);
$this->errors[] = "Error on BonPrelevement creation";
if (!$errorforinvoice) {
$result = $bon->set_infotrans($user, $now, 'internet');
if ($result < 0) {
$error++;
$errorforinvoice++;
dol_syslog("Error on BonPrelevement creation", LOG_ERR);
$this->errors[] = "Error on BonPrelevement creation";
}
}
if (!$errorforinvoice) {