mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Fix 31370 Pb with external account
This commit is contained in:
parent
40e22cc40e
commit
cf0c04c6ee
|
|
@ -140,13 +140,13 @@ if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
|
||||
$sql .= " AND p.fk_soc = s.rowid";
|
||||
$sql .= " AND p.fk_statut = ".Propal::STATUS_DRAFT;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -239,13 +239,13 @@ if (isModEnabled('supplier_proposal') && $user->hasRight("supplier_proposal", "l
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE p.entity IN (".getEntity($supplierproposalstatic->element).")";
|
||||
$sql .= " AND p.fk_statut = ".SupplierProposal::STATUS_DRAFT;
|
||||
$sql .= " AND p.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -336,13 +336,13 @@ if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
|
||||
$sql .= " AND c.fk_statut = ".Commande::STATUS_DRAFT;
|
||||
$sql .= " AND c.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -436,13 +436,13 @@ if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMO
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE cf.entity IN (".getEntity($supplierorderstatic->element).")";
|
||||
$sql .= " AND cf.fk_statut = ".CommandeFournisseur::STATUS_DRAFT;
|
||||
$sql .= " AND cf.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -534,7 +534,7 @@ if (isModEnabled('intervention')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
|
||||
|
|
@ -543,7 +543,7 @@ if (isModEnabled('intervention')) {
|
|||
if ($socid) {
|
||||
$sql .= " AND f.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
|
||||
|
|
@ -617,12 +617,12 @@ if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= ", s.datec, s.tms";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
|
||||
$sql .= " AND s.client IN (".Societe::CUSTOMER.", ".Societe::PROSPECT.", ".Societe::CUSTOMER_AND_PROSPECT.")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
// Add where from hooks
|
||||
|
|
@ -725,7 +725,7 @@ if (isModEnabled('propal')) {
|
|||
$sql .= " AND c.fk_soc = s.rowid";
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
// Search on sale representative
|
||||
|
|
@ -820,7 +820,7 @@ if (isModEnabled('order')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
|
|
@ -829,7 +829,7 @@ if (isModEnabled('order')) {
|
|||
if ($socid) {
|
||||
$sql .= " AND c.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " ORDER BY c.tms DESC";
|
||||
|
|
@ -908,12 +908,12 @@ if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $use
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= ", s.datec as dc, s.tms as dm";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
|
||||
$sql .= " AND s.fournisseur = ".Societe::SUPPLIER;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
// Add where from hooks
|
||||
|
|
@ -1023,13 +1023,13 @@ if (isModEnabled('contract') && $user->hasRight("contrat", "lire") && 0) { // TO
|
|||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."contrat as c";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."product as p";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.entity IN (".getEntity($staticcontrat->element).")";
|
||||
$sql .= " AND c.fk_soc = s.rowid";
|
||||
$sql .= " AND c.fk_product = p.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -1098,13 +1098,13 @@ if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
|
||||
$sql .= " AND p.fk_soc = s.rowid";
|
||||
$sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -1217,13 +1217,13 @@ if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
|
||||
$sql .= " AND c.fk_soc = s.rowid";
|
||||
$sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_SHIPMENTONPROCESS.")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
|
|||
|
|
@ -2861,7 +2861,7 @@ class Propal extends CommonObject
|
|||
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
// Search on sale representative
|
||||
|
|
@ -3384,7 +3384,7 @@ class Propal extends CommonObject
|
|||
}
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
// Search on sale representative
|
||||
|
|
@ -3561,7 +3561,7 @@ class Propal extends CommonObject
|
|||
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
// Search on sale representative
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class PropaleStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, COUNT(*) as nb";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -147,7 +147,7 @@ class PropaleStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(".$this->field_date.",'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -171,7 +171,7 @@ class PropaleStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, SUM(p.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -196,7 +196,7 @@ class PropaleStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(".$this->field_date.",'%m') as dm, AVG(p.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -219,7 +219,7 @@ class PropaleStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(".$this->field_date.",'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -247,7 +247,7 @@ class PropaleStats extends Stats
|
|||
$sql .= " FROM ".$this->from;
|
||||
$sql .= " INNER JOIN ".$this->from_line." ON p.rowid = tl.fk_propal";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
|
|||
|
|
@ -2715,16 +2715,16 @@ class Commande extends CommonOrder
|
|||
|
||||
$sql = "SELECT s.rowid, s.nom as name, s.client,";
|
||||
$sql .= " c.rowid as cid, c.ref";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", sc.fk_soc, sc.fk_user";
|
||||
}
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.entity IN (".getEntity('commande').")";
|
||||
$sql .= " AND c.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -3551,7 +3551,7 @@ class Commande extends CommonOrder
|
|||
|
||||
$sql = "SELECT c.rowid, c.date_creation as datec, c.date_commande, c.date_livraison as delivery_date, c.fk_statut, c.total_ht";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = " AND";
|
||||
|
|
@ -4059,7 +4059,7 @@ class Commande extends CommonOrder
|
|||
$sql = "SELECT count(co.rowid) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as co";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON co.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = "AND";
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ class CommandeStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_commande,'%m') as dm, COUNT(*) as nb";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -148,7 +148,7 @@ class CommandeStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_commande,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -172,7 +172,7 @@ class CommandeStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_commande,'%m') as dm, SUM(c.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -197,7 +197,7 @@ class CommandeStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_commande,'%m') as dm, AVG(c.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -220,7 +220,7 @@ class CommandeStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_commande,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -246,7 +246,7 @@ class CommandeStats extends Stats
|
|||
$sql .= " FROM ".$this->from;
|
||||
$sql .= " INNER JOIN ".$this->from_line." ON c.rowid = tl.fk_commande";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ if (isModEnabled('order')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
|
|
@ -107,7 +107,7 @@ if (isModEnabled('order')) {
|
|||
if ($socid) {
|
||||
$sql .= " AND c.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ $sql .= ", s.code_client";
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
|
|
@ -173,7 +173,7 @@ $sql .= " AND c.entity IN (".getEntity('commande').")";
|
|||
if ($socid) {
|
||||
$sql .= " AND c.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " ORDER BY c.tms DESC";
|
||||
|
|
@ -250,7 +250,7 @@ if (isModEnabled('order')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
|
|
@ -259,7 +259,7 @@ if (isModEnabled('order')) {
|
|||
if ($socid) {
|
||||
$sql .= " AND c.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " ORDER BY c.rowid DESC";
|
||||
|
|
@ -339,7 +339,7 @@ if (isModEnabled('order')) {
|
|||
$sql .= ", s.canvas";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
|
|
@ -348,7 +348,7 @@ if (isModEnabled('order')) {
|
|||
if ($socid) {
|
||||
$sql .= " AND c.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " ORDER BY c.rowid DESC";
|
||||
|
|
|
|||
|
|
@ -906,9 +906,8 @@ $sql .= ' AND c.entity IN ('.getEntity('commande').')';
|
|||
if ($socid > 0) {
|
||||
$sql .= ' AND s.rowid = '.((int) $socid);
|
||||
}
|
||||
|
||||
// Restriction on sale representative
|
||||
if (!$permissiontoreadallthirdparty) {
|
||||
if (empty($user->socid) && !$permissiontoreadallthirdparty) {
|
||||
$sql .= " AND (EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).")";
|
||||
if (getDolGlobalInt('MAIN_SEE_SUBORDINATES') && $userschilds) {
|
||||
$sql .= " OR EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user IN (".$db->sanitize(implode(',', $userschilds))."))";
|
||||
|
|
@ -1619,7 +1618,7 @@ if (!empty($arrayfields['p.title']['checked'])) {
|
|||
// Thirpdarty
|
||||
if (!empty($arrayfields['s.nom']['checked'])) {
|
||||
print '<td class="liste_titre" align="left">';
|
||||
print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
|
||||
print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"'.(!empty($user->socid) ? " disabled" : "").'>';
|
||||
print '</td>';
|
||||
}
|
||||
// Alias
|
||||
|
|
|
|||
|
|
@ -4753,7 +4753,7 @@ class Facture extends CommonInvoice
|
|||
}
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
// Search on sale representative
|
||||
|
|
@ -4946,7 +4946,7 @@ class Facture extends CommonInvoice
|
|||
|
||||
$sql = "SELECT f.rowid, f.date_lim_reglement as datefin, f.fk_statut as status, f.total_ht";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = " AND";
|
||||
|
|
@ -5194,7 +5194,7 @@ class Facture extends CommonInvoice
|
|||
$sql = "SELECT count(f.rowid) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = "AND";
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class FactureStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -162,7 +162,7 @@ class FactureStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -187,7 +187,7 @@ class FactureStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -213,7 +213,7 @@ class FactureStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -236,7 +236,7 @@ class FactureStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.") as total, AVG(f.".$this->field.") as avg";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -260,7 +260,7 @@ class FactureStats extends Stats
|
|||
|
||||
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
|
||||
$sql .= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
@ -288,7 +288,7 @@ class FactureStats extends Stats
|
|||
$startYear = $endYear - $numberYears;
|
||||
$sql = "SELECT date_format(datef,'%Y') as dm, SUM(f.".$this->field.")";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= $this->join;
|
||||
|
|
|
|||
|
|
@ -304,15 +304,15 @@ $object->fields = dol_sort_array($object->fields, 'position');
|
|||
$arrayfields = dol_sort_array($arrayfields, 'position');
|
||||
'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
|
||||
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
|
||||
// Security check
|
||||
$fieldid = (!empty($ref) ? 'ref' : 'rowid');
|
||||
if (!empty($user->socid)) {
|
||||
$socid = $user->socid;
|
||||
}
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
|
||||
$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
|
|||
$sql .= " AND f.fk_soc = ".((int) $socid);
|
||||
}
|
||||
// Filter on sale representative
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $user->id).")";
|
||||
}
|
||||
// Add where from hooks
|
||||
|
|
@ -304,7 +304,7 @@ if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMO
|
|||
$sql .= " AND ff.fk_soc = ".((int) $socid);
|
||||
}
|
||||
// Filter on sale representative
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = ff.fk_soc AND sc.fk_user = ".((int) $user->id).")";
|
||||
}
|
||||
// Add where from hooks
|
||||
|
|
@ -624,7 +624,7 @@ if (isModEnabled('invoice') && isModEnabled('order') && $user->hasRight("command
|
|||
$sql .= " AND c.fk_statut = ".((int) Commande::STATUS_CLOSED);
|
||||
$sql .= " AND c.facture = 0";
|
||||
// Filter on sale representative
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).")";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2279,7 +2279,7 @@ class Contrat extends CommonObject
|
|||
$this->from = " FROM ".MAIN_DB_PREFIX."contrat as c";
|
||||
$this->from .= ", ".MAIN_DB_PREFIX."contratdet as cd";
|
||||
$this->from .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$this->from .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
|
||||
|
|
@ -2310,7 +2310,7 @@ class Contrat extends CommonObject
|
|||
if ($user->socid) {
|
||||
$sql .= " AND c.fk_soc = ".((int) $user->socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
|
||||
|
|
@ -2376,7 +2376,7 @@ class Contrat extends CommonObject
|
|||
$sql = "SELECT count(c.rowid) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = "AND";
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ $object->fields = dol_sort_array($object->fields, 'position');
|
|||
$arrayfields = dol_sort_array($arrayfields, 'position');
|
||||
'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
|
||||
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
|
||||
|
|
@ -875,7 +875,7 @@ if (!empty($arrayfields['c.ref_supplier']['checked'])) {
|
|||
}
|
||||
if (!empty($arrayfields['s.nom']['checked'])) {
|
||||
print '<td class="liste_titre">';
|
||||
print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
|
||||
print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'"'.($user->socid > 0 ? " disabled" : "").'>';
|
||||
print '</td>';
|
||||
}
|
||||
if (!empty($arrayfields['s.email']['checked'])) {
|
||||
|
|
|
|||
|
|
@ -83,14 +83,14 @@ class box_actions extends ModeleBoxes
|
|||
$sql .= ", s.code_client, s.code_compta, s.client";
|
||||
$sql .= ", s.logo, s.email, s.entity";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
|
||||
}
|
||||
$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 IN (".getEntity('actioncomm').")";
|
||||
$sql .= " AND a.percent >= 0 AND a.percent < 100";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -85,14 +85,14 @@ class box_actions_future extends ModeleBoxes
|
|||
$sql .= ", s.code_client, s.code_compta, s.client";
|
||||
$sql .= ", s.logo, s.email, s.entity";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
|
||||
}
|
||||
$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 IN (".getEntity('actioncomm').")";
|
||||
//$sql .= " AND a.percent >= 0 AND a.percent < 100";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -104,13 +104,13 @@ class box_activity extends ModeleBoxes
|
|||
|
||||
$sql = "SELECT p.fk_statut, SUM(p.total_ttc) as Mnttot, COUNT(*) as nb";
|
||||
$sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= ")";
|
||||
$sql .= " WHERE p.entity IN (".getEntity('propal').")";
|
||||
$sql .= " AND p.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
@ -193,13 +193,13 @@ class box_activity extends ModeleBoxes
|
|||
|
||||
$sql = "SELECT c.fk_statut, sum(c.total_ttc) as Mnttot, count(*) as nb";
|
||||
$sql .= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= ")";
|
||||
$sql .= " WHERE c.entity IN (".getEntity('commande').")";
|
||||
$sql .= " AND c.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
@ -278,12 +278,12 @@ class box_activity extends ModeleBoxes
|
|||
$data = array();
|
||||
$sql = "SELECT f.fk_statut, SUM(f.total_ttc) as Mnttot, COUNT(*) as nb";
|
||||
$sql .= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= ")";
|
||||
$sql .= " WHERE f.entity IN (".getEntity('invoice').')';
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -85,12 +85,12 @@ class box_clients extends ModeleBoxes
|
|||
$sql .= ", s.logo, s.email, s.entity";
|
||||
$sql .= ", s.datec, s.tms, s.status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.client IN (1, 3)";
|
||||
$sql .= " AND s.entity IN (".getEntity('societe').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
// Add where from hooks
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class box_commandes extends ModeleBoxes
|
|||
$sql .= ", c.total_tva";
|
||||
$sql .= ", c.total_ttc";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
|
|
@ -100,7 +100,7 @@ class box_commandes extends ModeleBoxes
|
|||
if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY')) {
|
||||
$sql .= " AND c.fk_statut = 1";
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -98,11 +98,11 @@ class box_contacts extends ModeleBoxes
|
|||
if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE sp.entity IN (".getEntity('contact').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " AND ((sp.fk_user_creat = ".((int) $user->id)." AND sp.priv = 1) OR sp.priv = 0)"; // check if this is a private contact
|
||||
|
|
|
|||
|
|
@ -77,12 +77,12 @@ class box_contracts extends ModeleBoxes
|
|||
$sql .= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.tms as date_modification, c.fin_validite, c.date_cloture,";
|
||||
$sql .= " c.ref_customer, c.ref_supplier";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
$sql .= " AND c.entity = ".$conf->entity;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -84,12 +84,12 @@ class box_customers_outstanding_bill_reached extends ModeleBoxes
|
|||
$sql .= ", s.outstanding_limit";
|
||||
$sql .= ", s.datec, s.tms, s.status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.client IN (1, 3)";
|
||||
$sql .= " AND s.entity IN (".getEntity('societe').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -93,12 +93,12 @@ class box_factures extends ModeleBoxes
|
|||
$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 .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE f.fk_soc = s.rowid";
|
||||
$sql .= " AND f.entity IN (".getEntity('invoice').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -91,12 +91,12 @@ class box_factures_fourn extends ModeleBoxes
|
|||
$sql .= ', f.date_lim_reglement as datelimite, f.tms, f.type';
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE f.fk_soc = s.rowid";
|
||||
$sql .= " AND f.entity = ".$conf->entity;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -93,14 +93,14 @@ class box_factures_fourn_imp extends ModeleBoxes
|
|||
$sql2 = " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql2 .= ",".MAIN_DB_PREFIX."facture_fourn as f";
|
||||
$sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql2 .= " WHERE f.fk_soc = s.rowid";
|
||||
$sql2 .= " AND f.entity IN (".getEntity('supplier_invoice').")";
|
||||
$sql2 .= " AND f.paye = 0";
|
||||
$sql2 .= " AND fk_statut = 1";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class box_factures_imp extends ModeleBoxes
|
|||
if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
|
||||
$sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql2 .= ", ".MAIN_DB_PREFIX."facture as f";
|
||||
|
|
@ -111,7 +111,7 @@ class box_factures_imp extends ModeleBoxes
|
|||
$sql2 .= " AND f.entity IN (".getEntity('invoice').")";
|
||||
$sql2 .= " AND f.paye = 0";
|
||||
$sql2 .= " AND fk_statut = 1";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -80,13 +80,13 @@ class box_ficheinter extends ModeleBoxes
|
|||
$sql .= ", s.code_client, s.code_compta, s.client";
|
||||
$sql .= ", s.logo, s.email, s.entity";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
|
||||
$sql .= " WHERE f.fk_soc = s.rowid ";
|
||||
$sql .= " AND f.entity = ".$conf->entity;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -78,12 +78,12 @@ class box_fournisseurs extends ModeleBoxes
|
|||
$sql .= ", s.logo, s.email, s.entity";
|
||||
$sql .= ", s.datec, s.tms, s.status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.fournisseur = 1";
|
||||
$sql .= " AND s.entity IN (".getEntity('societe').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
// Add where from hooks
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class box_graph_propales_permonth extends ModeleBoxes
|
|||
if ($user->socid) {
|
||||
$socid = $user->socid;
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$prefix .= 'private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,12 +81,12 @@ class box_propales extends ModeleBoxes
|
|||
$sql .= ", s.logo, s.email, s.entity";
|
||||
$sql .= ", p.rowid, p.ref, p.fk_statut as status, p.datep as dp, p.datec, p.fin_validite, p.date_cloture, p.total_ht, p.total_tva, p.total_ttc, p.tms";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE p.fk_soc = s.rowid";
|
||||
$sql .= " AND p.entity IN (".getEntity('propal').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -86,12 +86,12 @@ class box_prospect extends ModeleBoxes
|
|||
$sql .= ", s.fk_stcomm";
|
||||
$sql .= ", s.datec, s.tms, s.status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.client IN (2, 3)";
|
||||
$sql .= " AND s.entity IN (".getEntity('societe').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
// Add where from hooks
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class box_services_contracts extends ModeleBoxes
|
|||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= ")";
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class box_services_expired extends ModeleBoxes
|
|||
$sql .= " s.nom as name, s.rowid as socid, s.email, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
|
||||
$sql .= " MIN(cd.date_fin_validite) as date_line, COUNT(cd.rowid) as nb_services";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe s, ".MAIN_DB_PREFIX."contratdet as cd";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE cd.statut = 4 AND cd.date_fin_validite <= '".$this->db->idate($now)."'";
|
||||
|
|
@ -83,7 +83,7 @@ class box_services_expired extends ModeleBoxes
|
|||
if ($user->socid) {
|
||||
$sql .= ' AND c.fk_soc = '.((int) $user->socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " GROUP BY c.rowid, c.ref, c.statut, c.date_contrat, c.ref_customer, c.ref_supplier, s.nom, s.rowid";
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class box_shipments extends ModeleBoxes
|
|||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
|
||||
}
|
||||
$sql .= " WHERE e.entity IN (".getEntity('expedition').")";
|
||||
|
|
@ -102,7 +102,7 @@ class box_shipments extends ModeleBoxes
|
|||
if ($user->socid > 0) {
|
||||
$sql.= " AND s.rowid = ".((int) $user->socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND sc.fk_user = ".((int) $user->id);
|
||||
} else {
|
||||
$sql .= " ORDER BY e.tms DESC, e.date_delivery DESC, e.ref DESC";
|
||||
|
|
|
|||
|
|
@ -84,12 +84,12 @@ class box_supplier_orders extends ModeleBoxes
|
|||
$sql .= ", c.fk_statut as status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
$sql .= " AND c.entity IN (".getEntity('supplier_order').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -81,14 +81,14 @@ class box_supplier_orders_awaiting_reception extends ModeleBoxes
|
|||
$sql .= ", c.fk_statut as status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
$sql .= " AND c.entity IN (".getEntity('supplier_order').")";
|
||||
$sql .= " AND c.date_livraison IS NOT NULL";
|
||||
$sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($user->socid) {
|
||||
|
|
|
|||
|
|
@ -492,6 +492,7 @@ function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
|
|||
$result = '';
|
||||
|
||||
if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
|
||||
|
||||
$tmpinvoice = new Facture($db);
|
||||
|
|
@ -502,16 +503,16 @@ function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
|
|||
$sql .= ", s.rowid as socid, s.email";
|
||||
$sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
|
||||
$sql .= ", cc.rowid as country_id, cc.code as country_code";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", sc.fk_soc, sc.fk_user ";
|
||||
}
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture 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->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
|
||||
$sql .= " AND f.entity IN (".getEntity('invoice').")";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
|
||||
|
|
@ -526,7 +527,7 @@ function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
|
|||
$sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,";
|
||||
$sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
|
||||
$sql .= " cc.rowid, cc.code";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", sc.fk_soc, sc.fk_user";
|
||||
}
|
||||
|
||||
|
|
@ -642,6 +643,7 @@ function getDraftSupplierTable($maxCount = 500, $socid = 0)
|
|||
$result = '';
|
||||
|
||||
if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
|
||||
|
||||
$facturesupplierstatic = new FactureFournisseur($db);
|
||||
|
|
@ -653,12 +655,12 @@ function getDraftSupplierTable($maxCount = 500, $socid = 0)
|
|||
$sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
|
||||
$sql .= ", cc.rowid as country_id, cc.code as country_code";
|
||||
$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->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
|
||||
$sql .= " AND f.entity IN (".getEntity('invoice').')';
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -773,12 +775,12 @@ function getDraftSupplierTable($maxCount = 500, $socid = 0)
|
|||
function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
|
||||
{
|
||||
global $conf, $db, $langs, $user;
|
||||
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datec,";
|
||||
$sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE f.fk_soc = s.rowid";
|
||||
|
|
@ -786,7 +788,7 @@ function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
|
|||
if ($socid) {
|
||||
$sql .= " AND f.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " ORDER BY f.tms DESC";
|
||||
|
|
@ -881,12 +883,12 @@ function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
|
|||
function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
|
||||
{
|
||||
global $conf, $db, $langs, $user;
|
||||
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.datec,";
|
||||
$sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE f.fk_soc = s.rowid";
|
||||
|
|
@ -894,7 +896,7 @@ function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
|
|||
if ($socid) {
|
||||
$sql .= " AND f.fk_soc = ".((int) $socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " ORDER BY f.tms DESC";
|
||||
|
|
@ -999,6 +1001,7 @@ function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
|
|||
$result = '';
|
||||
|
||||
if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$tmpinvoice = new Facture($db);
|
||||
|
||||
$sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms";
|
||||
|
|
@ -1011,12 +1014,12 @@ function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
|
|||
$sql .= ", sum(pf.amount) as am";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays,".MAIN_DB_PREFIX."facture as f";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
|
||||
$sql .= " AND f.entity IN (".getEntity('invoice').')';
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
@ -1187,6 +1190,7 @@ function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
|
|||
$result = '';
|
||||
|
||||
if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$facstatic = new FactureFournisseur($db);
|
||||
|
||||
$sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye";
|
||||
|
|
@ -1198,14 +1202,14 @@ function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
|
|||
$sql .= ", sum(pf.amount) as am";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE s.rowid = ff.fk_soc";
|
||||
$sql .= " AND ff.entity = ".$conf->entity;
|
||||
$sql .= " AND ff.paye = 0";
|
||||
$sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
if ($socid) {
|
||||
|
|
|
|||
|
|
@ -239,11 +239,11 @@ function getCustomerOrderPieChart($socid = 0)
|
|||
/*
|
||||
* Statistics
|
||||
*/
|
||||
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$sql = "SELECT count(c.rowid) as nb, c.fk_statut as status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."commande as c";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc = s.rowid";
|
||||
|
|
@ -251,7 +251,7 @@ function getCustomerOrderPieChart($socid = 0)
|
|||
if ($user->socid) {
|
||||
$sql .= ' AND c.fk_soc = '.((int) $user->socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " GROUP BY c.fk_statut";
|
||||
|
|
|
|||
|
|
@ -217,15 +217,15 @@ function getCustomerProposalPieChart($socid = 0)
|
|||
if (!isModEnabled('propal') || !$user->hasRight('propal', 'lire')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
$listofstatus = array(Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED);
|
||||
|
||||
$propalstatic = new Propal($db);
|
||||
|
||||
if ($user->socid > 0) $socid = $user->socid;
|
||||
$sql = "SELECT count(p.rowid) as nb, p.fk_statut as status";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."propal as p";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if ($user->socid == 0 && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
|
||||
|
|
@ -233,7 +233,7 @@ function getCustomerProposalPieChart($socid = 0)
|
|||
if ($user->socid) {
|
||||
$sql .= ' AND p.fk_soc = '.((int) $user->socid);
|
||||
}
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if ($user->socid == 0 && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " AND p.fk_statut IN (".$db->sanitize(implode(" ,", $listofstatus)).")";
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class FichinterStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||
|
|
@ -122,7 +122,7 @@ class FichinterStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, 0";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE ".$this->where;
|
||||
|
|
@ -145,7 +145,7 @@ class FichinterStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_valid,'%m') as dm, 0";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||
|
|
@ -169,7 +169,7 @@ class FichinterStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_valid,'%m') as dm, 0";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
|
||||
|
|
@ -191,7 +191,7 @@ class FichinterStats extends Stats
|
|||
|
||||
$sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, 0 as total, 0 as avg";
|
||||
$sql .= " FROM ".$this->from;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= " WHERE ".$this->where;
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ $parameters = array();
|
|||
$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
$sql .= $hookmanager->resPrint;
|
||||
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
}
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
|
|
|
|||
|
|
@ -3207,7 +3207,7 @@ class CommandeFournisseur extends CommonOrder
|
|||
$sql = "SELECT count(co.rowid) as nb";
|
||||
$sql .= " FROM ".$this->db->prefix()."commande_fournisseur as co";
|
||||
$sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON co.fk_soc = s.rowid";
|
||||
if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
|
||||
if (empty($user->socid) && !$user->hasRight("societe", "client", "voir") && !$user->socid) {
|
||||
$sql .= " LEFT JOIN ".$this->db->prefix()."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = "AND";
|
||||
|
|
@ -3243,7 +3243,7 @@ class CommandeFournisseur extends CommonOrder
|
|||
|
||||
$sql = "SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
|
||||
$sql .= " FROM ".$this->db->prefix()."commande_fournisseur as c";
|
||||
if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
|
||||
if (empty($user->socid) && !$user->hasRight("societe", "client", "voir") && !$user->socid) {
|
||||
$sql .= " JOIN ".$this->db->prefix()."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= " WHERE c.entity = ".$conf->entity;
|
||||
|
|
|
|||
|
|
@ -2703,7 +2703,7 @@ class FactureFournisseur extends CommonInvoice
|
|||
|
||||
$sql = 'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut as status, ff.total_ht, ff.total_ttc';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as ff';
|
||||
if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
|
||||
if (empty($user->socid) && !$user->hasRight("societe", "client", "voir")) {
|
||||
$sql .= " JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ff.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
||||
}
|
||||
$sql .= ' WHERE ff.paye = 0';
|
||||
|
|
@ -3123,7 +3123,7 @@ class FactureFournisseur extends CommonInvoice
|
|||
$sql = "SELECT count(f.rowid) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
|
||||
if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
|
||||
if (empty($user->socid) && !$user->hasRight("societe", "client", "voir")) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = "AND";
|
||||
|
|
|
|||
|
|
@ -1943,7 +1943,7 @@ class SupplierProposal extends CommonObject
|
|||
$ga = array();
|
||||
|
||||
$search_sale = 0;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
|
||||
|
|
@ -2212,7 +2212,7 @@ class SupplierProposal extends CommonObject
|
|||
public function load_board($user, $mode)
|
||||
{
|
||||
// phpcs:enable
|
||||
global $conf, $user, $langs;
|
||||
global $conf, $langs;
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
|
|
@ -2220,7 +2220,7 @@ class SupplierProposal extends CommonObject
|
|||
|
||||
$sql = "SELECT p.rowid, p.ref, p.datec as datec, p.date_cloture as datefin";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = " AND";
|
||||
|
|
@ -2377,7 +2377,7 @@ class SupplierProposal extends CommonObject
|
|||
$sql = "SELECT count(p.rowid) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = "AND";
|
||||
|
|
|
|||
|
|
@ -891,7 +891,7 @@ class Ticket extends CommonObject
|
|||
$socid = $user->socid ? $user->socid : 0;
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
$search_sale = 0;
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$search_sale = $user->id;
|
||||
}
|
||||
// Search on sale representative
|
||||
|
|
@ -3156,7 +3156,7 @@ class Ticket extends CommonObject
|
|||
|
||||
$sql = "SELECT p.rowid, p.ref, p.datec as datec";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."ticket as p";
|
||||
if (isModEnabled('societe') && !$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
|
||||
if (empty($user->socid) && isModEnabled('societe') && !$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = " AND";
|
||||
|
|
@ -3220,7 +3220,7 @@ class Ticket extends CommonObject
|
|||
$sql = "SELECT count(p.rowid) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."ticket as p";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
|
||||
if (!$user->hasRight('societe', 'client', 'voir')) {
|
||||
if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".((int) $user->id);
|
||||
$clause = "AND";
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user