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 >
2017-11-26 00:14:54 +01:00
* Copyright ( C ) 2004 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-02-28 08:46:40 +01:00
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2017-08-23 21:23:18 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . com >
2015-07-15 20:30:33 +02:00
* Copyright ( C ) 2015 Alexandre Spangaro < aspangaro . dolibarr @ gmail . com >
2018-04-20 10:38:16 +02:00
* Copyright ( C ) 2018 Ferran Marcet < fmarcet @ 2 byte . es >
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
*/
/**
2016-09-01 11:29:30 +02:00
* \file htdocs / expensereport / list . 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 " ;
2016-09-09 15:36:33 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2017-10-19 20:56:23 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/usergroups.lib.php' ;
2017-10-20 17:02:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport_ik.class.php' ;
2015-02-14 18:39:45 +01:00
2018-05-26 20:51:17 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'companies' , 'users' , 'trips' ));
2015-02-14 18:39:45 +01:00
2017-09-16 22:03:25 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2016-09-09 15:36:33 +02:00
$massaction = GETPOST ( 'massaction' , 'alpha' );
$show_files = GETPOST ( 'show_files' , 'int' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$toselect = GETPOST ( 'toselect' , 'array' );
2018-03-31 18:48:27 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'expensereportlist' ;
2016-09-09 15:36:33 +02:00
2015-02-14 18:39:45 +01:00
// Security check
2017-09-16 22:03:25 +02:00
$socid = GETPOST ( 'socid' , 'int' );
2015-02-14 18:39:45 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'expensereport' , '' , '' );
2016-09-09 15:36:33 +02:00
$diroutputmassaction = $conf -> expensereport -> dir_output . '/temp/massgeneration/' . $user -> id ;
2016-12-22 15:57:19 +01:00
// Load variable for pagination
2017-06-08 14:55:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2016-12-22 15:57:19 +01:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2016-09-09 15:36:33 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2016-12-22 15:57:19 +01:00
if ( ! $sortorder ) $sortorder = " DESC " ;
if ( ! $sortfield ) $sortfield = " d.date_debut " ;
2017-10-19 20:56:23 +02:00
$id = GETPOST ( 'id' , 'int' );
2016-09-09 15:36:33 +02:00
2017-12-12 11:31:30 +01:00
$sall = trim (( GETPOST ( 'search_all' , 'alphanohtml' ) != '' ) ? GETPOST ( 'search_all' , 'alphanohtml' ) : GETPOST ( 'sall' , 'alphanohtml' ));
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' );
2016-09-09 15:36:33 +02:00
$search_amount_vat = GETPOST ( 'search_amount_vat' , 'alpha' );
2015-05-03 08:10:22 +02:00
$search_amount_ttc = GETPOST ( 'search_amount_ttc' , 'alpha' );
2018-04-06 17:22:14 +02:00
$search_status = ( GETPOST ( 'search_status' , 'intcomma' ) != '' ? GETPOST ( 'search_status' , 'intcomma' ) : GETPOST ( 'statut' , 'intcomma' ));
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 " );
2017-12-12 11:31:30 +01:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
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 ;
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2018-03-31 18:48:27 +02:00
$object = new ExpenseReport ( $db );
2016-07-03 21:06:02 +02:00
$hookmanager -> initHooks ( array ( 'expensereportlist' ));
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
$extralabels = $extrafields -> fetch_name_optionals_label ( 'expensereport' );
$search_array_options = $extrafields -> getOptionalsFromPost ( $extralabels , '' , 'search_' );
2015-10-17 01:40:46 +02:00
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array (
'd.ref' => 'Ref' ,
2016-09-09 15:36:33 +02:00
'd.note_public' => " NotePublic " ,
2015-10-17 01:40:46 +02:00
'u.lastname' => 'Lastname' ,
'u.firstname' => " Firstname " ,
2016-09-09 15:36:33 +02:00
'u.login' => " Login " ,
2015-10-17 01:40:46 +02:00
);
2016-09-09 15:36:33 +02:00
if ( empty ( $user -> socid )) $fieldstosearchall [ " d.note_private " ] = " NotePrivate " ;
$arrayfields = array (
'd.ref' => array ( 'label' => $langs -> trans ( " Ref " ), 'checked' => 1 ),
2016-11-13 22:00:57 +01:00
'user' => array ( 'label' => $langs -> trans ( " User " ), 'checked' => 1 ),
2016-09-09 15:36:33 +02:00
'd.date_debut' => array ( 'label' => $langs -> trans ( " DateStart " ), 'checked' => 1 ),
'd.date_fin' => array ( 'label' => $langs -> trans ( " DateEnd " ), 'checked' => 1 ),
2016-12-22 17:27:58 +01:00
'd.date_valid' => array ( 'label' => $langs -> trans ( " DateValidation " ), 'checked' => 1 ),
'd.date_approve' => array ( 'label' => $langs -> trans ( " DateApprove " ), 'checked' => 1 ),
2016-09-09 15:36:33 +02:00
'd.total_ht' => array ( 'label' => $langs -> trans ( " AmountHT " ), 'checked' => 1 ),
'd.total_vat' => array ( 'label' => $langs -> trans ( " AmountVAT " ), 'checked' => 1 ),
'd.total_ttc' => array ( 'label' => $langs -> trans ( " AmountTTC " ), 'checked' => 1 ),
2017-11-26 00:14:54 +01:00
'd.date_create' => array ( 'label' => $langs -> trans ( " DateCreation " ), 'checked' => 0 , 'position' => 500 ),
2016-09-09 15:36:33 +02:00
'd.tms' => array ( 'label' => $langs -> trans ( " DateModificationShort " ), 'checked' => 0 , 'position' => 500 ),
'd.fk_statut' => array ( 'label' => $langs -> trans ( " Status " ), 'checked' => 1 , 'position' => 1000 ),
);
// Extra fields
if ( is_array ( $extrafields -> attribute_label ) && count ( $extrafields -> attribute_label ))
{
foreach ( $extrafields -> attribute_label as $key => $val )
{
2017-10-29 11:00:02 +01:00
if ( ! empty ( $extrafields -> attribute_list [ $key ])) $arrayfields [ " ef. " . $key ] = array ( 'label' => $extrafields -> attribute_label [ $key ], 'checked' => (( $extrafields -> attribute_list [ $key ] < 0 ) ? 0 : 1 ), 'position' => $extrafields -> attribute_pos [ $key ], 'enabled' => ( abs ( $extrafields -> attribute_list [ $key ]) != 3 && $extrafields -> attribute_perms [ $key ]));
2016-09-09 15:36:33 +02:00
}
}
2015-10-17 01:40:46 +02:00
2017-10-20 17:02:26 +02:00
$canedituser = ( ! empty ( $user -> admin ) || $user -> rights -> user -> user -> creer );
$object = new ExpenseReport ( $db );
$objectuser = new User ( $db );
2015-10-17 01:40:46 +02:00
2016-07-03 21:06:02 +02:00
/*
2017-06-14 11:28:42 +02:00
* Actions
2016-07-03 21:06:02 +02:00
*/
2017-09-15 10:50:50 +02:00
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) { $massaction = '' ; }
2016-09-09 15:36:33 +02:00
2016-07-03 21:06:02 +02:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
2016-09-09 15:36:33 +02:00
if ( empty ( $reshook ))
{
2017-09-16 22:03:25 +02:00
// Purge search criteria
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) // Both test must be present to be compatible with all browsers
{
$search_ref = " " ;
$search_user = " " ;
$search_amount_ht = " " ;
$search_amount_vat = " " ;
$search_amount_ttc = " " ;
$search_status = " " ;
$month_start = " " ;
$year_start = " " ;
$month_end = " " ;
$year_end = " " ;
$toselect = '' ;
$search_array_options = array ();
}
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )
|| GETPOST ( 'button_search_x' , 'alpha' ) || GETPOST ( 'button_search.x' , 'alpha' ) || GETPOST ( 'button_search' , 'alpha' ))
{
$massaction = '' ; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
// Mass actions
2016-09-09 15:36:33 +02:00
$objectclass = 'ExpenseReport' ;
$objectlabel = 'ExpenseReport' ;
$permtoread = $user -> rights -> expensereport -> lire ;
$permtodelete = $user -> rights -> expensereport -> supprimer ;
$uploaddir = $conf -> expensereport -> dir_output ;
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
2017-10-20 17:02:26 +02:00
if ( $action == 'update' && ! $cancel )
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
if ( $canedituser ) // Case we can edit all field
{
$error = 0 ;
if ( ! $error )
{
$objectuser -> fetch ( $id );
$objectuser -> oldcopy = clone $objectuser ;
$db -> begin ();
$objectuser -> default_range = GETPOST ( 'default_range' );
$objectuser -> default_c_exp_tax_cat = GETPOST ( 'default_c_exp_tax_cat' );
if ( ! $error ) {
$ret = $objectuser -> update ( $user );
if ( $ret < 0 ) {
$error ++ ;
if ( $db -> errno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorLoginAlreadyExists " , $objectuser -> login ), null , 'errors' );
}
else
{
setEventMessages ( $objectuser -> error , $objectuser -> errors , 'errors' );
}
}
}
if ( ! $error && ! count ( $objectuser -> errors )) {
setEventMessages ( $langs -> trans ( " UserModified " ), null , 'mesgs' );
$db -> commit ();
}
else {
$db -> rollback ();
}
}
}
}
2016-09-09 15:36:33 +02:00
}
2016-07-03 21:06:02 +02:00
2015-02-14 18:39:45 +01:00
/*
* View
*/
2015-12-05 19:20:39 +01:00
$form = new Form ( $db );
2015-02-14 18:39:45 +01:00
$formother = new FormOther ( $db );
2016-09-09 15:36:33 +02:00
$formfile = new FormFile ( $db );
2015-02-14 18:39:45 +01:00
2017-10-19 20:56:23 +02:00
$fuser = new User ( $db );
2017-09-16 22:03:25 +02:00
$title = $langs -> trans ( " ListOfTrips " );
llxHeader ( '' , $title );
2015-02-14 18:39:45 +01:00
$max_year = 5 ;
$min_year = 5 ;
2017-10-19 20:56:23 +02:00
// Récupération de l'ID de l'utilisateur
$user_id = $user -> id ;
if ( $id > 0 )
{
// Charge utilisateur edite
$fuser -> fetch ( $id , '' , '' , 1 );
$fuser -> getrights ();
$user_id = $fuser -> id ;
$search_user = $user_id ;
}
2015-02-14 18:39:45 +01:00
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, " ;
2017-01-02 13:51:05 +01:00
$sql .= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve, d.note_private, d.note_public, " ;
2017-09-16 22:03:25 +02:00
$sql .= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.email, u.statut, u.photo " ;
2016-09-09 15:36:33 +02:00
// Add fields from extrafields
foreach ( $extrafields -> attribute_label as $key => $val ) $sql .= ( $extrafields -> attribute_type [ $key ] != 'separate' ? " ,ef. " . $key . ' as options_' . $key : '' );
// Add fields from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2015-03-07 15:31:23 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as d " ;
2016-09-09 15:36:33 +02:00
if ( is_array ( $extrafields -> attribute_label ) && count ( $extrafields -> attribute_label )) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " expensereport_extrafields as ef on (d.rowid = ef.fk_object) " ;
$sql .= " , " . MAIN_DB_PREFIX . " user as u " ;
2017-05-30 18:50:54 +02:00
$sql .= " WHERE d.fk_user_author = u.rowid AND d.entity IN ( " . getEntity ( 'expensereport' ) . " ) " ;
2015-10-17 01:40:46 +02:00
// Search all
2016-09-09 15:36:33 +02:00
if ( ! empty ( $sall )) $sql .= natural_search ( array_keys ( $fieldstosearchall ), $sall );
2015-05-03 14:25:37 +02:00
// Ref
2016-09-09 15:36:33 +02:00
if ( ! empty ( $search_ref )) $sql .= natural_search ( 'd.ref' , $search_ref );
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
2016-09-09 15:36:33 +02:00
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
2016-09-09 15:36:33 +02:00
if ( $search_user != '' && $search_user >= 0 ) $sql .= " AND u.rowid = ' " . $db -> escape ( $search_user ) . " ' " ;
2015-03-08 08:21:49 +01:00
// Status
2018-04-06 17:22:14 +02:00
if ( $search_status != '' && $search_status >= 0 ) $sql .= " AND d.fk_statut IN ( " . $db -> escape ( $search_status ) . " ) " ;
2015-02-14 18:39:45 +01:00
// RESTRICT RIGHTS
2016-11-13 22:00:57 +01:00
if ( empty ( $user -> rights -> expensereport -> readall ) && empty ( $user -> rights -> expensereport -> lire_tous )
2017-01-26 18:08:00 +01:00
&& ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || empty ( $user -> rights -> expensereport -> writeall_advance )))
2015-02-21 16:15:54 +01:00
{
2018-07-09 14:35:22 +02:00
$childids = $user -> getAllChildIds ( 1 );
2015-02-21 16:15:54 +01:00
$sql .= " AND d.fk_user_author IN ( " . join ( ',' , $childids ) . " ) \n " ;
2015-02-14 18:39:45 +01:00
}
2016-09-09 15:36:33 +02:00
// Add where from extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php' ;
2016-09-09 15:36:33 +02:00
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2015-02-14 18:39:45 +01:00
2015-02-15 13:42:21 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2016-09-09 15:36:33 +02:00
2017-09-16 22:03:25 +02:00
// Count total nb of records
2017-01-15 20:49:20 +01:00
$nbtotalofrecords = '' ;
2015-11-28 20:33:18 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST ))
{
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
2018-04-24 11:37:57 +02:00
if (( $page * $limit ) > $nbtotalofrecords ) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
$page = 0 ;
$offset = 0 ;
}
2015-11-28 20:33:18 +01:00
}
2018-04-24 11:37:57 +02:00
2015-02-15 13:42:21 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2015-02-14 18:39:45 +01:00
//print $sql;
2017-09-16 22:03:25 +02:00
$resql = $db -> query ( $sql );
2015-02-14 18:39:45 +01:00
if ( $resql )
{
$num = $db -> num_rows ( $resql );
2016-09-09 15:36:33 +02:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2016-11-28 06:53:34 +01:00
2017-09-16 22:03:25 +02:00
$param = '' ;
2016-07-03 21:06:02 +02:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . $contextpage ;
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . $limit ;
2016-09-09 13:58:41 +02:00
if ( $sall ) $param .= " &sall= " . $sall ;
2015-05-03 14:25:37 +02:00
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 ;
2016-07-03 21:06:02 +02:00
if ( $optioncss != '' ) $param .= '&optioncss=' . $optioncss ;
// Add $param from extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
// List of mass actions available
$arrayofmassactions = array (
2017-09-16 22:03:25 +02:00
'presend' => $langs -> trans ( " SendByMail " ),
2017-03-18 11:51:45 +01:00
'builddoc' => $langs -> trans ( " PDFMerge " ),
2016-09-09 15:36:33 +02:00
);
2017-11-15 11:39:11 +01:00
if ( $user -> rights -> expensereport -> supprimer ) $arrayofmassactions [ 'predelete' ] = $langs -> trans ( " Delete " );
2017-11-11 16:03:22 +01:00
if ( in_array ( $massaction , array ( 'presend' , 'predelete' ))) $arrayofmassactions = array ();
2016-09-09 15:36:33 +02:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2016-11-28 06:53:34 +01:00
2017-09-16 22:03:25 +02:00
// Lines of title fields
print '<form id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
2015-10-04 12:31:32 +02:00
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
2015-10-17 01:40:46 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2016-09-09 15:36:33 +02:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
2017-10-20 17:02:26 +02:00
print '<input type="hidden" name="action" value="' . ( $action == 'edit' ? 'update' : 'list' ) . '">' ;
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-09-16 22:03:25 +02:00
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
2015-10-17 01:40:46 +02:00
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2017-10-19 20:56:23 +02:00
if ( $id > 0 ) print '<input type="hidden" name="id" value="' . $id . '">' ;
if ( $id > 0 ) // For user tab
{
$title = $langs -> trans ( " User " );
2018-04-06 00:36:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/user/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-10-19 20:56:23 +02:00
$head = user_prepare_head ( $fuser );
dol_fiche_head ( $head , 'expensereport' , $title , - 1 , 'user' );
dol_banner_tab ( $fuser , 'id' , $linkback , $user -> rights -> user -> user -> lire || $user -> admin );
2017-10-20 17:02:26 +02:00
print '<div class="fichecenter">' ;
2017-10-19 20:56:23 +02:00
print '<div class="underbanner clearboth"></div>' ;
2017-10-20 17:02:26 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_EXPENSE_IK ))
{
print '<table class="border centpercent">' ;
if ( $action == 'edit' )
{
print '<tr><td class="titlefield">' . $langs -> trans ( " DefaultCategoryCar " ) . '</td>' ;
print '<td>' ;
print $form -> selectExpenseCategories ( $fuser -> default_c_exp_tax_cat , 'default_c_exp_tax_cat' , 1 );
print '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " DefaultRangeNumber " ) . '</td>' ;
print '<td>' ;
$maxRangeNum = ExpenseReportIk :: getMaxRangeNumber ( $fuser -> default_c_exp_tax_cat );
print $form -> selectarray ( 'default_range' , range ( 0 , $maxRangeNum ), $fuser -> default_range );
print '</td></tr>' ;
}
else
{
print '<tr><td class="titlefield">' . $langs -> trans ( " DefaultCategoryCar " ) . '</td>' ;
print '<td class="fk_c_exp_tax_cat">' ;
print dol_getIdFromCode ( $db , $fuser -> default_c_exp_tax_cat , 'c_exp_tax_cat' , 'rowid' , 'label' );
print '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " DefaultRangeNumber " ) . '</td>' ;
print '<td>' ;
print $fuser -> default_range ;
print '</td></tr>' ;
}
print '</table>' ;
}
print '</div>' ;
2017-10-19 20:56:23 +02:00
/* if ( empty ( $conf -> global -> HOLIDAY_HIDE_BALANCE ))
{
print '<div class="underbanner clearboth"></div>' ;
print '<br>' ;
showMyBalance ( $holiday , $user_id );
} */
dol_fiche_end ();
2017-10-20 17:02:26 +02:00
if ( $action != 'edit' )
{
print '<div class="tabsAction">' ;
2015-10-17 01:40:46 +02:00
2017-10-20 17:02:26 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_EXPENSE_IK ))
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit&id=' . $user_id . '" class="butAction">' . $langs -> trans ( " Modify " ) . '</a>' ;
}
2017-10-19 20:56:23 +02:00
2018-07-09 14:35:22 +02:00
$childids = $user -> getAllChildIds ( 1 );
$canedit = (( in_array ( $user_id , $childids ) && $user -> rights -> expensereport -> creer )
|| ( $conf -> global -> MAIN_USE_ADVANCED_PERMS && $user -> rights -> expensereport -> writeall_advance ));
2017-10-20 17:02:26 +02:00
// Boutons d'actions
if ( $canedit )
{
2018-07-09 14:35:22 +02:00
print '<a href="' . DOL_URL_ROOT . '/expensereport/card.php?action=create&fk_user_author=' . $fuser -> id . '" class="butAction">' . $langs -> trans ( " AddTrip " ) . '</a>' ;
2017-10-20 17:02:26 +02:00
}
print '</div>' ;
}
else
2017-10-19 20:56:23 +02:00
{
2017-10-20 17:02:26 +02:00
print '<div class="center">' ;
print '<input type="submit" class="button" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
print '</div><br>' ;
2017-10-19 20:56:23 +02:00
}
}
else
{
$title = $langs -> trans ( " ListTripsAndExpenses " );
2018-03-30 16:54:38 +02:00
$newcardbutton = '' ;
if ( $user -> rights -> expensereport -> creer )
{
2018-06-13 22:57:41 +02:00
$newcardbutton = '<a class="butActionNew" href="' . DOL_URL_ROOT . '/expensereport/card.php?action=create"><span class="valignmiddle">' . $langs -> trans ( 'NewTrip' ) . '</span>' ;
2018-04-18 03:26:15 +02:00
$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>' ;
$newcardbutton .= '</a>' ;
2018-03-30 16:54:38 +02:00
}
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'title_generic.png' , 0 , $newcardbutton , '' , $limit );
2017-10-19 20:56:23 +02:00
}
2017-06-14 11:28:42 +02:00
2017-11-11 16:03:22 +01:00
$topicmail = " SendExpenseReport " ;
$modelmail = " expensereport " ;
$objecttmp = new ExpenseReport ( $db );
2017-11-15 11:39:11 +01:00
$trackid = 'exp' . $object -> id ;
2017-11-11 16:03:22 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php' ;
2017-09-16 15:39:52 +02:00
2016-09-09 15:36:33 +02:00
if ( $sall )
2015-10-17 01:40:46 +02:00
{
foreach ( $fieldstosearchall as $key => $val ) $fieldstosearchall [ $key ] = $langs -> trans ( $val );
2018-06-22 22:53:53 +02:00
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $sall ) . join ( ', ' , $fieldstosearchall ) . '</div>' ;
2015-10-17 01:40:46 +02:00
}
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
$moreforfilter = '' ;
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
if ( empty ( $reshook )) $moreforfilter .= $hookmanager -> resPrint ;
else $moreforfilter = $hookmanager -> resPrint ;
2017-06-14 11:28:42 +02:00
2016-09-09 15:36:33 +02:00
if ( ! empty ( $moreforfilter ))
{
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
print '</div>' ;
}
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
2017-04-07 14:18:04 +02:00
if ( $massactionbutton ) $selectedfields .= $form -> showCheckAddButtons ( 'checkforselect' , 1 );
2017-06-14 11:28:42 +02:00
2016-11-27 11:41:10 +01:00
print '<div class="div-table-responsive">' ;
2016-09-09 15:36:33 +02:00
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2017-06-14 11:28:42 +02:00
2015-02-23 22:36:26 +01:00
// Filters
2017-04-07 14:18:04 +02:00
print '<tr class="liste_titre_filter">' ;
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.ref' ][ 'checked' ]))
{
print '<td class="liste_titre" align="left">' ;
print '<input class="flat" size="15" type="text" name="search_ref" value="' . $search_ref . '">' ;
print '</td>' ;
}
2015-02-14 18:39:45 +01:00
// User
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'user' ][ 'checked' ]))
2016-06-06 16:31:50 +02:00
{
2016-09-09 15:36:33 +02:00
if ( $user -> rights -> expensereport -> readall || $user -> rights -> expensereport -> lire_tous )
{
print '<td class="liste_titre maxwidthonspartphone" align="left">' ;
2017-06-14 11:28:42 +02:00
print $form -> select_dolusers ( $search_user , 'search_user' , 1 , '' , 0 , '' , '' , 0 , 0 , 0 , '' , 0 , '' , 'maxwidth200' );
2016-09-09 15:36:33 +02:00
print '</td>' ;
} else {
print '<td class="liste_titre"> </td>' ;
}
2015-02-14 18:39:45 +01:00
}
2016-09-09 15:36:33 +02:00
// Date start
if ( ! empty ( $arrayfields [ 'd.date_debut' ][ 'checked' ]))
{
print '<td class="liste_titre" align="center">' ;
2018-06-23 15:10:44 +02:00
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_start" value="' . $month_start . '">' ;
2016-09-09 15:36:33 +02:00
$formother -> select_year ( $year_start , 'year_start' , 1 , $min_year , $max_year );
print '</td>' ;
}
// Date end
if ( ! empty ( $arrayfields [ 'd.date_fin' ][ 'checked' ]))
{
print '<td class="liste_titre" align="center">' ;
2018-06-23 15:10:44 +02:00
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_end" value="' . $month_end . '">' ;
2016-09-09 15:36:33 +02:00
$formother -> select_year ( $year_end , 'year_end' , 1 , $min_year , $max_year );
print '</td>' ;
}
2016-12-22 17:27:58 +01:00
// Date valid
if ( ! empty ( $arrayfields [ 'd.date_valid' ][ 'checked' ]))
{
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>' ;
}
// Date approve
if ( ! empty ( $arrayfields [ 'd.date_approve' ][ 'checked' ]))
{
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>' ;
}
// Amount with no tax
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.total_ht' ][ 'checked' ]))
{
print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_ht" value="' . $search_amount_ht . '"></td>' ;
}
if ( ! empty ( $arrayfields [ 'd.total_vat' ][ 'checked' ]))
{
print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_vat" value="' . $search_amount_vat . '"></td>' ;
}
2015-05-03 08:10:22 +02:00
// Amount with all taxes
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.total_ttc' ][ 'checked' ]))
{
print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_ttc" value="' . $search_amount_ttc . '"></td>' ;
}
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
2016-09-09 15:36:33 +02:00
// Fields from hook
$parameters = array ( 'arrayfields' => $arrayfields );
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Date creation
2017-11-26 00:14:54 +01:00
if ( ! empty ( $arrayfields [ 'd.date_create' ][ 'checked' ]))
2016-09-09 15:36:33 +02:00
{
print '<td class="liste_titre">' ;
print '</td>' ;
}
// Date modification
if ( ! empty ( $arrayfields [ 'd.tms' ][ 'checked' ]))
{
print '<td class="liste_titre">' ;
print '</td>' ;
2017-06-14 11:28:42 +02:00
}
2015-02-14 18:39:45 +01:00
// Status
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.fk_statut' ][ 'checked' ]))
{
print '<td class="liste_titre" align="right">' ;
select_expensereport_statut ( $search_status , 'search_status' , 1 , 1 );
print '</td>' ;
}
// Action column
print '<td class="liste_titre" align="middle">' ;
2017-05-14 21:06:33 +02:00
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
2015-02-14 18:39:45 +01:00
print '</td>' ;
2015-02-23 22:36:26 +01:00
2015-02-14 18:39:45 +01:00
print " </tr> \n " ;
2017-04-07 14:18:04 +02:00
print '<tr class="liste_titre">' ;
if ( ! empty ( $arrayfields [ 'd.ref' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.ref' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.ref " , " " , $param , '' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'user' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'user' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " u.lastname " , " " , $param , '' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.date_debut' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.date_debut' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.date_debut " , " " , $param , 'align="center"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.date_fin' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.date_fin' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.date_fin " , " " , $param , 'align="center"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.date_valid' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.date_valid' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.date_valid " , " " , $param , 'align="center"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.date_approve' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.date_approve' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.date_approve " , " " , $param , 'align="center"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.total_ht' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.total_ht' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.total_ht " , " " , $param , 'align="right"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.total_vat' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.total_vat' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.total_tva " , " " , $param , 'align="right"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.total_ttc' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.total_ttc' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.total_ttc " , " " , $param , 'align="right"' , $sortfield , $sortorder );
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
2017-04-07 14:18:04 +02:00
// Hook fields
2018-04-20 10:38:16 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
2017-04-07 14:18:04 +02:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2017-11-26 00:14:54 +01:00
if ( ! empty ( $arrayfields [ 'd.date_create' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.date_create' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.date_create " , " " , $param , 'align="center" class="nowrap"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.tms' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.tms' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.tms " , " " , $param , 'align="center" class="nowrap"' , $sortfield , $sortorder );
if ( ! empty ( $arrayfields [ 'd.fk_statut' ][ 'checked' ])) print_liste_field_titre ( $arrayfields [ 'd.fk_statut' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " d.fk_statut " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2017-04-07 14:18:04 +02:00
print_liste_field_titre ( $selectedfields , $_SERVER [ " PHP_SELF " ], " " , '' , '' , 'align="center"' , $sortfield , $sortorder , 'maxwidthsearch ' );
2017-06-14 11:28:42 +02:00
print " </tr> \n " ;
2015-02-14 18:39:45 +01:00
$total_total_ht = 0 ;
$total_total_ttc = 0 ;
$total_total_tva = 0 ;
2016-11-28 06:53:34 +01:00
2015-06-29 06:41:24 +02:00
$expensereportstatic = new ExpenseReport ( $db );
2016-09-01 11:29:30 +02:00
$usertmp = new User ( $db );
2016-11-28 06:53:34 +01:00
2016-06-06 16:31:50 +02:00
if ( $num > 0 )
2015-02-14 18:39:45 +01:00
{
2016-09-09 15:36:33 +02:00
$i = 0 ;
$totalarray = array ();
while ( $i < min ( $num , $limit ))
2015-02-14 18:39:45 +01:00
{
2016-09-01 11:29:30 +02:00
$obj = $db -> fetch_object ( $resql );
$expensereportstatic -> id = $obj -> rowid ;
$expensereportstatic -> ref = $obj -> ref ;
$expensereportstatic -> status = $obj -> status ;
2016-12-22 15:54:01 +01:00
$expensereportstatic -> date_debut = $db -> jdate ( $obj -> date_debut );
$expensereportstatic -> date_fin = $db -> jdate ( $obj -> date_fin );
$expensereportstatic -> date_create = $db -> jdate ( $obj -> date_create );
$expensereportstatic -> date_modif = $db -> jdate ( $obj -> date_modif );
2016-12-22 17:27:58 +01:00
$expensereportstatic -> date_valid = $db -> jdate ( $obj -> date_valid );
$expensereportstatic -> date_approve = $db -> jdate ( $obj -> date_approve );
2017-01-02 13:51:05 +01:00
$expensereportstatic -> note_private = $obj -> note_private ;
$expensereportstatic -> note_public = $obj -> note_public ;
2017-06-14 11:28:42 +02:00
2017-04-07 14:18:04 +02:00
print '<tr class="oddeven">' ;
2017-01-02 13:51:05 +01:00
// Ref
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.ref' ][ 'checked' ])) {
print '<td>' ;
2017-01-02 13:51:05 +01:00
print '<table class="nobordernopadding"><tr class="nocellnopadd">' ;
print '<td class="nobordernopadding nowrap">' ;
2016-09-09 15:36:33 +02:00
print $expensereportstatic -> getNomUrl ( 1 );
2017-01-02 13:51:05 +01:00
print '</td>' ;
// Warning late icon and note
print '<td class="nobordernopadding nowrap">' ;
2016-09-09 15:36:33 +02:00
if ( $expensereportstatic -> status == 2 && $expensereportstatic -> hasDelay ( 'toappove' )) print img_warning ( $langs -> trans ( " Late " ));
if ( $expensereportstatic -> status == 5 && $expensereportstatic -> hasDelay ( 'topay' )) print img_warning ( $langs -> trans ( " Late " ));
2017-01-02 13:51:05 +01:00
if ( ! empty ( $obj -> note_private ) || ! empty ( $obj -> note_public ))
{
print ' <span class="note">' ;
2017-02-08 19:18:16 +01:00
print '<a href="' . DOL_URL_ROOT . '/expensereport/note.php?id=' . $obj -> rowid . '">' . img_picto ( $langs -> trans ( " ViewPrivateNote " ), 'object_generic' ) . '</a>' ;
2017-01-02 13:51:05 +01:00
print '</span>' ;
}
print '</td>' ;
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">' ;
$filename = dol_sanitizeFileName ( $obj -> ref );
$filedir = $conf -> expensereport -> dir_output . '/' . dol_sanitizeFileName ( $obj -> ref );
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?id=' . $obj -> rowid ;
2017-01-02 13:52:32 +01:00
print $formfile -> getDocumentsLink ( $expensereportstatic -> element , $filename , $filedir );
2017-01-02 13:51:05 +01:00
print '</td>' ;
print '</tr></table>' ;
2016-09-09 15:36:33 +02:00
print '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2017-01-02 13:51:05 +01:00
// User
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'user' ][ 'checked' ])) {
print '<td align="left">' ;
$usertmp -> id = $obj -> id_user ;
$usertmp -> lastname = $obj -> lastname ;
$usertmp -> firstname = $obj -> firstname ;
$usertmp -> login = $obj -> login ;
$usertmp -> statut = $obj -> statut ;
$usertmp -> photo = $obj -> photo ;
2017-09-16 22:03:25 +02:00
$usertmp -> email = $obj -> email ;
2016-09-09 15:36:33 +02:00
print $usertmp -> getNomUrl ( - 1 );
print '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2017-01-02 13:51:05 +01:00
// Start date
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.date_debut' ][ 'checked' ])) {
2017-10-20 17:02:26 +02:00
print '<td align="center">' . ( $obj -> date_debut > 0 ? dol_print_date ( $db -> jdate ( $obj -> date_debut ), 'day' ) : '' ) . '</td>' ;
2016-09-09 15:36:33 +02:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2017-01-02 13:51:05 +01:00
// End date
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.date_fin' ][ 'checked' ])) {
2017-10-20 17:02:26 +02:00
print '<td align="center">' . ( $obj -> date_fin > 0 ? dol_print_date ( $db -> jdate ( $obj -> date_fin ), 'day' ) : '' ) . '</td>' ;
2016-09-09 15:36:33 +02:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2017-01-02 13:51:05 +01:00
// Date validation
2016-12-22 17:27:58 +01:00
if ( ! empty ( $arrayfields [ 'd.date_valid' ][ 'checked' ])) {
2017-10-20 17:02:26 +02:00
print '<td align="center">' . ( $obj -> date_valid > 0 ? dol_print_date ( $db -> jdate ( $obj -> date_valid ), 'day' ) : '' ) . '</td>' ;
2016-12-22 17:27:58 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2017-01-02 13:51:05 +01:00
// Date approval
2016-12-22 17:27:58 +01:00
if ( ! empty ( $arrayfields [ 'd.date_approve' ][ 'checked' ])) {
2017-10-20 17:02:26 +02:00
print '<td align="center">' . ( $obj -> date_approve > 0 ? dol_print_date ( $db -> jdate ( $obj -> date_approve ), 'day' ) : '' ) . '</td>' ;
2016-12-22 17:27:58 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
// Amount HT
2016-09-09 15:36:33 +02:00
if ( ! empty ( $arrayfields [ 'd.total_ht' ][ 'checked' ]))
{
print '<td align="right">' . price ( $obj -> total_ht ) . " </td> \n " ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
if ( ! $i ) $totalarray [ 'totalhtfield' ] = $totalarray [ 'nbfield' ];
$totalarray [ 'totalht' ] += $obj -> total_ht ;
}
// Amount VAT
if ( ! empty ( $arrayfields [ 'd.total_vat' ][ 'checked' ]))
{
print '<td align="right">' . price ( $obj -> total_tva ) . " </td> \n " ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
if ( ! $i ) $totalarray [ 'totalvatfield' ] = $totalarray [ 'nbfield' ];
$totalarray [ 'totalvat' ] += $obj -> total_tva ;
}
// Amount TTC
if ( ! empty ( $arrayfields [ 'd.total_ttc' ][ 'checked' ]))
{
print '<td align="right">' . price ( $obj -> total_ttc ) . " </td> \n " ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
if ( ! $i ) $totalarray [ 'totalttcfield' ] = $totalarray [ 'nbfield' ];
$totalarray [ 'totalttc' ] += $obj -> total_ttc ;
}
2017-06-14 11:28:42 +02:00
2016-09-09 15:36:33 +02:00
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
2016-09-09 15:36:33 +02:00
// Fields from hook
$parameters = array ( 'arrayfields' => $arrayfields , 'obj' => $obj );
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Date creation
2017-11-26 00:14:54 +01:00
if ( ! empty ( $arrayfields [ 'd.date_create' ][ 'checked' ]))
2016-09-09 15:36:33 +02:00
{
print '<td align="center" class="nowrap">' ;
2016-11-28 06:53:34 +01:00
print dol_print_date ( $db -> jdate ( $obj -> date_create ), 'dayhour' );
2016-09-09 15:36:33 +02:00
print '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
// Date modification
if ( ! empty ( $arrayfields [ 'd.tms' ][ 'checked' ]))
{
print '<td align="center" class="nowrap">' ;
2016-11-28 06:53:34 +01:00
print dol_print_date ( $db -> jdate ( $obj -> date_modif ), 'dayhour' );
2016-09-09 15:36:33 +02:00
print '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
// Status
if ( ! empty ( $arrayfields [ 'd.fk_statut' ][ 'checked' ]))
{
print '<td align="right" class="nowrap">' . $expensereportstatic -> getLibStatut ( 5 ) . '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
// Action column
print '<td class="nowrap" align="center">' ;
if ( $massactionbutton || $massaction ) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
$selected = 0 ;
if ( in_array ( $obj -> rowid , $arrayofselected )) $selected = 1 ;
print '<input id="cb' . $obj -> rowid . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $obj -> rowid . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
}
print '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2015-06-30 13:14:19 +02:00
2015-02-14 18:39:45 +01:00
print " </tr> \n " ;
2016-09-01 11:29:30 +02:00
$total_total_ht = $total_total_ht + $obj -> total_ht ;
$total_total_tva = $total_total_tva + $obj -> total_tva ;
$total_total_ttc = $total_total_ttc + $obj -> total_ttc ;
2015-02-14 18:39:45 +01:00
$i ++ ;
}
2016-09-09 15:36:33 +02:00
}
2015-02-14 18:39:45 +01:00
else
{
2017-06-22 15:22:44 +02:00
$colspan = 1 ;
foreach ( $arrayfields as $key => $val ) { if ( ! empty ( $val [ 'checked' ])) $colspan ++ ; }
print '<tr>' . '<td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</td></tr>' ;
2015-02-14 18:39:45 +01:00
}
2016-09-09 15:36:33 +02:00
// Show total line
if ( isset ( $totalarray [ 'totalhtfield' ]))
{
print '<tr class="liste_total">' ;
$i = 0 ;
while ( $i < $totalarray [ 'nbfield' ])
{
$i ++ ;
if ( $i == 1 )
{
2017-05-10 11:57:59 +02:00
if ( $num < $limit && empty ( $offset )) print '<td align="left">' . $langs -> trans ( " Total " ) . '</td>' ;
2016-09-09 15:36:33 +02:00
else print '<td align="left">' . $langs -> trans ( " Totalforthispage " ) . '</td>' ;
}
elseif ( $totalarray [ 'totalhtfield' ] == $i ) print '<td align="right">' . price ( $totalarray [ 'totalht' ]) . '</td>' ;
elseif ( $totalarray [ 'totalvatfield' ] == $i ) print '<td align="right">' . price ( $totalarray [ 'totalvat' ]) . '</td>' ;
elseif ( $totalarray [ 'totalttcfield' ] == $i ) print '<td align="right">' . price ( $totalarray [ 'totalttc' ]) . '</td>' ;
else print '<td></td>' ;
}
print '</tr>' ;
}
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
$db -> free ( $resql );
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'sql' => $sql );
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
print '</table>' . " \n " ;
2016-11-27 11:41:10 +01:00
print '</div>' ;
2016-11-28 06:53:34 +01:00
2016-09-09 15:36:33 +02:00
print '</form>' . " \n " ;
2016-11-28 06:53:34 +01:00
2017-10-19 20:56:23 +02:00
if ( empty ( $id ))
2016-09-09 15:36:33 +02:00
{
2018-02-21 11:02:45 +01:00
$hidegeneratedfilelistifempty = 1 ;
if ( $massaction == 'builddoc' || $action == 'remove_file' || $show_files ) $hidegeneratedfilelistifempty = 0 ;
2017-06-14 11:28:42 +02:00
2018-02-21 11:02:45 +01:00
// Show list of available documents
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder ;
$urlsource .= str_replace ( '&' , '&' , $param );
2017-06-14 11:28:42 +02:00
2018-02-21 11:02:45 +01:00
$filedir = $diroutputmassaction ;
$genallowed = $user -> rights -> expensereport -> lire ;
$delallowed = $user -> rights -> expensereport -> creer ;
print $formfile -> showdocuments ( 'massfilesarea_expensereport' , '' , $filedir , $urlsource , 0 , $delallowed , '' , 1 , 1 , 0 , 48 , 1 , $param , $title , '' , '' , '' , null , $hidegeneratedfilelistifempty );
2016-09-09 15:36:33 +02:00
}
2015-02-14 18:39:45 +01:00
}
else
{
dol_print_error ( $db );
}
llxFooter ();
$db -> close ();