Fix: linkExistingPayment and linkMultipleExistingPayments not updating transaction
When linking paid invoices that already have bank entries: - Added missing commit() and return after update() in bank_line branch - Added proper error handling for update() failures - Fixed both single invoice (linkExistingPayment) and multi-invoice linking Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
94efa59df3
commit
2dc9279143
1 changed files with 79 additions and 31 deletions
|
|
@ -1687,10 +1687,16 @@ class BankImportTransaction extends CommonObject
|
||||||
$this->status = self::STATUS_MATCHED;
|
$this->status = self::STATUS_MATCHED;
|
||||||
$this->fk_user_match = $user->id;
|
$this->fk_user_match = $user->id;
|
||||||
$this->date_match = dol_now();
|
$this->date_match = dol_now();
|
||||||
$this->update($user);
|
|
||||||
|
$result = $this->update($user);
|
||||||
|
if ($result <= 0) {
|
||||||
|
$this->error = 'Failed to update transaction: '.$this->error;
|
||||||
|
$this->db->rollback();
|
||||||
|
return -6;
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $paiementfourn->bank_line;
|
return $paiementfourn->bank_line > 0 ? $paiementfourn->bank_line : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create bank entry for existing payment
|
// Create bank entry for existing payment
|
||||||
|
|
@ -2125,7 +2131,28 @@ class BankImportTransaction extends CommonObject
|
||||||
|
|
||||||
// Check if payment already has a bank entry
|
// Check if payment already has a bank entry
|
||||||
if (!empty($paiementfourn->bank_line) && $paiementfourn->bank_line > 0) {
|
if (!empty($paiementfourn->bank_line) && $paiementfourn->bank_line > 0) {
|
||||||
|
// Payment already has a bank entry in Dolibarr
|
||||||
|
// Just link this imported transaction to the existing payment WITHOUT creating new bank entry
|
||||||
$bankLineId = $paiementfourn->bank_line;
|
$bankLineId = $paiementfourn->bank_line;
|
||||||
|
|
||||||
|
$this->fk_paiementfourn = $firstPaymentId;
|
||||||
|
$this->fk_bank = $bankLineId;
|
||||||
|
$this->fk_facture_fourn = $invoices[0]['id'];
|
||||||
|
$this->fk_societe = $socid;
|
||||||
|
$this->status = self::STATUS_MATCHED;
|
||||||
|
$this->fk_user_match = $user->id;
|
||||||
|
$this->date_match = dol_now();
|
||||||
|
$this->note_private = ($this->note_private ? $this->note_private."\n" : '').'Multi-invoice link: '.implode(', ', $invoiceRefs);
|
||||||
|
|
||||||
|
$result = $this->update($user);
|
||||||
|
if ($result <= 0) {
|
||||||
|
$this->error = 'Failed to update transaction: '.$this->error;
|
||||||
|
$this->db->rollback();
|
||||||
|
return -6;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return $bankLineId > 0 ? $bankLineId : 1;
|
||||||
} else {
|
} else {
|
||||||
// Create bank entry for existing payment
|
// Create bank entry for existing payment
|
||||||
$bankLineId = $paiementfourn->addPaymentToBank(
|
$bankLineId = $paiementfourn->addPaymentToBank(
|
||||||
|
|
@ -2136,7 +2163,6 @@ class BankImportTransaction extends CommonObject
|
||||||
$this->name,
|
$this->name,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if ($bankLineId > 0) {
|
if ($bankLineId > 0) {
|
||||||
$this->fk_paiementfourn = $firstPaymentId;
|
$this->fk_paiementfourn = $firstPaymentId;
|
||||||
|
|
@ -2152,6 +2178,7 @@ class BankImportTransaction extends CommonObject
|
||||||
$this->error = 'Failed to add payment to bank';
|
$this->error = 'Failed to add payment to bank';
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||||
$paiement = new Paiement($this->db);
|
$paiement = new Paiement($this->db);
|
||||||
|
|
@ -2163,7 +2190,28 @@ class BankImportTransaction extends CommonObject
|
||||||
|
|
||||||
// Check if payment already has a bank entry
|
// Check if payment already has a bank entry
|
||||||
if (!empty($paiement->bank_line) && $paiement->bank_line > 0) {
|
if (!empty($paiement->bank_line) && $paiement->bank_line > 0) {
|
||||||
|
// Payment already has a bank entry in Dolibarr
|
||||||
|
// Just link this imported transaction to the existing payment WITHOUT creating new bank entry
|
||||||
$bankLineId = $paiement->bank_line;
|
$bankLineId = $paiement->bank_line;
|
||||||
|
|
||||||
|
$this->fk_paiement = $firstPaymentId;
|
||||||
|
$this->fk_bank = $bankLineId;
|
||||||
|
$this->fk_facture = $invoices[0]['id'];
|
||||||
|
$this->fk_societe = $socid;
|
||||||
|
$this->status = self::STATUS_MATCHED;
|
||||||
|
$this->fk_user_match = $user->id;
|
||||||
|
$this->date_match = dol_now();
|
||||||
|
$this->note_private = ($this->note_private ? $this->note_private."\n" : '').'Multi-invoice link: '.implode(', ', $invoiceRefs);
|
||||||
|
|
||||||
|
$result = $this->update($user);
|
||||||
|
if ($result <= 0) {
|
||||||
|
$this->error = 'Failed to update transaction: '.$this->error;
|
||||||
|
$this->db->rollback();
|
||||||
|
return -6;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return $bankLineId > 0 ? $bankLineId : 1;
|
||||||
} else {
|
} else {
|
||||||
// Create bank entry for existing payment
|
// Create bank entry for existing payment
|
||||||
$bankLineId = $paiement->addPaymentToBank(
|
$bankLineId = $paiement->addPaymentToBank(
|
||||||
|
|
@ -2174,7 +2222,6 @@ class BankImportTransaction extends CommonObject
|
||||||
$this->name,
|
$this->name,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if ($bankLineId > 0) {
|
if ($bankLineId > 0) {
|
||||||
$this->fk_paiement = $firstPaymentId;
|
$this->fk_paiement = $firstPaymentId;
|
||||||
|
|
@ -2191,6 +2238,7 @@ class BankImportTransaction extends CommonObject
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($error) {
|
if ($error) {
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
|
@ -2198,7 +2246,7 @@ class BankImportTransaction extends CommonObject
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $bankLineId;
|
return $bankLineId > 0 ? $bankLineId : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue