Fix: Miscellaneous fixes for multicompany

This commit is contained in:
Laurent Destailleur 2014-12-06 14:41:56 +01:00
parent 0d9aa452b8
commit 0459477097
8 changed files with 19 additions and 14 deletions

View File

@ -180,7 +180,7 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as ut ON a.fk_user_action = ut.rowid";
if ($usergroup > 0) $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ugu"; if ($usergroup > 0) $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ugu";
$sql.= " WHERE c.id = a.fk_action"; $sql.= " WHERE c.id = a.fk_action";
$sql.= ' AND a.fk_user_author = u.rowid'; $sql.= ' AND a.fk_user_author = u.rowid';
$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; // To limit to entity $sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')';
if ($actioncode) $sql.=" AND c.code='".$db->escape($actioncode)."'"; if ($actioncode) $sql.=" AND c.code='".$db->escape($actioncode)."'";
if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid); if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";

View File

@ -610,7 +610,7 @@ else
$sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity"; $sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
$sql.= " WHERE u.entity IN (".getEntity('user').")"; $sql.= " WHERE u.entity IN (".getEntity('user',1).")";
if ($usergroup > 0) $sql.= " AND ug.fk_usergroup = ".$usergroup; if ($usergroup > 0) $sql.= " AND ug.fk_usergroup = ".$usergroup;
if (GETPOST("usertodo","int",3) > 0) $sql.=" AND u.rowid = ".GETPOST("usertodo","int",3); if (GETPOST("usertodo","int",3) > 0) $sql.=" AND u.rowid = ".GETPOST("usertodo","int",3);
//print $sql; //print $sql;

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Eric Seigne <erics@rycks.com> * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -55,6 +55,7 @@ $result = restrictedArea($user, 'agenda', $socid, '', 'myactions');
/* /*
* Actions * Actions
*/ */
if ($action == 'builddoc') if ($action == 'builddoc')
{ {
$cat = new CommActionRapport($db, $month, $year); $cat = new CommActionRapport($db, $month, $year);
@ -79,7 +80,7 @@ $sql.= " date_format(a.datep, '%Y') as year";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a,"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a,";
$sql.= " ".MAIN_DB_PREFIX."user as u"; $sql.= " ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE a.fk_user_author = u.rowid"; $sql.= " WHERE a.fk_user_author = u.rowid";
$sql.= " AND a.entity = ".$conf->entity; $sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')';
//$sql.= " AND percent = 100"; //$sql.= " AND percent = 100";
$sql.= " GROUP BY year, month, df"; $sql.= " GROUP BY year, month, df";
$sql.= " ORDER BY year DESC, month DESC, df DESC"; $sql.= " ORDER BY year DESC, month DESC, df DESC";

View File

@ -1140,6 +1140,8 @@ ALTER TABLE llx_facture_rec ADD COLUMN revenuestamp double(24,8) DEFAULT 0;
ALTER TABLE llx_facturedet_rec MODIFY COLUMN tva_tx double(6,3); ALTER TABLE llx_facturedet_rec MODIFY COLUMN tva_tx double(6,3);
ALTER TABLE llx_facturedet_rec ADD COLUMN fk_contract_line integer NULL; ALTER TABLE llx_facturedet_rec ADD COLUMN fk_contract_line integer NULL;
ALTER TABLE llx_resource MODIFY COLUMN entity integer DEFAULT 1 NOT NULL;
-- This request make mysql drop (mysql bug, so we add it at end): -- This request make mysql drop (mysql bug, so we add it at end):
--ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type(rowid); --ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type(rowid);

View File

@ -17,7 +17,7 @@
CREATE TABLE llx_resource CREATE TABLE llx_resource
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer, entity integer DEFAULT 1 NOT NULL,
ref varchar(255), ref varchar(255),
description text, description text,
fk_code_type_resource varchar(32), fk_code_type_resource varchar(32),

View File

@ -123,7 +123,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$result = $db->query($sql); $result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result); $nbtotalofrecords = $db->num_rows($result);
} }
$sql.= " WHERE p.entity = ".getEntity('survey'); $sql.= " WHERE p.entity = ".getEntity('survey',1);
if ($status == 'expired') $sql.=" AND date_fin < '".$db->idate($now)."'"; if ($status == 'expired') $sql.=" AND date_fin < '".$db->idate($now)."'";
if ($status == 'opened') $sql.=" AND date_fin >= '".$db->idate($now)."'"; if ($status == 'opened') $sql.=" AND date_fin >= '".$db->idate($now)."'";
if ($surveytitle) $sql.=" AND titre LIKE '%".$db->escape($surveytitle)."%'"; if ($surveytitle) $sql.=" AND titre LIKE '%".$db->escape($surveytitle)."%'";

