Skip bank entries for carry-forward VAT credits

- Skip bank journal entries when VAT credit is below threshold
- Only create bank entries for immediate refunds (above threshold)
- Add explanation in PDF when bank entries are skipped
- Show carry-forward amount and threshold in PDF explanation
This commit is contained in:
Frank Cools 2025-10-09 11:49:16 +02:00
parent 7a0a7bd921
commit a503ed6bf6
2 changed files with 71 additions and 38 deletions

View File

@ -1116,28 +1116,30 @@ class DeclarationTVA
$threshold_enabled = $threshold_config['refund_threshold_enabled'];
if ($threshold_enabled && $vat_credit < $refund_threshold) {
// Use carry-forward account
$vat_account = $journal_config['vat_to_receive'];
// Carry-forward case - NO bank entries needed
// Only create accounting entries for carry-forward (no bank transaction)
error_log("DEBUG: VAT credit below threshold (" . $vat_credit . " < " . $refund_threshold . ") - skipping bank entries, using carry-forward");
return array(); // Return empty array - no bank entries for carry-forward
} else {
// Use immediate refund account
$vat_account = $journal_config['vat_refund'];
// Immediate refund case - create bank entries
error_log("DEBUG: VAT credit above threshold (" . $vat_credit . " >= " . $refund_threshold . ") - creating bank entries for immediate refund");
$entries[] = array(
'account_code' => $bank_account['account_code'],
'account_label' => $bank_account['account_label'],
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => $vat_credit,
'credit' => ''
);
$entries[] = array(
'account_code' => $journal_config['vat_refund'],
'account_label' => $this->getAccountLabel($journal_config['vat_refund']),
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => '',
'credit' => $vat_credit
);
}
$entries[] = array(
'account_code' => $bank_account['account_code'],
'account_label' => $bank_account['account_label'],
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => $vat_credit,
'credit' => ''
);
$entries[] = array(
'account_code' => $vat_account,
'account_label' => $this->getAccountLabel($vat_account),
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => '',
'credit' => $vat_credit
);
}
// Get bank journal code from bank account

View File

@ -2054,7 +2054,28 @@ class DeclarationTVA_PDF
if (empty($bank_entries)) {
$pdf->SetFont('helvetica', '', 12);
$pdf->Cell(0, 8, 'Aucune écriture bancaire à générer.', 0, 1);
// Check if this is a carry-forward case
$line_16_amount = $this->getLineAmount($declaration, '16');
$line_23_amount = $this->getLineAmount($declaration, '23');
$td_amount = $line_16_amount - $line_23_amount;
if ($td_amount < 0) {
// VAT credit case - check if below threshold
$vat_credit = abs($td_amount);
$threshold_config = $this->getVATRefundThresholdConfiguration();
$refund_threshold = $threshold_config['refund_threshold'];
$threshold_enabled = $threshold_config['refund_threshold_enabled'];
if ($threshold_enabled && $vat_credit < $refund_threshold) {
$pdf->Cell(0, 8, 'Aucune écriture bancaire - Crédit TVA reporté au mois suivant', 0, 1);
$pdf->Cell(0, 8, '(Montant: ' . $this->formatAmountReal($vat_credit) . ' € < Seuil: ' . $this->formatAmountReal($refund_threshold) . ' €)', 0, 1);
} else {
$pdf->Cell(0, 8, 'Aucune écriture bancaire à générer.', 0, 1);
}
} else {
$pdf->Cell(0, 8, 'Aucune écriture bancaire à générer.', 0, 1);
}
return;
}
@ -2161,24 +2182,34 @@ class DeclarationTVA_PDF
);
} elseif ($vat_credit > 0) {
// VAT refund case - money coming in
// 1. Bank account (debit - money coming in)
$entries[] = array(
'account_code' => $bank_account['account_code'],
'account_label' => $bank_account['account_label'],
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => $this->formatAmountReal($vat_credit),
'credit' => ''
);
// VAT refund case - check threshold for carry-forward
$threshold_config = $this->getVATRefundThresholdConfiguration();
$refund_threshold = $threshold_config['refund_threshold'];
$threshold_enabled = $threshold_config['refund_threshold_enabled'];
// 2. VAT account (credit - VAT being received)
$entries[] = array(
'account_code' => $journal_config['vat_to_receive'],
'account_label' => $this->getAccountLabel($journal_config['vat_to_receive']),
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => '',
'credit' => $this->formatAmountReal($vat_credit)
);
if ($threshold_enabled && $vat_credit < $refund_threshold) {
// Carry-forward case - NO bank entries for PDF
return $entries; // Return empty array - no bank entries for carry-forward
} else {
// Immediate refund case - create bank entries
// 1. Bank account (debit - money coming in)
$entries[] = array(
'account_code' => $bank_account['account_code'],
'account_label' => $bank_account['account_label'],
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => $this->formatAmountReal($vat_credit),
'credit' => ''
);
// 2. VAT account (credit - VAT being received)
$entries[] = array(
'account_code' => $journal_config['vat_to_receive'],
'account_label' => $this->getAccountLabel($journal_config['vat_to_receive']),
'entry_label' => 'Remboursement TVA - ' . $declaration->declaration_name,
'debit' => '',
'credit' => $this->formatAmountReal($vat_credit)
);
}
}
return $entries;