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 string $executiondate Date to execute the transfer
* @param int $notrigger Disable triggers * @param int $notrigger Disable triggers
* @param string $type 'direct-debit' or 'bank-transfer' * @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 * @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 // phpcs:enable
global $conf, $langs, $user; global $conf, $langs, $user;
@ -811,7 +812,9 @@ class BonPrelevement extends CommonObject
$sql .= " AND pfd.traite = 0"; $sql .= " AND pfd.traite = 0";
$sql .= " AND f.total_ttc > 0"; $sql .= " AND f.total_ttc > 0";
$sql .= " AND pfd.ext_payment_id IS NULL"; $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); dol_syslog(__METHOD__."::Read invoices,", LOG_DEBUG);
$resql = $this->db->query($sql); $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 // TODO Create a prelevement_bon and set its status to sent instead of this
$bon = new BonPrelevement($db); $bon = new BonPrelevement($this->db);
$nbinvoices = $bon->create(); $nbinvoices = $bon->create(0, 0, 'real', 'ALL', '', 0, 'direct-debit', $did);
if ($nbinvoices <= 0) { if ($nbinvoices <= 0) {
$error++; $error++;
$errorforinvoice++; $errorforinvoice++;
@ -1451,12 +1451,14 @@ abstract class CommonInvoice extends CommonObject
$this->errors[] = "Error on BonPrelevement creation"; $this->errors[] = "Error on BonPrelevement creation";
} }
$result = $bon->set_infotrans($user, $now, 'internet'); if (!$errorforinvoice) {
if ($result < 0) { $result = $bon->set_infotrans($user, $now, 'internet');
$error++; if ($result < 0) {
$errorforinvoice++; $error++;
dol_syslog("Error on BonPrelevement creation", LOG_ERR); $errorforinvoice++;
$this->errors[] = "Error on BonPrelevement creation"; dol_syslog("Error on BonPrelevement creation", LOG_ERR);
$this->errors[] = "Error on BonPrelevement creation";
}
} }
if (!$errorforinvoice) { if (!$errorforinvoice) {