Add comprehensive OD journal debugging

- Add debugging to check total OD journal entries in system
- Add debugging to show recent OD journal entries with amounts
- Verify entries are being created in the correct journal
- Help identify if entries exist but are not visible in UI
This commit is contained in:
Frank Cools 2025-10-08 23:08:30 +02:00
parent d48b093ddd
commit ec6642c379

View File

@ -1393,20 +1393,41 @@ class DeclarationTVA
error_log("DEBUG: Final verification - Total entries in database for declaration " . $declaration->declaration_name . ": " . $final_check_obj->total_entries);
}
// Check what's actually in the database
$detail_check_sql = "SELECT rowid, doc_date, doc_ref, code_journal, numero_compte, label_compte, montant, sens, fk_doc, entity, date_creation, tms FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
WHERE doc_ref = '" . $this->db->escape($declaration->declaration_name) . "'
ORDER BY rowid DESC LIMIT 5";
$detail_check_result = $this->db->query($detail_check_sql);
if ($detail_check_result && $this->db->num_rows($detail_check_result) > 0) {
error_log("DEBUG: Recent entries in database with dates:");
while ($detail_obj = $this->db->fetch_object($detail_check_result)) {
error_log("DEBUG: Entry ID: " . $detail_obj->rowid . ", Account: " . $detail_obj->numero_compte . ", Amount: " . $detail_obj->montant . ", Sens: " . $detail_obj->sens . ", Journal: " . $detail_obj->code_journal . ", Entity: " . $detail_obj->entity);
error_log("DEBUG: - doc_date: " . $detail_obj->doc_date . " (operation date)");
error_log("DEBUG: - date_creation: " . $detail_obj->date_creation . " (creation date)");
error_log("DEBUG: - tms: " . $detail_obj->tms . " (modification date)");
}
}
// Check what's actually in the database
$detail_check_sql = "SELECT rowid, doc_date, doc_ref, code_journal, numero_compte, label_compte, montant, sens, fk_doc, entity, date_creation, tms FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
WHERE doc_ref = '" . $this->db->escape($declaration->declaration_name) . "'
ORDER BY rowid DESC LIMIT 5";
$detail_check_result = $this->db->query($detail_check_sql);
if ($detail_check_result && $this->db->num_rows($detail_check_result) > 0) {
error_log("DEBUG: Recent entries in database with dates:");
while ($detail_obj = $this->db->fetch_object($detail_check_result)) {
error_log("DEBUG: Entry ID: " . $detail_obj->rowid . ", Account: " . $detail_obj->numero_compte . ", Amount: " . $detail_obj->montant . ", Sens: " . $detail_obj->sens . ", Journal: " . $detail_obj->code_journal . ", Entity: " . $detail_obj->entity);
error_log("DEBUG: - doc_date: " . $detail_obj->doc_date . " (operation date)");
error_log("DEBUG: - date_creation: " . $detail_obj->date_creation . " (creation date)");
error_log("DEBUG: - tms: " . $detail_obj->tms . " (modification date)");
}
}
// Check if entries exist in OD journal specifically
$od_check_sql = "SELECT COUNT(*) as od_count FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
WHERE code_journal = 'OD' AND entity = " . $this->entity;
$od_check_result = $this->db->query($od_check_sql);
if ($od_check_result && $this->db->num_rows($od_check_result) > 0) {
$od_obj = $this->db->fetch_object($od_check_result);
error_log("DEBUG: Total OD journal entries in system: " . $od_obj->od_count);
}
// Check recent OD entries
$recent_od_sql = "SELECT rowid, doc_ref, numero_compte, montant, sens, code_journal FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
WHERE code_journal = 'OD' AND entity = " . $this->entity . "
ORDER BY rowid DESC LIMIT 10";
$recent_od_result = $this->db->query($recent_od_sql);
if ($recent_od_result && $this->db->num_rows($recent_od_result) > 0) {
error_log("DEBUG: Recent OD journal entries:");
while ($od_obj = $this->db->fetch_object($recent_od_result)) {
error_log("DEBUG: OD Entry - ID: " . $od_obj->rowid . ", Ref: " . $od_obj->doc_ref . ", Account: " . $od_obj->numero_compte . ", Amount: " . $od_obj->montant . ", Sens: " . $od_obj->sens);
}
}
// Check what journal codes exist in the system
$journal_check_sql = "SELECT code, label FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE entity = " . $this->entity;