* Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/expensereport/index.php * \ingroup expensereport * \brief list of expense reports */ require "../main.inc.php"; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; $langs->load("companies"); $langs->load("users"); $langs->load("trips"); // Security check $socid = $_GET["socid"]?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'expensereport','',''); $search_ref = GETPOST('search_ref'); $search_user = GETPOST('search_user','int'); $search_amount_ht = GETPOST('search_amount_ht','alpha'); $search_amount_ttc = GETPOST('search_amount_ttc','alpha'); $search_status = (GETPOST('search_status','alpha')!=''?GETPOST('search_status','alpha'):GETPOST('statut','alpha')); $month_start = GETPOST("month_start","int"); $year_start = GETPOST("year_start","int"); $month_end = GETPOST("month_end","int"); $year_end = GETPOST("year_end","int"); if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test must be present to be compatible with all browsers { $search_ref=""; $search_user=""; $search_amount_ht=""; $search_amount_ttc=""; $search_status=""; $month_start=""; $year_start=""; $month_end=""; $year_end=""; } if ($search_status == '') $search_status=-1; if ($search_user == '') $search_user=-1; /* * View */ $html = new Form($db); $formother = new FormOther($db); $expensereporttmp=new ExpenseReport($db); llxHeader('', $langs->trans("ListOfTrips")); $max_year = 5; $min_year = 5; $sortorder = GETPOST("sortorder"); $sortfield = GETPOST("sortfield"); $page = GETPOST("page"); if (!$sortorder) $sortorder="DESC"; if (!$sortfield) $sortfield="d.date_debut"; if ($page == -1) { $page = 0 ; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; $limit = $conf->liste_limit; $sql = "SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,"; $sql.= " d.date_debut, d.date_fin,"; $sql.= " u.rowid as id_user, u.firstname, u.lastname"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user_author = u.rowid"; $sql.= " WHERE d.entity = ".$conf->entity; // Ref if(!empty($search_ref)){ $sql.= " AND d.ref LIKE '%".$db->escape($search_ref)."%'"; } // Date Start if ($month_start > 0) { if ($year_start > 0 && empty($day)) $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,$month_start,false))."' AND '".$db->idate(dol_get_last_day($year_start,$month_start,false))."'"; else if ($year_start > 0 && ! empty($day)) $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_start, $day, $year_start))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_start, $day, $year_start))."'"; else $sql.= " AND date_format(d.date_debut, '%m') = '".$month_start."'"; } else if ($year_start > 0) { $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,1,false))."' AND '".$db->idate(dol_get_last_day($year_start,12,false))."'"; } // Date Start if ($month_end > 0) { if ($year_end > 0 && empty($day)) $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,$month_end,false))."' AND '".$db->idate(dol_get_last_day($year_end,$month_end,false))."'"; else if ($year_end > 0 && ! empty($day)) $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_end, $day, $year_end))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_end, $day, $year_end))."'"; else $sql.= " AND date_format(d.date_fin, '%m') = '".$month_end."'"; } else if ($year_end > 0) { $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,1,false))."' AND '".$db->idate(dol_get_last_day($year_end,12,false))."'"; } // Amount if ($search_amount_ht != '') { $sql.= natural_search('d.total_ht', $search_amount_ht, 1); } if ($search_amount_ttc != '') { $sql.= natural_search('d.total_ttc', $search_amount_ttc, 1); } // User if ($search_user != '' && $search_user >= 0) { $sql.= " AND u.rowid = '".$db->escape($search_user)."'"; } // Status if ($search_status != '' && $search_status >= 0) { if (strstr($search_status, ',')) $sql.=" AND d.fk_statut IN (".$db->escape($search_status).")"; else $sql.=" AND d.fk_statut = ".$search_status; } // RESTRICT RIGHTS if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) { $childids = $user->getAllChildIds(); $childids[]=$user->id; $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n"; } $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit+1, $offset); //print $sql; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $param=""; if ($search_ref) $param.="&search_ref=".$search_ref; if ($search_user) $param.="&search_user=".$search_user; if ($search_amount_ht) $param.="&search_amount_ht=".$search_amount_ht; if ($search_amount_ttc) $param.="&search_amount_ttc=".$search_amount_ttc; if ($search_status >= 0) $param.="&search_status=".$search_status; print_barre_liste($langs->trans("ListTripsAndExpenses"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords); print '
'."\n"; print ''; print ""; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid","",$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"d.date_debut","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateEnd"),$_SERVER["PHP_SELF"],"d.date_fin","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Person"),$_SERVER["PHP_SELF"],"u.lastname","",$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("TotalHT"),$_SERVER["PHP_SELF"],"d.total_ht","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("TotalVAT"),$_SERVER["PHP_SELF"],"d.total_tva","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("TotalTTC"),$_SERVER["PHP_SELF"],"d.total_ttc","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Statut"),$_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; // Filters print ''; print ''; // Date end print ''; // User if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous){ print ''; } else { print ''; } // Amount with no tax print ''; print ''; // Amount with all taxes print ''; // Status print ''; print ''; print "\n"; $var=true; $total_total_ht = 0; $total_total_ttc = 0; $total_total_tva = 0; $expensereportstatic=new ExpenseReport($db); if($num > 0) { while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); $expensereportstatic->id=$objp->rowid; $expensereportstatic->ref=$objp->ref; $var=!$var; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $expensereporttmp->status=$objp->status; print ''; print ''; print "\n"; $total_total_ht = $total_total_ht + $objp->total_ht; $total_total_tva = $total_total_tva + $objp->total_tva; $total_total_ttc = $total_total_ttc + $objp->total_ttc; $i++; } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } else { print ''.''; } print "
'; print ''; // Date start print ''; print ''; $formother->select_year($year_start,'year_start',1, $min_year, $max_year); print ''; print ''; $formother->select_year($year_end,'year_end',1, $min_year, $max_year); print ''; $html->select_users($search_user,"search_user",1,"",0,''); print '  '; select_expensereport_statut($search_status,'search_status'); print ''; print ''; print ''; print '
'.$expensereportstatic->getNomUrl(1).''.($objp->date_debut > 0 ? dol_print_date($objp->date_debut, 'day') : '').''.($objp->date_fin > 0 ? dol_print_date($objp->date_fin, 'day') : '').''.img_object($langs->trans("ShowUser"),"user").' '.dolGetFirstLastname($objp->firstname, $objp->lastname).''.price($objp->total_ht).''.price($objp->total_tva).''.price($objp->total_ttc).''; //print $objp->status; print $expensereporttmp->getLibStatut(5); print '
'.$langs->trans("Total").''.price($total_total_ht).''.price($total_total_tva).''.price($total_total_ttc).'
'.$langs->trans("NoRecordFound").'
"; print "
"; print '
'; print ''.$langs->trans("NewTrip").''; print '
'; $db->free($resql); } else { dol_print_error($db); } llxFooter(); $db->close();