Add account validation and existing entry comparison

- Check if account number exists in accounting_account table
- Compare with existing accounting entries to see field differences
- Help identify if account validation is causing the -1 return
- Debug the exact validation requirements
This commit is contained in:
Frank Cools 2025-10-08 22:21:05 +02:00
parent 855b0c6d9b
commit c6984d8527

View File

@ -1269,6 +1269,25 @@ class DeclarationTVA
error_log("DEBUG: Journal code 'OD' NOT FOUND in system - this might be the issue");
}
// Check if account number exists
$account_check_sql = "SELECT account_number FROM " . MAIN_DB_PREFIX . "accounting_account WHERE account_number = '" . $this->db->escape($entry['account_code']) . "' AND entity = " . $this->entity;
$account_check_result = $this->db->query($account_check_sql);
if ($account_check_result && $this->db->num_rows($account_check_result) > 0) {
error_log("DEBUG: Account number '" . $entry['account_code'] . "' exists in system");
} else {
error_log("DEBUG: Account number '" . $entry['account_code'] . "' NOT FOUND in system - this might be the issue");
}
// Check existing accounting entries to see what fields they have
$existing_sql = "SELECT * FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE entity = " . $this->entity . " LIMIT 1";
$existing_result = $this->db->query($existing_sql);
if ($existing_result && $this->db->num_rows($existing_result) > 0) {
$existing_obj = $this->db->fetch_object($existing_result);
error_log("DEBUG: Existing entry fields - doc_date: " . $existing_obj->doc_date . ", doc_ref: " . $existing_obj->doc_ref . ", code_journal: " . $existing_obj->code_journal . ", numero_compte: " . $existing_obj->numero_compte . ", montant: " . $existing_obj->montant . ", sens: " . $existing_obj->sens);
} else {
error_log("DEBUG: No existing accounting entries found in system");
}
$result = $debit->create($user);
error_log("DEBUG: Debit entry create result: " . $result . " (type: " . gettype($result) . ")");