From 3603952301e4048e94e7b95785aa9930e3e84ffd Mon Sep 17 00:00:00 2001 From: priojk Date: Fri, 24 Mar 2023 13:43:49 +0100 Subject: [PATCH] add hooks to customize automatic closing of invoices (e.g. cash discount) --- htdocs/compta/paiement/class/paiement.class.php | 15 ++++++++++++++- htdocs/fourn/class/paiementfourn.class.php | 14 +++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index ec1392e9ea7..6425e23903b 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -11,6 +11,7 @@ * Copyright (C) 2018-2022 Frédéric France * Copyright (C) 2020 Andreu Bisquerra Gaya * Copyright (C) 2021 OpenDsi + * Copyright (C) 2023 Joachim Kueter * * 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 diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index bdf4f8aa457..20ac5330e75 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -7,6 +7,7 @@ * Copyright (C) 2014 Marcos García * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018 Frédéric France + * Copyright (C) 2023 Joachim Kueter * * 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."); + } } }