Fix recalculateCA3Amounts() method

Fixed:
- Replaced non-existent getDeclarationInfo() with direct database query
- Fetches start_date and end_date from declarationtva_declarations table
- Proper error handling for missing declarations
- recalculateCA3Amounts() now works without undefined method errors
This commit is contained in:
Frank Cools 2025-10-02 20:56:21 +02:00
parent 877a66057d
commit a363c301ff

View File

@ -536,12 +536,17 @@ class DeclarationTVA
*/
public function recalculateCA3Amounts($declaration_id)
{
// Get declaration info
$declaration = $this->getDeclarationInfo($declaration_id);
if (!$declaration) {
// Get declaration info directly from database
$sql = "SELECT start_date, end_date FROM " . MAIN_DB_PREFIX . "declarationtva_declarations
WHERE rowid = " . $declaration_id . " AND entity = " . $this->entity;
$result = $this->db->query($sql);
if (!$result || $this->db->num_rows($result) == 0) {
return false;
}
$obj = $this->db->fetch_object($result);
// Clear existing CA-3 lines
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "declarationtva_ca3_lines
WHERE declaration_id = " . $declaration_id;
@ -549,8 +554,8 @@ class DeclarationTVA
// Recalculate using declaration dates
$period = array(
'start_date' => $declaration['start_date'],
'end_date' => $declaration['end_date']
'start_date' => $obj->start_date,
'end_date' => $obj->end_date
);
return $this->calculateCA3Amounts($declaration_id, $period);