Remove ALL rounding from difference calculation
- Completely removed rounding logic - Now uses real difference values only (formatAmountReal) - No more rounded amounts or complex rounding logic - Simple: real difference goes to 4455100/4456700 with real value - Should show 4455100 with 0.90 instead of 1.00
This commit is contained in:
parent
c00894db2d
commit
673a2e4fda
@ -2077,106 +2077,28 @@ class DeclarationTVA_PDF
|
|||||||
error_log("DeclarationTVA: Total difference: " . $difference);
|
error_log("DeclarationTVA: Total difference: " . $difference);
|
||||||
error_log("DeclarationTVA: Difference > 0: " . ($difference > 0 ? 'true' : 'false'));
|
error_log("DeclarationTVA: Difference > 0: " . ($difference > 0 ? 'true' : 'false'));
|
||||||
|
|
||||||
// Calculate rounded difference for main entry
|
// Use real difference, no rounding
|
||||||
$rounded_difference = round($difference);
|
if (abs($difference) >= 0.01) {
|
||||||
|
error_log("DeclarationTVA: Creating balancing entry for real difference: " . $difference);
|
||||||
// For very small differences, don't create main balancing entry
|
|
||||||
if (abs($difference) < 1.0) {
|
|
||||||
error_log("DeclarationTVA: Small difference detected: " . $difference . ", creating rounding-only entry");
|
|
||||||
if (abs($difference) >= 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($difference),
|
|
||||||
'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($difference))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($rounded_difference != 0) {
|
|
||||||
// Main balancing entry with rounded amount
|
|
||||||
if ($difference > 0) {
|
if ($difference > 0) {
|
||||||
// More credits than debits - need debit entry (4456700)
|
// More credits than debits - need debit entry (4456700)
|
||||||
error_log("DeclarationTVA: Creating 4456700 debit entry for " . $rounded_difference);
|
|
||||||
$balancing_entries[] = array(
|
$balancing_entries[] = array(
|
||||||
'account_code' => '4456700',
|
'account_code' => '4456700',
|
||||||
'account_label' => $this->getAccountLabel('4456700'),
|
'account_label' => $this->getAccountLabel('4456700'),
|
||||||
'entry_label' => $declaration->declaration_name,
|
'entry_label' => $declaration->declaration_name,
|
||||||
'debit' => $this->formatAmount($rounded_difference),
|
'debit' => $this->formatAmountReal($difference),
|
||||||
'credit' => ''
|
'credit' => ''
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// More debits than credits - need credit entry (4455100)
|
// More debits than credits - need credit entry (4455100)
|
||||||
error_log("DeclarationTVA: Creating 4455100 credit entry for " . abs($rounded_difference));
|
|
||||||
$balancing_entries[] = array(
|
$balancing_entries[] = array(
|
||||||
'account_code' => '4455100',
|
'account_code' => '4455100',
|
||||||
'account_label' => $this->getAccountLabel('4455100'),
|
'account_label' => $this->getAccountLabel('4455100'),
|
||||||
'entry_label' => $declaration->declaration_name,
|
'entry_label' => $declaration->declaration_name,
|
||||||
'debit' => '',
|
'debit' => '',
|
||||||
'credit' => $this->formatAmount(abs($rounded_difference))
|
'credit' => $this->formatAmountReal(abs($difference))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rounding entry for the difference between real and rounded
|
|
||||||
$rounding_diff = $difference - $rounded_difference;
|
|
||||||
error_log("DeclarationTVA: Rounding difference: " . $rounding_diff);
|
|
||||||
|
|
||||||
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))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If rounded difference is 0, but real difference is not 0, create rounding entry only
|
|
||||||
if (abs($difference) >= 0.01) {
|
|
||||||
error_log("DeclarationTVA: Creating rounding-only entry for " . $difference);
|
|
||||||
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($difference),
|
|
||||||
'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($difference))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $balancing_entries;
|
return $balancing_entries;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user