Fix filter on employee

This commit is contained in:
Laurent Destailleur 2021-03-10 17:31:33 +01:00
parent 46d835b2bd
commit e015f66936
2 changed files with 14 additions and 13 deletions

View File

@ -62,8 +62,8 @@ class SalariesStats extends Stats
$this->from = MAIN_DB_PREFIX.$object->table_element;
$this->field = 'amount';
$this->where .= " entity = ".$conf->entity;
if ($this->socid) {
$this->where = " entity = ".$conf->entity;
if ($this->socid > 0) {
$this->where .= " AND fk_soc = ".$this->socid;
}
if (is_array($this->userid) && count($this->userid) > 0) {
@ -83,8 +83,8 @@ class SalariesStats extends Stats
{
$sql = "SELECT YEAR(datep) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY dm DESC";
//$sql .= " WHERE ".$this->where;
return $this->_getNbByYear($sql);
}
@ -102,12 +102,12 @@ class SalariesStats extends Stats
$sql = "SELECT MONTH(datep) as dm, count(*)";
$sql .= " FROM ".$this->from;
$sql .= " WHERE YEAR(datep) = ".$year;
//$sql .= " AND ".$this->where;
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
$sql .= $this->db->order('dm', 'DESC');
$res = $this->_getNbByMonth($year, $sql, $format);
//var_dump($res);print '<br>';
return $res;
}
@ -124,12 +124,11 @@ class SalariesStats extends Stats
$sql = "SELECT date_format(datep,'%m') as dm, sum(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " WHERE date_format(datep,'%Y') = '".$this->db->escape($year)."'";
//$sql .= " AND ".$this->where;
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
$sql .= $this->db->order('dm', 'DESC');
$res = $this->_getAmountByMonth($year, $sql, $format);
//var_dump($res);print '<br>';
return $res;
}
@ -145,7 +144,7 @@ class SalariesStats extends Stats
$sql = "SELECT date_format(datep,'%m') as dm, avg(".$this->field.")";
$sql .= " FROM ".$this->from;
$sql .= " WHERE date_format(datep,'%Y') = '".$this->db->escape($year)."'";
//$sql .= " AND ".$this->where;
$sql .= " AND ".$this->where;
$sql .= " GROUP BY dm";
$sql .= $this->db->order('dm', 'DESC');
@ -161,7 +160,7 @@ class SalariesStats extends Stats
{
$sql = "SELECT date_format(datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
$sql .= " FROM ".$this->from;
//$sql .= " WHERE ".$this->where;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
$sql .= $this->db->order('year', 'DESC');

View File

@ -33,10 +33,12 @@ $langs->loadLangs(array("salaries", "companies", "bills"));
$WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
$userid = GETPOST('userid', 'int'); if ($userid < 0) {
$userid = GETPOST('userid', 'int');
if ($userid < 0) {
$userid = 0;
}
$socid = GETPOST('socid', 'int'); if ($socid < 0) {
$socid = GETPOST('socid', 'int');
if ($socid < 0) {
$socid = 0;
}
$id = GETPOST('id', 'int');
@ -201,8 +203,8 @@ print '<input type="hidden" name="token" value="'.newToken().'">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
// User
print '<tr><td>'.$langs->trans("User").'</td><td>';
print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
print '<tr><td>'.$langs->trans("Employee").'</td><td>';
print $form->select_dolusers(($userid ? $userid : -1), 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
print '</td></tr>';
// Year
print '<tr><td>'.$langs->trans("Year").'</td><td>';