View File

@ -298,7 +298,7 @@ class Project extends CommonObject
else if (! empty($ref)) else if (! empty($ref))
{ {
$sql.= " WHERE ref='".$this->db->escape($ref)."'"; $sql.= " WHERE ref='".$this->db->escape($ref)."'";
$sql.= " AND entity IN (".getEntity('project').")"; $sql.= " AND entity IN (".getEntity('project',1).")";
} }
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@ -910,7 +910,7 @@ class Project extends CommonObject
$sql.= ", " . MAIN_DB_PREFIX . "element_contact as ec"; $sql.= ", " . MAIN_DB_PREFIX . "element_contact as ec";
$sql.= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; $sql.= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc";
} }
$sql.= " WHERE p.entity IN (".getEntity('project').")"; $sql.= " WHERE p.entity IN (".getEntity('project',1).")";
// Internal users must see project he is contact to even if project linked to a third party he can't see. // Internal users must see project he is contact to even if project linked to a third party he can't see.
//if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
if ($socid > 0) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; if ($socid > 0) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")";

View File

@ -388,7 +388,7 @@ class Resource extends CommonObject
$sql.= " ty.label as type_label"; $sql.= " ty.label as type_label";
$sql.= " FROM ".MAIN_DB_PREFIX."resource as t"; $sql.= " FROM ".MAIN_DB_PREFIX."resource as t";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource";
//$sql.= " WHERE t.entity IN (".getEntity('resource').")"; $sql.= " WHERE t.entity IN (".getEntity('resource',1).")";
//Manage filter //Manage filter
if (!empty($filter)){ if (!empty($filter)){
@ -402,7 +402,7 @@ class Resource extends CommonObject
} }
} }
$sql.= " GROUP BY t.rowid"; $sql.= " GROUP BY t.rowid";
$sql.= " ORDER BY $sortfield $sortorder "; $sql.= $this->db->order($sortfield,$sortorder);
if ($limit) $sql.= $this->db->plimit($limit+1,$offset); if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
@ -462,7 +462,7 @@ class Resource extends CommonObject
$sql.= " t.fk_user_create,"; $sql.= " t.fk_user_create,";
$sql.= " t.tms"; $sql.= " t.tms";
$sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t '; $sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t ';
//$sql.= " WHERE t.entity IN (".getEntity('resource').")"; $sql.= " WHERE t.entity IN (".getEntity('resource',1).")";
//Manage filter //Manage filter
if (!empty($filter)){ if (!empty($filter)){
@ -476,7 +476,8 @@ class Resource extends CommonObject
} }
} }
$sql.= " GROUP BY t.rowid"; $sql.= " GROUP BY t.rowid";
$sql.= " ORDER BY $sortfield $sortorder " . $this->db->plimit($limit+1,$offset); $sql.= $this->db->order($sortfield,$sortorder);
if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -547,7 +548,7 @@ class Resource extends CommonObject
$sql.= " t.fk_user_create,"; $sql.= " t.fk_user_create,";
$sql.= " t.tms"; $sql.= " t.tms";
$sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t '; $sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t ';
//$sql.= " WHERE t.entity IN (".getEntity('resource').")"; $sql.= " WHERE t.entity IN (".getEntity('resource',1).")";
//Manage filter //Manage filter
if (!empty($filter)){ if (!empty($filter)){
@ -561,7 +562,8 @@ class Resource extends CommonObject
} }
} }
$sql.= " GROUP BY t.resource_id"; $sql.= " GROUP BY t.resource_id";
$sql.= " ORDER BY " . $sortfield . " " . $sortorder . " " . $this->db->plimit($limit+1,$offset); $sql.= $this->db->order($sortfield,$sortorder);
if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);