Fix for multicompany management

This commit is contained in:
Laurent Destailleur 2016-09-29 12:36:59 +02:00
parent b412baa880
commit fee47f7583
2 changed files with 50 additions and 17 deletions

View File

@ -55,12 +55,17 @@ class BookKeeping extends CommonObject
*/ */
public $table_element = 'accounting_bookkeeping'; public $table_element = 'accounting_bookkeeping';
public $entity = 1;
/** /**
* *
* @var BookKeepingLine[] Lines * @var BookKeepingLine[] Lines
*/ */
public $lines = array (); public $lines = array ();
/** /**
* *
* @var int ID * @var int ID
@ -212,7 +217,6 @@ class BookKeeping extends CommonObject
} }
$sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("; $sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " (";
$sql .= "doc_date"; $sql .= "doc_date";
$sql .= ", doc_type"; $sql .= ", doc_type";
$sql .= ", doc_ref"; $sql .= ", doc_ref";
@ -229,9 +233,8 @@ class BookKeeping extends CommonObject
$sql .= ", import_key"; $sql .= ", import_key";
$sql .= ", code_journal"; $sql .= ", code_journal";
$sql .= ", piece_num"; $sql .= ", piece_num";
$sql .= ', entity';
$sql .= ") VALUES ("; $sql .= ") VALUES (";
$sql .= "'" . $this->doc_date . "'"; $sql .= "'" . $this->doc_date . "'";
$sql .= ",'" . $this->doc_type . "'"; $sql .= ",'" . $this->doc_type . "'";
$sql .= ",'" . $this->doc_ref . "'"; $sql .= ",'" . $this->doc_ref . "'";
@ -248,7 +251,7 @@ class BookKeeping extends CommonObject
$sql .= ",'" . $this->date_create . "'"; $sql .= ",'" . $this->date_create . "'";
$sql .= ",'" . $this->code_journal . "'"; $sql .= ",'" . $this->code_journal . "'";
$sql .= "," . $this->piece_num; $sql .= "," . $this->piece_num;
$sql .= ", " . (! isset($this->entity) ? '1' : $this->entity);
$sql .= ")"; $sql .= ")";
dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
@ -391,10 +394,9 @@ class BookKeeping extends CommonObject
$sql .= 'fk_user_author,'; $sql .= 'fk_user_author,';
$sql .= 'import_key,'; $sql .= 'import_key,';
$sql .= 'code_journal,'; $sql .= 'code_journal,';
$sql .= 'piece_num'; $sql .= 'piece_num,';
$sql .= 'entity';
$sql .= ') VALUES ('; $sql .= ') VALUES (';
$sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ','; $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ',';
$sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ','; $sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ',';
$sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ',';
@ -410,8 +412,8 @@ class BookKeeping extends CommonObject
$sql .= ' ' . $user->id . ','; $sql .= ' ' . $user->id . ',';
$sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ','; $sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ',';
$sql .= ' ' . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ',';
$sql .= ' ' . (! isset($this->piece_num) ? 'NULL' : $this->piece_num); $sql .= ' ' . (! isset($this->piece_num) ? 'NULL' : $this->piece_num).',';
$sql .= ' ' . (! isset($this->entity) ? '1' : $this->entity);
$sql .= ')'; $sql .= ')';
$this->db->begin(); $this->db->begin();
@ -481,10 +483,14 @@ class BookKeeping extends CommonObject
$sql .= " t.piece_num"; $sql .= " t.piece_num";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
$sql .= ' WHERE 1 = 1';
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
}
if (null !== $ref) { if (null !== $ref) {
$sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; $sql .= ' AND t.ref = ' . '\'' . $ref . '\'';
} else { } else {
$sql .= ' WHERE t.rowid = ' . $id; $sql .= ' AND t.rowid = ' . $id;
} }
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -586,13 +592,17 @@ class BookKeeping extends CommonObject
} }
} }
if (count($sqlwhere) > 0) { $sql.= ' WHERE 1 = 1';
$sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); if (! empty($conf->multicompany->enabled)) {
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
} }
// Affichage par compte comptable if (count($sqlwhere) > 0) {
$sql .= ' ORDER BY t.numero_compte ASC'; $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
}
// Affichage par compte comptable
$sql .= ' ORDER BY t.numero_compte ASC';
if (! empty($sortfield)) { if (! empty($sortfield)) {
$sql .= ', ' . $sortfield . ' ' .$sortorder; $sql .= ', ' . $sortfield . ' ' .$sortorder;
} }
if (! empty($limit)) { if (! empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit + 1, $offset); $sql .= ' ' . $this->db->plimit($limit + 1, $offset);
@ -696,8 +706,12 @@ class BookKeeping extends CommonObject
} }
} }
$sql.= ' WHERE 1 = 1';
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
}
if (count($sqlwhere) > 0) { if (count($sqlwhere) > 0) {
$sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
} }
if (! empty($sortfield)) { if (! empty($sortfield)) {

View File

@ -41,6 +41,9 @@ class FormVentilation extends Form
$options = array(); $options = array();
$sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping'; $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
if (! empty($conf->multicompany->enabled)) {
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
}
$sql .= ' ORDER BY import_key DESC'; $sql .= ' ORDER BY import_key DESC';
dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG); dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG);
@ -227,6 +230,9 @@ class FormVentilation extends Form
// Auxiliary customer account // Auxiliary customer account
$sql = "SELECT DISTINCT code_compta, nom "; $sql = "SELECT DISTINCT code_compta, nom ";
$sql .= " FROM ".MAIN_DB_PREFIX."societe"; $sql .= " FROM ".MAIN_DB_PREFIX."societe";
if (! empty($conf->multicompany->enabled)) {
$sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
}
$sql .= " ORDER BY code_compta"; $sql .= " ORDER BY code_compta";
dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -246,6 +252,9 @@ class FormVentilation extends Form
// Auxiliary supplier account // Auxiliary supplier account
$sql = "SELECT DISTINCT code_compta_fournisseur, nom "; $sql = "SELECT DISTINCT code_compta_fournisseur, nom ";
$sql .= " FROM ".MAIN_DB_PREFIX."societe"; $sql .= " FROM ".MAIN_DB_PREFIX."societe";
if (! empty($conf->multicompany->enabled)) {
$sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
}
$sql .= " ORDER BY code_compta_fournisseur"; $sql .= " ORDER BY code_compta_fournisseur";
dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -280,10 +289,15 @@ class FormVentilation extends Form
*/ */
function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html') function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html')
{ {
global $conf;
$out_array = array(); $out_array = array();
$sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear"; $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
if (! empty($conf->multicompany->enabled)) {
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
}
$sql .= " ORDER BY date_format(doc_date,'%Y')"; $sql .= " ORDER BY date_format(doc_date,'%Y')";
dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -316,10 +330,15 @@ class FormVentilation extends Form
*/ */
function selectjournal_accountancy_bookkepping($selected = '', $htmlname = 'journalid', $useempty = 0, $output_format = 'html') function selectjournal_accountancy_bookkepping($selected = '', $htmlname = 'journalid', $useempty = 0, $output_format = 'html')
{ {
global $conf;
$out_array = array(); $out_array = array();
$sql = "SELECT DISTINCT code_journal"; $sql = "SELECT DISTINCT code_journal";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
if (! empty($conf->multicompany->enabled)) {
$sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
}
$sql .= " ORDER BY code_journal"; $sql .= " ORDER BY code_journal";
dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);