From c4409e44f97d05da752ec04333cfbd98c2b4bb57 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 13 Oct 2024 16:47:47 +0200 Subject: [PATCH] QUAL Use table_element in sql querries (#31355) * Use table element in sql querries * Use table element in sql querries * Use also $this->db->prefix() * Use table_element in sql querries --- .../class/accountancycategory.class.php | 34 +++--- .../class/accountingaccount.class.php | 28 ++--- .../accountancy/class/bookkeeping.class.php | 102 +++++++++--------- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index f5092e7a9a8..a916328aaeb 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -194,7 +194,7 @@ class AccountancyCategory // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_accounting_category("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; if ($this->rowid > 0) { $sql .= "rowid, "; } @@ -269,7 +269,7 @@ class AccountancyCategory // extends CommonObject $sql .= " t.position,"; $sql .= " t.fk_country,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as t"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); } else { @@ -354,7 +354,7 @@ class AccountancyCategory // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_accounting_category SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; $sql .= " range_account=".(isset($this->range_account) ? "'".$this->db->escape($this->range_account)."'" : "null").","; @@ -402,7 +402,7 @@ class AccountancyCategory // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_accounting_category"; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); @@ -439,7 +439,7 @@ class AccountancyCategory // extends CommonObject { global $conf; $sql = "SELECT t.rowid, t.account_number, t.label"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; $sql .= " WHERE t.fk_accounting_category = ".((int) $id); $sql .= " AND t.entity = ".$conf->entity; @@ -475,8 +475,8 @@ class AccountancyCategory // extends CommonObject global $conf; $sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " FROM ".$this->db->prefix()."accounting_account as aa"; + $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " WHERE (aa.fk_accounting_category <> ".((int) $id)." OR aa.fk_accounting_category IS NULL)"; $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS')); $sql .= " AND aa.active = 1"; @@ -522,8 +522,8 @@ class AccountancyCategory // extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; $sql = "SELECT aa.rowid, aa.account_number"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " FROM ".$this->db->prefix()."accounting_account as aa"; + $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS')); $sql .= " AND aa.active = 1"; $sql .= " AND aa.entity = ".$conf->entity; @@ -550,7 +550,7 @@ class AccountancyCategory // extends CommonObject if (array_key_exists($account_number_formated, $cpts)) { $accountincptsadded[$account_number_formated] = 1; // We found an account number that is in list $cpts of account to add - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account"; + $sql = "UPDATE ".$this->db->prefix()."accounting_account"; $sql .= " SET fk_accounting_category=".((int) $id_cat); $sql .= " WHERE rowid=".((int) $obj->rowid); dol_syslog(__METHOD__, LOG_DEBUG); @@ -589,7 +589,7 @@ class AccountancyCategory // extends CommonObject { $error = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account as aa"; + $sql = "UPDATE ".$this->db->prefix()."accounting_account as aa"; $sql .= " SET fk_accounting_category= 0"; $sql .= " WHERE aa.rowid = ".((int) $cpt_id); $this->db->begin(); @@ -657,7 +657,7 @@ class AccountancyCategory // extends CommonObject if (is_array($cpt)) { $sql .= ", t.numero_compte as accountancy_account"; } - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t"; + $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping as t"; //if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date'; $sql .= " WHERE t.entity = ".((int) $conf->entity); if (is_array($cpt)) { @@ -727,9 +727,9 @@ class AccountancyCategory // extends CommonObject $sql = "SELECT t.rowid, t.account_number, t.label as account_label,"; $sql .= " cat.code, cat.position, cat.label as name_cat, cat.sens, cat.category_type, cat.formula"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t, ".MAIN_DB_PREFIX."c_accounting_category as cat"; + $sql .= " FROM ".$this->db->prefix()."accounting_account as t, ".$this->db->prefix()."c_accounting_category as cat"; $sql .= " WHERE t.fk_accounting_category IN (SELECT c.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.active = 1"; $sql .= " AND c.entity = ".$conf->entity; $sql .= " AND (c.fk_country = ".((int) $mysoc->country_id)." OR c.fk_country = 0)"; @@ -788,7 +788,7 @@ class AccountancyCategory // extends CommonObject } $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type, c.sens"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.active = " . (int) $active; $sql .= " AND c.entity = ".$conf->entity; if ($categorytype >= 0) { @@ -860,7 +860,7 @@ class AccountancyCategory // extends CommonObject if (!empty($cat_id)) { $sql = "SELECT t.rowid, t.account_number, t.label as account_label"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t"; + $sql .= " FROM ".$this->db->prefix()."accounting_account as t"; $sql .= " WHERE t.fk_accounting_category = ".((int) $cat_id); $sql .= " AND t.entity = ".$conf->entity; $sql .= " AND t.active = 1"; @@ -868,7 +868,7 @@ class AccountancyCategory // extends CommonObject $sql .= " ORDER BY t.account_number"; } else { $sql = "SELECT t.rowid, t.account_number, t.label as account_label"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t"; + $sql .= " FROM ".$this->db->prefix()."accounting_account as t"; $sql .= " WHERE ".$predefinedgroupwhere; $sql .= " AND t.entity = ".$conf->entity; $sql .= ' AND t.active = 1'; diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 60022ab0cff..72e077f525c 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -164,7 +164,7 @@ class AccountingAccount extends CommonObject $this->db = $db; $this->ismultientitymanaged = 1; - $this->next_prev_filter = "fk_pcg_version IN (SELECT pcg_version FROM ".MAIN_DB_PREFIX."accounting_system WHERE rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS')).")"; // Used to add a filter in Form::showrefnav method + $this->next_prev_filter = "fk_pcg_version IN (SELECT pcg_version FROM ".$this->db->prefix()."accounting_system WHERE rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS')).")"; // Used to add a filter in Form::showrefnav method } /** @@ -183,8 +183,8 @@ class AccountingAccount extends CommonObject if ($rowid || $account_number) { $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconcilable"; $sql .= ", ca.label as category_label"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as a"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as a"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; $sql .= " WHERE"; if ($rowid) { $sql .= " a.rowid = ".(int) $rowid; @@ -193,7 +193,7 @@ class AccountingAccount extends CommonObject $sql .= " AND a.entity = ".$conf->entity; } if (!empty($limittocurrentchart)) { - $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid = '.((int) getDolGlobalInt('CHARTOFACCOUNTS')).')'; + $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.$this->db->prefix().'accounting_system WHERE rowid = '.((int) getDolGlobalInt('CHARTOFACCOUNTS')).')'; } if (!empty($limittoachartaccount)) { $sql .= " AND a.fk_pcg_version = '".$this->db->escape($limittoachartaccount)."'"; @@ -276,7 +276,7 @@ class AccountingAccount extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account("; + $sql = "INSERT INTO " . $this->db->prefix() . $this->table_element . " ("; $sql .= "datec"; $sql .= ", entity"; $sql .= ", fk_pcg_version"; @@ -314,7 +314,7 @@ class AccountingAccount extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_account"); + $this->id = $this->db->last_insert_id($this->db->prefix() . $this->table_element); // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. @@ -356,7 +356,7 @@ class AccountingAccount extends CommonObject $this->db->begin(); - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; + $sql = "UPDATE " . $this->db->prefix() . $this->table_element; $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null"); $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null"); $sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'"; @@ -397,10 +397,10 @@ class AccountingAccount extends CommonObject global $langs; // TODO Looks a stupid check - $sql = "(SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX."facturedet"; + $sql = "(SELECT fk_code_ventilation FROM ".$this->db->prefix()."facturedet"; $sql .= " WHERE fk_code_ventilation=".((int) $this->id).")"; $sql .= "UNION"; - $sql .= " (SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX."facture_fourn_det"; + $sql .= " (SELECT fk_code_ventilation FROM ".$this->db->prefix()."facture_fourn_det"; $sql .= " WHERE fk_code_ventilation=".((int) $this->id).")"; dol_syslog(get_class($this)."::checkUsage", LOG_DEBUG); @@ -437,7 +437,7 @@ class AccountingAccount extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account"; + $sql = "DELETE FROM " . $this->db->prefix() . $this->table_element; $sql .= " WHERE rowid=" . ((int) $this->id); dol_syslog(get_class($this) . "::delete sql=" . $sql); @@ -586,7 +586,7 @@ class AccountingAccount extends CommonObject public function info($id) { $sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms as date_modification'; - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a'; + $sql .= ' FROM ' . $this->db->prefix() . $this->table_element . ' as a'; $sql .= ' WHERE a.rowid = ' . ((int) $id); dol_syslog(get_class($this) . '::info sql=' . $sql); @@ -628,8 +628,8 @@ class AccountingAccount extends CommonObject if ($result > 0) { $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account "; - $sql .= "SET ".$this->db->sanitize($fieldtouse)." = 0"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; + $sql .= " SET ".$this->db->sanitize($fieldtouse)." = 0"; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this)."::accountDeactivate ".$fieldtouse, LOG_DEBUG); @@ -666,7 +666,7 @@ class AccountingAccount extends CommonObject $fieldtouse = 'reconcilable'; } - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ".$this->db->sanitize($fieldtouse)." = 1"; $sql .= " WHERE rowid = ".((int) $id); diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 2671adb04df..3c8e8fdb6e1 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -329,7 +329,7 @@ class BookKeeping extends CommonObject // WARNING: This is not reliable, label may have been modified. This is just a small protection. // The page that make transfer make the test on couple (doc_type - fk_doc) only. $sql = "SELECT count(*) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE doc_type = '".$this->db->escape($this->doc_type)."'"; $sql .= " AND fk_doc = ".((int) $this->fk_doc); if (getDolGlobalString('ACCOUNTANCY_ENABLE_FKDOCDET')) { @@ -347,7 +347,7 @@ class BookKeeping extends CommonObject if ($row->nb == 0) { // Not already into bookkeeping // Check to know if piece_num already exists for data we try to insert to reuse the same value $sqlnum = "SELECT piece_num"; - $sqlnum .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sqlnum .= " FROM ".$this->db->prefix().$this->table_element; $sqlnum .= " WHERE doc_type = '".$this->db->escape($this->doc_type)."'"; // For example doc_type = 'bank' $sqlnum .= " AND fk_doc = ".((int) $this->fk_doc); if (getDolGlobalString('ACCOUNTANCY_ENABLE_FKDOCDET')) { @@ -367,7 +367,7 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this)."::create this->piece_num=".$this->piece_num, LOG_DEBUG); if (empty($this->piece_num)) { $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; - $sqlnum .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sqlnum .= " FROM ".$this->db->prefix().$this->table_element; $sqlnum .= " WHERE entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features $resqlnum = $this->db->query($sqlnum); @@ -383,7 +383,7 @@ class BookKeeping extends CommonObject $now = dol_now(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "doc_date"; $sql .= ", date_lim_reglement"; $sql .= ", doc_type"; @@ -433,7 +433,7 @@ class BookKeeping extends CommonObject $resql = $this->db->query($sql); if ($resql) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if ($id > 0) { $this->id = $id; @@ -655,7 +655,7 @@ class BookKeeping extends CommonObject $this->journal_label = $langs->trans($this->journal_label); // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.$mode.' ('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.$mode.' ('; $sql .= 'doc_date,'; $sql .= 'date_lim_reglement,'; $sql .= 'doc_type,'; @@ -713,7 +713,7 @@ class BookKeeping extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element.$mode); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element.$mode); // Call triggers if (! $notrigger) { $result = $this->call_trigger('BOOKKEEPING_CREATE', $user); @@ -778,7 +778,7 @@ class BookKeeping extends CommonObject $sql .= " t.date_export,"; } $sql .= " t.date_validated as date_validation"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.$mode.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.$mode.' as t'; $sql .= ' WHERE 1 = 1'; $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features if (null !== $ref) { @@ -951,7 +951,7 @@ class BookKeeping extends CommonObject } } } - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features if (count($sqlwhere) > 0) { $sql .= " AND ".implode(" ".$this->db->sanitize($filtermode)." ", $sqlwhere); @@ -1085,7 +1085,7 @@ class BookKeeping extends CommonObject $sql .= " t.tms as date_modification,"; $sql .= " t.date_export,"; $sql .= " t.date_validated as date_validation"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE t.entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features if ($showAlreadyExportMovements == 0) { @@ -1254,7 +1254,7 @@ class BookKeeping extends CommonObject } $sql .= " SUM(t.debit) as debit,"; $sql .= " SUM(t.credit) as credit"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t'; $sql .= ' WHERE entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features // Manage filter @@ -1450,7 +1450,7 @@ class BookKeeping extends CommonObject // Put here code to add a control on parameters values // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.$mode.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.$mode.' SET'; $sql .= ' doc_date = '.(isDolTms($this->doc_date) ? "'".$this->db->idate($this->doc_date)."'" : 'null').','; $sql .= ' doc_type = '.(isset($this->doc_type) ? "'".$this->db->escape($this->doc_type)."'" : "null").','; $sql .= ' doc_ref = '.(isset($this->doc_ref) ? "'".$this->db->escape($this->doc_ref)."'" : "null").','; @@ -1522,7 +1522,7 @@ class BookKeeping extends CommonObject $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element.$mode; + $sql = "UPDATE ".$this->db->prefix().$this->table_element.$mode; $sql .= " SET ".$this->db->sanitize($field)." = ".(is_numeric($value) ? ((float) $value) : "'".$this->db->escape($value)."'"); $sql .= " WHERE piece_num = ".((int) $piece_num); $sql .= $sql_filter; @@ -1584,7 +1584,7 @@ class BookKeeping extends CommonObject } if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.$mode; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.$mode; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); @@ -1625,7 +1625,7 @@ class BookKeeping extends CommonObject // first check if line not yet in bookkeeping $sql = "DELETE"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode; + $sql .= " FROM ".$this->db->prefix().$this->table_element.$mode; $sql .= " WHERE import_key = '".$this->db->escape($importkey)."'"; $sql .= $sql_filter; @@ -1673,7 +1673,7 @@ class BookKeeping extends CommonObject // Delete record in bookkeeping $sql = "DELETE"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode; + $sql .= " FROM ".$this->db->prefix().$this->table_element.$mode; $sql .= " WHERE 1 = 1"; $sql .= dolSqlDateFilter('doc_date', 0, $delmonth, $delyear); if (!empty($journal)) { @@ -1724,7 +1724,7 @@ class BookKeeping extends CommonObject // first check if line not yet in bookkeeping $sql = "DELETE"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode; + $sql .= " FROM ".$this->db->prefix().$this->table_element.$mode; $sql .= " WHERE piece_num = ".(int) $piecenum; $sql .= " AND date_validated IS NULL"; // For security, exclusion of validated entries at the time of deletion $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features @@ -1853,7 +1853,7 @@ class BookKeeping extends CommonObject if ($mode != "_tmp") { $sql .= ", date_export"; } - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode; + $sql .= " FROM ".$this->db->prefix().$this->table_element.$mode; $sql .= " WHERE piece_num = ".((int) $piecenum); $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features @@ -1895,7 +1895,7 @@ class BookKeeping extends CommonObject { global $conf; - $sql = "SELECT MAX(piece_num)+1 as max FROM ".MAIN_DB_PREFIX.$this->table_element.$mode; + $sql = "SELECT MAX(piece_num)+1 as max FROM ".$this->db->prefix().$this->table_element.$mode; $sql .= " WHERE entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features dol_syslog(get_class($this)."::getNextNumMvt", LOG_DEBUG); @@ -1938,7 +1938,7 @@ class BookKeeping extends CommonObject if ($mode != "_tmp") { $sql .= ", date_export"; } - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode; + $sql .= " FROM ".$this->db->prefix().$this->table_element.$mode; $sql .= " WHERE piece_num = ".((int) $piecenum); $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features @@ -2004,7 +2004,7 @@ class BookKeeping extends CommonObject $sql .= " numero_compte, label_compte, label_operation, debit, credit,"; $sql .= " montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,"; $sql .= " date_validated as date_validation"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features dol_syslog(get_class($this)."::export_bookkeeping", LOG_DEBUG); @@ -2083,7 +2083,7 @@ class BookKeeping extends CommonObject if (!$error) { // Delete if there is an empty line - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity)." AND numero_compte IS NULL AND debit = 0 AND credit = 0"; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity)." AND numero_compte IS NULL AND debit = 0 AND credit = 0"; $resql = $this->db->query($sql); if (!$resql) { $error++; @@ -2093,7 +2093,7 @@ class BookKeeping extends CommonObject } if (!$error) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' (doc_date, doc_type,'; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.' (doc_date, doc_type,'; $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)'; @@ -2101,7 +2101,7 @@ class BookKeeping extends CommonObject $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).", '".$this->db->idate($now)."'"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND numero_compte IS NOT NULL AND entity = ' .((int) $conf->entity); + $sql .= ' FROM '.$this->db->prefix().$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND numero_compte IS NOT NULL AND entity = ' .((int) $conf->entity); $sql .= $sql_filter; $resql = $this->db->query($sql); if (!$resql) { @@ -2112,7 +2112,7 @@ class BookKeeping extends CommonObject } if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; @@ -2122,7 +2122,7 @@ class BookKeeping extends CommonObject } } elseif ($direction == 1) { if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); $resql = $this->db->query($sql); if (!$resql) { $error++; @@ -2132,7 +2132,7 @@ class BookKeeping extends CommonObject } if (!$error) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'_tmp (doc_date, doc_type,'; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'_tmp (doc_date, doc_type,'; $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)'; @@ -2140,7 +2140,7 @@ class BookKeeping extends CommonObject $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); + $sql .= ' FROM '.$this->db->prefix().$this->table_element.' WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); $sql .= $sql_filter; $resql = $this->db->query($sql); if (!$resql) { @@ -2151,7 +2151,7 @@ class BookKeeping extends CommonObject } if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity); $sql .= $sql_filter; $resql = $this->db->query($sql); if (!$resql) { @@ -2170,10 +2170,10 @@ class BookKeeping extends CommonObject } /* $sql = "DELETE FROM "; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte"; + $sql .= " FROM " . $this->db->prefix() . "accounting_bookkeeping as ab"; + $sql .= " LEFT JOIN " . $this->db->prefix() . "accounting_account as aa ON aa.account_number = ab.numero_compte"; $sql .= " AND aa.active = 1"; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " INNER JOIN " . $this->db->prefix() . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . ((int) $pcgver); $sql .= " AND ab.entity IN (" . getEntity('accountancy') . ")"; $sql .= " ORDER BY account_number ASC"; @@ -2203,10 +2203,10 @@ class BookKeeping extends CommonObject $pcgver = getDolGlobalInt('CHARTOFACCOUNTS'); $sql = "SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.account_number = ab.numero_compte"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as ab"; + $sql .= " LEFT JOIN ".$this->db->prefix()."accounting_account as aa ON aa.account_number = ab.numero_compte"; $sql .= " AND aa.active = 1"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = ".((int) $pcgver); $sql .= " AND ab.entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features $sql .= " ORDER BY account_number ASC"; @@ -2266,11 +2266,11 @@ class BookKeeping extends CommonObject $sql = "SELECT root.rowid, root.account_number, root.label as label,"; $sql .= " parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " FROM ".$this->db->prefix()."accounting_account as aa"; + $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = ".((int) $pcgver); - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1"; + $sql .= " LEFT JOIN ".$this->db->prefix()."accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1"; + $sql .= " LEFT JOIN ".$this->db->prefix()."accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1"; $sql .= " WHERE aa.account_number = '".$this->db->escape($account)."'"; $sql .= " AND aa.entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features @@ -2306,12 +2306,12 @@ class BookKeeping extends CommonObject $pcgver = getDolGlobalInt('CHARTOFACCOUNTS'); $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa "; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " FROM ".$this->db->prefix()."accounting_account as aa "; + $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND aa.account_number = '".$this->db->escape($account)."'"; $sql .= " AND asy.rowid = ".((int) $pcgver); $sql .= " AND aa.active = 1"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; $sql .= " WHERE aa.entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features dol_syslog(get_class($this)."::select_account", LOG_DEBUG); @@ -2632,7 +2632,7 @@ class BookKeeping extends CommonObject $sql .= ", SUM(".$this->db->ifsql("MONTH(b.doc_date) = ".((int) $i), "1", "0") . ") AS month".((int) $i); } $sql .= ", COUNT(b.rowid) as total"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as b"; + $sql .= " FROM " . $this->db->prefix() . $this->table_element . " as b"; $sql .= " WHERE b.doc_date >= '" . $this->db->idate($date_start) . "'"; $sql .= " AND b.doc_date <= '" . $this->db->idate($date_end) . "'"; $sql .= " AND b.entity IN (" . getEntity('bookkeeping', 0) . ")"; // We don't share object for accountancy @@ -2693,7 +2693,7 @@ class BookKeeping extends CommonObject $now = dol_now(); // Specify as export : update field date_validated on selected month/year - $sql = " UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping"; + $sql = " UPDATE " . $this->db->prefix() . $this->table_element; $sql .= " SET date_validated = '" . $this->db->idate($now) . "'"; $sql .= " WHERE entity = " . ((int) $conf->entity); $sql .= " AND DATE(doc_date) >= '" . $this->db->idate($date_start) . "'"; @@ -2737,11 +2737,11 @@ class BookKeeping extends CommonObject $sql .= " t.numero_compte,"; $sql .= " aa.pcg_type,"; $sql .= " (SUM(t.credit) - SUM(t.debit)) as accounting_result"; - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'accounting_account as aa ON aa.account_number = t.numero_compte'; + $sql .= ' FROM ' . $this->db->prefix() . $this->table_element . ' as t'; + $sql .= ' LEFT JOIN ' . $this->db->prefix() . 'accounting_account as aa ON aa.account_number = t.numero_compte'; $sql .= ' WHERE t.entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features $sql .= " AND aa.entity = " . ((int) $conf->entity); - $sql .= ' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid = ' . ((int) getDolGlobalInt('CHARTOFACCOUNTS')) . ')'; + $sql .= ' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . $this->db->prefix() . 'accounting_system WHERE rowid = ' . ((int) getDolGlobalInt('CHARTOFACCOUNTS')) . ')'; $sql .= ' AND aa.pcg_type IN (' . $this->db->sanitize(implode(',', $pcg_type_filter), 1) . ')'; $sql .= " AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) . "'"; $sql .= " AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) . "'"; @@ -2868,11 +2868,11 @@ class BookKeeping extends CommonObject } $sql .= " aa.pcg_type,"; $sql .= " (SUM(t.credit) - SUM(t.debit)) as opening_balance"; - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'accounting_account as aa ON aa.account_number = t.numero_compte'; + $sql .= ' FROM ' . $this->db->prefix() . $this->table_element . ' as t'; + $sql .= ' LEFT JOIN ' . $this->db->prefix() . 'accounting_account as aa ON aa.account_number = t.numero_compte'; $sql .= ' WHERE t.entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features $sql .= " AND aa.entity = ". ((int) $conf->entity); - $sql .= ' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid = '.((int) getDolGlobalInt('CHARTOFACCOUNTS')).')'; + $sql .= ' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.$this->db->prefix().'accounting_system WHERE rowid = '.((int) getDolGlobalInt('CHARTOFACCOUNTS')).')'; $sql .= ' AND aa.pcg_type IN (' . $this->db->sanitize(implode(',', $pcg_type_filter), 1) . ')'; $sql .= " AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) . "'"; $sql .= " AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) . "'"; @@ -3074,7 +3074,7 @@ class BookKeeping extends CommonObject $this->db->begin(); $sql = 'SELECT t.rowid'; - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + $sql .= ' FROM ' . $this->db->prefix() . $this->table_element . ' as t'; $sql .= ' WHERE t.entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features $sql .= " AND code_journal = '" . $this->db->escape($inventory_journal->code) . "'"; $sql .= " AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) . "'";