2016-10-24 07:16:26 +02:00
< ? php
/* Copyright ( C ) 2013 - 2014 Olivier Geffroy < jeff @ jeffinfo . com >
2022-02-25 04:55:55 +01:00
* Copyright ( C ) 2013 - 2022 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2016-10-24 07:16:26 +02:00
* Copyright ( C ) 2014 - 2015 Ari Elbaz ( elarifr ) < github @ accedinfo . com >
* Copyright ( C ) 2013 - 2014 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es > s
* Copyright ( C ) 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2016-10-24 07:16:26 +02:00
*/
/**
2016-10-27 06:04:23 +02:00
* \file htdocs / accountancy / expensereport / list . php
2019-05-13 22:25:15 +02:00
* \ingroup Accountancy ( Double entries )
2016-10-27 06:04:23 +02:00
* \brief Ventilation page from expense reports
2016-10-24 07:16:26 +02:00
*/
require '../../main.inc.php' ;
2019-11-12 09:46:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
2020-05-19 09:36:07 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2019-11-12 09:46:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php' ;
2022-02-25 04:55:55 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2019-11-12 09:46:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2016-10-24 07:16:26 +02:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2020-05-19 09:36:07 +02:00
$langs -> loadLangs ( array ( " bills " , " companies " , " compta " , " accountancy " , " other " , " trips " , " productbatch " , " hrm " ));
2016-10-24 07:16:26 +02:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-11-12 09:46:08 +01:00
$massaction = GETPOST ( 'massaction' , 'alpha' );
$show_files = GETPOST ( 'show_files' , 'int' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2016-11-17 19:04:10 +01:00
$toselect = GETPOST ( 'toselect' , 'array' );
2020-09-25 10:27:30 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'expensereportlist' ; // To manage different context of search
2020-04-30 19:51:24 +02:00
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
2020-04-30 19:41:46 +02:00
2016-10-24 07:16:26 +02:00
// Select Box
2016-11-17 19:16:37 +01:00
$mesCasesCochees = GETPOST ( 'toselect' , 'array' );
2016-10-24 07:16:26 +02:00
// Search Getpost
2020-05-19 09:36:07 +02:00
$search_login = GETPOST ( 'search_login' , 'alpha' );
2019-12-16 12:38:51 +01:00
$search_lineid = GETPOST ( 'search_lineid' , 'alpha' );
2016-10-27 06:04:23 +02:00
$search_expensereport = GETPOST ( 'search_expensereport' , 'alpha' );
2016-10-24 07:16:26 +02:00
$search_label = GETPOST ( 'search_label' , 'alpha' );
$search_desc = GETPOST ( 'search_desc' , 'alpha' );
$search_amount = GETPOST ( 'search_amount' , 'alpha' );
$search_account = GETPOST ( 'search_account' , 'alpha' );
$search_vat = GETPOST ( 'search_vat' , 'alpha' );
2022-02-25 04:55:55 +01:00
$search_date_startday = GETPOST ( 'search_date_startday' , 'int' );
$search_date_startmonth = GETPOST ( 'search_date_startmonth' , 'int' );
$search_date_startyear = GETPOST ( 'search_date_startyear' , 'int' );
$search_date_endday = GETPOST ( 'search_date_endday' , 'int' );
$search_date_endmonth = GETPOST ( 'search_date_endmonth' , 'int' );
$search_date_endyear = GETPOST ( 'search_date_endyear' , 'int' );
$search_date_start = dol_mktime ( 0 , 0 , 0 , $search_date_startmonth , $search_date_startday , $search_date_startyear ); // Use tzserver
$search_date_end = dol_mktime ( 23 , 59 , 59 , $search_date_endmonth , $search_date_endday , $search_date_endyear );
2017-09-12 13:48:45 +02:00
2016-10-24 07:16:26 +02:00
// Load variable for pagination
2019-11-12 09:46:08 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : ( empty ( $conf -> global -> ACCOUNTING_LIMIT_LIST_VENTILATION ) ? $conf -> liste_limit : $conf -> global -> ACCOUNTING_LIMIT_LIST_VENTILATION );
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-22 21:36:42 +01:00
if ( empty ( $page ) || $page < 0 ) {
$page = 0 ;
}
2016-10-24 07:16:26 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-22 21:36:42 +01:00
if ( ! $sortfield ) {
2016-11-16 18:00:37 +01:00
$sortfield = " erd.date, erd.rowid " ;
2021-02-22 21:36:42 +01:00
}
2019-11-12 09:46:08 +01:00
if ( ! $sortorder ) {
2016-10-24 07:16:26 +02:00
if ( $conf -> global -> ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0 ) {
$sortorder = " DESC " ;
}
}
2022-02-25 04:55:55 +01:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'accountancyexpensereportlist' ));
2021-03-18 14:34:44 +01:00
$formaccounting = new FormAccounting ( $db );
$accounting = new AccountingAccount ( $db );
$chartaccountcode = dol_getIdFromCode ( $db , $conf -> global -> CHARTOFACCOUNTS , 'accounting_system' , 'rowid' , 'pcg_version' );
2016-10-24 07:16:26 +02:00
// Security check
2022-08-24 10:44:52 +02:00
if ( ! isModEnabled ( 'accounting' )) {
2021-03-18 14:34:44 +01:00
accessforbidden ();
}
2021-02-22 21:36:42 +01:00
if ( $user -> socid > 0 ) {
2016-10-24 07:16:26 +02:00
accessforbidden ();
2021-02-22 21:36:42 +01:00
}
2021-03-18 14:34:44 +01:00
if ( empty ( $user -> rights -> accounting -> mouvements -> lire )) {
2016-10-24 07:16:26 +02:00
accessforbidden ();
2021-02-22 21:36:42 +01:00
}
2016-10-24 07:16:26 +02:00
2016-11-17 19:16:37 +01:00
2016-10-24 07:16:26 +02:00
/*
2022-02-25 04:55:55 +01:00
* Actions
2016-10-24 07:16:26 +02:00
*/
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
$action = 'list' ; $massaction = '' ;
}
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) {
$massaction = '' ;
}
2016-11-17 19:16:37 +01:00
2022-02-25 04:55:55 +01:00
$parameters = array ();
$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' );
2016-10-24 07:16:26 +02:00
}
2022-02-25 04:55:55 +01:00
if ( empty ( $reshook )) {
// Purge search criteria
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All test are required to be compatible with all browsers
$search_login = '' ;
$search_expensereport = '' ;
$search_label = '' ;
$search_desc = '' ;
$search_amount = '' ;
$search_account = '' ;
$search_vat = '' ;
$search_date_startday = '' ;
$search_date_startmonth = '' ;
$search_date_startyear = '' ;
$search_date_endday = '' ;
$search_date_endmonth = '' ;
$search_date_endyear = '' ;
$search_date_start = '' ;
$search_date_end = '' ;
$search_country = '' ;
$search_tvaintra = '' ;
}
2022-02-25 19:39:34 +01:00
// Mass actions
2022-02-25 04:55:55 +01:00
$objectclass = 'ExpenseReport' ;
$objectlabel = 'ExpenseReport' ;
2022-06-12 22:39:25 +02:00
$permissiontoread = $user -> hasRight ( 'accounting' , 'read' );
$permissiontodelete = $user -> hasRight ( 'accounting' , 'delete' );
2022-02-25 04:55:55 +01:00
$uploaddir = $conf -> expensereport -> dir_output ;
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
2016-10-24 07:16:26 +02:00
}
2016-11-17 19:16:37 +01:00
2021-03-18 14:34:44 +01:00
if ( $massaction == 'ventil' && $user -> rights -> accounting -> bind -> write ) {
2019-11-12 09:46:08 +01:00
$msg = '' ;
2022-02-25 04:55:55 +01:00
2020-09-28 06:44:01 +02:00
//print '<div><span style="color:red">' . $langs->trans("Processing") . '...</span></div>';
2020-09-07 10:18:17 +02:00
if ( ! empty ( $mesCasesCochees )) {
$msg = '<div>' . $langs -> trans ( " SelectedLines " ) . ': ' . count ( $mesCasesCochees ) . '</div>' ;
$msg .= '<div class="detail">' ;
$cpt = 0 ;
$ok = 0 ;
$ko = 0 ;
foreach ( $mesCasesCochees as $maLigneCochee ) {
$maLigneCourante = explode ( " _ " , $maLigneCochee );
$monId = $maLigneCourante [ 0 ];
$monCompte = GETPOST ( 'codeventil' . $monId );
2021-02-22 21:36:42 +01:00
if ( $monCompte <= 0 ) {
2020-09-28 06:44:01 +02:00
$msg .= '<div><span style="color:red">' . $langs -> trans ( " Lineofinvoice " ) . ' ' . $monId . ' - ' . $langs -> trans ( " NoAccountSelected " ) . '</span></div>' ;
2020-09-07 10:18:17 +02:00
$ko ++ ;
} else {
$sql = " UPDATE " . MAIN_DB_PREFIX . " expensereport_det " ;
2021-03-30 03:37:54 +02:00
$sql .= " SET fk_code_ventilation = " . (( int ) $monCompte );
2021-03-30 17:53:25 +02:00
$sql .= " WHERE rowid = " . (( int ) $monId );
2020-09-07 10:18:17 +02:00
$accountventilated = new AccountingAccount ( $db );
2020-09-28 06:44:01 +02:00
$accountventilated -> fetch ( $monCompte , '' , 1 );
2020-09-07 10:18:17 +02:00
2022-02-25 04:55:55 +01:00
dol_syslog ( 'accountancy/expensereport/list.php:: sql=' . $sql , LOG_DEBUG );
2020-09-07 10:18:17 +02:00
if ( $db -> query ( $sql )) {
2020-09-28 06:44:01 +02:00
$msg .= '<div><span style="color:green">' . $langs -> trans ( " LineOfExpenseReport " ) . ' ' . $monId . ' - ' . $langs -> trans ( " VentilatedinAccount " ) . ' : ' . length_accountg ( $accountventilated -> account_number ) . '</span></div>' ;
2020-09-07 10:18:17 +02:00
$ok ++ ;
} else {
2021-04-19 21:30:25 +02:00
$msg .= '<div><span style="color:red">' . $langs -> trans ( " ErrorDB " ) . ' : ' . $langs -> trans ( " Lineofinvoice " ) . ' ' . $monId . ' - ' . $langs -> trans ( " NotVentilatedinAccount " ) . ' : ' . length_accountg ( $accountventilated -> account_number ) . '<br> <pre>' . $sql . '</pre></span></div>' ;
2020-09-07 10:18:17 +02:00
$ko ++ ;
}
}
$cpt ++ ;
}
$msg .= '</div>' ;
$msg .= '<div>' . $langs -> trans ( " EndProcessing " ) . '</div>' ;
}
2016-10-24 07:16:26 +02:00
}
/*
* View
*/
2016-11-17 19:04:10 +01:00
$form = new Form ( $db );
2017-09-12 13:48:45 +02:00
$formother = new FormOther ( $db );
2016-11-17 19:04:10 +01:00
2016-10-27 06:04:23 +02:00
llxHeader ( '' , $langs -> trans ( " ExpenseReportsVentilation " ));
2021-02-22 21:36:42 +01:00
if ( empty ( $chartaccountcode )) {
2017-11-27 21:53:22 +01:00
print $langs -> trans ( " ErrorChartOfAccountSystemNotSelected " );
2018-07-28 14:29:28 +02:00
// End of page
2020-09-07 10:18:17 +02:00
llxFooter ();
$db -> close ();
2017-11-27 21:53:22 +01:00
exit ;
}
2016-10-27 06:04:23 +02:00
// Expense report lines
2020-04-30 19:51:24 +02:00
$sql = " SELECT er.ref, er.rowid as erid, er.date_debut, er.date_valid, " ;
2019-11-12 09:46:08 +01:00
$sql .= " erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht as price, erd.fk_code_ventilation, erd.tva_tx as tva_tx_line, erd.vat_src_code, erd.date, " ;
$sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label, f.accountancy_code as code_buy, " ;
2020-10-16 11:57:36 +02:00
$sql .= " u.rowid as userid, u.login, u.lastname, u.firstname, u.email, u.gender, u.employee, u.photo, u.statut, " ;
2019-11-12 09:46:08 +01:00
$sql .= " aa.rowid as aarowid " ;
2022-02-25 04:55:55 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2019-11-12 09:46:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as er " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " expensereport_det as erd ON er.rowid = erd.fk_expensereport " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_type_fees as f ON f.id = erd.fk_c_type_fees " ;
2020-05-19 09:36:07 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u ON u.rowid = er.fk_user_author " ;
2020-09-19 20:11:04 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " accounting_account as aa ON f.accountancy_code = aa.account_number AND aa.fk_pcg_version = ' " . $db -> escape ( $chartaccountcode ) . " ' AND aa.entity = " . $conf -> entity ;
2019-11-12 09:46:08 +01:00
$sql .= " WHERE er.fk_statut IN ( " . ExpenseReport :: STATUS_APPROVED . " , " . ExpenseReport :: STATUS_CLOSED . " ) AND erd.fk_code_ventilation <= 0 " ;
2020-08-17 15:27:05 +02:00
// Define begin binding date
if ( ! empty ( $conf -> global -> ACCOUNTING_DATE_START_BINDING )) {
$sql .= " AND er.date_debut >= ' " . $db -> idate ( $conf -> global -> ACCOUNTING_DATE_START_BINDING ) . " ' " ;
}
2016-10-24 07:16:26 +02:00
// Add search filter like
2020-05-19 09:36:07 +02:00
if ( strlen ( trim ( $search_login ))) {
2020-09-07 10:18:17 +02:00
$sql .= natural_search ( " u.login " , $search_login );
2020-05-19 09:36:07 +02:00
}
2016-10-27 06:04:23 +02:00
if ( strlen ( trim ( $search_expensereport ))) {
2020-09-07 10:18:17 +02:00
$sql .= natural_search ( " er.ref " , $search_expensereport );
2016-10-24 07:16:26 +02:00
}
if ( strlen ( trim ( $search_label ))) {
2020-09-07 10:18:17 +02:00
$sql .= natural_search ( " f.label " , $search_label );
2016-10-24 07:16:26 +02:00
}
if ( strlen ( trim ( $search_desc ))) {
2020-09-07 10:18:17 +02:00
$sql .= natural_search ( " erd.comments " , $search_desc );
2016-10-24 07:16:26 +02:00
}
if ( strlen ( trim ( $search_amount ))) {
2020-09-07 10:18:17 +02:00
$sql .= natural_search ( " erd.total_ht " , $search_amount , 1 );
2016-10-24 07:16:26 +02:00
}
if ( strlen ( trim ( $search_account ))) {
2020-09-07 10:18:17 +02:00
$sql .= natural_search ( " aa.account_number " , $search_account );
2016-10-24 07:16:26 +02:00
}
if ( strlen ( trim ( $search_vat ))) {
2020-09-07 10:18:17 +02:00
$sql .= natural_search ( " erd.tva_tx " , $search_vat , 1 );
2016-10-24 07:16:26 +02:00
}
2022-02-25 04:55:55 +01:00
if ( $search_date_start ) {
$sql .= " AND erd.date >= ' " . $db -> idate ( $search_date_start ) . " ' " ;
}
if ( $search_date_end ) {
$sql .= " AND erd.date <= ' " . $db -> idate ( $search_date_end ) . " ' " ;
}
2019-11-12 09:46:08 +01:00
$sql .= " AND er.entity IN ( " . getEntity ( 'expensereport' , 0 ) . " ) " ; // We don't share object for accountancy
2016-10-24 07:16:26 +02:00
2022-02-25 04:55:55 +01: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 ;
2016-10-24 07:16:26 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
// Count total nb of records
2017-01-15 20:49:20 +01:00
$nbtotalofrecords = '' ;
2021-02-22 21:36:42 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2020-09-07 10:18:17 +02:00
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
2021-02-22 21:36:42 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2020-09-07 10:18:17 +02:00
$page = 0 ;
$offset = 0 ;
}
2016-10-24 07:16:26 +02:00
}
$sql .= $db -> plimit ( $limit + 1 , $offset );
2022-02-25 04:55:55 +01:00
dol_syslog ( " accountancy/expensereport/list.php " , LOG_DEBUG );
// MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso)
// This big SELECT command may exceed the MAX_JOIN_SIZE limit => Therefore we use SQL_BIG_SELECTS=1 to disable the MAX_JOIN_SIZE security
if ( $db -> type == 'mysqli' ) {
$db -> query ( " SET SQL_BIG_SELECTS=1 " );
}
2016-10-24 07:16:26 +02:00
$result = $db -> query ( $sql );
if ( $result ) {
$num_lines = $db -> num_rows ( $result );
$i = 0 ;
2019-11-12 09:46:08 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
$param = '' ;
2021-02-22 21:36:42 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $search_login ) {
$param .= '&search_login=' . urlencode ( $search_login );
}
if ( $search_lineid ) {
$param .= '&search_lineid=' . urlencode ( $search_lineid );
}
2022-02-25 04:55:55 +01:00
if ( $search_date_startday ) {
$param .= '&search_date_startday=' . urlencode ( $search_date_startday );
}
if ( $search_date_startmonth ) {
$param .= '&search_date_startmonth=' . urlencode ( $search_date_startmonth );
}
if ( $search_date_startyear ) {
$param .= '&search_date_startyear=' . urlencode ( $search_date_startyear );
2021-02-22 21:36:42 +01:00
}
2022-02-25 04:55:55 +01:00
if ( $search_date_endday ) {
$param .= '&search_date_endday=' . urlencode ( $search_date_endday );
2021-02-22 21:36:42 +01:00
}
2022-02-25 04:55:55 +01:00
if ( $search_date_endmonth ) {
$param .= '&search_date_endmonth=' . urlencode ( $search_date_endmonth );
}
if ( $search_date_endyear ) {
$param .= '&search_date_endyear=' . urlencode ( $search_date_endyear );
2021-02-22 21:36:42 +01:00
}
if ( $search_expensereport ) {
$param .= '&search_expensereport=' . urlencode ( $search_expensereport );
}
if ( $search_label ) {
$param .= '&search_label=' . urlencode ( $search_label );
}
if ( $search_desc ) {
$param .= '&search_desc=' . urlencode ( $search_desc );
}
if ( $search_amount ) {
$param .= '&search_amount=' . urlencode ( $search_amount );
}
if ( $search_vat ) {
$param .= '&search_vat=' . urlencode ( $search_vat );
}
2019-11-12 09:46:08 +01:00
$arrayofmassactions = array (
2021-04-14 14:45:55 +02:00
'ventil' => img_picto ( '' , 'check' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Ventilate " )
2016-11-17 19:16:37 +01:00
);
2019-11-12 09:46:08 +01:00
$massactionbutton = $form -> selectMassAction ( 'ventil' , $arrayofmassactions , 1 );
2017-06-22 14:48:13 +02:00
2019-11-12 09:46:08 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' . " \n " ;
2016-10-24 07:16:26 +02:00
print '<input type="hidden" name="action" value="ventil">' ;
2021-02-22 21:36:42 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2016-10-24 07:16:26 +02:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-06-22 14:48:13 +02:00
2016-11-17 19:16:37 +01:00
print_barre_liste ( $langs -> trans ( " ExpenseReportLines " ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num_lines , $nbtotalofrecords , 'title_accountancy' , 0 , '' , '' , $limit );
2016-10-24 07:16:26 +02:00
2019-11-12 09:46:08 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( " DescVentilTodoExpenseReport " ) . '</span></br><br>' ;
2016-10-27 06:04:23 +02:00
2022-06-12 22:33:58 +02:00
if ( ! empty ( $msg )) {
2021-02-22 21:36:42 +01:00
print $msg . '<br>' ;
}
2016-11-17 19:16:37 +01:00
2016-10-27 06:04:23 +02:00
$moreforfilter = '' ;
2020-09-07 10:18:17 +02:00
print '<div class="div-table-responsive">' ;
2019-11-12 09:46:08 +01:00
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2016-10-24 07:16:26 +02:00
2016-11-17 19:16:37 +01:00
// We add search filter
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre_filter">' ;
2020-09-07 10:18:17 +02:00
print '<td class="liste_titre"><input type="text" name="search_login" class="maxwidth50" value="' . $search_login . '"></td>' ;
2016-11-07 12:04:47 +01:00
print '<td class="liste_titre"></td>' ;
2019-11-12 09:46:08 +01:00
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_expensereport" value="' . dol_escape_htmltag ( $search_expensereport ) . '"></td>' ;
2020-09-08 21:27:28 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE )) {
2020-04-30 19:51:24 +02:00
print '<td class="liste_titre"></td>' ;
}
2022-02-25 04:55:55 +01:00
print '<td class="liste_titre center">' ;
print '<div class="nowrap">' ;
print $form -> selectDate ( $search_date_start ? $search_date_start : - 1 , 'search_date_start' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( 'From' ));
print '</div>' ;
print '<div class="nowrap">' ;
print $form -> selectDate ( $search_date_end ? $search_date_end : - 1 , 'search_date_end' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( 'to' ));
print '</div>' ;
2017-09-12 13:48:45 +02:00
print '</td>' ;
2019-11-12 09:46:08 +01:00
print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag ( $search_label ) . '"></td>' ;
print '<td class="liste_titre"><input type="text" class="flat maxwidthonsmartphone" name="search_desc" value="' . dol_escape_htmltag ( $search_desc ) . '"></td>' ;
2022-02-25 04:55:55 +01:00
print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="' . dol_escape_htmltag ( $search_amount ) . '"></td>' ;
print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" size="1" value="' . dol_escape_htmltag ( $search_vat ) . '"></td>' ;
2016-10-24 07:16:26 +02:00
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
2022-02-25 04:55:55 +01:00
print '<td class="center liste_titre">' ;
2019-11-12 09:46:08 +01:00
$searchpicto = $form -> showFilterButtons ();
2016-10-27 06:04:23 +02:00
print $searchpicto ;
2016-10-24 07:16:26 +02:00
print '</td>' ;
print '</tr>' ;
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre">' ;
2020-09-07 10:18:17 +02:00
print_liste_field_titre ( " Employee " , $_SERVER [ 'PHP_SELF' ], " u.login " , $param , " " , " " , $sortfield , $sortorder );
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " LineId " , $_SERVER [ " PHP_SELF " ], " erd.rowid " , " " , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " ExpenseReport " , $_SERVER [ " PHP_SELF " ], " er.ref " , " " , $param , '' , $sortfield , $sortorder );
2020-09-08 21:27:28 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE )) {
2020-04-30 19:51:24 +02:00
print_liste_field_titre ( " DateValidation " , $_SERVER [ " PHP_SELF " ], " er.date_valid " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
}
2020-04-30 19:41:46 +02:00
print_liste_field_titre ( " DateOfLine " , $_SERVER [ " PHP_SELF " ], " erd.date, erd.rowid " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " TypeFees " , $_SERVER [ " PHP_SELF " ], " f.label " , " " , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Description " , $_SERVER [ " PHP_SELF " ], " erd.comments " , " " , $param , '' , $sortfield , $sortorder );
2019-06-12 12:47:35 +02:00
print_liste_field_titre ( " Amount " , $_SERVER [ " PHP_SELF " ], " erd.total_ht " , " " , $param , '' , $sortfield , $sortorder , 'right maxwidth50 ' );
2019-03-03 10:31:46 +01:00
print_liste_field_titre ( " VATRate " , $_SERVER [ " PHP_SELF " ], " erd.tva_tx " , " " , $param , '' , $sortfield , $sortorder , 'right ' );
2020-03-14 02:17:08 +01:00
print_liste_field_titre ( " AccountAccountingSuggest " , '' , '' , '' , '' , '' , '' , '' , 'nowraponall ' );
print_liste_field_titre ( " IntoAccount " , '' , '' , '' , '' , '' , '' , '' , '' );
2019-11-12 09:46:08 +01:00
$checkpicto = '' ;
2021-02-22 21:36:42 +01:00
if ( $massactionbutton ) {
$checkpicto = $form -> showCheckAddButtons ( 'checkforselect' , 1 );
}
2019-03-03 10:31:46 +01:00
print_liste_field_titre ( $checkpicto , '' , '' , '' , '' , '' , '' , '' , 'center ' );
2017-04-01 12:46:47 +02:00
print " </tr> \n " ;
2017-06-22 14:48:13 +02:00
2016-10-27 06:04:23 +02:00
$expensereport_static = new ExpenseReport ( $db );
2020-05-19 09:36:07 +02:00
$userstatic = new User ( $db );
2016-10-24 07:16:26 +02:00
$form = new Form ( $db );
2019-11-12 09:46:08 +01:00
while ( $i < min ( $num_lines , $limit )) {
2016-10-24 07:16:26 +02:00
$objp = $db -> fetch_object ( $result );
$objp -> aarowid_suggest = '' ;
$objp -> aarowid_suggest = $objp -> aarowid ;
2016-10-27 06:04:23 +02:00
2016-11-16 18:00:37 +01:00
$expensereport_static -> ref = $objp -> ref ;
$expensereport_static -> id = $objp -> erid ;
2017-03-26 05:48:31 +02:00
2020-10-16 11:57:36 +02:00
$userstatic -> id = $objp -> userid ;
2020-09-07 10:18:17 +02:00
$userstatic -> ref = $objp -> label ;
$userstatic -> login = $objp -> login ;
$userstatic -> statut = $objp -> statut ;
$userstatic -> email = $objp -> email ;
$userstatic -> gender = $objp -> gender ;
$userstatic -> firstname = $objp -> firstname ;
$userstatic -> lastname = $objp -> lastname ;
$userstatic -> employee = $objp -> employee ;
$userstatic -> photo = $objp -> photo ;
print '<tr class="oddeven">' ;
// Login
print '<td class="nowraponall">' ;
print $userstatic -> getNomUrl ( - 1 , '' , 0 , 0 , 24 , 1 , 'login' , '' , 1 );
print '</td>' ;
2016-10-24 07:16:26 +02:00
2016-11-07 12:04:47 +01:00
// Line id
2019-11-12 09:46:08 +01:00
print '<td>' . $objp -> rowid . '</td>' ;
2016-11-07 12:04:47 +01:00
2016-10-27 06:04:23 +02:00
// Ref Expense report
2019-11-12 09:46:08 +01:00
print '<td>' . $expensereport_static -> getNomUrl ( 1 ) . '</td>' ;
2016-10-24 07:16:26 +02:00
2020-04-30 19:51:24 +02:00
// Date validation
2020-09-08 21:27:28 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE )) {
2020-04-30 19:51:24 +02:00
print '<td class="center">' . dol_print_date ( $db -> jdate ( $objp -> date_valid ), 'day' ) . '</td>' ;
}
2017-09-12 13:48:45 +02:00
// Date
2019-11-12 09:46:08 +01:00
print '<td class="center">' . dol_print_date ( $db -> jdate ( $objp -> date ), 'day' ) . '</td>' ;
2017-03-26 05:48:31 +02:00
2016-10-27 06:04:23 +02:00
// Fees label
2016-10-24 07:16:26 +02:00
print '<td>' ;
2017-03-26 06:20:05 +02:00
print ( $langs -> trans ( $objp -> type_fees_code ) == $objp -> type_fees_code ? $objp -> type_fees_label : $langs -> trans (( $objp -> type_fees_code )));
2016-10-24 07:16:26 +02:00
print '</td>' ;
2016-10-27 06:04:23 +02:00
// Fees description -- Can be null
2016-11-16 19:23:32 +01:00
print '<td>' ;
2022-03-16 21:22:03 +01:00
$text = dolGetFirstLineOfText ( dol_string_nohtmltag ( $objp -> comments , 1 ));
2017-06-22 14:48:13 +02:00
$trunclength = empty ( $conf -> global -> ACCOUNTING_LENGTH_DESCRIPTION ) ? 32 : $conf -> global -> ACCOUNTING_LENGTH_DESCRIPTION ;
2019-01-27 11:55:16 +01:00
print $form -> textwithtooltip ( dol_trunc ( $text , $trunclength ), $objp -> comments );
2016-11-16 19:23:32 +01:00
print '</td>' ;
2016-10-24 07:16:26 +02:00
2020-09-07 10:18:17 +02:00
// Amount without taxes
2021-06-13 06:37:44 +02:00
print '<td class="right nowraponall amount">' ;
2016-10-24 07:16:26 +02:00
print price ( $objp -> price );
print '</td>' ;
// Vat rate
2019-01-21 21:19:42 +01:00
print '<td class="right">' ;
2019-11-12 09:46:08 +01:00
print vatrate ( $objp -> tva_tx_line . ( $objp -> vat_src_code ? ' (' . $objp -> vat_src_code . ')' : '' ));
2016-10-24 07:16:26 +02:00
print '</td>' ;
2016-11-17 19:16:37 +01:00
// Current account
2020-03-13 18:51:58 +01:00
print '<td>' ;
2016-10-27 06:04:23 +02:00
print length_accountg ( html_entity_decode ( $objp -> code_buy ));
2016-10-24 07:16:26 +02:00
print '</td>' ;
2016-11-17 19:16:37 +01:00
// Suggested accounting account
2020-03-14 02:17:08 +01:00
print '<td>' ;
2017-11-27 15:51:28 +01:00
print $formaccounting -> select_account ( $objp -> aarowid_suggest , 'codeventil' . $objp -> rowid , 1 , array (), 0 , 0 , 'codeventil maxwidth300 maxwidthonsmartphone' , 'cachewithshowemptyone' );
2016-10-24 07:16:26 +02:00
print '</td>' ;
2016-10-27 06:04:23 +02:00
2019-03-03 10:31:46 +01:00
print '<td class="center">' ;
2019-11-12 09:46:08 +01:00
print '<input type="checkbox" class="flat checkforselect checkforselect' . $objp -> rowid . '" name="toselect[]" value="' . $objp -> rowid . " _ " . $i . '"' . ( $objp -> aarowid ? " checked " : " " ) . '/>' ;
2016-10-24 07:16:26 +02:00
print '</td>' ;
print " </tr> " ;
2019-11-12 09:46:08 +01:00
$i ++ ;
2016-10-24 07:16:26 +02:00
}
print '</table>' ;
2016-11-27 11:41:10 +01:00
print " </div> " ;
2017-06-22 14:48:13 +02:00
2016-10-24 07:16:26 +02:00
print '</form>' ;
} else {
print $db -> error ();
}
2022-02-25 04:55:55 +01:00
if ( $db -> type == 'mysqli' ) {
$db -> query ( " SET SQL_BIG_SELECTS=0 " ); // Enable MAX_JOIN_SIZE limitation
}
2016-10-24 07:16:26 +02:00
2017-11-27 15:51:28 +01:00
// Add code to auto check the box when we select an account
2021-11-29 15:09:18 +01:00
print ' < script type = " text/javascript " >
2017-11-27 15:51:28 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( " .codeventil " ) . change ( function () {
var s = $ ( this ) . attr ( " id " ) . replace ( " codeventil " , " " )
console . log ( s + " " + $ ( this ) . val ());
if ( $ ( this ) . val () == - 1 ) jQuery ( " .checkforselect " + s ) . prop ( " checked " , false );
else jQuery ( " .checkforselect " + s ) . prop ( " checked " , true );
});
});
</ script > ' ;
2018-07-28 14:29:28 +02:00
// End of page
2016-10-24 07:16:26 +02:00
llxFooter ();
$db -> close ();