diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 36b59309298..dccf44399e0 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -46,6 +46,10 @@ $show_files=GETPOST('show_files','int'); $confirm=GETPOST('confirm','alpha'); $toselect = GETPOST('toselect', 'array'); +$dfmonth=GETPOST('dfmonth')?GETPOST('dfmonth'):date("n"); +$dfyear=GETPOST('dfyear'); +$filter_op2df=GETPOST('filter_op2df'); + $search_name=GETPOST('search_name'); $search_email=GETPOST('search_email'); $search_town=GETPOST('search_town','alpha'); @@ -126,6 +130,7 @@ $arrayfields=array( 'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1), 'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), 'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), + 'first_date_fin_validite'=>array('label'=>"1er ".$langs->trans("DateEndPlannedShort"), 'checked'=>1, 'position'=>900), 'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), ); // Extra fields @@ -157,6 +162,9 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', $day=''; $month=''; $year=''; + $dfmonth=''; + $dfyear=''; + $filter_op2df=''; $search_name=""; $search_email=""; $search_town=''; @@ -205,6 +213,7 @@ $sql.= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_ $sql.= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; $sql.= " typent.code as typent_code,"; $sql.= " state.code_departement as state_code, state.nom as state_name,"; +$sql.= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as first_date_fin_validite,"; $sql.= ' SUM('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,'; $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')",1,0).') as nb_running,'; $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')",1,0).') as nb_expired,'; @@ -289,6 +298,11 @@ $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; +if ($dfyear > 0) +{ + $sql.= " HAVING first_date_fin_validite ".$filter_op2df."= '".$db->idate(($filter_op2df == "<" ? dol_get_last_day($dfyear,$dfmonth,false) : dol_get_first_day($dfyear,$dfmonth,false)))."'"; +} + $sql.= $db->order($sortfield,$sortorder); $totalnboflines=0; @@ -538,6 +552,18 @@ if ($resql) print '