$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,';
$sql.=' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < ".$db->idate($now-$conf->contrat->services->expires->warning_delay).")",1,0).') as nb_late,';
$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,';
$sql.=' sum('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now-$conf->contrat->services->expires->warning_delay)."')",1,0).') as nb_late,';
$sql.=' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
$sql.=" c.rowid as cid, c.ref, c.datec, c.tms, c.statut, s.nom, s.rowid as socid";