Fix split entries for proper balancing
- Main entry: rounded amount on 4455100/4456700 (formatAmount) - Rounding entry: real difference on 758000/658000 (formatAmountReal) - For difference -0.90: 4455100 credit 1.00 + 758000 credit 0.90 - Should now show correct split between main and rounding accounts
This commit is contained in:
parent
673a2e4fda
commit
93830f309f
@ -2077,27 +2077,59 @@ class DeclarationTVA_PDF
|
||||
error_log("DeclarationTVA: Total difference: " . $difference);
|
||||
error_log("DeclarationTVA: Difference > 0: " . ($difference > 0 ? 'true' : 'false'));
|
||||
|
||||
// Use real difference, no rounding
|
||||
// Split into main entry (rounded) and rounding entry (real difference)
|
||||
if (abs($difference) >= 0.01) {
|
||||
error_log("DeclarationTVA: Creating balancing entry for real difference: " . $difference);
|
||||
$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
|
||||
if ($difference > 0) {
|
||||
// More credits than debits - need debit entry (4456700)
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '4456700',
|
||||
'account_label' => $this->getAccountLabel('4456700'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => $this->formatAmountReal($difference),
|
||||
'credit' => ''
|
||||
);
|
||||
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' => ''
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// More debits than credits - need credit entry (4455100)
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '4455100',
|
||||
'account_label' => $this->getAccountLabel('4455100'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => '',
|
||||
'credit' => $this->formatAmountReal(abs($difference))
|
||||
);
|
||||
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))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Rounding entry for the real difference
|
||||
if (abs($rounding_diff) >= 0.01) {
|
||||
if ($difference > 0) {
|
||||
// Credit difference - rounding goes to 658000 debit
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '658000',
|
||||
'account_label' => $this->getAccountLabel('658000'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => $this->formatAmountReal(abs($rounding_diff)),
|
||||
'credit' => ''
|
||||
);
|
||||
} else {
|
||||
// Debit difference - rounding goes to 758000 credit
|
||||
$balancing_entries[] = array(
|
||||
'account_code' => '758000',
|
||||
'account_label' => $this->getAccountLabel('758000'),
|
||||
'entry_label' => $declaration->declaration_name,
|
||||
'debit' => '',
|
||||
'credit' => $this->formatAmountReal(abs($rounding_diff))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user