From 4431510ce431dad8f8dc306a2c7a4af2d3d01509 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 1 Feb 2012 11:32:55 +0100 Subject: [PATCH] Fix: use entity field of object --- htdocs/asterisk/cidlookup.php | 2 +- htdocs/comm/action/class/actioncomm.class.php | 4 +-- htdocs/comm/action/listactions.php | 2 +- htdocs/comm/index.php | 7 ++-- htdocs/comm/propal.php | 2 +- .../comm/propal/class/propalestats.class.php | 2 +- htdocs/comm/propal/index.php | 14 ++++---- htdocs/comm/prospect/class/prospect.class.php | 4 +-- htdocs/comm/prospect/index.php | 4 +-- htdocs/commande/class/commandestats.class.php | 2 +- htdocs/commande/index.php | 12 +++---- htdocs/commande/liste.php | 2 +- htdocs/compta/charges/index.php | 26 +++++++------- htdocs/compta/clients.php | 16 ++++----- htdocs/compta/facture/fiche-rec.php | 17 +++++----- htdocs/compta/facture/impayees.php | 2 +- htdocs/compta/index.php | 16 ++++----- htdocs/compta/paiement/fiche.php | 2 +- htdocs/compta/paiement/liste.php | 5 +-- htdocs/compta/prelevement/lignes.php | 6 ++-- htdocs/compta/prelevement/stats.php | 28 +++++++-------- htdocs/compta/resultat/clientfourn.php | 34 +++++++++---------- htdocs/compta/resultat/index.php | 22 ++++++------ htdocs/compta/sociales/charges.php | 6 ++-- htdocs/compta/sociales/index.php | 30 ++++++++-------- htdocs/compta/tva/quadri.php | 4 +-- htdocs/contrat/class/contrat.class.php | 4 +-- htdocs/contrat/index.php | 14 ++++---- htdocs/contrat/liste.php | 2 +- htdocs/contrat/services.php | 2 +- htdocs/core/boxes/box_actions.php | 2 +- htdocs/core/boxes/box_clients.php | 2 +- htdocs/core/boxes/box_commandes.php | 12 +++---- htdocs/core/boxes/box_contacts.php | 2 +- htdocs/core/boxes/box_factures.php | 2 +- htdocs/core/boxes/box_factures_fourn.php | 2 +- htdocs/core/boxes/box_factures_fourn_imp.php | 2 +- htdocs/core/boxes/box_factures_imp.php | 2 +- htdocs/core/boxes/box_fournisseurs.php | 2 +- htdocs/core/boxes/box_members.php | 10 +++--- htdocs/core/boxes/box_propales.php | 2 +- htdocs/core/boxes/box_prospect.php | 2 +- htdocs/core/boxes/box_services_vendus.php | 2 +- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/class/notify.class.php | 2 +- htdocs/core/lib/agenda.lib.php | 6 ++-- htdocs/core/lib/company.lib.php | 2 +- .../modules/mailings/contacts1.modules.php | 9 ++--- .../modules/mailings/contacts2.modules.php | 3 +- .../modules/mailings/contacts3.modules.php | 6 ++-- .../modules/mailings/framboise.modules.php | 20 +++++------ .../modules/mailings/thirdparties.modules.php | 8 ++--- htdocs/core/modules/modFacture.class.php | 2 +- htdocs/core/modules/modSociete.class.php | 2 +- htdocs/fourn/class/fournisseur.class.php | 4 +-- .../fourn/class/fournisseur.product.class.php | 4 +-- htdocs/fourn/commande/index.php | 2 +- htdocs/fourn/commande/liste.php | 4 +-- htdocs/fourn/index.php | 2 +- htdocs/fourn/liste.php | 2 +- .../install/mysql/migration/3.1.0-3.2.0.sql | 1 + htdocs/install/mysql/tables/llx_paiement.sql | 14 ++++---- htdocs/product/class/product.class.php | 22 ++++++------ htdocs/product/stats/commande.php | 2 +- htdocs/product/stats/commande_fournisseur.php | 2 +- htdocs/product/stats/contrat.php | 2 +- htdocs/product/stats/facture.php | 2 +- htdocs/product/stats/facture_fournisseur.php | 2 +- htdocs/product/stats/propal.php | 2 +- htdocs/product/stock/index.php | 11 +++--- htdocs/product/stock/mouvement.php | 14 ++++---- htdocs/societe/ajaxcompanies.php | 2 +- htdocs/societe/class/societe.class.php | 14 ++++---- htdocs/societe/lien.php | 2 +- htdocs/societe/notify/index.php | 2 +- htdocs/societe/societe.php | 23 +++++++------ 76 files changed, 269 insertions(+), 265 deletions(-) diff --git a/htdocs/asterisk/cidlookup.php b/htdocs/asterisk/cidlookup.php index bbd5883f283..1815d4d8d00 100644 --- a/htdocs/asterisk/cidlookup.php +++ b/htdocs/asterisk/cidlookup.php @@ -42,7 +42,7 @@ if (empty($phone)) $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid"; -$sql.= " WHERE s.entity=".$conf->entity; +$sql.= " WHERE s.entity IN (".getEntity(societe, 1).")"; $sql.= " AND (s.tel='".$db->escape($phone)."'"; $sql.= " OR sp.phone='".$db->escape($phone)."'"; $sql.= " OR sp.phone_perso='".$db->escape($phone)."'"; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 2ac3afab931..c982bfbcdbd 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -528,7 +528,7 @@ class ActionComm extends CommonObject $sql.= " FROM (".MAIN_DB_PREFIX."actioncomm as a"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid AND s.entity IN (0, ".$conf->entity.")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " WHERE a.percent >= 0 AND a.percent < 100"; $sql.= " AND a.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND a.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -800,7 +800,7 @@ class ActionComm extends CommonObject $sql.= " c.id as type_id, c.code as type_code, c.libelle"; $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm as a)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc AND s.entity IN (0, ".$conf->entity.")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc"; $sql.= " WHERE a.fk_action=c.id"; $sql.= " AND a.entity = ".$conf->entity; foreach ($filters as $key => $value) diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index bc293d9485f..76a15422aa1 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -156,7 +156,7 @@ $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c,"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,"; $sql.= " ".MAIN_DB_PREFIX.'user as u,'; $sql.= " ".MAIN_DB_PREFIX."actioncomm as a)"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid AND s.entity IN (0, ".$conf->entity.")"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON a.fk_user_author = ua.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ut ON a.fk_user_action = ut.rowid"; diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 025ee92c122..cb000b35c36 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -285,7 +285,7 @@ if ($conf->societe->enabled && $user->rights->societe->lire) $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.client IN (1, 2, 3)"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity(societe, 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = $socid"; $sql .= " ORDER BY s.tms DESC"; @@ -345,7 +345,7 @@ if ($conf->fournisseur->enabled && $user->rights->societe->lire) $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fournisseur = 1"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity(societe, 1).")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql.= " ORDER BY s.datec DESC"; @@ -420,8 +420,7 @@ if ($conf->contrat->enabled && $user->rights->contrat->lire && 0) // TODO A REFA $sql.= ", ".MAIN_DB_PREFIX."product as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; - //$sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND c.fk_product = p.rowid"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index a9f088dd77b..e1a50e5e6fa 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1808,7 +1808,7 @@ else if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid'; $sql.= ' WHERE p.fk_soc = s.rowid'; - $sql.= ' AND s.entity = '.$conf->entity; + $sql.= ' AND p.entity = '.$conf->entity; if (!$user->rights->societe->client->voir && !$socid) //restriction { diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 1a070e87d8a..28feac26022 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -67,7 +67,7 @@ class PropaleStats extends Stats $this->field='total_ht'; $this->where.= " fk_statut > 0"; - $this->where.= " AND p.fk_soc = s.rowid AND s.entity = ".$conf->entity; + $this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if($this->socid) { diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php index 79cb2befc58..665b01882a5 100644 --- a/htdocs/comm/propal/index.php +++ b/htdocs/comm/propal/index.php @@ -79,16 +79,16 @@ print "
\n"; * Statistics */ -$sql = "SELECT count(cf.rowid), cf.fk_statut"; +$sql = "SELECT count(p.rowid), p.fk_statut"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; -$sql.= ", ".MAIN_DB_PREFIX."propal as cf"; +$sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -$sql.= " WHERE cf.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; -if ($user->societe_id) $sql.=' AND cf.fk_soc = '.$user->societe_id; +$sql.= " WHERE p.fk_soc = s.rowid"; +$sql.= " AND p.entity = ".$conf->entity; +if ($user->societe_id) $sql.=' AND p.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; -$sql.= " AND cf.fk_statut in (0,1,2,3,4)"; -$sql.= " GROUP BY cf.fk_statut"; +$sql.= " AND p.fk_statut IN (0,1,2,3,4)"; +$sql.= " GROUP BY p.fk_statut"; $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/comm/prospect/class/prospect.class.php b/htdocs/comm/prospect/class/prospect.class.php index 63c3d2cb56a..9a1719e484e 100644 --- a/htdocs/comm/prospect/class/prospect.class.php +++ b/htdocs/comm/prospect/class/prospect.class.php @@ -69,8 +69,8 @@ class Prospect extends Societe $sql.= " WHERE sc.fk_user = " .$user->id; $clause = "AND"; } - $sql.= " ".$clause." s.client in (1,2,3)"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " ".$clause." s.client IN (1,2,3)"; + $sql.= " AND s.entity IN (".getEntity(societe, 1).")"; $sql.= " GROUP BY s.client"; $resql=$this->db->query($sql); diff --git a/htdocs/comm/prospect/index.php b/htdocs/comm/prospect/index.php index b93c0706b4a..0c649eb77cc 100644 --- a/htdocs/comm/prospect/index.php +++ b/htdocs/comm/prospect/index.php @@ -75,7 +75,7 @@ $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st "; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_stcomm = st.id"; $sql.= " AND s.client IN (2, 3)"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity(societe, 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY st.id"; $sql.= " ORDER BY st.id"; @@ -241,7 +241,7 @@ $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_stcomm = 1"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity(societe, 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " ORDER BY s.tms ASC"; $sql.= $db->plimit(15, 0); diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index 8b6a5bb304f..bc8ca78ad55 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -76,7 +76,7 @@ class CommandeStats extends Stats $this->field='total_ht'; $this->where.= " c.fk_statut > 0"; } - $this->where.= " AND c.fk_soc = s.rowid AND s.entity = ".$conf->entity; + $this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if($this->socid) diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index 576f3b6e246..a3978f8b099 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -78,15 +78,15 @@ print "
\n"; * Statistics */ -$sql = "SELECT count(cf.rowid), cf.fk_statut, cf.facture"; +$sql = "SELECT count(cf.rowid), c.fk_statut, c.facture"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; -$sql.= ", ".MAIN_DB_PREFIX."commande as cf"; +$sql.= ", ".MAIN_DB_PREFIX."commande as c"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -$sql.= " WHERE cf.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; -if ($user->societe_id) $sql.=' AND cf.fk_soc = '.$user->societe_id; +$sql.= " WHERE c.fk_soc = s.rowid"; +$sql.= " AND c.entity = ".$conf->entity; +if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; -$sql.= " GROUP BY cf.fk_statut, cf.facture"; +$sql.= " GROUP BY c.fk_statut, c.facture"; $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/commande/liste.php b/htdocs/commande/liste.php index ff35059d812..6ffe19b3df9 100644 --- a/htdocs/commande/liste.php +++ b/htdocs/commande/liste.php @@ -81,7 +81,7 @@ $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql.= ', '.MAIN_DB_PREFIX.'commande as c'; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ' WHERE c.fk_soc = s.rowid'; -$sql.= ' AND s.entity = '.$conf->entity; +$sql.= ' AND c.entity = '.$conf->entity; if ($socid) $sql.= ' AND s.rowid = '.$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($sref) diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index ef8b6c25ab2..6195ba4cd73 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -87,30 +87,30 @@ if ($_GET["mode"] == 'sconly') print ''; print ""; -print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"s.date_ech","",$param,'width="120"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'width="120"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"c.libelle","",$param,'',$sortfield,$sortorder); -print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"s.fk_type","",$param,'',$sortfield,$sortorder); -print_liste_field_titre($langs->trans("ExpectedToPay"),$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder); -print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"pid","",$param,'',$sortfield,$sortorder); -print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"datep","",$param,'align="center"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"cs.fk_type","",$param,'',$sortfield,$sortorder); +print_liste_field_titre($langs->trans("ExpectedToPay"),$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"pc.rowid","",$param,'',$sortfield,$sortorder); +print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"pc.datep","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"pc.amount","",$param,'align="right"',$sortfield,$sortorder); print "\n"; $sql = "SELECT c.id, c.libelle as lib,"; -$sql.= " s.rowid, s.libelle, s.fk_type as type, s.periode, s.date_ech, s.amount as total,"; +$sql.= " cs.rowid, cs.libelle, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total,"; $sql.= " pc.rowid as pid, pc.datep, pc.amount as totalpaye"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; -$sql.= " ".MAIN_DB_PREFIX."chargesociales as s"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = s.rowid"; -$sql.= " WHERE s.fk_type = c.id"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " ".MAIN_DB_PREFIX."chargesociales as cs"; +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid"; +$sql.= " WHERE cs.fk_type = c.id"; +$sql.= " AND cs.entity = ".$conf->entity; if ($year > 0) { $sql .= " AND ("; // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire - $sql .= " (s.periode is not null and s.periode between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; - $sql .= "or (s.periode is null and s.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; + $sql .= " (cs.periode IS NOT NULL AND cs.periode between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; + $sql .= "OR (cs.periode IS NULL AND cs.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; $sql .= ")"; } $sql.= $db->order($sortfield,$sortorder); @@ -145,7 +145,7 @@ if ($resql) print $socialcontrib->getNomUrl(1,'20'); print ''; // Type - print ''; + print ''; // Expected to pay print ''; // Ref payment diff --git a/htdocs/compta/clients.php b/htdocs/compta/clients.php index dcb76232589..eb3292da8f1 100644 --- a/htdocs/compta/clients.php +++ b/htdocs/compta/clients.php @@ -80,8 +80,8 @@ if ($action == 'note') if ($mode == 'search') { if ($modesearch == 'soc') { $sql = "SELECT s.rowid FROM ".MAIN_DB_PREFIX."societe as s "; - $sql.= " WHERE lower(s.nom) like '%".$db->escape(strtolower($socname))."%'"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " WHERE lower(s.nom) LIKE '%".$db->escape(strtolower($socname))."%'"; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; } $resql=$db->query($sql); @@ -106,7 +106,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_stcomm = st.id AND s.client in (1, 3)"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (dol_strlen($stcomm)) { @@ -114,25 +114,25 @@ if (dol_strlen($stcomm)) } if ($socname) { - $sql.= " AND s.nom like '%".$db->escape(strtolower($socname))."%'"; + $sql.= " AND s.nom LIKE '%".$db->escape(strtolower($socname))."%'"; $sortfield = "s.nom"; $sortorder = "ASC"; } if ($_GET["search_nom"]) { - $sql.= " AND s.nom like '%".$db->escape(strtolower($_GET["search_nom"]))."%'"; + $sql.= " AND s.nom LIKE '%".$db->escape(strtolower($_GET["search_nom"]))."%'"; } if ($_GET["search_compta"]) { - $sql.= " AND s.code_compta like '%".$db->escape($_GET["search_compta"])."%'"; + $sql.= " AND s.code_compta LIKE '%".$db->escape($_GET["search_compta"])."%'"; } if ($_GET["search_code_client"]) { - $sql.= " AND s.code_client like '%".$db->escape($_GET["search_code_client"])."%'"; + $sql.= " AND s.code_client LIKE '%".$db->escape($_GET["search_code_client"])."%'"; } if (dol_strlen($begin)) { - $sql.= " AND s.nom like '".$db->escape($begin)."'"; + $sql.= " AND s.nom LIKE '".$db->escape($begin)."'"; } if ($socid) { diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 4bcf25ece22..36f8777f234 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -474,7 +474,7 @@ else if ($fac->statut == 0 && $user->rights->facture->supprimer) { - print ''.$langs->trans('Delete').''; + print ''.$langs->trans('Delete').''; } print ''; @@ -496,7 +496,7 @@ else $sql = "SELECT s.nom, s.rowid as socid, f.titre, f.total, f.rowid as facid"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql .= " AND s.rowid = ".$socid; //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; @@ -507,13 +507,13 @@ else if ($result) { $num = $db->num_rows($result); - print_barre_liste($langs->trans("RepeatableInvoices"),$page,"fiche-rec.php","&socid=$socid",$sortfield,$sortorder,'',$num); + print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],"&socid=$socid",$sortfield,$sortorder,'',$num); $i = 0; - print "
'.$obj->lib.''.$obj->lib.''.price($obj->total).'
"; + print '
'; print ''; print ''; - print_liste_field_titre($langs->trans("Company"),"fiche-rec.php","s.nom","","&socid=$socid","",$sortfiled,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER['PHP_SELF'],"s.nom","","&socid=$socid","",$sortfiled,$sortorder); print ''; print ''; print "\n"; @@ -528,11 +528,11 @@ else print ""; - print '\n"; print ''; - print "\n"; + print ''."\n"; if (! $objp->paye) { @@ -566,7 +566,8 @@ else } +llxFooter(); + $db->close(); -llxFooter(); ?> diff --git a/htdocs/compta/facture/impayees.php b/htdocs/compta/facture/impayees.php index 1a025f0e836..9ce5dca35dd 100644 --- a/htdocs/compta/facture/impayees.php +++ b/htdocs/compta/facture/impayees.php @@ -192,7 +192,7 @@ if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PRE $sql.= ",".MAIN_DB_PREFIX."facture as f"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture "; $sql.= " WHERE f.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.type IN (0,1,3) AND f.fk_statut = 1"; $sql.= " AND f.paye = 0"; if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'"; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 4166a4ab130..2dc1e6f46ed 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -429,7 +429,7 @@ if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.rowid = ff.fk_soc"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND ff.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; if ($socid) $sql.= " AND ff.fk_soc = ".$socid; $sql.= " GROUP BY ff.rowid, ff.facnumber, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_ttc, ff.tms, ff.paye, s.nom, s.rowid"; @@ -503,10 +503,10 @@ if ($conf->don->enabled && $user->rights->societe->lire) $langs->load("boxes"); $donationstatic=new Don($db); - $sql = "SELECT s.rowid, s.nom, s.prenom, s.societe, s.datedon as date, s.tms as dm, s.amount, s.fk_statut"; - $sql.= " FROM ".MAIN_DB_PREFIX."don as s"; - $sql.= " WHERE s.entity = ".$conf->entity; - $sql.= $db->order("s.tms","DESC"); + $sql = "SELECT d.rowid, d.nom, d.prenom, d.societe, d.datedon as date, d.tms as dm, d.amount, d.fk_statut"; + $sql.= " FROM ".MAIN_DB_PREFIX."don as d"; + $sql.= " WHERE d.entity = ".$conf->entity; + $sql.= $db->order("d.tms","DESC"); $sql.= $db->plimit($max, 0); $result = $db->query($sql); @@ -928,7 +928,7 @@ if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.rowid = ff.fk_soc"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND ff.entity = ".$conf->entity; $sql.= " AND ff.paye = 0"; $sql.= " AND ff.fk_statut = 1"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; @@ -1027,8 +1027,8 @@ print ''; print '
'.$langs->trans("Ref").''.$langs->trans("Amount").' 
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre; + print ''.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre; print "'.$objp->nom.'".price($objp->total)."'.price($objp->total).'
'; +llxFooter(); + $db->close(); - -llxFooter(); ?> diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php index 5a8234c6970..0fd3e886354 100644 --- a/htdocs/compta/paiement/fiche.php +++ b/htdocs/compta/paiement/fiche.php @@ -269,7 +269,7 @@ $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.total_ttc, f.paye, f.fk_ $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s'; $sql.= ' WHERE pf.fk_facture = f.rowid'; $sql.= ' AND f.fk_soc = s.rowid'; -$sql.= ' AND s.entity = '.$conf->entity; +$sql.= ' AND f.entity = '.$conf->entity; $sql.= ' AND pf.fk_paiement = '.$paiement->id; $resql=$db->query($sql); if ($resql) diff --git a/htdocs/compta/paiement/liste.php b/htdocs/compta/paiement/liste.php index a9237f22b11..8c930856137 100644 --- a/htdocs/compta/paiement/liste.php +++ b/htdocs/compta/paiement/liste.php @@ -89,13 +89,14 @@ else $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid AND s.entity = ".$conf->entity; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$socid) { $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; } $sql.= " WHERE p.fk_paiement = c.id"; - if (!$user->rights->societe->client->voir && !$socid) + $sql.= " AND p.entity = ".$conf->entity; + if (! $user->rights->societe->client->voir && ! $socid) { $sql.= " AND sc.fk_user = " .$user->id; } diff --git a/htdocs/compta/prelevement/lignes.php b/htdocs/compta/prelevement/lignes.php index 6333000b8ad..6df698b529a 100644 --- a/htdocs/compta/prelevement/lignes.php +++ b/htdocs/compta/prelevement/lignes.php @@ -122,10 +122,12 @@ $pagenext = $page + 1; $sql = "SELECT pl.rowid, pl.statut, pl.amount"; $sql.= ", s.rowid as socid, s.nom"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; +$sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; $sql.= ", ".MAIN_DB_PREFIX."societe as s"; -$sql.= " WHERE pl.fk_prelevement_bons=".$prev_id; +$sql.= " WHERE pl.fk_prelevement_bons = ".$prev_id; +$sql.= " AND pl.fk_prelevement_bons = pb.rowid"; +$sql.= " AND pb.entity = ".$conf->entity; $sql.= " AND pl.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql.= " ORDER BY $sortfield $sortorder "; $sql.= $db->plimit($conf->liste_limit+1, $offset); diff --git a/htdocs/compta/prelevement/stats.php b/htdocs/compta/prelevement/stats.php index 63bae197f5a..85b525d2917 100644 --- a/htdocs/compta/prelevement/stats.php +++ b/htdocs/compta/prelevement/stats.php @@ -47,9 +47,9 @@ print_fiche_titre($langs->trans("Statistics")); // Define total and nbtotal $sql = "SELECT sum(pl.amount), count(pl.amount)"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; -$sql.= ", ".MAIN_DB_PREFIX."societe as s"; -$sql.= " WHERE pl.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; +$sql.= " WHERE pl.fk_prelevement_bons = pb.rowid"; +$sql.= " AND pb.entity = ".$conf->entity; $resql=$db->query($sql); if ($resql) { @@ -76,9 +76,9 @@ $ligne=new LignePrelevement($db,$user); $sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; -$sql.= ", ".MAIN_DB_PREFIX."societe as s"; -$sql.= " WHERE pl.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; +$sql.= " WHERE pl.fk_prelevement_bons = pb.rowid"; +$sql.= " AND pb.entity = ".$conf->entity; $sql.= " GROUP BY pl.statut"; $resql=$db->query($sql); @@ -146,9 +146,9 @@ print_titre($langs->trans("WithdrawRejectStatistics")); // Define total and nbtotal $sql = "SELECT sum(pl.amount), count(pl.amount)"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; -$sql.= ", ".MAIN_DB_PREFIX."societe as s"; -$sql.= " WHERE pl.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; +$sql.= " WHERE pl.fk_prelevement_bons = pb.rowid"; +$sql.= " AND pb.entity = ".$conf->entity; $sql.= " AND pl.statut = 3"; $resql=$db->query($sql); if ($resql) @@ -169,10 +169,10 @@ if ($resql) */ $sql = "SELECT sum(pl.amount), count(pl.amount) as cc, pr.motif"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; -$sql.= " , ".MAIN_DB_PREFIX."prelevement_rejet as pr"; -$sql.= ", ".MAIN_DB_PREFIX."societe as s"; -$sql.= " WHERE pl.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; +$sql.= ", ".MAIN_DB_PREFIX."prelevement_rejet as pr"; +$sql.= " WHERE pl.fk_prelevement_bons = pb.rowid"; +$sql.= " AND pb.entity = ".$conf->entity; $sql.= " AND pl.statut = 3"; $sql.= " AND pr.fk_prelevement_lignes = pl.rowid"; $sql.= " GROUP BY pr.motif"; @@ -232,8 +232,8 @@ else dol_print_error($db); } +llxFooter(); $db->close(); -llxFooter(); ?> diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index b81a6444cc7..d9f764f5e87 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -344,25 +344,25 @@ print ''.$langs->trans("SocialContributions").''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; + $sql = "SELECT c.libelle as nom, sum(cs.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; - $sql.= " WHERE s.fk_type = c.id"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql.= " WHERE cs.fk_type = c.id"; $sql.= " AND c.deductible = 0"; - if ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; + if ($date_start && $date_end) $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; } else { $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql.= " WHERE p.fk_charge = s.rowid"; - $sql.= " AND s.fk_type = c.id"; + $sql.= " WHERE p.fk_charge = cs.rowid"; + $sql.= " AND cs.fk_type = c.id"; $sql.= " AND c.deductible = 0"; if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle"; dol_syslog("get social contributions deductible=0 sql=".$sql); @@ -414,26 +414,26 @@ print ''.$langs->trans("SocialContributions").''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; + $sql = "SELECT c.libelle as nom, sum(cs.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; - $sql.= " WHERE s.fk_type = c.id"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql.= " WHERE cs.fk_type = c.id"; $sql.= " AND c.deductible = 1"; - if ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; - $sql.= " AND s.entity = ".$conf->entity; + if ($date_start && $date_end) $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; + $sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle DESC"; } else { $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql .= " WHERE p.fk_charge = s.rowid"; - $sql.= " AND s.fk_type = c.id"; + $sql .= " WHERE p.fk_charge = cs.rowid"; + $sql.= " AND cs.fk_type = c.id"; $sql.= " AND c.deductible = 1"; if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle"; } diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index ed738e9864b..db4adcd63fc 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -346,23 +346,23 @@ $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, date_format(s.date_ech,'%Y-%m') as dm, sum(s.amount) as amount_ht, sum(s.amount) as amount_ttc"; + $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount_ht, sum(cs.amount) as amount_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; - $sql.= " WHERE s.fk_type = c.id"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql.= " WHERE cs.fk_type = c.id"; $sql.= " AND c.deductible = 0"; } else { $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ht, sum(p.amount) as amount_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql.= " WHERE p.fk_charge = s.rowid"; - $sql.= " AND s.fk_type = c.id"; + $sql.= " WHERE p.fk_charge = cs.rowid"; + $sql.= " AND cs.fk_type = c.id"; $sql.= " AND c.deductible = 0"; } -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle, dm"; dol_syslog("get social contributions deductible=0 sql=".$sql); @@ -403,13 +403,13 @@ else { $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ht, sum(p.amount) as amount_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql.= " WHERE p.fk_charge = s.rowid"; - $sql.= " AND s.fk_type = c.id"; + $sql.= " WHERE p.fk_charge = cs.rowid"; + $sql.= " AND cs.fk_type = c.id"; $sql.= " AND c.deductible = 1"; } -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND cs.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle, dm"; dol_syslog("get social contributions paid deductible=1 sql=".$sql); diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index e017add6c9b..e674b07026d 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -320,10 +320,10 @@ if ($chid > 0) $sql.= "c.libelle as paiement_type"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " WHERE p.fk_charge = ".$chid; - $sql.= " AND p.fk_charge = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND p.fk_charge = cs.rowid"; + $sql.= " AND cs.entity = ".$conf->entity; $sql.= " AND p.fk_typepaiement = c.id"; $sql.= " ORDER BY dp DESC"; diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php index 398e06e73d6..e70f23066b0 100644 --- a/htdocs/compta/sociales/index.php +++ b/htdocs/compta/sociales/index.php @@ -40,7 +40,7 @@ $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; $limit = $conf->liste_limit; -if (! $sortfield) $sortfield="s.date_ech"; +if (! $sortfield) $sortfield="cs.date_ech"; if (! $sortorder) $sortorder="DESC"; $year=$_GET["year"]; @@ -53,7 +53,7 @@ if (empty($_REQUEST['typeid'])) foreach($filterarray as $val) { $part=explode(':',$val); - if ($part[0] == 's.fk_type') $typeid=$part[1]; + if ($part[0] == 'cs.fk_type') $typeid=$part[1]; } } else @@ -71,21 +71,21 @@ llxHeader(); $form = new Form($db); -$sql = "SELECT s.rowid as id, s.fk_type as type, "; -$sql.= " s.amount, s.date_ech, s.libelle, s.paye, s.periode,"; +$sql = "SELECT cs.rowid as id, cs.fk_type as type, "; +$sql.= " cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode,"; $sql.= " c.libelle as type_lib"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; -$sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; -$sql.= " WHERE s.fk_type = c.id"; -$sql.= " AND s.entity = ".$conf->entity; -if (GETPOST("search_label")) $sql.=" AND s.libelle like '%".GETPOST("search_label")."%'"; +$sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; +$sql.= " WHERE cs.fk_type = c.id"; +$sql.= " AND cs.entity = ".$conf->entity; +if (GETPOST("search_label")) $sql.=" AND cs.libelle LIKE '%".GETPOST("search_label")."%'"; if ($year > 0) { $sql .= " AND ("; // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire - $sql .= " (s.periode is not null and date_format(s.periode, '%Y') = '".$year."') "; - $sql .= "or (s.periode is null and date_format(s.date_ech, '%Y') = '".$year."')"; + $sql .= " (cs.periode IS NOT NULL AND date_format(cs.periode, '%Y') = '".$year."') "; + $sql .= "OR (cs.periode IS NULL AND date_format(cs.date_ech, '%Y') = '".$year."')"; $sql .= ")"; } if ($filtre) { @@ -93,7 +93,7 @@ if ($filtre) { $sql .= " AND ".$filtre; } if ($typeid) { - $sql .= " AND s.fk_type=".$typeid; + $sql .= " AND cs.fk_type=".$typeid; } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit+1,$offset); @@ -142,12 +142,12 @@ if ($resql) print ""; print_liste_field_titre($langs->trans("Ref"),"index.php","id","",$param,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),"index.php","s.libelle","",$param,'align="left"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),"index.php","cs.libelle","",$param,'align="left"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Type"),"index.php","type","",$param,'align="left"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PeriodEndDate"),"index.php","periode","",$param,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Amount"),"index.php","s.amount","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateDue"),"index.php","s.date_ech","",$param,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),"index.php","s.paye","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Amount"),"index.php","cs.amount","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateDue"),"index.php","cs.date_ech","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),"index.php","cs.paye","",$param,'align="right"',$sortfield,$sortorder); print "\n"; print ''; diff --git a/htdocs/compta/tva/quadri.php b/htdocs/compta/tva/quadri.php index 3154c5de299..70eb871b5c8 100644 --- a/htdocs/compta/tva/quadri.php +++ b/htdocs/compta/tva/quadri.php @@ -67,7 +67,7 @@ function tva_coll($db,$y,$q) $sql.= ", ".MAIN_DB_PREFIX."facturedet as d" ; $sql.= ", ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.fk_statut in (1,2)"; $sql.= " AND f.rowid = d.fk_facture "; $sql.= " AND date_format(f.datef,'%Y') = '".$y."'"; @@ -134,7 +134,7 @@ function tva_paye($db, $y,$q) $sql.= ", ".MAIN_DB_PREFIX."facture_fourn_det as d" ; $sql.= ", ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.fk_statut = 1 "; $sql.= " AND f.rowid = d.fk_facture_fourn "; $sql.= " AND date_format(f.datef,'%Y') = '".$y."'"; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 97af3767f55..9eca94bd8c0 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1358,7 +1358,7 @@ class Contrat extends CommonObject $sql.= " AND cd.date_fin_validite < '".$this->db->idate(time())."'"; } $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; $resql=$this->db->query($sql); @@ -1403,7 +1403,7 @@ class Contrat extends CommonObject $sql.= " WHERE sc.fk_user = " .$user->id; $clause = "AND"; } - $sql.= " ".$clause." s.entity = ".$conf->entity; + $sql.= " ".$clause." c.entity = ".$conf->entity; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index 301610daaf8..d0045156eed 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -103,7 +103,7 @@ $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid"; $sql.= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate(dol_now('tzref'))."')))"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY cd.statut"; @@ -140,7 +140,7 @@ $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid"; $sql.= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate(dol_now('tzref'))."')"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY cd.statut"; @@ -229,7 +229,7 @@ if ($conf->contrat->enabled && $user->rights->contrat->lire) $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.rowid = c.fk_soc"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND c.statut = 0"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.fk_soc = ".$socid; @@ -300,7 +300,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX. $sql.= " ".MAIN_DB_PREFIX."contrat as c"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; $sql.= " AND c.statut > 0"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -374,7 +374,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql.= " WHERE cd.fk_contrat = c.rowid"; $sql.= " AND c.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql.= " ORDER BY cd.tms DESC"; @@ -454,7 +454,7 @@ $sql.= " WHERE c.statut=1"; $sql.= " AND cd.statut = 0"; $sql.= " AND cd.fk_contrat = c.rowid"; $sql.= " AND c.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql.= " ORDER BY cd.tms DESC"; @@ -534,7 +534,7 @@ $sql.= " AND cd.statut = 4"; $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'"; $sql.= " AND cd.fk_contrat = c.rowid"; $sql.= " AND c.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql.= " ORDER BY cd.tms DESC"; diff --git a/htdocs/contrat/liste.php b/htdocs/contrat/liste.php index 7a86d16fea3..ea8ff2a549a 100644 --- a/htdocs/contrat/liste.php +++ b/htdocs/contrat/liste.php @@ -76,7 +76,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX $sql.= ", ".MAIN_DB_PREFIX."contrat as c"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; $sql.= " WHERE c.fk_soc = s.rowid "; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; if ($socid) $sql.= " AND s.rowid = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($search_nom) $sql.= " AND s.nom like '%".$db->escape($search_nom)."%'"; diff --git a/htdocs/contrat/services.php b/htdocs/contrat/services.php index e6d3ddd2e8c..24a788f8fd7 100644 --- a/htdocs/contrat/services.php +++ b/htdocs/contrat/services.php @@ -87,7 +87,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; $sql.= " WHERE"; $sql.= " c.rowid = cd.fk_contrat"; $sql.= " AND c.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($mode == "0") $sql.= " AND cd.statut = 0"; if ($mode == "4") $sql.= " AND cd.statut = 4"; diff --git a/htdocs/core/boxes/box_actions.php b/htdocs/core/boxes/box_actions.php index 2a4043e1da2..e909e60620a 100644 --- a/htdocs/core/boxes/box_actions.php +++ b/htdocs/core/boxes/box_actions.php @@ -79,7 +79,7 @@ class box_actions extends ModeleBoxes $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm AS ta, "; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " ".MAIN_DB_PREFIX."societe_commerciaux AS sc, "; $sql.= MAIN_DB_PREFIX."actioncomm AS a)"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid AND s.entity IN (0, ".$conf->entity.")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " WHERE a.fk_action = ta.id"; $sql.= " AND a.entity = ".$conf->entity; $sql.= " AND a.percent >= 0 AND a.percent < 100"; diff --git a/htdocs/core/boxes/box_clients.php b/htdocs/core/boxes/box_clients.php index 3fee3837ef1..05654cc43aa 100644 --- a/htdocs/core/boxes/box_clients.php +++ b/htdocs/core/boxes/box_clients.php @@ -78,7 +78,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.client IN (1, 3)"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = $user->societe_id"; $sql.= " ORDER BY s.tms DESC"; diff --git a/htdocs/core/boxes/box_commandes.php b/htdocs/core/boxes/box_commandes.php index bea55ca2d9f..f729b6881ec 100644 --- a/htdocs/core/boxes/box_commandes.php +++ b/htdocs/core/boxes/box_commandes.php @@ -75,16 +75,16 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); { $sql = "SELECT s.nom, s.rowid as socid,"; - $sql.= " p.ref, p.tms, p.rowid,"; - $sql.= " p.fk_statut, p.facture"; + $sql.= " c.ref, c.tms, c.rowid,"; + $sql.= " c.fk_statut, c.facture"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."commande as p"; + $sql.= ", ".MAIN_DB_PREFIX."commande as c"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " WHERE c.fk_soc = s.rowid"; + $sql.= " AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; - $sql.= " ORDER BY p.date_commande DESC, p.ref DESC "; + $sql.= " ORDER BY c.date_commande DESC, c.ref DESC "; $sql.= $db->plimit($max, 0); $result = $db->query($sql); diff --git a/htdocs/core/boxes/box_contacts.php b/htdocs/core/boxes/box_contacts.php index 36d9448c337..15f7a77b9cb 100755 --- a/htdocs/core/boxes/box_contacts.php +++ b/htdocs/core/boxes/box_contacts.php @@ -75,7 +75,7 @@ include_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"); $sql = "SELECT s.rowid, s.name, s.firstname, s.civilite, s.datec, s.tms"; $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE s.entity = ".$conf->entity; + $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = $user->societe_id"; $sql.= " ORDER BY s.tms DESC"; diff --git a/htdocs/core/boxes/box_factures.php b/htdocs/core/boxes/box_factures.php index bcbb167eecb..d34c50750bb 100644 --- a/htdocs/core/boxes/box_factures.php +++ b/htdocs/core/boxes/box_factures.php @@ -84,7 +84,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " ORDER BY f.tms DESC"; diff --git a/htdocs/core/boxes/box_factures_fourn.php b/htdocs/core/boxes/box_factures_fourn.php index e30440b4674..7899e8b4491 100644 --- a/htdocs/core/boxes/box_factures_fourn.php +++ b/htdocs/core/boxes/box_factures_fourn.php @@ -84,7 +84,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " ORDER BY f.tms DESC"; diff --git a/htdocs/core/boxes/box_factures_fourn_imp.php b/htdocs/core/boxes/box_factures_fourn_imp.php index dacc305976c..c9013d9a6db 100644 --- a/htdocs/core/boxes/box_factures_fourn_imp.php +++ b/htdocs/core/boxes/box_factures_fourn_imp.php @@ -80,7 +80,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); $sql.= ",".MAIN_DB_PREFIX."facture_fourn as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.paye=0"; $sql.= " AND fk_statut = 1"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/core/boxes/box_factures_imp.php b/htdocs/core/boxes/box_factures_imp.php index c0cbcb0be35..dff509b025d 100644 --- a/htdocs/core/boxes/box_factures_imp.php +++ b/htdocs/core/boxes/box_factures_imp.php @@ -82,7 +82,7 @@ require_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'); $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.paye = 0"; $sql.= " AND fk_statut = 1"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/core/boxes/box_fournisseurs.php b/htdocs/core/boxes/box_fournisseurs.php index 15c7bb1ddc3..0270f0c12c9 100644 --- a/htdocs/core/boxes/box_fournisseurs.php +++ b/htdocs/core/boxes/box_fournisseurs.php @@ -77,7 +77,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fournisseur = 1"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " ORDER BY s.tms DESC "; diff --git a/htdocs/core/boxes/box_members.php b/htdocs/core/boxes/box_members.php index 2bfb498fd4b..ccdd906577b 100755 --- a/htdocs/core/boxes/box_members.php +++ b/htdocs/core/boxes/box_members.php @@ -74,12 +74,12 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); if ($user->rights->societe->lire) { - $sql = "SELECT s.rowid, s.nom as lastname, s.prenom as firstname, s.datec, s.tms, s.statut as status, s.datefin as date_end_subscription,"; + $sql = "SELECT a.rowid, a.nom as lastname, a.prenom as firstname, a.datec, a.tms, a.statut as status, a.datefin as date_end_subscription,"; $sql.= " t.cotisation"; - $sql.= " FROM ".MAIN_DB_PREFIX."adherent as s, ".MAIN_DB_PREFIX."adherent_type as t"; - $sql.= " WHERE s.entity = ".$conf->entity; - $sql.= " AND s.fk_adherent_type = t.rowid"; - $sql.= " ORDER BY s.tms DESC"; + $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as t"; + $sql.= " WHERE a.entity = ".$conf->entity; + $sql.= " AND a.fk_adherent_type = t.rowid"; + $sql.= " ORDER BY a.tms DESC"; $sql.= $db->plimit($max, 0); $result = $db->query($sql); diff --git a/htdocs/core/boxes/box_propales.php b/htdocs/core/boxes/box_propales.php index fa0afed279f..33230db1a54 100644 --- a/htdocs/core/boxes/box_propales.php +++ b/htdocs/core/boxes/box_propales.php @@ -80,7 +80,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND p.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " ORDER BY p.datep DESC, p.ref DESC "; diff --git a/htdocs/core/boxes/box_prospect.php b/htdocs/core/boxes/box_prospect.php index 3793694019f..19607d4d791 100644 --- a/htdocs/core/boxes/box_prospect.php +++ b/htdocs/core/boxes/box_prospect.php @@ -82,7 +82,7 @@ include_once(DOL_DOCUMENT_ROOT."/comm/prospect/class/prospect.class.php"); $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.client IN (2, 3)"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " ORDER BY s.tms DESC"; diff --git a/htdocs/core/boxes/box_services_vendus.php b/htdocs/core/boxes/box_services_vendus.php index c99a0c327a2..a5be4a29b59 100644 --- a/htdocs/core/boxes/box_services_vendus.php +++ b/htdocs/core/boxes/box_services_vendus.php @@ -84,7 +84,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")"; $sql.= " WHERE s.rowid = c.fk_soc"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND c.rowid = cd.fk_contrat"; $sql.= " AND cd.fk_product = p.rowid"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f2c0f2aedc4..3fb98a41da6 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -745,7 +745,7 @@ class Form $sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur"; $sql.= " FROM ".MAIN_DB_PREFIX ."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE s.entity = ".$conf->entity; + $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; if ($filter) $sql.= " AND ".$filter; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " ORDER BY nom ASC"; diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index f674831504b..9c51db1dd4f 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -96,7 +96,7 @@ class Notify $sql.= " AND n.fk_soc = s.rowid"; if (is_numeric($action)) $sql.= " AND n.fk_action = ".$action; // Old usage else $sql.= " AND a.code = '".$action."'"; // New usage - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; $sql.= " AND s.rowid = ".$socid; dol_syslog("Notify.class::countDefinedNotifications ".$action.", ".$socid." sql=".$sql); diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 14424322984..6dd2a1bb0b4 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -185,8 +185,9 @@ function show_array_actions_to_do($max=5) $sql.= " ".MAIN_DB_PREFIX."actioncomm as a"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ")"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid AND s.entity IN (0, ".$conf->entity.")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " WHERE c.id = a.fk_action"; + $sql.= " AND a.entity = ".$conf->entity; $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -283,8 +284,9 @@ function show_array_last_actions_done($max=5) $sql.= " ".MAIN_DB_PREFIX."actioncomm as a"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.=")"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid AND s.entity IN (0, ".$conf->entity.")"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " WHERE c.id = a.fk_action"; + $sql.= " AND a.entity = ".$conf->entity; $sql.= " AND (a.percent >= 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index a6d96583054..2b2a1110b57 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -989,7 +989,7 @@ function show_subsidiaries($conf,$langs,$db,$object) $sql = "SELECT s.rowid, s.nom as name, s.address, s.cp as zip, s.ville as town, s.code_client, s.canvas"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE s.parent = ".$object->id; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; $sql.= " ORDER BY s.nom"; $result = $db->query($sql); diff --git a/htdocs/core/modules/mailings/contacts1.modules.php b/htdocs/core/modules/mailings/contacts1.modules.php index e0b7fb782c4..7ef9713bd46 100755 --- a/htdocs/core/modules/mailings/contacts1.modules.php +++ b/htdocs/core/modules/mailings/contacts1.modules.php @@ -73,8 +73,7 @@ class mailing_contacts1 extends MailingTargets $statssql[0].= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; $statssql[0].= " ".MAIN_DB_PREFIX."societe as s"; $statssql[0].= " WHERE s.rowid = c.fk_soc"; - $statssql[0].= " AND s.entity = ".$conf->entity; - $statssql[0].= " AND c.entity = ".$conf->entity; + $statssql[0].= " AND c.entity IN (".getEntity('societe', 1).")"; $statssql[0].= " AND s.client IN (1, 3)"; $statssql[0].= " AND c.email != ''"; // Note that null != '' is false @@ -97,8 +96,7 @@ class mailing_contacts1 extends MailingTargets $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; $sql .= " ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE s.rowid = c.fk_soc"; - $sql .= " AND c.entity = ".$conf->entity; - $sql .= " AND s.entity = ".$conf->entity; + $sql .= " AND c.entity IN (".getEntity('societe', 1).")"; $sql .= " AND c.email != ''"; // Note that null != '' is false // La requete doit retourner un champ "nb" pour etre comprise @@ -204,8 +202,7 @@ class mailing_contacts1 extends MailingTargets $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; $sql.= " ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE s.rowid = c.fk_soc"; - $sql.= " AND c.entity = ".$conf->entity; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('societe', 1).")"; $sql.= " AND c.email != ''"; foreach($filtersarray as $key) { diff --git a/htdocs/core/modules/mailings/contacts2.modules.php b/htdocs/core/modules/mailings/contacts2.modules.php index 386c1d20666..21fd42c95ec 100755 --- a/htdocs/core/modules/mailings/contacts2.modules.php +++ b/htdocs/core/modules/mailings/contacts2.modules.php @@ -163,8 +163,7 @@ class mailing_contacts2 extends MailingTargets $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp,"; $sql.= " ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE s.rowid = sp.fk_soc"; - $sql.= " AND s.entity = ".$conf->entity; - $sql.= " AND sp.entity = ".$conf->entity; + $sql.= " AND sp.entity IN (".getEntity('societe', 1).")"; $sql.= " AND sp.email != ''"; // Note that null != '' is false //$sql.= " AND sp.poste != ''"; // La requete doit retourner un champ "nb" pour etre comprise diff --git a/htdocs/core/modules/mailings/contacts3.modules.php b/htdocs/core/modules/mailings/contacts3.modules.php index a9973722d6c..228961fe990 100755 --- a/htdocs/core/modules/mailings/contacts3.modules.php +++ b/htdocs/core/modules/mailings/contacts3.modules.php @@ -169,8 +169,7 @@ class mailing_contacts3 extends MailingTargets $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; $sql.= " ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE s.rowid = c.fk_soc"; - $sql.= " AND c.entity = ".$conf->entity; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity IN (".getEntity('societe', 1).")"; $sql.= " AND c.email != ''"; // Note that null != '' is false /* $sql = "SELECT count(distinct(sp.email)) as nb"; @@ -179,8 +178,7 @@ class mailing_contacts3 extends MailingTargets $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; $sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs"; $sql.= " WHERE s.rowid = sp.fk_soc"; - $sql.= " AND sp.entity = ".$conf->entity; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND sp.entity IN (".getEntity('societe', 1).")"; $sql.= " AND sp.email != ''"; // Note that null != '' is false $sql.= " AND cs.fk_categorie = c.rowid"; $sql.= " AND cs.fk_societe = sp.fk_soc"; diff --git a/htdocs/core/modules/mailings/framboise.modules.php b/htdocs/core/modules/mailings/framboise.modules.php index fbb0aeea420..86afa59054b 100644 --- a/htdocs/core/modules/mailings/framboise.modules.php +++ b/htdocs/core/modules/mailings/framboise.modules.php @@ -63,19 +63,19 @@ class mailing_framboise extends MailingTargets // CHANGE THIS // Select the members from category - $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname,"; + $sql = "SELECT a.rowid as id, a.email as email, a.nom as name, null as fk_contact, null as firstname,"; if ($_POST['filter']) $sql.= " c.label"; else $sql.=" null as label"; - $sql.= " FROM ".MAIN_DB_PREFIX."adherent as s"; + $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; if ($_POST['filter']) { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = s.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie"; } - $sql.= " WHERE s.email != ''"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " WHERE a.email != ''"; + $sql.= " AND a.entity = ".$conf->entity; if ($_POST['filter']) $sql.= " AND c.rowid='".$_POST['filter']."'"; - $sql.= " ORDER BY s.email"; + $sql.= " ORDER BY a.email"; // Stocke destinataires dans cibles $result=$this->db->query($sql); @@ -150,10 +150,10 @@ class mailing_framboise extends MailingTargets { global $conf; - $sql = "SELECT count(distinct(s.email)) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."adherent as s"; - $sql.= " WHERE s.email != ''"; - $sql.= " AND s.entity = ".$conf->entity; + $sql = "SELECT count(distinct(a.email)) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; + $sql.= " WHERE a.email != ''"; + $sql.= " AND a.entity = ".$conf->entity; // La requete doit retourner un champ "nb" pour etre comprise // par parent::getNbOfRecipients diff --git a/htdocs/core/modules/mailings/thirdparties.modules.php b/htdocs/core/modules/mailings/thirdparties.modules.php index 7cf0eb6ef4a..9bfda30d8f9 100755 --- a/htdocs/core/modules/mailings/thirdparties.modules.php +++ b/htdocs/core/modules/mailings/thirdparties.modules.php @@ -67,14 +67,14 @@ class mailing_thirdparties extends MailingTargets $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE s.email != ''"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; } else { $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_societe as cs, ".MAIN_DB_PREFIX."categorie as c"; $sql.= " WHERE s.email != ''"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; $sql.= " AND cs.fk_societe = s.rowid"; $sql.= " AND c.rowid = cs.fk_categorie"; $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; @@ -82,7 +82,7 @@ class mailing_thirdparties extends MailingTargets $sql.= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_fournisseur as cs, ".MAIN_DB_PREFIX."categorie as c"; $sql.= " WHERE s.email != ''"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; $sql.= " AND cs.fk_societe = s.rowid"; $sql.= " AND c.rowid = cs.fk_categorie"; $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; @@ -164,7 +164,7 @@ class mailing_thirdparties extends MailingTargets $sql = "SELECT count(distinct(s.email)) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE s.email != ''"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; // La requete doit retourner un champ "nb" pour etre comprise // par parent::getNbOfRecipients diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 6aa523b18cc..e06da8453f9 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -182,7 +182,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd)'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; - $this->export_sql_end[$r] .=' AND s.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND f.entity = '.$conf->entity; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index f716fa4c8cc..ab20a588b15 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -222,7 +222,7 @@ class modSociete extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; - $this->export_sql_end[$r] .=' WHERE s.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe', 1).')'; // Export list of contacts and attributes $r++; diff --git a/htdocs/fourn/class/fournisseur.class.php b/htdocs/fourn/class/fournisseur.class.php index d384a3bade6..20117e34e8c 100644 --- a/htdocs/fourn/class/fournisseur.class.php +++ b/htdocs/fourn/class/fournisseur.class.php @@ -125,7 +125,7 @@ class Fournisseur extends Societe $clause = "AND"; } $sql.= " ".$clause." s.fournisseur = 1"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; $resql=$this->db->query($sql); if ($resql) @@ -188,7 +188,7 @@ class Fournisseur extends Societe $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$this->user->rights->societe->client->voir && !$this->user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fournisseur = 1"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (!$this->user->rights->societe->client->voir && !$this->user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$this->user->id; $resql=$this->db->query($sql); diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 9427bb327a1..75f50eee054 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -331,7 +331,7 @@ class ProductFournisseur extends Product $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " ON pfp.fk_soc = s.rowid"; - $sql.= " WHERE s.entity = ".$conf->entity; + $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; $sql.= " AND pfp.fk_product = ".$prodid; $sql.= " ORDER BY s.nom, pfp.quantity, pfp.price"; @@ -408,7 +408,7 @@ class ProductFournisseur extends Product $sql.= " pfp.rowid as product_fourn_price_id, pfp.ref_fourn,"; $sql.= " pfp.price, pfp.quantity, pfp.unitprice"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; - $sql.= " WHERE s.entity = ".$conf->entity; + $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; $sql.= " AND pfp.fk_product = ".$prodid; $sql.= " AND pfp.fk_soc = s.rowid"; $sql.= " ORDER BY pfp.unitprice"; diff --git a/htdocs/fourn/commande/index.php b/htdocs/fourn/commande/index.php index 29377968798..0cb66532dcf 100644 --- a/htdocs/fourn/commande/index.php +++ b/htdocs/fourn/commande/index.php @@ -77,7 +77,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE cf.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND cf.entity = ".$conf->entity; if ($user->societe_id) $sql.=' AND cf.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY cf.fk_statut"; diff --git a/htdocs/fourn/commande/liste.php b/htdocs/fourn/commande/liste.php index 57338dc67e9..3e182374e84 100644 --- a/htdocs/fourn/commande/liste.php +++ b/htdocs/fourn/commande/liste.php @@ -81,7 +81,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX $sql.= ")"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; $sql.= " WHERE cf.fk_soc = s.rowid "; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND cf.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($sref) { @@ -101,7 +101,7 @@ if ($sttc) } if ($sall) { - $sql.= " AND (cf.ref like '%".$db->escape($sall)."%' OR cf.note like '%".$db->escape($sall)."%')"; + $sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')"; } if ($socid) $sql.= " AND s.rowid = ".$socid; diff --git a/htdocs/fourn/index.php b/htdocs/fourn/index.php index e8b8ab122a9..8169429b8cb 100644 --- a/htdocs/fourn/index.php +++ b/htdocs/fourn/index.php @@ -235,7 +235,7 @@ $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_stcomm = st.id"; $sql.= " AND s.fournisseur = 1"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql .= " AND s.rowid = ".$socid; $sql.= " ORDER BY s.tms DESC"; diff --git a/htdocs/fourn/liste.php b/htdocs/fourn/liste.php index 9c89c441d06..71da3a75c5b 100644 --- a/htdocs/fourn/liste.php +++ b/htdocs/fourn/liste.php @@ -74,7 +74,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st"; if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as cf"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_stcomm = st.id AND s.fournisseur = 1"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if ($search_categ) $sql.= " AND s.rowid = cf.fk_societe"; // Join for the needed table to filter by categ if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql .= " AND s.rowid = ".$socid; diff --git a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql index 0de2be26be0..918606565da 100755 --- a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql +++ b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql @@ -182,3 +182,4 @@ update llx_cotisation set fk_bank = null where fk_bank not in (select rowid from insert into llx_c_chargesociales (id, libelle, deductible, active, code, fk_pays) values (12, 'Cotisation foncière des entreprises', 0, 1, 'TAXCFE', '1'); insert into llx_c_chargesociales (id, libelle, deductible, active, code, fk_pays) values (13, 'Cotisation sur la valeur ajoutée des entreprises', 0, 1, 'TAXCVAE', '1'); +ALTER TABLE llx_paiement ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; diff --git a/htdocs/install/mysql/tables/llx_paiement.sql b/htdocs/install/mysql/tables/llx_paiement.sql index 9fb7d68c757..3fd4bdcbce2 100644 --- a/htdocs/install/mysql/tables/llx_paiement.sql +++ b/htdocs/install/mysql/tables/llx_paiement.sql @@ -1,6 +1,7 @@ -- =================================================================== --- Copyright (C) 2001-2002,2004 Rodolphe Quiedeville --- Copyright (C) 2004 Laurent Destailleur +-- Copyright (C) 2001-2004 Rodolphe Quiedeville +-- Copyright (C) 2004 Laurent Destailleur +-- Copyright (C) 2012 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -24,16 +25,17 @@ create table llx_paiement ( rowid integer AUTO_INCREMENT PRIMARY KEY, - datec datetime, -- date de creation + entity integer DEFAULT 1 NOT NULL, -- Multi company id + datec datetime, -- date de creation tms timestamp, - datep datetime, -- payment date + datep datetime, -- payment date amount double(24,8) DEFAULT 0, fk_paiement integer NOT NULL, num_paiement varchar(50), note text, fk_bank integer NOT NULL DEFAULT 0, - fk_user_creat integer, -- utilisateur qui a cree l'info - fk_user_modif integer, -- utilisateur qui a modifie l'info + fk_user_creat integer, -- utilisateur qui a cree l'info + fk_user_modif integer, -- utilisateur qui a modifie l'info statut smallint DEFAULT 0 NOT NULL, fk_export_compta integer DEFAULT 0 NOT NULL diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f072d5c709e..e88f5e127f6 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1173,7 +1173,7 @@ class Product extends CommonObject if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.rowid = pd.fk_propal"; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND p.entity = ".$conf->entity; $sql.= " AND pd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND pr.fk_statut != 0"; @@ -1216,7 +1216,7 @@ class Product extends CommonObject if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.rowid = cd.fk_commande"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid; @@ -1258,7 +1258,7 @@ class Product extends CommonObject if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.rowid = cd.fk_commande"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid; @@ -1301,7 +1301,7 @@ class Product extends CommonObject if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE e.rowid = ed.fk_expedition"; $sql.= " AND e.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND e.entity = ".$conf->entity; $sql.= " AND ed.fk_origin_line = cd.rowid"; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -1344,7 +1344,7 @@ class Product extends CommonObject if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.rowid = cd.fk_contrat"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND cd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND c.statut != 0"; @@ -1386,7 +1386,7 @@ class Product extends CommonObject if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.rowid = fd.fk_facture"; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND fd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND f.fk_statut != 0"; @@ -1428,7 +1428,7 @@ class Product extends CommonObject if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.rowid = fd.fk_facture_fourn"; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND fd.fk_product = ".$this->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; //$sql.= " AND f.fk_statut != 0"; @@ -1526,7 +1526,7 @@ class Product extends CommonObject $sql.= " WHERE f.rowid = d.fk_facture"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND f.fk_soc = $socid"; $sql.= " GROUP BY date_format(f.datef,'%Y%m')"; @@ -1555,7 +1555,7 @@ class Product extends CommonObject $sql.= " WHERE f.rowid = d.fk_facture_fourn"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND f.fk_soc = $socid"; $sql.= " GROUP BY date_format(f.datef,'%Y%m')"; @@ -1584,7 +1584,7 @@ class Product extends CommonObject $sql.= " WHERE p.rowid = d.fk_propal"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND p.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND p.fk_soc = ".$socid; $sql.= " GROUP BY date_format(p.datep,'%Y%m')"; @@ -1611,7 +1611,7 @@ class Product extends CommonObject $sql.= " WHERE c.rowid = d.fk_commande"; $sql.= " AND d.fk_product =".$this->id; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid; $sql.= " GROUP BY date_format(c.date_commande,'%Y%m')"; diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php index 7b2c54fee8b..9c07675e474 100644 --- a/htdocs/product/stats/commande.php +++ b/htdocs/product/stats/commande.php @@ -121,7 +121,7 @@ if ($_GET["id"] || $_GET["ref"]) $sql.= ", ".MAIN_DB_PREFIX."commandedet as d"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND d.fk_commande = c.rowid"; $sql.= " AND d.fk_product =".$product->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/product/stats/commande_fournisseur.php b/htdocs/product/stats/commande_fournisseur.php index 35ef2e9c310..bcaca43d05a 100644 --- a/htdocs/product/stats/commande_fournisseur.php +++ b/htdocs/product/stats/commande_fournisseur.php @@ -115,7 +115,7 @@ if ($_GET["id"] || $_GET["ref"]) $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as d"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND d.fk_commande = c.rowid"; $sql.= " AND d.fk_product =".$product->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/product/stats/contrat.php b/htdocs/product/stats/contrat.php index 92786ff9516..0d483acfd2b 100644 --- a/htdocs/product/stats/contrat.php +++ b/htdocs/product/stats/contrat.php @@ -127,7 +127,7 @@ if ($_GET["id"] || $_GET["ref"]) $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " WHERE c.rowid = cd.fk_contrat"; $sql.= " AND c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND c.entity = ".$conf->entity; $sql.= " AND cd.fk_product =".$product->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index dde6d04e2ab..209d6266ecc 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -124,7 +124,7 @@ if ($_GET["id"] || $_GET["ref"]) $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND d.fk_facture = f.rowid"; $sql.= " AND d.fk_product =".$product->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/product/stats/facture_fournisseur.php b/htdocs/product/stats/facture_fournisseur.php index bdaaf1e20da..eb92ae363e8 100644 --- a/htdocs/product/stats/facture_fournisseur.php +++ b/htdocs/product/stats/facture_fournisseur.php @@ -124,7 +124,7 @@ if ($_GET["id"] || $_GET["ref"]) $sql.= ", ".MAIN_DB_PREFIX."facture_fourn_det as d"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND d.fk_facture_fourn = f.rowid"; $sql.= " AND d.fk_product =".$product->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index 170f786fda5..84180d01a62 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -118,7 +118,7 @@ if ($_GET["id"] || $_GET["ref"]) $sql.= ", ".MAIN_DB_PREFIX."propaldet as d"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND p.entity = ".$conf->entity; $sql.= " AND d.fk_propal = p.rowid"; $sql.= " AND d.fk_product =".$product->id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/product/stock/index.php b/htdocs/product/stock/index.php index fc90693fa4f..8ba96764615 100644 --- a/htdocs/product/stock/index.php +++ b/htdocs/product/stock/index.php @@ -106,14 +106,14 @@ print ''; // Last movements $max=10; $sql = "SELECT p.rowid, p.label as produit,"; -$sql.= " s.label as stock, s.rowid as entrepot_id,"; +$sql.= " e.label as stock, e.rowid as entrepot_id,"; $sql.= " m.value, m.datem"; -$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as s"; +$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e"; $sql.= ", ".MAIN_DB_PREFIX."stock_mouvement as m"; $sql.= ", ".MAIN_DB_PREFIX."product as p"; $sql.= " WHERE m.fk_product = p.rowid"; -$sql.= " AND m.fk_entrepot = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND m.fk_entrepot = e.rowid"; +$sql.= " AND e.entity = ".$conf->entity; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0"; $sql.= $db->order("datem","DESC"); $sql.= $db->plimit($max,0); @@ -159,7 +159,8 @@ if ($resql) print ''; +llxFooter(); + $db->close(); -llxFooter(); ?> diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 1de22cd3e2c..e25bffa27ba 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -75,20 +75,20 @@ $form=new Form($db); $formother=new FormOther($db); $sql = "SELECT p.rowid, p.label as produit, p.fk_product_type as type,"; -$sql.= " s.label as stock, s.rowid as entrepot_id,"; +$sql.= " e.label as stock, e.rowid as entrepot_id,"; $sql.= " m.rowid as mid, m.value, m.datem, m.fk_user_author, m.label,"; $sql.= " u.login"; -$sql.= " FROM (".MAIN_DB_PREFIX."entrepot as s,"; +$sql.= " FROM (".MAIN_DB_PREFIX."entrepot as e,"; $sql.= " ".MAIN_DB_PREFIX."stock_mouvement as m,"; $sql.= " ".MAIN_DB_PREFIX."product as p)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid"; $sql.= " WHERE m.fk_product = p.rowid"; -$sql.= " AND m.fk_entrepot = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND m.fk_entrepot = e.rowid"; +$sql.= " AND e.entity = ".$conf->entity; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0"; if ($_GET["id"]) { - $sql.= " AND s.rowid ='".$_GET["id"]."'"; + $sql.= " AND e.rowid ='".$_GET["id"]."'"; } if ($month > 0) { @@ -111,7 +111,7 @@ if (! empty($search_product)) } if (! empty($search_warehouse)) { - $sql.= " AND s.label LIKE '%".$db->escape($search_warehouse)."%'"; + $sql.= " AND e.label LIKE '%".$db->escape($search_warehouse)."%'"; } if (! empty($search_user)) { @@ -341,8 +341,8 @@ else dol_print_error($db); } +llxFooter(); $db->close(); -llxFooter(); ?> diff --git a/htdocs/societe/ajaxcompanies.php b/htdocs/societe/ajaxcompanies.php index b8264ea29cd..1127542dc78 100644 --- a/htdocs/societe/ajaxcompanies.php +++ b/htdocs/societe/ajaxcompanies.php @@ -61,7 +61,7 @@ if (GETPOST('newcompany') || GETPOST('socid') || GETPOST('id_fourn')) $sql = "SELECT rowid, nom"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE s.entity = ".$conf->entity; + $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; if ($socid) { $sql.=" AND ("; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 95916e06388..6b8571079cc 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -650,13 +650,13 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id'; if ($rowid) $sql .= ' WHERE s.rowid = '.$rowid; - if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity = ".$conf->entity; - if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity = ".$conf->entity; - if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity = ".$conf->entity; - if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity = ".$conf->entity; - if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity = ".$conf->entity; - if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity = ".$conf->entity; - if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity = ".$conf->entity; + if ($ref) $sql .= " WHERE s.nom = '".$this->db->escape($ref)."' AND s.entity IN (".getEntity($this->element, 1).")"; + if ($ref_ext) $sql .= " WHERE s.ref_ext = '".$this->db->escape($ref_ext)."' AND s.entity IN (".getEntity($this->element, 1).")"; + if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity IN (".getEntity($this->element, 1).")"; + if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity IN (".getEntity($this->element, 1).")"; + if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity IN (".getEntity($this->element, 1).")"; + if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity IN (".getEntity($this->element, 1).")"; + if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element, 1).")"; $resql=$this->db->query($sql); dol_syslog(get_class($this)."::fetch ".$sql); diff --git a/htdocs/societe/lien.php b/htdocs/societe/lien.php index 4b52f35ac13..6ae5d7fb4dc 100644 --- a/htdocs/societe/lien.php +++ b/htdocs/societe/lien.php @@ -239,7 +239,7 @@ if ($socid) $sql.= ", ".MAIN_DB_PREFIX."c_typent as te"; if (! $user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_typent = te.id"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (! $user->rights->societe->client->voir) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (dol_strlen(trim($_GET["search_nom"]))) $sql.= " AND s.nom LIKE '%".$_GET["search_nom"]."%'"; $sql.= $db->order("s.nom","ASC"); diff --git a/htdocs/societe/notify/index.php b/htdocs/societe/notify/index.php index f0944e5d930..42aad61b93b 100644 --- a/htdocs/societe/notify/index.php +++ b/htdocs/societe/notify/index.php @@ -65,7 +65,7 @@ $sql.= " ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE n.fk_contact = c.rowid"; $sql.= " AND a.rowid = n.fk_action"; $sql.= " AND n.fk_soc = s.rowid"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if ($socid > 0) $sql.= " AND s.rowid = " . $user->societe_id; $sql.= $db->order($sortfield,$sortorder); diff --git a/htdocs/societe/societe.php b/htdocs/societe/societe.php index 3de7fe71666..d81ad8c1c4e 100644 --- a/htdocs/societe/societe.php +++ b/htdocs/societe/societe.php @@ -75,13 +75,13 @@ if ($mode == 'search') if ($search_sale || !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We'll need this table joined to the select in order to filter by categ if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs"; - $sql.= " WHERE ("; - $sql.= " s.nom like '%".$db->escape($socname)."%'"; + $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; + $sql.= " AND ("; + $sql.= " s.nom LIKE '%".$db->escape($socname)."%'"; $sql.= " OR s.code_client LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.email like '%".$db->escape($socname)."%'"; - $sql.= " OR s.url like '%".$db->escape($socname)."%'"; + $sql.= " OR s.email LIKE '%".$db->escape($socname)."%'"; + $sql.= " OR s.url LIKE '%".$db->escape($socname)."%'"; $sql.= ")"; - $sql.= " AND s.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale @@ -175,7 +175,7 @@ if ($search_sale || !$user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_P // We'll need this table joined to the select in order to filter by categ if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs"; $sql.= " WHERE s.fk_stcomm = st.id"; -$sql.= " AND s.entity = ".$conf->entity; +$sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale @@ -204,8 +204,8 @@ if ($search_all) $sql.= " AND ("; $sql.= "s.nom LIKE '%".$db->escape($search_all)."%'"; $sql.= " OR s.code_client LIKE '%".$db->escape($search_all)."%'"; - $sql.= " OR s.email like '%".$db->escape($search_all)."%'"; - $sql.= " OR s.url like '%".$db->escape($search_all)."%'"; + $sql.= " OR s.email LIKE '%".$db->escape($search_all)."%'"; + $sql.= " OR s.url LIKE '%".$db->escape($search_all)."%'"; $sql.= ")"; } if ($search_nom) @@ -213,8 +213,8 @@ if ($search_nom) $sql.= " AND ("; $sql.= "s.nom LIKE '%".$db->escape($search_nom)."%'"; $sql.= " OR s.code_client LIKE '%".$db->escape($search_nom)."%'"; - $sql.= " OR s.email like '%".$db->escape($search_nom)."%'"; - $sql.= " OR s.url like '%".$db->escape($search_nom)."%'"; + $sql.= " OR s.email LIKE '%".$db->escape($search_nom)."%'"; + $sql.= " OR s.url LIKE '%".$db->escape($search_nom)."%'"; $sql.= ")"; } @@ -417,7 +417,8 @@ else dol_print_error($db); } +llxFooter(); + $db->close(); -llxFooter(); ?>