2015-02-14 18:39:45 +01:00
< ? php
2015-02-28 08:46:40 +01:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2008 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis @ dolibarr . fr >
2015-05-03 14:25:37 +02:00
* Copyright ( C ) 2015 Alexandre Spangaro < alexandre . spangaro @ gmail . com >
2015-02-14 18:39:45 +01:00
*
* 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
2015-02-23 22:04:01 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2015-02-14 18:39:45 +01:00
* ( 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
2015-02-15 19:13:16 +01:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2015-02-14 18:39:45 +01:00
*/
/**
* \file htdocs / expensereport / index . php
2015-03-17 11:23:45 +01:00
* \ingroup expensereport
2015-03-08 08:21:49 +01:00
* \brief list of expense reports
2015-02-14 18:39:45 +01:00
*/
require " ../main.inc.php " ;
2015-03-07 15:41:30 +01:00
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2015-03-08 08:21:49 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2015-02-14 18:39:45 +01:00
$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' , '' , '' );
2015-02-23 22:36:26 +01:00
$search_ref = GETPOST ( 'search_ref' );
$search_user = GETPOST ( 'search_user' , 'int' );
2015-05-03 08:10:22 +02:00
$search_amount_ht = GETPOST ( 'search_amount_ht' , 'alpha' );
$search_amount_ttc = GETPOST ( 'search_amount_ttc' , 'alpha' );
2015-05-03 14:25:37 +02:00
$search_status = ( GETPOST ( 'search_status' , 'alpha' ) != '' ? GETPOST ( 'search_status' , 'alpha' ) : GETPOST ( 'statut' , 'alpha' ));
2015-02-23 22:36:26 +01:00
$month_start = GETPOST ( " month_start " , " int " );
$year_start = GETPOST ( " year_start " , " int " );
$month_end = GETPOST ( " month_end " , " int " );
$year_end = GETPOST ( " year_end " , " int " );
2015-02-14 18:39:45 +01:00
2015-02-23 22:36:26 +01:00
if ( GETPOST ( " button_removefilter_x " ) || GETPOST ( " button_removefilter " )) // Both test must be present to be compatible with all browsers
{
$search_ref = " " ;
$search_user = " " ;
2015-05-03 08:10:22 +02:00
$search_amount_ht = " " ;
$search_amount_ttc = " " ;
2015-03-08 08:21:49 +01:00
$search_status = " " ;
2015-02-23 22:36:26 +01:00
$month_start = " " ;
$year_start = " " ;
$month_end = " " ;
$year_end = " " ;
}
2015-02-14 18:39:45 +01:00
2015-05-03 14:25:37 +02:00
if ( $search_status == '' ) $search_status =- 1 ;
if ( $search_user == '' ) $search_user =- 1 ;
2015-02-14 18:39:45 +01:00
/*
* View
*/
$html = new Form ( $db );
$formother = new FormOther ( $db );
$expensereporttmp = new ExpenseReport ( $db );
2015-02-28 08:50:47 +01:00
llxHeader ( '' , $langs -> trans ( " ListOfTrips " ));
2015-02-14 18:39:45 +01:00
$max_year = 5 ;
$min_year = 5 ;
2015-03-08 08:21:49 +01:00
$sortorder = GETPOST ( " sortorder " );
$sortfield = GETPOST ( " sortfield " );
$page = GETPOST ( " page " );
2015-02-14 18:39:45 +01:00
if ( ! $sortorder ) $sortorder = " DESC " ;
if ( ! $sortfield ) $sortfield = " d.date_debut " ;
if ( $page == - 1 ) {
$page = 0 ;
}
$limit = $conf -> liste_limit ;
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2015-05-03 14:25:37 +02:00
$sql = " SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status, " ;
2015-02-14 18:39:45 +01:00
$sql .= " d.date_debut, d.date_fin, " ;
$sql .= " u.rowid as id_user, u.firstname, u.lastname " ;
2015-03-07 15:31:23 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as d " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " user as u ON d.fk_user_author = u.rowid " ;
2015-05-03 14:25:37 +02:00
$sql .= " WHERE d.entity = " . $conf -> entity ;
2015-02-14 18:39:45 +01:00
2015-05-03 14:25:37 +02:00
// Ref
2015-02-14 18:39:45 +01:00
if ( ! empty ( $search_ref )){
2015-05-03 14:25:37 +02:00
$sql .= " AND d.ref LIKE '% " . $db -> escape ( $search_ref ) . " %' " ;
2015-02-14 18:39:45 +01:00
}
2015-03-08 08:21:49 +01:00
// 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 )) . " ' " ;
2015-02-14 18:39:45 +01:00
}
2015-03-08 08:21:49 +01:00
// 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 )) . " ' " ;
}
2015-05-03 08:10:22 +02:00
// 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 );
}
2015-03-08 08:21:49 +01:00
// User
2015-05-03 14:25:37 +02:00
if ( $search_user != '' && $search_user >= 0 )
2015-03-08 08:21:49 +01:00
{
2015-05-03 14:25:37 +02:00
$sql .= " AND u.rowid = ' " . $db -> escape ( $search_user ) . " ' " ;
2015-03-08 08:21:49 +01:00
}
// Status
2015-05-03 14:25:37 +02:00
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 ;
}
2015-02-14 18:39:45 +01:00
// RESTRICT RIGHTS
2015-02-21 16:15:54 +01:00
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 " ;
2015-02-14 18:39:45 +01:00
}
2015-02-15 13:42:21 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
$sql .= $db -> plimit ( $limit + 1 , $offset );
2015-02-14 18:39:45 +01:00
//print $sql;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
2015-05-03 14:25:37 +02:00
$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 '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
2015-02-14 18:39:45 +01:00
print '<table class="noborder" width="100%">' ;
print " <tr class= \" liste_titre \" > " ;
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 );
2015-02-23 22:36:26 +01:00
print '<td class="liste_titre"> </td>' ;
2015-02-14 18:39:45 +01:00
print " </tr> \n " ;
2015-02-23 22:36:26 +01:00
// Filters
2015-02-14 18:39:45 +01:00
print '<tr class="liste_titre">' ;
print '<td class="liste_titre" align="left">' ;
print '<input class="flat" size="15" type="text" name="search_ref" value="' . $search_ref . '">' ;
// Date start
print '<td class="liste_titre" align="center">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="' . $month_start . '">' ;
$formother -> select_year ( $year_start , 'year_start' , 1 , $min_year , $max_year );
print '</td>' ;
// Date end
print '<td class="liste_titre" align="center">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="' . $month_end . '">' ;
$formother -> select_year ( $year_end , 'year_end' , 1 , $min_year , $max_year );
print '</td>' ;
// User
if ( $user -> rights -> expensereport -> readall || $user -> rights -> expensereport -> lire_tous ){
print '<td class="liste_titre" align="left">' ;
$html -> select_users ( $search_user , " search_user " , 1 , " " , 0 , '' );
print '</td>' ;
} else {
print '<td class="liste_titre"> </td>' ;
}
2015-05-03 08:10:22 +02:00
// Amount with no taxe
print '<td class="liste_titre" align="right"><input class="flat" type="text" size="6" name="search_amount_ht" value="' . $search_amount_ht . '"></td>' ;
2015-02-14 18:39:45 +01:00
print '<td class="liste_titre"> </td>' ;
2015-05-03 08:10:22 +02:00
// Amount with all taxes
print '<td class="liste_titre" align="right"><input class="flat" type="text" size="6" name="search_amount_ttc" value="' . $search_amount_ttc . '"></td>' ;
2015-02-14 18:39:45 +01:00
// Status
print '<td class="liste_titre" align="right">' ;
2015-03-08 08:21:49 +01:00
select_expensereport_statut ( $search_status , 'search_status' );
2015-02-14 18:39:45 +01:00
print '</td>' ;
2015-02-23 22:36:26 +01:00
print '<td class="liste_titre" align="right">' ;
print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto ( $langs -> trans ( " Search " ), 'search.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto ( $langs -> trans ( " Search " ), 'searchclear.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " RemoveFilter " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " RemoveFilter " )) . '">' ;
print '</td>' ;
2015-02-14 18:39:45 +01:00
print " </tr> \n " ;
$var = true ;
$total_total_ht = 0 ;
$total_total_ttc = 0 ;
$total_total_tva = 0 ;
if ( $num > 0 )
{
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
print " <tr " . $bc [ $var ] . " > " ;
2015-02-15 22:49:23 +01:00
print '<td><a href="card.php?id=' . $objp -> rowid . '">' . img_object ( $langs -> trans ( " ShowTrip " ), " trip " ) . ' ' . $objp -> ref . '</a></td>' ;
2015-02-14 18:39:45 +01:00
print '<td align="center">' . ( $objp -> date_debut > 0 ? dol_print_date ( $objp -> date_debut , 'day' ) : '' ) . '</td>' ;
print '<td align="center">' . ( $objp -> date_fin > 0 ? dol_print_date ( $objp -> date_fin , 'day' ) : '' ) . '</td>' ;
print '<td align="left"><a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $objp -> id_user . '">' . img_object ( $langs -> trans ( " ShowUser " ), " user " ) . ' ' . dolGetFirstLastname ( $objp -> firstname , $objp -> lastname ) . '</a></td>' ;
print '<td align="right">' . price ( $objp -> total_ht ) . '</td>' ;
print '<td align="right">' . price ( $objp -> total_tva ) . '</td>' ;
print '<td align="right">' . price ( $objp -> total_ttc ) . '</td>' ;
2015-02-15 19:13:16 +01:00
$expensereporttmp -> status = $objp -> status ;
print '<td align="right" colspan="2">' ;
//print $objp->status;
print $expensereporttmp -> getLibStatut ( 5 );
print '</td>' ;
2015-02-14 18:39:45 +01:00
print " </tr> \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 '<tr class="liste_total">' ;
print '<td colspan="4">' . $langs -> trans ( " Total " ) . '</td>' ;
2015-03-08 08:21:49 +01:00
2015-05-03 07:05:19 +02:00
print '<td style="text-align:right;">' . price ( $total_total_ht ) . '</td>' ;
print '<td style="text-align:right;">' . price ( $total_total_tva ) . '</td>' ;
print '<td style="text-align:right;">' . price ( $total_total_ttc ) . '</td>' ;
2015-02-14 18:39:45 +01:00
print '<td></td>' ;
print '<td></td>' ;
print '</tr>' ;
}
else
{
print '<td colspan="9">' . $langs -> trans ( " NoRecordFound " ) . '</td>' ;
}
print " </table> " ;
print " </form> " ;
print '<div class="tabsAction">' ;
2015-02-28 08:46:40 +01:00
print '<a href="' . dol_buildpath ( '/expensereport/card.php' , 1 ) . '?action=create" class="butAction">' . $langs -> trans ( " NewTrip " ) . '</a>' ;
2015-02-14 18:39:45 +01:00
print '</div>' ;
$db -> free ( $resql );
}
else
{
dol_print_error ( $db );
}
llxFooter ();
$db -> close ();