NEW : unexistant function load_state_board() on several objects

This commit is contained in:
gauthier 2017-09-26 12:32:58 +02:00
parent 79049f55b7
commit 7f938bc517
5 changed files with 356 additions and 169 deletions

View File

@ -962,6 +962,48 @@ class ActionComm extends CommonObject
} }
} }
/**
* Charge indicateurs this->nb de tableau de bord
*
* @return int <0 if ko, >0 if ok
*/
function load_state_board()
{
global $user;
$this->nb=array();
$sql = "SELECT count(a.id) as nb";
$sql.= " FROM (".MAIN_DB_PREFIX."actioncomm as a";
$sql.= ")";
if (! $user->rights->societe->client->voir && ! $user->societe_id) $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.entity IN (".getEntity('agenda').")";
if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id;
if (! $user->rights->agenda->allactions->read) $sql.= " AND (a.fk_user_author = ".$user->id . " OR a.fk_user_action = ".$user->id . " OR a.fk_user_done = ".$user->id . ")";
$resql=$this->db->query($sql);
if ($resql)
{
$agenda_static = new ActionComm($this->db);
while ($obj=$this->db->fetch_object($resql))
{
$this->nb["actionscomm"]=$obj->nb;
}
$this->db->free($resql);
return 1;
}
else
{
dol_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
/** /**
* Charge les informations d'ordre info dans l'objet facture * Charge les informations d'ordre info dans l'objet facture

View File

@ -1207,6 +1207,44 @@ class Account extends CommonObject
} }
} }
/**
* Charge indicateurs this->nb de tableau de bord
*
* @return int <0 if ko, >0 if ok
*/
function load_state_board($filteraccountid = 0)
{
global $user;
if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
$sql = "SELECT count(b.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b,";
$sql.= " ".MAIN_DB_PREFIX."bank_account as ba";
$sql.= " WHERE b.fk_account = ba.rowid";
$sql.= " AND ba.entity IN (".getEntity('bank_account').")";
$sql.= " AND (ba.rappro = 1 AND ba.courant != 2)"; // Compte rapprochable
$sql.= " AND clos = 0";
if ($filteraccountid) $sql.=" AND ba.rowid = ".$filteraccountid;
$resql=$this->db->query($sql);
if ($resql)
{
while ($obj=$this->db->fetch_object($resql))
{
$this->nb["banklines"]=$obj->nb;
}
$this->db->free($resql);
return 1;
}
else
{
dol_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
/** /**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate) * Load indicators for dashboard (this->nbtodo and this->nbtodolate)

View File

@ -533,6 +533,45 @@ class RemiseCheque extends CommonObject
} }
/**
* Charge indicateurs this->nb de tableau de bord
*
* @return int <0 if ko, >0 if ok
*/
function load_state_board()
{
global $user;
if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
$sql = "SELECT count(b.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql.= " WHERE b.fk_account = ba.rowid";
$sql.= " AND ba.entity IN (".getEntity('bank_account').")";
$sql.= " AND b.fk_type = 'CHQ'";
$sql.= " AND b.amount > 0";
$resql=$this->db->query($sql);
if ($resql)
{
while ($obj=$this->db->fetch_object($resql))
{
$this->nb["cheques"]=$obj->nb;
}
$this->db->free($resql);
return 1;
}
else
{
dol_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
/** /**
* Build document * Build document
* *

View File

@ -375,8 +375,12 @@ if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->read)
{ {
include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
$board=new ActionComm($db); $board=new ActionComm($db);
$wb_res = $board->load_board($user);
$dashboardlines[] = $board->load_board($user); if(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
$board->load_state_board();
$wb_res->nbtotal = (int)$board->nb['actionscomm'];
}
$dashboardlines[] = $wb_res;
} }
// Number of project opened // Number of project opened
@ -397,7 +401,12 @@ if (! empty($conf->projet->enabled) && empty($conf->global->PROJECT_HIDE_TASKS)
{ {
include_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; include_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
$board=new Task($db); $board=new Task($db);
$dashboardlines[] = $board->load_board($user); $wb_res = $board->load_board($user);
if(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
$board->load_state_board();
$wb_res->nbtotal = (int)$board->nb['tasks'];
}
$dashboardlines[] = $wb_res;
} }
// Number of commercial proposals opened (expired) // Number of commercial proposals opened (expired)
@ -513,7 +522,12 @@ if (! empty($conf->banque->enabled) && $user->rights->banque->lire && ! $user->s
$nb = $board::countAccountToReconcile(); // Get nb of account to reconciliate $nb = $board::countAccountToReconcile(); // Get nb of account to reconciliate
if ($nb > 0) if ($nb > 0)
{ {
$dashboardlines[] = $board->load_board($user); $wb_res = $board->load_board($user);
if(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
$board->load_state_board();
$wb_res->nbtotal = (int)$board->nb['banklines'];
}
$dashboardlines[] = $wb_res;
} }
} }
@ -522,7 +536,12 @@ if (! empty($conf->banque->enabled) && $user->rights->banque->lire && ! $user->s
{ {
include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
$board=new RemiseCheque($db); $board=new RemiseCheque($db);
$dashboardlines[] = $board->load_board($user); $wb_res = $board->load_board($user);
if(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
$board->load_state_board();
$wb_res->nbtotal = (int)$board->nb['cheques'];
}
$dashboardlines[] = $wb_res;
} }
// Number of foundation members // Number of foundation members

View File

@ -1764,6 +1764,55 @@ class Task extends CommonObject
} }
} }
/**
* Charge indicateurs this->nb de tableau de bord
*
* @return int <0 if ko, >0 if ok
*/
function load_state_board()
{
global $user;
$mine=0; $socid=$user->societe_id;
$projectstatic = new Project($this->db);
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1,$socid);
// List of tasks (does not care about permissions. Filtering will be done later)
$sql = "SELECT count(p.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
if (! $user->rights->societe->client->voir && ! $socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
$sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
$sql.= " WHERE p.entity IN (".getEntity('project', 0).')';
$sql.= " AND t.fk_projet = p.rowid"; // tasks to do
if ($mine || ! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")";
// No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
//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) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
$resql=$this->db->query($sql);
if ($resql)
{
// This assignment in condition is not a bug. It allows walking the results.
while ($obj=$this->db->fetch_object($resql))
{
$this->nb["tasks"]=$obj->nb;
}
$this->db->free($resql);
return 1;
}
else
{
dol_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
/** /**
* Is the task delayed? * Is the task delayed?
* *