Filter out paid invoices already linked to bank entries

When showing paid invoices for linking, exclude those whose
payment is already linked to a bank entry (fk_bank > 0).
A paid invoice can only be linked to one bank transaction.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Eduard Wisch 2026-02-20 09:18:41 +01:00
parent 2f0f438ec4
commit 48b8fe2773
2 changed files with 31 additions and 5 deletions

View file

@ -765,8 +765,21 @@ if ($object->id > 0) {
$isPaid = ($obj->fk_statut == 2); $isPaid = ($obj->fk_statut == 2);
// Show if unpaid OR if showing paid invoices // For paid invoices, check if payment is already linked to a bank entry
if ($remainToPay > 0 || $isPaid) { $hasLinkedBankEntry = false;
if ($isPaid) {
$sqlPay = "SELECT pf.fk_bank FROM ".MAIN_DB_PREFIX."paiementfourn pf";
$sqlPay .= " JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn pff ON pf.rowid = pff.fk_paiementfourn";
$sqlPay .= " WHERE pff.fk_facturefourn = ".((int) $obj->rowid);
$sqlPay .= " AND pf.fk_bank IS NOT NULL AND pf.fk_bank > 0";
$resqlPay = $db->query($sqlPay);
if ($resqlPay && $db->num_rows($resqlPay) > 0) {
$hasLinkedBankEntry = true;
}
}
// Show if unpaid OR if paid but not yet linked to bank
if ($remainToPay > 0 || ($isPaid && !$hasLinkedBankEntry)) {
$invoiceList[] = array( $invoiceList[] = array(
'id' => $obj->rowid, 'id' => $obj->rowid,
'ref' => $obj->ref, 'ref' => $obj->ref,
@ -818,8 +831,21 @@ if ($object->id > 0) {
$isPaid = ($obj->fk_statut == 2); $isPaid = ($obj->fk_statut == 2);
// Show if unpaid OR if showing paid invoices // For paid invoices, check if payment is already linked to a bank entry
if ($remainToPay > 0 || $isPaid) { $hasLinkedBankEntry = false;
if ($isPaid) {
$sqlPay = "SELECT p.fk_bank FROM ".MAIN_DB_PREFIX."paiement p";
$sqlPay .= " JOIN ".MAIN_DB_PREFIX."paiement_facture pf ON p.rowid = pf.fk_paiement";
$sqlPay .= " WHERE pf.fk_facture = ".((int) $obj->rowid);
$sqlPay .= " AND p.fk_bank IS NOT NULL AND p.fk_bank > 0";
$resqlPay = $db->query($sqlPay);
if ($resqlPay && $db->num_rows($resqlPay) > 0) {
$hasLinkedBankEntry = true;
}
}
// Show if unpaid OR if paid but not yet linked to bank
if ($remainToPay > 0 || ($isPaid && !$hasLinkedBankEntry)) {
$invoiceList[] = array( $invoiceList[] = array(
'id' => $obj->rowid, 'id' => $obj->rowid,
'ref' => $obj->ref, 'ref' => $obj->ref,

View file

@ -76,7 +76,7 @@ class modBankImport extends DolibarrModules
$this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@bankimport' $this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@bankimport'
// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z' // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z'
$this->version = '1.9'; $this->version = '2.0';
// Url to the file with your last numberversion of this module // Url to the file with your last numberversion of this module
//$this->url_last_version = 'http://www.example.com/versionmodule.txt'; //$this->url_last_version = 'http://www.example.com/versionmodule.txt';