Use correct Dolibarr bookkeeping class

- Use htdocs/accountancy/class/bookkeeping.class.php
- Replace direct SQL with proper Dolibarr Bookkeeping class
- Maintains proper Dolibarr integration and error handling
This commit is contained in:
Frank Cools 2025-10-08 21:48:42 +02:00
parent be9238e84c
commit 340c4c0ffd

View File

@ -1215,18 +1215,26 @@ class DeclarationTVA
return true; // No entries to save return true; // No entries to save
} }
// Insert accounting entries directly into the accounting table // Use Dolibarr's bookkeeping class
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
$bookkeeping = new Bookkeeping($this->db);
foreach ($entries as $entry) { foreach ($entries as $entry) {
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping // Create accounting entry
(doc_type, doc_ref, doc_date, account_number, account_label, debit, credit, label, entity, date_creation, tms) $bookkeeping->doc_type = 'declarationtva';
VALUES ('declarationtva', '" . $this->db->escape($declaration->declaration_name) . "', '" . $declaration->end_date . "', $bookkeeping->doc_ref = $declaration->declaration_name;
'" . $this->db->escape($entry['account_code']) . "', '" . $this->db->escape($entry['account_label']) . "', $bookkeeping->doc_date = $declaration->end_date; // Use declaration end date for OD entries
" . (float)$entry['debit'] . ", " . (float)$entry['credit'] . ", $bookkeeping->account_number = $entry['account_code'];
'" . $this->db->escape($entry['entry_label']) . "', " . $this->entity . ", NOW(), NOW())"; $bookkeeping->account_label = $entry['account_label'];
$bookkeeping->debit = $entry['debit'];
$bookkeeping->credit = $entry['credit'];
$bookkeeping->label = $entry['entry_label'];
$bookkeeping->entity = $this->entity;
$result = $this->db->query($sql); $result = $bookkeeping->create($user);
if (!$result) { if (!$result) {
$this->error = 'Failed to create accounting entry: ' . $this->db->lasterror(); $this->error = 'Failed to create accounting entry: ' . $bookkeeping->error;
return false; return false;
} }
} }