2014-03-06 21:21:16 +01:00
< ? php
2022-06-20 04:24:32 +02:00
/* Copyright ( C ) 2011 - 2022 Alexandre Spangaro < aspangaro @ open - dsi . fr >
* Copyright ( C ) 2015 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
* Copyright ( C ) 2021 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2014-03-06 21:21:16 +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
* 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 />.
2014-03-06 21:21:16 +01:00
*/
/**
2019-07-19 23:08:24 +02:00
* \file htdocs / salaries / list . php
2014-03-25 21:35:52 +01:00
* \ingroup salaries
* \brief List of salaries payments
2014-03-06 21:21:16 +01:00
*/
2019-07-19 23:08:24 +02:00
require '../main.inc.php' ;
2021-02-05 11:12:55 +01:00
require_once DOL_DOCUMENT_ROOT . '/salaries/class/paymentsalary.class.php' ;
2016-08-11 18:41:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2022-08-29 10:53:11 +02:00
if ( isModEnabled ( 'accounting' )) {
2020-12-29 21:44:41 +01:00
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
}
2014-03-06 21:21:16 +01:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2019-12-16 13:06:25 +01:00
$langs -> loadLangs ( array ( " compta " , " salaries " , " bills " , " hrm " ));
2014-03-06 21:21:16 +01:00
2020-12-03 10:13:13 +01:00
$action = GETPOST ( 'action' , 'aZ09' ) ? GETPOST ( 'action' , 'aZ09' ) : 'view' ; // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST ( 'massaction' , 'alpha' ); // The bulk action (combo box choice into lists)
$show_files = GETPOST ( 'show_files' , 'int' ); // Show files area generated by bulk actions ?
$confirm = GETPOST ( 'confirm' , 'alpha' ); // Result of a confirmation
$cancel = GETPOST ( 'cancel' , 'alpha' ); // We click on a Cancel button
$toselect = GETPOST ( 'toselect' , 'array' ); // Array of ids of elements selected into a list
2022-07-07 17:14:21 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : str_replace ( '_' , '' , basename ( dirname ( __FILE__ )) . basename ( __FILE__ , '.php' )); // To manage different context of search
2020-12-03 10:13:13 +01:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
// Load variable for pagination
2019-12-16 13:06:25 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-12-03 10:13:13 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2020-12-29 21:44:41 +01:00
if ( empty ( $page ) || $page == - 1 || GETPOST ( 'button_search' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' ) || ( empty ( $toselect ) && $massaction === '0' )) {
$page = 0 ;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
2020-12-03 10:13:13 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2020-12-29 21:44:41 +01:00
if ( ! $sortfield ) {
$sortfield = " s.datep,s.rowid " ;
}
if ( ! $sortorder ) {
$sortorder = " DESC,DESC " ;
}
2020-12-03 10:13:13 +01:00
// Initialize technical objects
$object = new PaymentSalary ( $db );
$extrafields = new ExtraFields ( $db );
$diroutputmassaction = $conf -> user -> dir_output . '/temp/massgeneration/' . $user -> id ;
$hookmanager -> initHooks ( array ( 'salarieslist' )); // Note that conf->hooks_modules contains array
// Fetch optionals attributes and labels
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
$search_array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element , '' , 'search_' );
2020-12-29 21:44:41 +01:00
if ( ! $sortfield ) {
$sortfield = " s.datep,s.rowid " ;
}
if ( ! $sortorder ) {
$sortorder = " DESC,DESC " ;
}
2020-12-03 10:13:13 +01:00
2019-01-27 11:55:16 +01:00
$search_ref = GETPOST ( 'search_ref' , 'int' );
$search_user = GETPOST ( 'search_user' , 'alpha' );
$search_label = GETPOST ( 'search_label' , 'alpha' );
2021-02-04 17:21:08 +01:00
$search_date_start_from = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_date_start_frommonth' , 'int' ), GETPOST ( 'search_date_start_fromday' , 'int' ), GETPOST ( 'search_date_start_fromyear' , 'int' ));
$search_date_start_to = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_date_start_tomonth' , 'int' ), GETPOST ( 'search_date_start_today' , 'int' ), GETPOST ( 'search_date_start_toyear' , 'int' ));
$search_date_end_from = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_date_end_frommonth' , 'int' ), GETPOST ( 'search_date_end_fromday' , 'int' ), GETPOST ( 'search_date_end_fromyear' , 'int' ));
$search_date_end_to = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_date_end_tomonth' , 'int' ), GETPOST ( 'search_date_end_today' , 'int' ), GETPOST ( 'search_date_end_toyear' , 'int' ));
2019-01-27 11:55:16 +01:00
$search_amount = GETPOST ( 'search_amount' , 'alpha' );
$search_account = GETPOST ( 'search_account' , 'int' );
2021-02-04 17:21:08 +01:00
$search_status = GETPOST ( 'search_status' , 'int' );
2022-06-20 04:24:32 +02:00
$search_type_id = GETPOST ( 'search_type_id' , 'int' );
2016-08-11 18:41:31 +02:00
2020-09-18 01:29:17 +02:00
$filtre = GETPOST ( " filtre " , 'restricthtml' );
2014-05-01 08:58:19 +02:00
2020-11-13 09:55:53 +01:00
$childids = $user -> getAllChildIds ( 1 );
2020-12-03 10:13:13 +01:00
// Initialize array of search criterias
$search_all = GETPOST ( " search_all " , 'alpha' );
$search = array ();
2020-12-29 21:44:41 +01:00
foreach ( $object -> fields as $key => $val ) {
if ( GETPOST ( 'search_' . $key , 'alpha' ) !== '' ) {
$search [ $key ] = GETPOST ( 'search_' . $key , 'alpha' );
}
2021-03-04 21:43:01 +01:00
if ( preg_match ( '/^(date|timestamp|datetime)/' , $val [ 'type' ])) {
$search [ $key . '_dtstart' ] = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_' . $key . '_dtstartmonth' , 'int' ), GETPOST ( 'search_' . $key . '_dtstartday' , 'int' ), GETPOST ( 'search_' . $key . '_dtstartyear' , 'int' ));
$search [ $key . '_dtend' ] = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_' . $key . '_dtendmonth' , 'int' ), GETPOST ( 'search_' . $key . '_dtendday' , 'int' ), GETPOST ( 'search_' . $key . '_dtendyear' , 'int' ));
}
2020-12-03 10:13:13 +01:00
}
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array ();
2020-12-29 21:44:41 +01:00
foreach ( $object -> fields as $key => $val ) {
2021-06-14 01:55:58 +02:00
if ( ! empty ( $val [ 'searchall' ])) {
2020-12-29 21:44:41 +01:00
$fieldstosearchall [ 't.' . $key ] = $val [ 'label' ];
}
2020-12-03 10:13:13 +01:00
}
2021-03-04 21:43:01 +01:00
// Definition of array of fields for columns
$arrayfields = array ();
foreach ( $object -> fields as $key => $val ) {
// If $val['visible']==0, then we never show the field
if ( ! empty ( $val [ 'visible' ])) {
2022-03-01 16:38:06 +01:00
$visible = ( int ) dol_eval ( $val [ 'visible' ], 1 , 1 , '1' );
2021-03-04 21:43:01 +01:00
$arrayfields [ 't.' . $key ] = array (
'label' => $val [ 'label' ],
'checked' => (( $visible < 0 ) ? 0 : 1 ),
2022-03-01 16:38:06 +01:00
'enabled' => ( $visible != 3 && dol_eval ( $val [ 'enabled' ], 1 , 1 , '1' )),
2021-03-04 21:43:01 +01:00
'position' => $val [ 'position' ],
2021-07-05 14:51:34 +02:00
'help' => isset ( $val [ 'help' ]) ? $val [ 'help' ] : ''
2021-03-04 21:43:01 +01:00
);
}
}
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php' ;
$object -> fields = dol_sort_array ( $object -> fields , 'position' );
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
2020-12-03 10:13:13 +01:00
$permissiontoread = $user -> rights -> salaries -> read ;
$permissiontoadd = $user -> rights -> salaries -> write ;
$permissiontodelete = $user -> rights -> salaries -> delete ;
2017-07-01 02:22:08 +02:00
2021-04-02 23:23:44 +02:00
// Security check
$socid = GETPOST ( " socid " , " int " );
if ( $user -> socid ) {
$socid = $user -> socid ;
}
restrictedArea ( $user , 'salaries' , '' , 'salary' , '' );
2017-07-01 02:22:08 +02:00
/*
* Actions
*/
2020-12-29 21:44:41 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
2020-12-29 21:48:53 +01:00
$action = 'list' ;
$massaction = '' ;
2020-12-29 21:44:41 +01:00
}
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) {
$massaction = '' ;
}
2020-12-03 10:13:13 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2020-12-29 21:44:41 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-12-03 10:13:13 +01:00
2020-12-29 21:44:41 +01:00
if ( empty ( $reshook )) {
2020-12-03 10:13:13 +01:00
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
2014-11-01 14:59:39 +01:00
2020-12-03 10:13:13 +01:00
// Purge search criteria
2020-12-29 21:44:41 +01:00
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
2020-12-03 10:13:13 +01:00
$search_ref = " " ;
$search_user = " " ;
$search_label = " " ;
2021-02-05 09:29:20 +01:00
$search_date_start_from = '' ;
$search_date_start_to = '' ;
$search_date_end_from = '' ;
$search_date_end_to = '' ;
2020-12-03 10:13:13 +01:00
$search_date_end = '' ;
$search_amount = " " ;
$search_account = '' ;
2021-02-05 09:29:20 +01:00
$search_status = '' ;
2020-12-03 10:13:13 +01:00
$search_type_id = " " ;
}
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )
2020-12-29 21:44:41 +01:00
|| GETPOST ( 'button_search_x' , 'alpha' ) || GETPOST ( 'button_search.x' , 'alpha' ) || GETPOST ( 'button_search' , 'alpha' )) {
2020-12-03 10:13:13 +01:00
$massaction = '' ; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
// Mass actions
$objectclass = 'PaymentSalary' ;
$objectlabel = 'SalariesPayments' ;
2020-12-21 14:43:23 +01:00
$uploaddir = $conf -> salaries -> dir_output ;
2020-12-03 10:13:13 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
// Validate records
2020-12-29 21:44:41 +01:00
if ( ! $error && $massaction == 'buildsepa' && $permissiontoadd ) {
2020-12-03 10:13:13 +01:00
$objecttmp = new $objectclass ( $db );
// TODO
}
}
2017-07-01 02:22:08 +02:00
2014-03-06 21:21:16 +01:00
/*
* View
*/
2014-05-01 08:58:19 +02:00
$form = new Form ( $db );
2021-02-04 17:21:08 +01:00
$salstatic = new Salary ( $db );
2014-03-06 21:21:16 +01:00
$userstatic = new User ( $db );
2016-08-11 18:41:31 +02:00
$accountstatic = new Account ( $db );
2014-03-17 14:30:55 +01:00
2020-12-03 10:13:13 +01:00
$now = dol_now ();
//$help_url="EN:Module_BillOfMaterials|FR:Module_BillOfMaterials_FR|ES:Módulo_BillOfMaterials";
$help_url = '' ;
2021-02-05 09:29:20 +01:00
$title = $langs -> trans ( 'Salaries' );
2020-12-03 10:13:13 +01:00
2017-12-18 11:55:34 +01:00
$sql = " SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.admin, u.salary as current_salary, u.fk_soc as fk_soc, u.statut as status, " ;
2021-03-25 10:39:12 +01:00
$sql .= " s.rowid, s.fk_account, s.paye, s.fk_user, s.amount, s.salary, s.label, s.datesp, s.dateep, s.fk_typepayment as paymenttype, " ;
2021-03-29 16:22:22 +02:00
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos, " ;
2021-02-04 17:21:08 +01:00
$sql .= " pst.code as payment_code, " ;
$sql .= " SUM(ps.amount) as alreadypayed " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " salary as s " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " payment_salary as ps ON (ps.fk_salary = s.rowid) " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as pst ON (s.fk_typepayment = pst.id) " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " bank_account ba ON (ba.rowid = s.fk_account), " ;
//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_salary as ps ON ps.fk_salary = s.rowid, ";
2019-12-16 13:06:25 +01:00
$sql .= " " . MAIN_DB_PREFIX . " user as u " ;
$sql .= " WHERE u.rowid = s.fk_user " ;
2020-12-03 00:40:41 +01:00
$sql .= " AND s.entity IN ( " . getEntity ( 'payment_salaries' ) . " ) " ;
2020-12-29 21:44:41 +01:00
if ( empty ( $user -> rights -> salaries -> readall )) {
2021-03-22 11:30:18 +01:00
$sql .= " AND s.fk_user IN ( " . $db -> sanitize ( join ( ',' , $childids )) . " ) " ;
2020-12-29 21:44:41 +01:00
}
2014-11-01 14:59:39 +01:00
// Search criteria
2020-12-29 21:44:41 +01:00
if ( $search_ref ) {
$sql .= " AND s.rowid= " . (( int ) $search_ref );
}
if ( $search_user ) {
$sql .= natural_search ( array ( 'u.login' , 'u.lastname' , 'u.firstname' , 'u.email' ), $search_user );
}
if ( $search_label ) {
$sql .= natural_search ( array ( 's.label' ), $search_label );
}
2022-03-23 13:01:24 +01:00
if ( ! empty ( $search_date_start_from )) {
$sql .= " AND s.datesp >= ' " . $db -> idate ( $search_date_start_from ) . " ' " ;
2020-12-29 21:44:41 +01:00
}
2022-03-23 13:01:24 +01:00
if ( ! empty ( $search_date_end_from )) {
$sql .= " AND s.dateep >= ' " . $db -> idate ( $search_date_end_from ) . " ' " ;
2020-12-29 21:44:41 +01:00
}
2022-03-23 13:01:24 +01:00
if ( ! empty ( $search_date_start_to )) {
$sql .= " AND s.datesp <= ' " . $db -> idate ( $search_date_start_to ) . " ' " ;
}
if ( ! empty ( $search_date_end_to )) {
$sql .= " AND s.dateep <= ' " . $db -> idate ( $search_date_end_to ) . " ' " ;
}
2020-12-29 21:44:41 +01:00
if ( $search_amount ) {
$sql .= natural_search ( " s.amount " , $search_amount , 1 );
}
if ( $search_account > 0 ) {
2021-03-29 16:22:22 +02:00
$sql .= " AND s.fk_account= " . (( int ) $search_account );
2020-12-29 21:44:41 +01:00
}
2021-02-05 09:29:20 +01:00
if ( $search_status != '' && $search_status >= 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND s.paye = " . (( int ) $search_status );
2021-02-05 09:29:20 +01:00
}
2020-12-03 10:13:13 +01:00
if ( $search_type_id ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND s.fk_typepayment= " . (( int ) $search_type_id );
2014-05-01 08:58:19 +02:00
}
2021-03-04 18:57:03 +01:00
$sql .= " GROUP BY u.rowid, u.lastname, u.firstname, u.login, u.email, u.admin, u.salary, u.fk_soc, u.statut, " ;
2021-03-25 10:39:12 +01:00
$sql .= " s.rowid, s.fk_account, s.paye, s.fk_user, s.amount, s.salary, s.label, s.datesp, s.dateep, s.fk_typepayment, s.fk_bank, " ;
2021-03-29 16:22:22 +02:00
$sql .= " ba.rowid, ba.ref, ba.number, ba.account_number, ba.fk_accountancy_journal, ba.label, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, " ;
2021-03-04 18:57:03 +01:00
$sql .= " pst.code " ;
2019-12-16 13:06:25 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2016-02-16 17:43:05 +01:00
2020-12-03 10:13:13 +01:00
// Count total nb of records
$nbtotalofrecords = '' ;
2020-12-29 21:44:41 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2020-12-03 10:13:13 +01:00
$resql = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $resql );
2020-12-29 21:44:41 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total of record found is smaller than page * limit, goto and load page 0
2020-12-03 10:13:13 +01:00
$page = 0 ;
$offset = 0 ;
}
2015-12-28 00:20:48 +01:00
}
2020-12-03 10:13:13 +01:00
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
2020-12-29 21:44:41 +01:00
if ( is_numeric ( $nbtotalofrecords ) && ( $limit > $nbtotalofrecords || empty ( $limit ))) {
2020-12-03 10:13:13 +01:00
$num = $nbtotalofrecords ;
} else {
2020-12-29 21:44:41 +01:00
if ( $limit ) {
$sql .= $db -> plimit ( $limit + 1 , $offset );
}
2020-12-03 10:13:13 +01:00
$resql = $db -> query ( $sql );
2020-12-29 21:44:41 +01:00
if ( ! $resql ) {
2020-12-03 10:13:13 +01:00
dol_print_error ( $db );
exit ;
}
2014-03-06 21:21:16 +01:00
2020-12-03 10:13:13 +01:00
$num = $db -> num_rows ( $resql );
}
2020-04-20 14:53:17 +02:00
2020-12-03 10:13:13 +01:00
// Output page
// --------------------------------------------------------------------
llxHeader ( '' , $title , $help_url );
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
$param = '' ;
2020-12-29 21:44:41 +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_type_id ) {
$param .= '&search_type_id=' . urlencode ( $search_type_id );
}
if ( $optioncss != '' ) {
$param .= '&optioncss=' . urlencode ( $optioncss );
}
if ( $search_ref ) {
$param .= '&search_ref=' . urlencode ( $search_ref );
}
if ( $search_user > 0 ) {
$param .= '&search_user=' . urlencode ( $search_user );
}
if ( $search_label ) {
$param .= '&search_label=' . urlencode ( $search_label );
}
if ( $search_account ) {
$param .= '&search_account=' . urlencode ( $search_account );
}
2021-02-05 09:29:20 +01:00
if ( $search_status != '' && $search_status != '-1' ) {
$param .= '&search_status=' . urlencode ( $search_status );
}
if ( ! empty ( $search_date_start_from )) {
$param .= '&search_date_start_fromday=' . urlencode ( GETPOST ( 'search_date_start_fromday' )) . '&search_date_start_frommonth=' . urlencode ( GETPOST ( 'search_date_start_frommonth' )) . '&search_date_start_fromyear=' . urlencode ( GETPOST ( 'search_date_start_fromyear' ));
}
if ( ! empty ( $search_date_start_to )) {
$param .= " &search_date_start_today= " . urlencode ( GETPOST ( 'search_date_start_today' )) . " &search_date_start_tomonth= " . urlencode ( GETPOST ( 'search_date_start_tomonth' )) . " &search_date_start_toyear= " . urlencode ( GETPOST ( 'search_date_start_toyear' ));
}
if ( ! empty ( $search_date_end_from )) {
$param .= '&search_date_end_fromday=' . urlencode ( GETPOST ( 'search_date_end_fromday' )) . '&search_date_end_frommonth=' . urlencode ( GETPOST ( 'search_date_end_frommonth' )) . '&search_date_end_fromyear=' . urlencode ( GETPOST ( 'search_date_end_fromyear' ));
2020-12-29 21:44:41 +01:00
}
2021-02-05 09:29:20 +01:00
if ( ! empty ( $search_date_end_to )) {
$param .= " &search_date_end_today= " . urlencode ( GETPOST ( 'search_date_end_today' )) . " &search_date_end_tomonth= " . urlencode ( GETPOST ( 'search_date_end_tomonth' )) . " &search_date_end_toyear= " . urlencode ( GETPOST ( 'search_date_end_toyear' ));
2020-12-29 21:44:41 +01:00
}
2021-02-04 17:21:08 +01:00
2020-12-03 10:13:13 +01:00
// Add $param from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
// List of mass actions available
$arrayofmassactions = array (
2021-04-14 12:28:01 +02:00
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
//'buildsepa'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("BuildSepa"), // TODO
2020-12-03 10:13:13 +01:00
);
2021-04-14 14:45:55 +02:00
//if ($permissiontodelete) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
2020-12-29 21:44:41 +01:00
if ( GETPOST ( 'nomassaction' , 'int' ) || in_array ( $massaction , array ( 'presend' , 'predelete' ))) {
$arrayofmassactions = array ();
}
2020-12-03 10:13:13 +01:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2020-12-29 21:44:41 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2020-12-03 10:13:13 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
$url = DOL_URL_ROOT . '/salaries/card.php?action=create' ;
2020-12-29 21:44:41 +01:00
if ( ! empty ( $socid )) {
$url .= '&socid=' . $socid ;
}
2020-12-03 10:13:13 +01:00
$newcardbutton = dolGetButtonTitle ( $langs -> trans ( 'NewSalaryPayment' ), '' , 'fa fa-plus-circle' , $url , '' , $user -> rights -> salaries -> write );
2021-02-04 20:44:38 +01:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'salary' , 0 , $newcardbutton , '' , $limit , 0 , 0 , 1 );
2020-12-03 10:13:13 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
//$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
$selectedfields = '' ;
$selectedfields .= ( count ( $arrayofmassactions ) ? $form -> showCheckAddButtons ( 'checkforselect' , 1 ) : '' );
2021-02-04 20:44:38 +01:00
$moreforfilter = '' ;
2020-12-03 10:13:13 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable nobottomiftotal liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
// Fields title search
// --------------------------------------------------------------------
print '<tr class="liste_titre_filter">' ;
// Ref
print '<td class="liste_titre left">' ;
print '<input class="flat" type="text" size="3" name="search_ref" value="' . $db -> escape ( $search_ref ) . '">' ;
print '</td>' ;
2021-03-26 10:23:44 +01:00
// Label
print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="' . $db -> escape ( $search_label ) . '"></td>' ;
2021-02-05 09:29:20 +01:00
// Date start
2020-12-03 10:13:13 +01:00
print '<td class="liste_titre center">' ;
print '<div class="nowrap">' ;
2021-03-04 18:57:03 +01:00
print $form -> selectDate ( $search_date_start_from ? $search_date_start_from : - 1 , 'search_date_start_from' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( 'From' ));
2020-12-03 10:13:13 +01:00
print '</div>' ;
print '<div class="nowrap">' ;
2021-03-04 18:57:03 +01:00
print $form -> selectDate ( $search_date_start_to ? $search_date_start_to : - 1 , 'search_date_start_to' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( 'to' ));
2020-12-03 10:13:13 +01:00
print '</div>' ;
print '</td>' ;
2021-02-05 09:29:20 +01:00
// Date End
2020-12-21 14:54:20 +01:00
print '<td class="liste_titre center">' ;
2021-02-05 09:29:20 +01:00
print '<div class="nowrap">' ;
2021-03-04 18:57:03 +01:00
print $form -> selectDate ( $search_date_end_from ? $search_date_end_from : - 1 , 'search_date_end_from' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( 'From' ));
2021-02-05 09:29:20 +01:00
print '</div>' ;
print '<div class="nowrap">' ;
2021-03-04 18:57:03 +01:00
print $form -> selectDate ( $search_date_end_to ? $search_date_end_to : - 1 , 'search_date_end_to' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( 'to' ));
2021-02-05 09:29:20 +01:00
print '</div>' ;
2020-12-21 14:54:20 +01:00
print '</td>' ;
2021-02-05 09:29:20 +01:00
2021-03-26 16:14:00 +01:00
// Employee
print '<td class="liste_titre">' ;
print '<input class="flat" type="text" size="6" name="search_user" value="' . $db -> escape ( $search_user ) . '">' ;
print '</td>' ;
2020-12-03 10:13:13 +01:00
// Type
2021-03-29 16:22:22 +02:00
print '<td class="liste_titre left">' ;
2020-12-03 10:13:13 +01:00
$form -> select_types_paiements ( $search_type_id , 'search_type_id' , '' , 0 , 1 , 1 , 16 );
print '</td>' ;
2021-03-04 18:57:03 +01:00
// Bank account
2022-08-29 10:53:11 +02:00
if ( isModEnabled ( 'banque' )) {
2015-05-13 08:57:00 +02:00
print '<td class="liste_titre">' ;
2020-12-03 10:13:13 +01:00
$form -> select_comptes ( $search_account , 'search_account' , 0 , '' , 1 );
2019-11-07 08:44:09 +01:00
print '</td>' ;
2021-03-29 16:22:22 +02:00
}
2021-03-04 18:57:03 +01:00
2020-12-03 10:13:13 +01:00
// Amount
print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="' . $db -> escape ( $search_amount ) . '"></td>' ;
2021-02-05 09:29:20 +01:00
print '<td class="liste_titre maxwidthonsmartphone right">' ;
$liststatus = array ( '0' => $langs -> trans ( " Unpaid " ), '1' => $langs -> trans ( " Paid " ));
print $form -> selectarray ( 'search_status' , $liststatus , $search_status , 1 );
print '</td>' ;
2020-12-03 10:13:13 +01:00
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
// Fields from hook
$parameters = array ( 'arrayfields' => $arrayfields );
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters , $object ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Action column
print '<td class="liste_titre maxwidthsearch">' ;
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
print '</td>' ;
print '</tr>' . " \n " ;
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">' ;
print_liste_field_titre ( " Ref " , $_SERVER [ " PHP_SELF " ], " s.rowid " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Label " , $_SERVER [ " PHP_SELF " ], " s.label " , " " , $param , 'class="left"' , $sortfield , $sortorder );
2021-03-04 17:57:08 +01:00
print_liste_field_titre ( " DateStart " , $_SERVER [ " PHP_SELF " ], " s.datesp,s.rowid " , " " , $param , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( " DateEnd " , $_SERVER [ " PHP_SELF " ], " s.dateep,s.rowid " , " " , $param , 'align="center"' , $sortfield , $sortorder );
2021-03-26 16:14:00 +01:00
print_liste_field_titre ( " Employee " , $_SERVER [ " PHP_SELF " ], " u.lastname " , " " , $param , " " , $sortfield , $sortorder );
2021-03-29 16:22:22 +02:00
print_liste_field_titre ( " DefaultPaymentMode " , $_SERVER [ " PHP_SELF " ], " type " , " " , $param , 'class="left"' , $sortfield , $sortorder );
2022-08-29 10:53:11 +02:00
if ( isModEnabled ( 'banque' )) {
2021-03-04 18:57:03 +01:00
print_liste_field_titre ( " DefaultBankAccount " , $_SERVER [ " PHP_SELF " ], " ba.label " , " " , $param , " " , $sortfield , $sortorder );
2021-03-29 16:22:22 +02:00
}
2021-02-05 09:29:20 +01:00
print_liste_field_titre ( " Amount " , $_SERVER [ " PHP_SELF " ], " s.amount " , " " , $param , 'class="right"' , $sortfield , $sortorder );
print_liste_field_titre ( 'Status' , $_SERVER [ " PHP_SELF " ], " s.paye " , '' , $param , 'class="right"' , $sortfield , $sortorder );
2020-12-03 10:13:13 +01:00
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
// Hook fields
$parameters = array ( 'arrayfields' => $arrayfields , 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Action column
print getTitleFieldOfList ( $selectedfields , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' , $sortfield , $sortorder , 'center maxwidthsearch ' ) . " \n " ;
print '</tr>' . " \n " ;
// Detect if we need a fetch on each output line
$needToFetchEachLine = 0 ;
2022-04-30 19:50:20 +02:00
if ( isset ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && is_array ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) > 0 ) {
2020-12-29 21:44:41 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ] as $key => $val ) {
if ( preg_match ( '/\$object/' , $val )) {
$needToFetchEachLine ++ ; // There is at least one compute field that use $object
}
2020-10-31 14:32:18 +01:00
}
2020-12-03 10:13:13 +01:00
}
2017-06-09 09:25:15 +02:00
2020-12-03 10:13:13 +01:00
// Loop on record
// --------------------------------------------------------------------
$i = 0 ;
$total = 0 ;
$totalarray = array ();
2022-06-20 04:24:32 +02:00
$totalarray [ 'nbfield' ] = 0 ;
$totalarray [ 'val' ] = array ();
$totalarray [ 'val' ][ 'totalttcfield' ] = 0 ;
2020-12-29 21:44:41 +01:00
while ( $i < ( $limit ? min ( $num , $limit ) : $num )) {
2020-12-03 10:13:13 +01:00
$obj = $db -> fetch_object ( $resql );
2020-12-29 21:44:41 +01:00
if ( empty ( $obj )) {
break ; // Should not happen
}
2014-05-10 18:57:04 +02:00
2020-12-03 10:13:13 +01:00
// Store properties in $object
$object -> setVarsFromFetchObj ( $obj );
2017-06-09 09:25:15 +02:00
2020-12-03 10:13:13 +01:00
$userstatic -> id = $obj -> uid ;
$userstatic -> lastname = $obj -> lastname ;
$userstatic -> firstname = $obj -> firstname ;
$userstatic -> admin = $obj -> admin ;
$userstatic -> login = $obj -> login ;
$userstatic -> email = $obj -> email ;
$userstatic -> socid = $obj -> fk_soc ;
$userstatic -> statut = $obj -> status ;
2015-05-13 08:57:00 +02:00
2020-12-03 10:13:13 +01:00
$salstatic -> id = $obj -> rowid ;
$salstatic -> ref = $obj -> rowid ;
2021-04-18 16:43:09 +02:00
$salstatic -> label = $obj -> label ;
$salstatic -> paye = $obj -> paye ;
$salstatic -> datesp = $db -> jdate ( $obj -> datesp );
$salstatic -> dateep = $db -> jdate ( $obj -> dateep );
2018-11-08 10:04:25 +01:00
2021-02-04 20:44:38 +01:00
// Show here line of result
print '<tr class="oddeven">' ;
2020-12-03 10:13:13 +01:00
// Ref
print " <td> " . $salstatic -> getNomUrl ( 1 ) . " </td> \n " ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2019-11-27 02:45:43 +01:00
2021-03-26 10:23:44 +01:00
// Label payment
print " <td> " . dol_trunc ( $obj -> label , 40 ) . " </td> \n " ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2019-11-27 02:45:43 +01:00
2021-02-05 09:29:20 +01:00
// Date Start
print '<td class="center">' . dol_print_date ( $db -> jdate ( $obj -> datesp ), 'day' ) . " </td> \n " ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2019-11-27 02:45:43 +01:00
2021-02-05 09:29:20 +01:00
// Date End
print '<td class="center">' . dol_print_date ( $db -> jdate ( $obj -> dateep ), 'day' ) . " </td> \n " ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-12-21 14:54:20 +01:00
2021-03-26 16:14:00 +01:00
// Employee
print " <td> " . $userstatic -> getNomUrl ( 1 ) . " </td> \n " ;
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-12-03 10:13:13 +01:00
// Type
2021-03-29 16:22:22 +02:00
print '<td>' ;
2021-03-29 16:25:36 +02:00
if ( ! empty ( $obj -> payment_code )) print $langs -> trans ( " PaymentTypeShort " . $obj -> payment_code );
2021-03-29 16:22:22 +02:00
print '</td>' ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2019-11-27 02:45:43 +01:00
2020-12-03 10:13:13 +01:00
// Account
2022-08-29 10:53:11 +02:00
if ( isModEnabled ( 'banque' )) {
2020-12-03 10:13:13 +01:00
print '<td>' ;
2021-02-05 09:29:20 +01:00
if ( $obj -> fk_account > 0 ) {
2020-12-03 10:13:13 +01:00
//$accountstatic->fetch($obj->fk_bank);
$accountstatic -> id = $obj -> bid ;
$accountstatic -> ref = $obj -> bref ;
2021-03-25 11:59:22 +01:00
$accountstatic -> label = $obj -> blabel ;
2020-12-03 10:13:13 +01:00
$accountstatic -> number = $obj -> bnumber ;
2021-03-25 11:59:22 +01:00
$accountstatic -> iban = $obj -> iban ;
$accountstatic -> bic = $obj -> bic ;
$accountstatic -> currency_code = $langs -> trans ( " Currency " . $obj -> currency_code );
$accountstatic -> account_number = $obj -> account_number ;
2021-03-29 16:22:22 +02:00
$accountstatic -> clos = $obj -> clos ;
2020-12-03 10:13:13 +01:00
2022-08-29 10:53:11 +02:00
if ( isModEnabled ( 'accounting' )) {
2020-12-03 10:13:13 +01:00
$accountstatic -> account_number = $obj -> account_number ;
2019-11-27 02:45:43 +01:00
2020-12-03 10:13:13 +01:00
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $obj -> fk_accountancy_journal );
2014-03-06 21:21:16 +01:00
2020-12-03 10:13:13 +01:00
$accountstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
}
2021-02-05 09:29:20 +01:00
//$accountstatic->label = $obj->blabel;
2020-12-03 10:13:13 +01:00
print $accountstatic -> getNomUrl ( 1 );
2020-12-29 21:44:41 +01:00
} else {
print ' ' ;
}
2020-12-03 10:13:13 +01:00
print '</td>' ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2021-03-29 16:22:22 +02:00
}
2019-11-27 02:45:43 +01:00
2021-02-05 13:08:05 +01:00
// if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield';
2017-06-09 09:25:15 +02:00
2020-12-03 10:13:13 +01:00
// Amount
2021-03-29 13:00:17 +02:00
print '<td class="nowrap right"><span class="amount">' . price ( $obj -> amount ) . '</span></td>' ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
if ( ! $i ) {
$totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 'totalttcfield' ;
}
2020-12-03 10:13:13 +01:00
$totalarray [ 'val' ][ 'totalttcfield' ] += $obj -> amount ;
2021-02-05 11:12:55 +01:00
print '<td class="nowrap right">' . $salstatic -> LibStatut ( $obj -> paye , 5 , $obj -> alreadypayed ) . '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2020-12-03 10:13:13 +01:00
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
// Fields from hook
$parameters = array ( 'arrayfields' => $arrayfields , 'object' => $object , 'obj' => $obj , 'i' => $i , 'totalarray' =>& $totalarray );
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $object ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Action column
print '<td class="nowrap center">' ;
2020-12-29 21:44:41 +01:00
if ( $massactionbutton || $massaction ) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2020-12-03 10:13:13 +01:00
$selected = 0 ;
2020-12-29 21:44:41 +01:00
if ( in_array ( $object -> id , $arrayofselected )) {
$selected = 1 ;
}
2020-12-03 10:13:13 +01:00
print '<input id="cb' . $object -> id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object -> id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
2020-10-31 14:32:18 +01:00
}
2020-12-03 10:13:13 +01:00
print '</td>' ;
2020-12-29 21:44:41 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2016-08-29 21:21:10 +02:00
2020-12-03 10:13:13 +01:00
print '</tr>' . " \n " ;
2014-03-06 21:21:16 +01:00
2020-12-03 10:13:13 +01:00
$i ++ ;
}
2014-05-10 18:57:04 +02:00
2020-12-03 10:13:13 +01:00
// Show total line
include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php' ;
// If no record found
2020-12-29 21:44:41 +01:00
if ( $num == 0 ) {
2021-03-04 21:43:01 +01:00
/* $colspan = 1 ;
2020-12-29 21:44:41 +01:00
foreach ( $arrayfields as $key => $val ) {
if ( ! empty ( $val [ 'checked' ])) {
$colspan ++ ;
}
2021-03-04 21:43:01 +01:00
} */
$colspan = 9 ;
2022-08-29 10:53:11 +02:00
if ( isModEnabled ( 'banque' )) { $colspan ++ ; }
2020-12-03 10:13:13 +01:00
print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</td></tr>' ;
2014-03-06 21:21:16 +01:00
}
2020-12-03 10:13:13 +01:00
$db -> free ( $resql );
$parameters = array ( 'arrayfields' => $arrayfields , 'sql' => $sql );
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters , $object ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
print '</table>' . " \n " ;
print '</div>' . " \n " ;
print '</form>' . " \n " ;
2018-08-08 12:29:36 +02:00
// End of page
2014-03-06 21:21:16 +01:00
llxFooter ();
2014-08-28 15:07:33 +02:00
$db -> close ();