add hooks to customize automatic closing of invoices (e.g. cash discount)

This commit is contained in:
priojk 2023-03-24 13:43:49 +01:00
parent 344b165acc
commit 3603952301
2 changed files with 27 additions and 2 deletions

View File

@ -11,6 +11,7 @@
* Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Andreu Bisquerra Gaya <jove@bisquerra.com>
* Copyright (C) 2021 OpenDsi <support@open-dsi.fr>
* Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -383,7 +384,19 @@ class Paiement extends CommonObject
if (!in_array($invoice->type, $affected_types)) {
dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
} elseif ($remaintopay) {
dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
// hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
global $hookmanager;
$hookmanager->initHooks(array('paymentdao'));
$parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
$action = 'CLOSEPAIDINVOICE';
$reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
$this->errors[] = $hookmanager->error;
$this->error = $hookmanager->error;
$error++;
} elseif ($reshook == 0) {
dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
}
// } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
} else {
// If invoice is a down payment, we also convert down payment to discount

View File

@ -7,6 +7,7 @@
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018 Frédéric France <frederic.francenetlogic.fr>
* Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -341,7 +342,18 @@ class PaiementFourn extends Paiement
}
}
} else {
dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
// hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
global $hookmanager;
$hookmanager->initHooks(array('payment_supplierdao'));
$parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
$action = 'CLOSEPAIDSUPPLIERINVOICE';
$reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
$this->error = $hookmanager->error;
$error++;
} elseif ($reshook == 0) {
dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
}
}
}