Improve getAccountLabel with multiple query approaches to find account names
- Added multiple query strategies to handle different database configurations - Tries with entity filter, without entity filter, and without active filter - Enhanced debugging to show which query succeeds - Based on successful patterns from other methods in the codebase - Should now properly retrieve account names from Dolibarr chart of accounts
This commit is contained in:
parent
61bc28597b
commit
009ad50d65
@ -2117,14 +2117,29 @@ class DeclarationTVA_PDF
|
||||
*/
|
||||
private function getAccountLabel($account_code)
|
||||
{
|
||||
$sql = "SELECT label FROM " . MAIN_DB_PREFIX . "accounting_account
|
||||
// Try multiple approaches to find the account
|
||||
$possible_queries = array(
|
||||
// With entity filter
|
||||
"SELECT label FROM " . MAIN_DB_PREFIX . "accounting_account
|
||||
WHERE account_number = '" . $this->db->escape($account_code) . "'
|
||||
AND entity = " . $this->entity . "
|
||||
AND active = 1
|
||||
LIMIT 1",
|
||||
|
||||
// Without entity filter
|
||||
"SELECT label FROM " . MAIN_DB_PREFIX . "accounting_account
|
||||
WHERE account_number = '" . $this->db->escape($account_code) . "'
|
||||
AND active = 1
|
||||
LIMIT 1";
|
||||
LIMIT 1",
|
||||
|
||||
// Debug logging
|
||||
error_log("DeclarationTVA: Looking for account " . $account_code . " with entity " . $this->entity);
|
||||
error_log("DeclarationTVA: SQL query: " . $sql);
|
||||
// Without active filter
|
||||
"SELECT label FROM " . MAIN_DB_PREFIX . "accounting_account
|
||||
WHERE account_number = '" . $this->db->escape($account_code) . "'
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
foreach ($possible_queries as $sql) {
|
||||
error_log("DeclarationTVA: Trying query: " . $sql);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result && $this->db->num_rows($result) > 0) {
|
||||
@ -2132,8 +2147,9 @@ class DeclarationTVA_PDF
|
||||
error_log("DeclarationTVA: Found account label: " . $obj->label);
|
||||
return $obj->label;
|
||||
}
|
||||
}
|
||||
|
||||
error_log("DeclarationTVA: Account " . $account_code . " not found, using generic label");
|
||||
error_log("DeclarationTVA: Account " . $account_code . " not found in any query, using generic label");
|
||||
// If account not found in chart of accounts, return generic label
|
||||
return 'Compte ' . $account_code;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user