';
@@ -136,11 +139,11 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$sqls = array();
// Customer invoices
- $sql = "SELECT 'invoice' as family, f.rowid as objid, f.facnumber as ref, f.total_ttc, f.type, f.date_lim_reglement as dlr,";
+ $sql = "SELECT 'invoice' as family, f.rowid as objid, f.facnumber as ref, f.total_ttc, f.type, f.date_lim_reglement as dlr, f.entity,";
$sql.= " s.rowid as socid, s.nom as name, s.fournisseur";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
- $sql.= " WHERE f.entity = ".$conf->entity;
+ $sql.= " WHERE f.entity IN (".getEntity('facture').")";
$sql.= " AND f.paye = 0 AND f.fk_statut = 1"; // Not paid
$sql.= " AND (f.fk_account IN (0, ".$object->id.") OR f.fk_account IS NULL)"; // Id bank account of invoice
$sql.= " ORDER BY dlr ASC";
@@ -284,6 +287,13 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
else print $langs->trans("NotDefined");
print "";
print "
';
}
}
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 7c8a02ba693..4dc0adea029 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -3348,7 +3348,7 @@ class Facture extends CommonInvoice
$mybool=false;
- $file = $conf->global->FACTURE_ADDON.".php";
+
$constant = 'FACTURE_ADDON_'.$this->entity;
@@ -3357,7 +3357,7 @@ class Facture extends CommonInvoice
} else {
$classname = $conf->global->FACTURE_ADDON;
}
-
+ $file = $classname.".php";
// Include file with class
@@ -3391,7 +3391,7 @@ class Facture extends CommonInvoice
}
}
}
-
+
if (! $mybool)
{
dol_print_error('',"Failed to include file ".$file);
@@ -3493,7 +3493,7 @@ class Facture extends CommonInvoice
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql.= " WHERE f.entity = ".$conf->entity;
+ $sql.= " WHERE f.entity IN (".getEntity('facture').")";
$sql.= " AND f.fk_soc = s.rowid";
if (! $user->rights->societe->client->voir && ! $socid) //restriction
{
@@ -3565,7 +3565,7 @@ class Facture extends CommonInvoice
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON f.rowid = ff.fk_facture_source";
$sql.= " WHERE (f.fk_statut = ".self::STATUS_VALIDATED." OR (f.fk_statut = ".self::STATUS_ABANDONED." AND f.close_code = '".self::CLOSECODE_ABANDONED."'))";
- $sql.= " AND f.entity = ".$conf->entity;
+ $sql.= " AND f.entity IN (".getEntity('facture').")";
$sql.= " AND f.paye = 0"; // Pas classee payee completement
$sql.= " AND pf.fk_paiement IS NULL"; // Aucun paiement deja fait
$sql.= " AND ff.fk_statut IS NULL"; // Renvoi vrai si pas facture de remplacement
@@ -3614,7 +3614,7 @@ class Facture extends CommonInvoice
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON (f.rowid = ff.fk_facture_source AND ff.type=".self::TYPE_REPLACEMENT.")";
- $sql.= " WHERE f.entity = ".$conf->entity;
+ $sql.= " WHERE f.entity IN (".getEntity('facture').")";
$sql.= " AND f.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
// $sql.= " WHERE f.fk_statut >= 1";
// $sql.= " AND (f.paye = 1"; // Classee payee completement
@@ -3830,7 +3830,7 @@ class Facture extends CommonInvoice
$clause = " AND";
}
$sql.= $clause." f.paye=0";
- $sql.= " AND f.entity = ".$conf->entity;
+ $sql.= " AND f.entity IN (".getEntity('facture').")";
$sql.= " AND f.fk_statut = ".self::STATUS_VALIDATED;
if ($user->societe_id) $sql.= " AND f.fk_soc = ".$user->societe_id;
@@ -4078,7 +4078,7 @@ class Facture extends CommonInvoice
$sql.= " WHERE sc.fk_user = " .$user->id;
$clause = "AND";
}
- $sql.= " ".$clause." f.entity = ".$conf->entity;
+ $sql.= " ".$clause." f.entity IN (".getEntity('facture').")";
$resql=$this->db->query($sql);
if ($resql)
diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php
index 7a9a9621a78..4aa50167842 100644
--- a/htdocs/compta/facture/class/facturestats.class.php
+++ b/htdocs/compta/facture/class/facturestats.class.php
@@ -80,7 +80,7 @@ class FactureStats extends Stats
}
$this->where = " f.fk_statut > 0";
- $this->where.= " AND f.entity = ".$conf->entity;
+ $this->where.= " AND f.entity IN (".getEntity('facture').")";
if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($mode == 'customer') $this->where.=" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
if ($this->socid)
diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php
index ac6479afc0b..df2688298fd 100644
--- a/htdocs/compta/index.php
+++ b/htdocs/compta/index.php
@@ -146,7 +146,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".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 = f.fk_soc AND f.fk_statut = 0";
- $sql.= " AND f.entity = ".$conf->entity;
+ $sql.= " AND f.entity IN (".getEntity('facture').")";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid)
@@ -236,7 +236,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture-
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0";
- $sql.= " AND f.entity = ".$conf->entity;
+ $sql.= " AND f.entity IN (".getEntity('facture').')';
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid;
// Add where from hooks
@@ -331,7 +331,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.rowid = f.fk_soc";
- $sql.= " AND f.entity = ".$conf->entity;
+ $sql.= " AND f.entity IN (".getEntity('facture').")";
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid;
// Add where from hooks
@@ -823,7 +823,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
- $sql.= " AND f.entity = ".$conf->entity;
+ $sql.= " AND f.entity IN (".getEntity('facture').')';
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND f.fk_soc = ".$socid;
// Add where from hooks
diff --git a/htdocs/compta/journal/purchasesjournal.php b/htdocs/compta/journal/purchasesjournal.php
index 8974c1b78e0..5a73f3a4b41 100644
--- a/htdocs/compta/journal/purchasesjournal.php
+++ b/htdocs/compta/journal/purchasesjournal.php
@@ -110,7 +110,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva as ct ON fd.tva_tx = ct.taux AND fd.i
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
$sql.= " JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
$sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc" ;
-$sql.= " WHERE f.fk_statut > 0 AND f.entity = ".$conf->entity;
+$sql.= " WHERE f.fk_statut > 0 AND f.entity IN (".getEntity('facture').")";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)";
else $sql.= " AND f.type IN (0,1,2,3)";
if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
diff --git a/htdocs/compta/journal/sellsjournal.php b/htdocs/compta/journal/sellsjournal.php
index f88f5643c40..bb0145ff227 100644
--- a/htdocs/compta/journal/sellsjournal.php
+++ b/htdocs/compta/journal/sellsjournal.php
@@ -110,7 +110,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
$sql.= " JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
$sql.= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_tva ct ON fd.tva_tx = ct.taux AND fd.info_bits = ct.recuperableonly AND ct.fk_pays = '".$idpays."'";
-$sql.= " WHERE f.entity = ".$conf->entity;
+$sql.= " WHERE f.entity IN (".getEntity('facture').")";
$sql.= " AND f.fk_statut > 0";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql.= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php
index 1898a270222..63631ca660a 100644
--- a/htdocs/compta/paiement/card.php
+++ b/htdocs/compta/paiement/card.php
@@ -320,11 +320,11 @@ dol_fiche_end();
* List of invoices
*/
-$sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid';
+$sql = 'SELECT f.rowid as facid, f.facnumber,f.entity, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid';
$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 f.entity = '.$conf->entity;
+$sql.= ' AND f.entity IN ('.getEntity('facture').')';
$sql.= ' AND pf.fk_paiement = '.$object->id;
$resql=$db->query($sql);
if ($resql)
@@ -344,10 +344,12 @@ if ($resql)
print '