Fix to create exactly 2 lines with correct amounts
- Changed difference calculation back to (debits - credits) - Creates exactly 2 lines: main amount + rounding difference - For difference 69.90: 4455100 credit 70.00 + 758000 credit 0.90 - Removed complex logic, simplified to 2 entries only
This commit is contained in:
parent
93830f309f
commit
da6bb79204
@ -2062,7 +2062,7 @@ class DeclarationTVA_PDF
|
||||
}
|
||||
}
|
||||
|
||||
$difference = $total_credits - $total_debits;
|
||||
$difference = $total_debits - $total_credits;
|
||||
|
||||
// If difference is very small (less than 0.01), no balancing entry needed
|
||||
if (abs($difference) < 0.01) {
|
||||
@ -2077,42 +2077,38 @@ class DeclarationTVA_PDF
|
||||
error_log("DeclarationTVA: Total difference: " . $difference);
|
||||
error_log("DeclarationTVA: Difference > 0: " . ($difference > 0 ? 'true' : 'false'));
|
||||
|
||||
// Split into main entry (rounded) and rounding entry (real difference)
|
||||
// Create exactly 2 lines: main amount + rounding difference
|
||||
if (abs($difference) >= 0.01) {
|
||||
$rounded_amount = round($difference);
|
||||
$rounding_diff = $difference - $rounded_amount;
|
||||
|
||||
error_log("DeclarationTVA: Difference: " . $difference . ", Rounded: " . $rounded_amount . ", Rounding diff: " . $rounding_diff);
|
||||
|
||||
// Main balancing entry with rounded amount
|
||||
// Main entry with rounded amount
|
||||
if ($difference > 0) {
|
||||
// More credits than debits - need debit entry (4456700)
|
||||
if ($rounded_amount != 0) {
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '4456700',
|
||||
'account_label' => $this->getAccountLabel('4456700'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => $this->formatAmount($rounded_amount),
|
||||
'credit' => ''
|
||||
);
|
||||
}
|
||||
// Credit difference - main entry on 4456700 debit
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '4456700',
|
||||
'account_label' => $this->getAccountLabel('4456700'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => $this->formatAmount($rounded_amount),
|
||||
'credit' => ''
|
||||
);
|
||||
} else {
|
||||
// More debits than credits - need credit entry (4455100)
|
||||
if ($rounded_amount != 0) {
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '4455100',
|
||||
'account_label' => $this->getAccountLabel('4455100'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => '',
|
||||
'credit' => $this->formatAmount(abs($rounded_amount))
|
||||
);
|
||||
}
|
||||
// Debit difference - main entry on 4455100 credit
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '4455100',
|
||||
'account_label' => $this->getAccountLabel('4455100'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => '',
|
||||
'credit' => $this->formatAmount(abs($rounded_amount))
|
||||
);
|
||||
}
|
||||
|
||||
// Rounding entry for the real difference
|
||||
// Rounding entry with real difference
|
||||
if (abs($rounding_diff) >= 0.01) {
|
||||
if ($difference > 0) {
|
||||
// Credit difference - rounding goes to 658000 debit
|
||||
// Credit difference - rounding on 658000 debit
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '658000',
|
||||
'account_label' => $this->getAccountLabel('658000'),
|
||||
@ -2121,7 +2117,7 @@ class DeclarationTVA_PDF
|
||||
'credit' => ''
|
||||
);
|
||||
} else {
|
||||
// Debit difference - rounding goes to 758000 credit
|
||||
// Debit difference - rounding on 758000 credit
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '758000',
|
||||
'account_label' => $this->getAccountLabel('758000'),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user