Fix statistics of leave requests (date valid not defined if status is
draft)
This commit is contained in:
parent
581b61bef1
commit
f875597c0b
@ -259,52 +259,50 @@ dol_fiche_head($head,'byyear',$langs->trans("Statistics"));
|
||||
print '<div class="fichecenter"><div class="fichethirdleft">';
|
||||
|
||||
|
||||
//if (empty($socid))
|
||||
//{
|
||||
// Show filter box
|
||||
print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="mode" value="'.$mode.'">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
|
||||
// Company
|
||||
print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
|
||||
if ($mode == 'customer') $filter='s.client in (1,2,3)';
|
||||
if ($mode == 'supplier') $filter='s.fournisseur = 1';
|
||||
print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
|
||||
print '</td></tr>';
|
||||
// User
|
||||
print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
|
||||
print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
|
||||
// Status
|
||||
print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
|
||||
if ($mode == 'customer')
|
||||
{
|
||||
$liststatus=array(
|
||||
Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraft"),
|
||||
Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
|
||||
Commande::STATUS_ACCEPTED=>$langs->trans("StatusOrderSent"),
|
||||
Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
|
||||
Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceled")
|
||||
);
|
||||
print $form->selectarray('object_status', $liststatus, GETPOST('object_status'), -4);
|
||||
}
|
||||
if ($mode == 'supplier')
|
||||
{
|
||||
$formorder->selectSupplierOrderStatus((strstr($object_status, ',')?-1:$object_status), 0, 'object_status');
|
||||
}
|
||||
print '</td></tr>';
|
||||
// Year
|
||||
print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
|
||||
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
||||
if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
|
||||
arsort($arrayyears);
|
||||
print $form->selectarray('year',$arrayyears,$year,0);
|
||||
print '</td></tr>';
|
||||
print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
|
||||
print '</table>';
|
||||
print '</form>';
|
||||
print '<br><br>';
|
||||
//}
|
||||
// Show filter box
|
||||
print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="mode" value="'.$mode.'">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
|
||||
// Company
|
||||
print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
|
||||
if ($mode == 'customer') $filter='s.client in (1,2,3)';
|
||||
if ($mode == 'supplier') $filter='s.fournisseur = 1';
|
||||
print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
|
||||
print '</td></tr>';
|
||||
// User
|
||||
print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
|
||||
print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
|
||||
// Status
|
||||
print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
|
||||
if ($mode == 'customer')
|
||||
{
|
||||
$liststatus=array(
|
||||
Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraft"),
|
||||
Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
|
||||
Commande::STATUS_ACCEPTED=>$langs->trans("StatusOrderSent"),
|
||||
Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
|
||||
Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceled")
|
||||
);
|
||||
print $form->selectarray('object_status', $liststatus, GETPOST('object_status'), -4);
|
||||
}
|
||||
if ($mode == 'supplier')
|
||||
{
|
||||
$formorder->selectSupplierOrderStatus((strstr($object_status, ',')?-1:$object_status), 0, 'object_status');
|
||||
}
|
||||
print '</td></tr>';
|
||||
// Year
|
||||
print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
|
||||
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
||||
if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
|
||||
arsort($arrayyears);
|
||||
print $form->selectarray('year',$arrayyears,$year,0);
|
||||
print '</td></tr>';
|
||||
print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
|
||||
print '</table>';
|
||||
print '</form>';
|
||||
print '<br><br>';
|
||||
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre" height="24">';
|
||||
@ -328,7 +326,6 @@ foreach ($data as $val)
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].' height="24">';
|
||||
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&mode='.$mode.($socid>0?'&socid='.$socid:'').($userid>0?'&userid='.$userid:'').'">'.$oldyear.'</a></td>';
|
||||
|
||||
print '<td align="right">0</td>';
|
||||
print '<td align="right"></td>';
|
||||
print '<td align="right">0</td>';
|
||||
|
||||
@ -489,7 +489,7 @@ class ExpenseReport extends CommonObject
|
||||
* Returns the label of a statut
|
||||
*
|
||||
* @param int $status id statut
|
||||
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
|
||||
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
|
||||
* @return string Label
|
||||
*/
|
||||
function LibStatut($status,$mode=0)
|
||||
@ -514,6 +514,8 @@ class ExpenseReport extends CommonObject
|
||||
if ($mode == 5)
|
||||
return '<span class="hideonsmartphone">'.$langs->transnoentities($this->statuts_short[$status]).' </span>'.img_picto($langs->transnoentities($this->statuts_short[$status]),$this->statuts_logo[$status]);
|
||||
|
||||
if ($mode == 6)
|
||||
return $langs->transnoentities($this->statuts[$status]).' '.img_picto($langs->transnoentities($this->statuts_short[$status]),$this->statuts_logo[$status]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -59,9 +59,9 @@ class ExpenseReportStats extends Stats
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element." as e";
|
||||
$this->field='total_ht';
|
||||
|
||||
$this->where = " e.fk_statut > 0";
|
||||
//$this->where = " e.fk_statut > 0";
|
||||
//$this->where.= " AND e.date_valid > '2000-01-01'"; // To filter only correct "valid date". If date is invalid, the group by on it will fails. Launch a repair.php if you have.
|
||||
$this->where.= ' AND e.entity IN ('.getEntity('expensereport', 1).')';
|
||||
$this->where.= ' e.entity IN ('.getEntity('expensereport', 1).')';
|
||||
|
||||
//$this->where.= " AND entity = ".$conf->entity;
|
||||
if ($this->socid)
|
||||
@ -88,7 +88,7 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getNbByYear()
|
||||
{
|
||||
$sql = "SELECT YEAR(date_valid) as dm, count(*)";
|
||||
$sql = "SELECT YEAR(".$this->db->ifsql('e.date_valid IS NULL','e.date_create','e.date_valid').") as dm, count(*)";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " GROUP BY dm DESC";
|
||||
$sql.= " WHERE ".$this->where;
|
||||
@ -105,7 +105,7 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getNbByMonth($year)
|
||||
{
|
||||
$sql = "SELECT MONTH(e.date_valid) as dm, count(*)";
|
||||
$sql = "SELECT MONTH(".$this->db->ifsql('e.date_valid IS NULL','e.date_create','e.date_valid').") as dm, count(*)";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE YEAR(e.date_valid) = ".$year;
|
||||
$sql.= " AND ".$this->where;
|
||||
@ -126,9 +126,9 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getAmountByMonth($year)
|
||||
{
|
||||
$sql = "SELECT date_format(e.date_valid,'%m') as dm, sum(".$this->field.")";
|
||||
$sql = "SELECT date_format(".$this->db->ifsql('e.date_valid IS NULL','e.date_create','e.date_valid').",'%m') as dm, sum(".$this->field.")";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE date_format(e.date_valid,'%Y') = '".$year."'";
|
||||
$sql.= " WHERE date_format(".$this->db->ifsql('e.date_valid IS NULL','e.date_create','e.date_valid').",'%Y') = '".$year."'";
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
@ -146,9 +146,9 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getAverageByMonth($year)
|
||||
{
|
||||
$sql = "SELECT date_format(e.date_valid,'%m') as dm, avg(".$this->field.")";
|
||||
$sql = "SELECT date_format(".$this->db->ifsql('e.date_valid IS NULL','e.date_create','e.date_valid').",'%m') as dm, avg(".$this->field.")";
|
||||
$sql.= " FROM ".$this->from;
|
||||
$sql.= " WHERE date_format(e.date_valid,'%Y') = '".$year."'";
|
||||
$sql.= " WHERE date_format(".$this->db->ifsql('e.date_valid IS NULL','e.date_create','e.date_valid').",'%Y') = '".$year."'";
|
||||
$sql.= " AND ".$this->where;
|
||||
$sql.= " GROUP BY dm";
|
||||
$sql.= $this->db->order('dm','DESC');
|
||||
@ -163,7 +163,7 @@ class ExpenseReportStats extends Stats
|
||||
*/
|
||||
function getAllByYear()
|
||||
{
|
||||
$sql = "SELECT date_format(e.date_valid,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
|
||||
$sql = "SELECT date_format(".$this->db->ifsql('e.date_valid IS NULL','e.date_create','e.date_valid').",'%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.= " GROUP BY year";
|
||||
|
||||
@ -33,6 +33,9 @@ $langs->load("companies");
|
||||
$WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
|
||||
$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
|
||||
|
||||
$mode=GETPOST("mode")?GETPOST("mode"):'customer';
|
||||
$object_status=GETPOST('object_status');
|
||||
|
||||
$userid=GETPOST('userid','int');
|
||||
$socid=GETPOST('socid','int'); if ($socid < 0) $socid=0;
|
||||
$id = GETPOST('id','int');
|
||||
@ -52,7 +55,6 @@ $year = GETPOST('year')>0?GETPOST('year'):$nowyear;
|
||||
$startyear=$year-1;
|
||||
$endyear=$year;
|
||||
|
||||
$mode=GETPOST("mode")?GETPOST("mode"):'customer';
|
||||
|
||||
|
||||
/*
|
||||
@ -60,18 +62,19 @@ $mode=GETPOST("mode")?GETPOST("mode"):'customer';
|
||||
*/
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
llxHeader();
|
||||
$tmpexpensereport=new ExpenseReport($db);
|
||||
|
||||
$title=$langs->trans("TripsAndExpensesStatistics");
|
||||
$dir=$conf->expensereport->dir_temp;
|
||||
|
||||
llxHeader('', $title);
|
||||
|
||||
print load_fiche_titre($title, $mesg);
|
||||
|
||||
dol_mkdir($dir);
|
||||
|
||||
$stats = new ExpenseReportStats($db, $socid, $userid);
|
||||
|
||||
if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND e.fk_statut IN ('.$object_status.')';
|
||||
|
||||
// Build graphic number of object
|
||||
// $data = array(array('Lib',val1,val2,val3),...)
|
||||
@ -227,6 +230,11 @@ $include='';
|
||||
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $include='hierarchy';
|
||||
print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300');
|
||||
print '</td></tr>';
|
||||
// Status
|
||||
print '<tr><td align="left">'.$langs->trans("Status").'</td><td align="left">';
|
||||
$liststatus=$tmpexpensereport->statuts;
|
||||
print $form->selectarray('object_status', $liststatus, GETPOST('object_status'), -4, 0, 0, '', 1);
|
||||
print '</td></tr>';
|
||||
// Year
|
||||
print '<tr><td>'.$langs->trans("Year").'</td><td>';
|
||||
if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
|
||||
@ -247,20 +255,24 @@ print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$oldyear=0;
|
||||
$var=true;
|
||||
foreach ($data as $val)
|
||||
{
|
||||
$year = $val['year'];
|
||||
while ($year && $oldyear > $year+1)
|
||||
{ // If we have empty year
|
||||
$oldyear--;
|
||||
print '<tr height="24">';
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].' height="24">';
|
||||
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&mode='.$mode.'">'.$oldyear.'</a></td>';
|
||||
print '<td align="right">0</td>';
|
||||
print '<td align="right">0</td>';
|
||||
print '<td align="right">0</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
print '<tr height="24">';
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].' height="24">';
|
||||
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&mode='.$mode.'">'.$year.'</a></td>';
|
||||
print '<td align="right">'.$val['nb'].'</td>';
|
||||
print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
|
||||
|
||||
@ -221,6 +221,8 @@ else
|
||||
}
|
||||
|
||||
print '<tr '.$bc[$var].'>';
|
||||
|
||||
// User
|
||||
print '<td>';
|
||||
$userstatic->id=$users['rowid'];
|
||||
$userstatic->lastname=$users['lastname'];
|
||||
@ -232,6 +234,7 @@ else
|
||||
print $userstatic->getNomUrl(-1);
|
||||
print '</td>';
|
||||
|
||||
// Amount for each type
|
||||
if (count($typeleaves))
|
||||
{
|
||||
foreach($typeleaves as $key => $val)
|
||||
@ -249,8 +252,10 @@ else
|
||||
{
|
||||
print '<td></td>';
|
||||
}
|
||||
|
||||
// Note
|
||||
print '<td style="text-align:center">';
|
||||
if ($canedit) print '<input type="text"'.($canedit?'':' disabled="disabled"').' value="" name="note_holiday['.$users['rowid'].']" size="30"/>';
|
||||
if ($canedit) print '<input type="text"'.($canedit?'':' disabled="disabled"').' class="maxwidthonsmartphone" value="" name="note_holiday['.$users['rowid'].']" size="30"/>';
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
if (! empty($user->rights->holiday->define_holiday))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user