Fix accounting entry creation by using direct SQL insert
- Remove dependency on non-existent AccountingBookkeeping class - Use direct SQL INSERT into accounting_bookkeeping table - Fixes 'Failed opening required' error for accounting class - Creates accounting entries directly in database
This commit is contained in:
parent
a03f883f28
commit
be9238e84c
@ -1215,26 +1215,18 @@ class DeclarationTVA
|
|||||||
return true; // No entries to save
|
return true; // No entries to save
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use Dolibarr's accounting integration
|
// Insert accounting entries directly into the accounting table
|
||||||
require_once DOL_DOCUMENT_ROOT . '/compta/accounting/class/accountingbookkeeping.class.php';
|
|
||||||
|
|
||||||
$bookkeeping = new AccountingBookkeeping($this->db);
|
|
||||||
|
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
// Create accounting entry
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping
|
||||||
$bookkeeping->doc_type = 'declarationtva';
|
(doc_type, doc_ref, doc_date, account_number, account_label, debit, credit, label, entity, date_creation, tms)
|
||||||
$bookkeeping->doc_ref = $declaration->declaration_number;
|
VALUES ('declarationtva', '" . $this->db->escape($declaration->declaration_name) . "', '" . $declaration->end_date . "',
|
||||||
$bookkeeping->doc_date = $declaration->end_date; // Use declaration end date for OD entries
|
'" . $this->db->escape($entry['account_code']) . "', '" . $this->db->escape($entry['account_label']) . "',
|
||||||
$bookkeeping->account_number = $entry['account_code'];
|
" . (float)$entry['debit'] . ", " . (float)$entry['credit'] . ",
|
||||||
$bookkeeping->account_label = $entry['account_label'];
|
'" . $this->db->escape($entry['entry_label']) . "', " . $this->entity . ", NOW(), NOW())";
|
||||||
$bookkeeping->debit = $entry['debit'];
|
|
||||||
$bookkeeping->credit = $entry['credit'];
|
|
||||||
$bookkeeping->label = $entry['entry_label'];
|
|
||||||
$bookkeeping->entity = $this->entity;
|
|
||||||
|
|
||||||
$result = $bookkeeping->create($user);
|
$result = $this->db->query($sql);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$this->error = 'Failed to create accounting entry: ' . $bookkeeping->error;
|
$this->error = 'Failed to create accounting entry: ' . $this->db->lasterror();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user