Add comprehensive debugging for accounting data queries
Debug Features: - Try multiple possible table names (accounting_bookkeeping, accounting_bookkeeping_tmp) - Try different column names (account_number, account) - Try with and without entity filter - Log successful queries and amounts found - Identify which query works with your Dolibarr setup
This commit is contained in:
parent
ca8b50241b
commit
a84729dd8e
@ -232,24 +232,59 @@ class DeclarationTVA
|
|||||||
*/
|
*/
|
||||||
public function getAccountAmounts($account_code, $start_date, $end_date)
|
public function getAccountAmounts($account_code, $start_date, $end_date)
|
||||||
{
|
{
|
||||||
// Query Dolibarr accounting entries
|
// Try different possible table and column names for Dolibarr accounting
|
||||||
$sql = "SELECT SUM(debit) as total_debit, SUM(credit) as total_credit
|
$possible_queries = array(
|
||||||
FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
|
// Standard Dolibarr accounting table
|
||||||
WHERE account_number = '" . $this->db->escape($account_code) . "'
|
"SELECT SUM(debit) as total_debit, SUM(credit) as total_credit
|
||||||
AND doc_date >= '" . $this->db->escape($start_date) . "'
|
FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
|
||||||
AND doc_date <= '" . $this->db->escape($end_date) . "'";
|
WHERE account_number = '" . $this->db->escape($account_code) . "'
|
||||||
|
AND doc_date >= '" . $this->db->escape($start_date) . "'
|
||||||
$result = $this->db->query($sql);
|
AND doc_date <= '" . $this->db->escape($end_date) . "'
|
||||||
if ($result && $this->db->num_rows($result) > 0) {
|
AND entity = " . $this->entity,
|
||||||
$obj = $this->db->fetch_object($result);
|
|
||||||
$total_amount = $obj->total_debit - $obj->total_credit;
|
|
||||||
|
|
||||||
return array(
|
// Alternative table name
|
||||||
'base_amount' => $total_amount,
|
"SELECT SUM(debit) as total_debit, SUM(credit) as total_credit
|
||||||
'vat_amount' => $total_amount,
|
FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping_tmp
|
||||||
'total_amount' => $total_amount
|
WHERE account_number = '" . $this->db->escape($account_code) . "'
|
||||||
);
|
AND doc_date >= '" . $this->db->escape($start_date) . "'
|
||||||
|
AND doc_date <= '" . $this->db->escape($end_date) . "'
|
||||||
|
AND entity = " . $this->entity,
|
||||||
|
|
||||||
|
// Alternative column name
|
||||||
|
"SELECT SUM(debit) as total_debit, SUM(credit) as total_credit
|
||||||
|
FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
|
||||||
|
WHERE account = '" . $this->db->escape($account_code) . "'
|
||||||
|
AND doc_date >= '" . $this->db->escape($start_date) . "'
|
||||||
|
AND doc_date <= '" . $this->db->escape($end_date) . "'
|
||||||
|
AND entity = " . $this->entity,
|
||||||
|
|
||||||
|
// Without entity filter
|
||||||
|
"SELECT SUM(debit) as total_debit, SUM(credit) as total_credit
|
||||||
|
FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping
|
||||||
|
WHERE account_number = '" . $this->db->escape($account_code) . "'
|
||||||
|
AND doc_date >= '" . $this->db->escape($start_date) . "'
|
||||||
|
AND doc_date <= '" . $this->db->escape($end_date) . "'"
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($possible_queries as $sql) {
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if ($result && $this->db->num_rows($result) > 0) {
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
$total_amount = $obj->total_debit - $obj->total_credit;
|
||||||
|
|
||||||
|
// Log successful query for debugging
|
||||||
|
error_log("DeclarationTVA: Found data with query: " . substr($sql, 0, 100) . "... Amount: $total_amount");
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'base_amount' => $total_amount,
|
||||||
|
'vat_amount' => $total_amount,
|
||||||
|
'total_amount' => $total_amount
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no data found, log the account code for debugging
|
||||||
|
error_log("DeclarationTVA: No data found for account $account_code in any accounting table");
|
||||||
return array('base_amount' => 0, 'vat_amount' => 0, 'total_amount' => 0);
|
return array('base_amount' => 0, 'vat_amount' => 0, 'total_amount' => 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user