diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php index a8f1ef3..985ce51 100644 --- a/core/class/declarationtva.class.php +++ b/core/class/declarationtva.class.php @@ -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) . ")");