Skip to content

Commit

Permalink
Fix: uniformize getEntity('intervention')
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Mar 22, 2018
1 parent 8781526 commit b5f3730
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion htdocs/fichinter/class/api_interventions.class.php
Expand Up @@ -124,7 +124,7 @@ function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page =

if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale

$sql.= ' WHERE t.entity IN ('.getEntity('fichinter').')';
$sql.= ' WHERE t.entity IN ('.getEntity('intervention').')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
Expand Down
23 changes: 10 additions & 13 deletions htdocs/fichinter/class/fichinter.class.php
Expand Up @@ -128,7 +128,7 @@ function load_state_board()
$sql.= " WHERE sc.fk_user = " .$user->id;
$clause = "AND";
}
$sql.= " ".$clause." fi.entity IN (".getEntity($this->element).")";
$sql.= " ".$clause." fi.entity IN (".getEntity('intervention').")";

$resql=$this->db->query($sql);
if ($resql)
Expand Down Expand Up @@ -348,7 +348,10 @@ function fetch($rowid,$ref='')
$sql.= " f.tms as datem,";
$sql.= " f.duree, f.fk_projet, f.note_public, f.note_private, f.model_pdf, f.extraparams, fk_contrat";
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f";
if ($ref) $sql.= " WHERE f.ref='".$this->db->escape($ref)."'";
if ($ref) {
$sql.= " WHERE f.entity IN (".getEntity('intervention').")";
$sql.= " AND f.ref='".$this->db->escape($ref)."'";
}
else $sql.= " WHERE f.rowid=".$rowid;

dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
Expand Down Expand Up @@ -783,7 +786,6 @@ function info($id)
$sql.= " f.fk_user_valid";
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f";
$sql.= " WHERE f.rowid = ".$id;
$sql.= " AND f.entity = ".$conf->entity;

$resql = $this->db->query($sql);
if ($resql)
Expand Down Expand Up @@ -887,7 +889,6 @@ function delete($user, $notrigger=0)
// Delete object
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;

dol_syslog("Fichinter::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
Expand Down Expand Up @@ -951,7 +952,6 @@ function set_date_delivery($user, $date_delivery)
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
$sql.= " SET datei = '".$this->db->idate($date_delivery)."'";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND fk_statut = 0";

if ($this->db->query($sql))
Expand Down Expand Up @@ -985,7 +985,6 @@ function set_description($user, $description)
$sql.= " SET description = '".$this->db->escape($description)."',";
$sql.= " fk_user_modif = ".$user->id;
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;

if ($this->db->query($sql))
{
Expand Down Expand Up @@ -1018,7 +1017,6 @@ function set_contrat($user, $contractid)
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
$sql.= " SET fk_contrat = '".$contractid."'";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;

if ($this->db->query($sql))
{
Expand Down Expand Up @@ -1401,7 +1399,7 @@ function insert($user, $notrigger=0)

if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$this->id=$this->rowid;
$this->id=$this->id;
$result=$this->insertExtraFields();
if ($result < 0)
{
Expand Down Expand Up @@ -1463,7 +1461,7 @@ function update($user,$notrigger=0)
$sql.= ",date='".$this->db->idate($this->datei)."'";
$sql.= ",duree=".$this->duration;
$sql.= ",rang='".$this->db->escape($this->rang)."'";
$sql.= " WHERE rowid = ".$this->rowid;
$sql.= " WHERE rowid = ".$this->id;

dol_syslog("FichinterLigne::update", LOG_DEBUG);
$resql=$this->db->query($sql);
Expand All @@ -1472,7 +1470,7 @@ function update($user,$notrigger=0)

if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$this->id=$this->rowid;
$this->id=$this->id;
$result=$this->insertExtraFields();
if ($result < 0)
{
Expand Down Expand Up @@ -1541,7 +1539,6 @@ function update_total()
$sql.= " , dateo = ".(! empty($obj->dateo)?"'".$this->db->idate($obj->dateo)."'":"null");
$sql.= " , datee = ".(! empty($obj->datee)?"'".$this->db->idate($obj->datee)."'":"null");
$sql.= " WHERE rowid = ".$this->fk_fichinter;
$sql.= " AND entity = ".$conf->entity;

dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
$resql=$this->db->query($sql);
Expand Down Expand Up @@ -1580,10 +1577,10 @@ function deleteline($user,$notrigger=0)

if ($this->statut == 0)
{
dol_syslog(get_class($this)."::deleteline lineid=".$this->rowid);
dol_syslog(get_class($this)."::deleteline lineid=".$this->id);
$this->db->begin();

$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE rowid = ".$this->rowid;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);

if ($resql)
Expand Down
16 changes: 8 additions & 8 deletions htdocs/fichinter/index.php
Expand Up @@ -81,8 +81,8 @@
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."fichinter as f";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.entity IN (".getEntity('societe').")";
$sql.= " WHERE f.entity IN (".getEntity('intervention').")";
$sql.= " AND f.fk_soc = s.rowid";
if ($user->societe_id) $sql.=' AND f.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 f.fk_statut";
Expand Down Expand Up @@ -180,8 +180,8 @@
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.entity IN (".getEntity('intervention').")";
$sql.= " WHERE f.entity IN (".getEntity('intervention').")";
$sql.= " AND f.fk_soc = s.rowid";
$sql.= " AND f.fk_statut = 0";
if ($socid) $sql.= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
Expand Down Expand Up @@ -228,8 +228,8 @@
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f,";
$sql.= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.entity IN (".getEntity('commande').")";
$sql.= " WHERE f.entity IN (".getEntity('intervention').")";
$sql.= " AND f.fk_soc = s.rowid";
//$sql.= " AND c.fk_statut > 2";
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
Expand Down Expand Up @@ -299,8 +299,8 @@
$sql.=" FROM ".MAIN_DB_PREFIX."fichinter as f";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE f.fk_soc = s.rowid";
$sql.= " AND f.entity IN (".getEntity('intervention').")";
$sql.= " WHERE f.entity IN (".getEntity('intervention').")";
$sql.= " AND f.fk_soc = s.rowid";
$sql.= " AND f.fk_statut = 1";
if ($socid) $sql.= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
Expand Down
4 changes: 2 additions & 2 deletions htdocs/fichinter/list.php
Expand Up @@ -194,8 +194,8 @@
if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON fd.fk_fichinter = f.rowid";
if (! $user->rights->societe->client->voir && empty($socid)) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE f.fk_soc = s.rowid ";
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " WHERE f.entity IN (".getEntity('intervention').")";
$sql.= " AND f.fk_soc = s.rowid";
if ($search_ref) {
$sql .= natural_search('f.ref', $search_ref);
}
Expand Down

0 comments on commit b5f3730

Please sign in to comment.