From a7c6ecc17748a6cb3e453a9171ec2d0a61c98089 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Oct 2016 16:05:25 +0200 Subject: [PATCH] Fix better compatibility with multicompany --- htdocs/accountancy/class/bookkeeping.class.php | 7 +++++-- htdocs/accountancy/customer/card.php | 4 +--- htdocs/accountancy/customer/index.php | 17 ++++------------- htdocs/accountancy/customer/lines.php | 8 ++------ htdocs/accountancy/customer/list.php | 4 +--- htdocs/accountancy/journal/bankjournal.php | 4 +--- htdocs/accountancy/journal/purchasesjournal.php | 4 +--- htdocs/accountancy/journal/sellsjournal.php | 4 +--- htdocs/accountancy/supplier/card.php | 4 +--- htdocs/accountancy/supplier/index.php | 10 ++-------- htdocs/accountancy/supplier/lines.php | 5 ++--- htdocs/accountancy/supplier/list.php | 5 ++--- htdocs/compta/facture/list.php | 2 +- htdocs/langs/en_US/errors.lang | 1 + 14 files changed, 25 insertions(+), 54 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 4da730e2551..ed4881ddff2 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -110,6 +110,8 @@ class BookKeeping extends CommonObject * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { + global $langs; + dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; @@ -164,9 +166,10 @@ class BookKeeping extends CommonObject if (empty($this->credit)) $this->credit = 0; // Check parameters - if (empty($this->numero_compte)) + if (empty($this->numero_compte) || $this->numero_compte == '-1') { - $this->errors[]='ErrorFieldAccountNotDefined'; + $langs->load("errors"); + $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet); return -1; } diff --git a/htdocs/accountancy/customer/card.php b/htdocs/accountancy/customer/card.php index 6a8f1cb67b3..ba6173d8ebf 100644 --- a/htdocs/accountancy/customer/card.php +++ b/htdocs/accountancy/customer/card.php @@ -95,9 +95,7 @@ if (! empty($id)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON l.fk_code_ventilation = aa.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = l.fk_facture"; $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id; - if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; - } + $sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 586d08acad0..08677974a6d 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -212,10 +212,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_factu $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; - -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; -} +$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy $sql .= " GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label"; @@ -259,12 +256,9 @@ $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; +$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; -} - -dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql); +dol_syslog('htdocs/accountancy/customer/index.php'); $resql = $db->query($sql); if ($resql) { $i = 0; @@ -303,10 +297,7 @@ if (! empty($conf->margin->enabled)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; - - if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; - } + $sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql); $resql = $db->query($sql); diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index 79adeecf543..94b3c7df6a4 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -160,9 +160,7 @@ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_factu $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays "; $sql .= " WHERE fd.fk_code_ventilation > 0 "; -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; -} +$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy $sql .= " AND f.fk_statut > 0"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; @@ -196,9 +194,7 @@ if (strlen(trim($search_country))) { if (strlen(trim($search_tvaintra))) { $sql .= " AND (s.tva_intra like'" . $search_tvaintra . "%')"; } -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; -} +$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy $sql .= $db->order($sortfield, $sortorder); // Count total nb of records diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 4a225f57ddc..080f79d1fce 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -191,10 +191,8 @@ if (strlen(trim($search_account))) { if (strlen(trim($search_vat))) { $sql .= " AND (l.tva_tx like '" . $search_vat . "%')"; } +$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; -} $sql .= $db->order($sortfield, $sortorder); // Count total nb of records diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 2d7702cf5c8..bd18388aacb 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -109,9 +109,7 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid"; $sql .= " WHERE ba.rowid=" . $id_bank_account; -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND ba.entity = " . $conf->entity; -} +$sql .= ' AND ba.entity IN ('.getEntity('banque', 0).')'; // We don't share object for accountancy if ($date_start && $date_end) $sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'"; $sql .= " ORDER BY b.datev"; diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 82f9c902280..00630c726f5 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -96,9 +96,7 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = fd.fk_factu $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " WHERE f.fk_statut > 0 "; $sql .= " AND fd.fk_code_ventilation > 0 "; -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; -} +$sql .= " AND f.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2)"; else diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 6a093df036f..a592f7b0659 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -99,9 +99,7 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; $sql .= " WHERE fd.fk_code_ventilation > 0"; -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; -} +$sql .= " AND f.entity IN (".getEntity('facture', 0).')'; // We don't share object for accountancy $sql .= " AND f.fk_statut > 0"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; diff --git a/htdocs/accountancy/supplier/card.php b/htdocs/accountancy/supplier/card.php index 0fd60928502..b8e709e152d 100644 --- a/htdocs/accountancy/supplier/card.php +++ b/htdocs/accountancy/supplier/card.php @@ -96,9 +96,7 @@ if (! empty($id)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON l.fk_code_ventilation = aa.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn "; $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id; - if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; - } + $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy dol_syslog("/accounting/supplier/card.php sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 63153328d14..f9a5100adbc 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -194,10 +194,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND ff.fk_statut > 0 "; - -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 1) . ")"; -} +$sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy $sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label"; @@ -242,10 +239,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND ff.fk_statut > 0 "; - -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 1) . ")"; -} +$sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql); $resql = $db->query($sql); diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php index 32398dbbe93..e9a6c127265 100644 --- a/htdocs/accountancy/supplier/lines.php +++ b/htdocs/accountancy/supplier/lines.php @@ -175,9 +175,8 @@ if (strlen(trim($search_account))) { if (strlen(trim($search_vat))) { $sql .= " AND (l.tva_tx like '" . $search_vat . "%')"; } -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; -} +$sql .= " AND f.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy + $sql .= $db->order($sortfield, $sortorder); // Count total nb of records diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 93e97d3de3e..09093494d0d 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -197,9 +197,8 @@ if (strlen(trim($search_account))) { if (strlen(trim($search_vat))) { $sql .= " AND (l.tva_tx like '" . $search_vat . "%')"; } -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")"; -} +$sql .= " AND f.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy + $sql .= $db->order($sortfield, $sortorder); // Count total nb of records diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 70e4cc03974..833396b0005 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -278,7 +278,7 @@ if ($search_user > 0) $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= ' WHERE f.fk_soc = s.rowid'; -$sql.= " AND f.entity = ".$conf->entity; +$sql.= ' AND f.entity IN ('.getEntity('facture', 1).')'; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 8d47d5322cb..00b151620fb 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -176,6 +176,7 @@ ErrorStockIsNotEnoughToAddProductOnShipment=Stock is not enougth for product %s ErrorStockIsNotEnoughToAddProductOnProposal=Stock is not enougth for product %s to add it into a new proposal. ErrorFailedToLoadLoginFileForMode=Failed to get the login file for mode '%s'. ErrorModuleNotFound=File of module was not found. +ErrorFieldAccountNotDefinedForBankLine=Value for Accounting account not defined for source bank line %s # Warnings WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.