Remove direct SQL approach and use proper Dolibarr error handling
- Remove direct SQL insert fallback that bypasses Dolibarr logic - Use proper result checking: if (result > 0) for success - Log actual entry IDs when successfully created - Use bookkeeping->error for proper error messages - Maintain Dolibarr's internal validation and business logic
This commit is contained in:
parent
b195156e2b
commit
038cd3ed67
@ -1252,36 +1252,14 @@ class DeclarationTVA
|
||||
$debit->entity = $this->entity;
|
||||
|
||||
$result = $debit->create($user);
|
||||
error_log("DEBUG: Debit entry create result: " . ($result ? "SUCCESS" : "FAILED - " . $debit->error));
|
||||
error_log("DEBUG: Debit entry create result: " . ($result ? "SUCCESS" : "FAILED"));
|
||||
|
||||
if (!$result) {
|
||||
// Try direct SQL insert as fallback
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping
|
||||
(doc_date, doc_ref, code_journal, numero_compte, label_compte, montant, sens, fk_doc, fk_docdet, societe_type, fk_user_author, code_tiers, piece_num, import_key, entity, date_creation, tms)
|
||||
VALUES ('" . $this->db->escape($declaration->end_date) . "',
|
||||
'" . $this->db->escape($declaration->declaration_name) . "',
|
||||
'OD',
|
||||
'" . $this->db->escape($entry['account_code']) . "',
|
||||
'" . $this->db->escape($entry['account_label']) . "',
|
||||
" . $debit_amount . ",
|
||||
'D',
|
||||
" . $declaration->rowid . ",
|
||||
0,
|
||||
1,
|
||||
" . $user->id . ",
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
" . $this->entity . ",
|
||||
NOW(), NOW())";
|
||||
|
||||
$sql_result = $this->db->query($sql);
|
||||
error_log("DEBUG: Direct SQL debit insert result: " . ($sql_result ? "SUCCESS" : "FAILED - " . $this->db->lasterror()));
|
||||
|
||||
if (!$sql_result) {
|
||||
$this->error = 'Failed to create debit entry: ' . $this->db->lasterror();
|
||||
return false;
|
||||
}
|
||||
if ($result > 0) {
|
||||
error_log("DEBUG: Debit entry created successfully with ID: " . $result);
|
||||
} else {
|
||||
error_log("DEBUG: Debit entry creation failed: " . $debit->error);
|
||||
$this->error = 'Failed to create debit entry: ' . $debit->error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1305,36 +1283,14 @@ class DeclarationTVA
|
||||
$credit->entity = $this->entity;
|
||||
|
||||
$result = $credit->create($user);
|
||||
error_log("DEBUG: Credit entry create result: " . ($result ? "SUCCESS" : "FAILED - " . $credit->error));
|
||||
error_log("DEBUG: Credit entry create result: " . ($result ? "SUCCESS" : "FAILED"));
|
||||
|
||||
if (!$result) {
|
||||
// Try direct SQL insert as fallback
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_bookkeeping
|
||||
(doc_date, doc_ref, code_journal, numero_compte, label_compte, montant, sens, fk_doc, fk_docdet, societe_type, fk_user_author, code_tiers, piece_num, import_key, entity, date_creation, tms)
|
||||
VALUES ('" . $this->db->escape($declaration->end_date) . "',
|
||||
'" . $this->db->escape($declaration->declaration_name) . "',
|
||||
'OD',
|
||||
'" . $this->db->escape($entry['account_code']) . "',
|
||||
'" . $this->db->escape($entry['account_label']) . "',
|
||||
" . $credit_amount . ",
|
||||
'C',
|
||||
" . $declaration->rowid . ",
|
||||
0,
|
||||
1,
|
||||
" . $user->id . ",
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
" . $this->entity . ",
|
||||
NOW(), NOW())";
|
||||
|
||||
$sql_result = $this->db->query($sql);
|
||||
error_log("DEBUG: Direct SQL credit insert result: " . ($sql_result ? "SUCCESS" : "FAILED - " . $this->db->lasterror()));
|
||||
|
||||
if (!$sql_result) {
|
||||
$this->error = 'Failed to create credit entry: ' . $this->db->lasterror();
|
||||
return false;
|
||||
}
|
||||
if ($result > 0) {
|
||||
error_log("DEBUG: Credit entry created successfully with ID: " . $result);
|
||||
} else {
|
||||
error_log("DEBUG: Credit entry creation failed: " . $credit->error);
|
||||
$this->error = 'Failed to create credit entry: ' . $credit->error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user