Fix missing dashboard stats for holidays

This commit is contained in:
Maxime Kohlhaas 2019-05-18 16:40:14 +02:00
parent 28a4785b3a
commit ea1efa5e88
2 changed files with 104 additions and 1 deletions

View File

@ -2177,4 +2177,91 @@ class Holiday extends CommonObject
$this->fk_type=1;
$this->statut=Holiday::STATUS_VALIDATED;
}
/**
* Load this->nb for dashboard
*
* @return int <0 if KO, >0 if OK
*/
public function load_state_board()
{
global $conf;
$this->nb=array();
$sql = "SELECT count(h.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday as h";
$sql.= " WHERE h.statut > 1";
$sql.= " AND h.entity IN (".getEntity('holiday').")";
$resql=$this->db->query($sql);
if ($resql) {
while ($obj=$this->db->fetch_object($resql)) {
$this->nb["holidays"]=$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)
*
* @param User $user Objet user
* @param string $option 'toapprove'
* @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
*/
public function load_board($user)
{
// phpcs:enable
global $conf, $langs;
if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
$now=dol_now();
$userchildids = $user->getAllChildIds(1);
$sql = "SELECT h.rowid, h.date_debut";
$sql.= " FROM ".MAIN_DB_PREFIX."holiday as h";
$sql.= " WHERE h.statut = 2";
$sql.= " AND h.entity IN (".getEntity('holiday').")";
$sql.= " AND (h.fk_user IN (".join(',', $userchildids).")";
$sql.= " OR h.fk_validator IN (".join(',', $userchildids)."))";
$resql=$this->db->query($sql);
if ($resql)
{
$langs->load("members");
$response = new WorkboardResponse();
$response->warning_delay=$conf->holiday->approve->warning_delay/60/60/24;
$response->label=$langs->trans("HolidaysToApprove");
$response->url=DOL_URL_ROOT.'/holiday/list.php?search_statut=2&leftmenu=hrm';
$response->img=img_object('', "holiday");
while ($obj=$this->db->fetch_object($resql))
{
$response->nbtodo++;
if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
$response->nbtodolate++;
}
}
return $response;
}
else
{
dol_print_error($this->db);
$this->error=$this->db->error();
return -1;
}
}
}

View File

@ -150,6 +150,7 @@ if (empty($user->societe_id))
! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS),
! empty($conf->projet->enabled) && $user->rights->projet->lire,
! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire,
! empty($conf->holiday->enabled) && $user->rights->holiday->read,
! empty($conf->don->enabled) && $user->rights->don->lire
);
// Class file containing the method load_state_board for each line
@ -172,6 +173,7 @@ if (empty($user->societe_id))
DOL_DOCUMENT_ROOT."/supplier_proposal/class/supplier_proposal.class.php",
DOL_DOCUMENT_ROOT."/projet/class/project.class.php",
DOL_DOCUMENT_ROOT."/expensereport/class/expensereport.class.php",
DOL_DOCUMENT_ROOT."/holiday/class/holiday.class.php",
DOL_DOCUMENT_ROOT."/don/class/don.class.php"
);
// Name class containing the method load_state_board for each line
@ -193,6 +195,7 @@ if (empty($user->societe_id))
'SupplierProposal',
'Project',
'ExpenseReport',
'Holiday',
'Don'
);
// Cle array returned by the method load_state_board for each line
@ -203,7 +206,7 @@ if (empty($user->societe_id))
'contacts',
'members',
'products',
'services',
'services',
'proposals',
'orders',
'invoices',
@ -214,6 +217,7 @@ if (empty($user->societe_id))
'askprice',
'projects',
'expensereports',
'holidays',
'donations'
);
// Dashboard Icon lines
@ -235,6 +239,7 @@ if (empty($user->societe_id))
'propal',
'projectpub',
'trip',
'holiday',
'generic'
);
// Translation keyword
@ -256,6 +261,7 @@ if (empty($user->societe_id))
"SupplierProposalShort",
"Projects",
"ExpenseReports",
"Holidays",
"Donations"
);
// Dashboard Link lines
@ -278,6 +284,7 @@ if (empty($user->societe_id))
DOL_URL_ROOT.'/supplier_proposal/list.php?mainmenu=commercial&leftmenu=',
DOL_URL_ROOT.'/projet/list.php?mainmenu=project',
DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport',
DOL_URL_ROOT.'/holiday/list.php?mainmenu=hrm&leftmenu=holiday',
DOL_URL_ROOT.'/don/list.php?leftmenu=donations'
);
// Translation lang files
@ -299,6 +306,7 @@ if (empty($user->societe_id))
"supplier_proposal",
"projects",
"trips",
"holidays",
"donations"
);
@ -496,6 +504,14 @@ if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->to_p
$dashboardlines[] = $board->load_board($user,'topay');
}
// Number of holidays to approve
if (! empty($conf->holiday->enabled) && $user->rights->holiday->approve)
{
include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
$board=new Holiday($db);
$dashboardlines[] = $board->load_board($user);
}
$object=new stdClass();
$parameters=array();
$action='';