2014-03-06 21:21:16 +01:00
< ? php
2016-08-29 21:14:11 +02:00
/* Copyright ( C ) 2011 - 2016 Alexandre Spangaro < aspangaro . dolibarr @ gmail . com >
* Copyright ( C ) 2015 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . 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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
2018-11-08 10:04:25 +01:00
* \file htdocs / compta / 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
*/
require '../../main.inc.php' ;
2014-03-11 06:26:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/salaries/class/paymentsalary.class.php' ;
2016-08-11 18:41:31 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2017-05-14 08:07:34 +02:00
if ( ! empty ( $conf -> accounting -> enabled )) 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
2018-04-28 19:54:41 +02:00
$langs -> loadLangs ( array ( " compta " , " salaries " , " bills " , " hrm " ));
2014-03-06 21:21:16 +01:00
// Security check
2014-05-10 18:57:04 +02:00
$socid = GETPOST ( " socid " , " int " );
2014-03-06 21:21:16 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2014-05-10 18:57:04 +02:00
$result = restrictedArea ( $user , 'salaries' , '' , '' , '' );
2014-03-06 21:21:16 +01:00
2018-04-21 12:16:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2014-11-01 14:59:39 +01:00
$search_ref = GETPOST ( 'search_ref' , 'int' );
2015-05-13 08:57:00 +02:00
$search_user = GETPOST ( 'search_user' , 'alpha' );
2014-11-01 14:59:39 +01:00
$search_label = GETPOST ( 'search_label' , 'alpha' );
$search_amount = GETPOST ( 'search_amount' , 'alpha' );
2016-08-11 18:41:31 +02:00
$search_account = GETPOST ( 'search_account' , 'int' );
2014-05-01 08:58:19 +02: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
2014-05-01 08:58:19 +02:00
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2018-04-28 19:54:41 +02:00
if ( ! $sortfield ) $sortfield = " s.datep,s.rowid " ;
if ( ! $sortorder ) $sortorder = " DESC,DESC " ;
2015-10-04 11:30:28 +02:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2014-05-01 08:58:19 +02:00
$filtre = $_GET [ " filtre " ];
if ( empty ( $_REQUEST [ 'typeid' ]))
{
$newfiltre = str_replace ( 'filtre=' , '' , $filtre );
$filterarray = explode ( '-' , $newfiltre );
foreach ( $filterarray as $val )
{
$part = explode ( ':' , $val );
if ( $part [ 0 ] == 's.fk_typepayment' ) $typeid = $part [ 1 ];
}
}
else
{
$typeid = $_REQUEST [ 'typeid' ];
}
2014-03-06 21:21:16 +01:00
2017-07-01 02:22:08 +02:00
/*
* Actions
*/
2017-07-13 00:35:10 +02: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
2014-11-01 14:59:39 +01:00
{
$search_ref = " " ;
$search_label = " " ;
$search_amount = " " ;
2016-08-11 18:41:31 +02:00
$search_account = '' ;
2014-11-01 14:59:39 +01:00
$typeid = " " ;
}
2017-07-01 02:22:08 +02:00
2014-03-06 21:21:16 +01:00
/*
* View
*/
2017-04-01 12:46:47 +02:00
llxHeader ( '' , $langs -> trans ( " Salaries " ));
2014-03-06 21:21:16 +01:00
2014-05-01 08:58:19 +02:00
$form = new Form ( $db );
2014-03-11 06:26:18 +01:00
$salstatic = new PaymentSalary ( $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
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, " ;
2016-08-11 18:41:31 +02:00
$sql .= " s.rowid, s.fk_user, s.amount, s.salary, s.label, s.datep as datep, s.datev as datev, s.fk_typepayment as type, s.num_payment, s.fk_bank, " ;
2017-05-14 08:07:34 +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, " ;
2014-08-28 15:07:33 +02:00
$sql .= " pst.code as payment_code " ;
2014-03-25 21:35:52 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_salary as s " ;
2018-03-07 17:32:57 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as pst ON s.fk_typepayment = pst.id " ;
2016-08-11 18:41:31 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " bank as b ON s.fk_bank = b.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " bank_account as ba ON b.fk_account = ba.rowid, " ;
2014-03-25 21:35:52 +01:00
$sql .= " " . MAIN_DB_PREFIX . " user as u " ;
2014-03-06 21:21:16 +01:00
$sql .= " WHERE u.rowid = s.fk_user " ;
$sql .= " AND s.entity = " . $conf -> entity ;
2014-11-01 14:59:39 +01:00
// Search criteria
if ( $search_ref ) $sql .= " AND s.rowid= " . $search_ref ;
2017-10-24 15:22:46 +02:00
if ( $search_user ) $sql .= natural_search ( array ( 'u.login' , 'u.lastname' , 'u.firstname' , 'u.email' ), $search_user );
2015-05-13 08:57:00 +02:00
if ( $search_label ) $sql .= natural_search ( array ( 's.label' ), $search_label );
2015-03-10 09:29:24 +01:00
if ( $search_amount ) $sql .= natural_search ( " s.amount " , $search_amount , 1 );
2016-08-11 18:41:31 +02:00
if ( $search_account > 0 ) $sql .= " AND b.fk_account= " . $search_account ;
2014-05-01 08:58:19 +02:00
if ( $filtre ) {
$filtre = str_replace ( " : " , " = " , $filtre );
$sql .= " AND " . $filtre ;
}
if ( $typeid ) {
$sql .= " AND s.fk_typepayment= " . $typeid ;
}
2016-02-16 17:43:05 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2014-08-28 15:07:33 +02:00
//$sql.= " GROUP BY u.rowid, u.lastname, u.firstname, s.rowid, s.fk_user, s.amount, s.label, s.datev, s.fk_typepayment, s.num_payment, pst.code";
2015-12-28 00:20:48 +01:00
$totalnboflines = 0 ;
$result = $db -> query ( $sql );
if ( $result )
{
$totalnboflines = $db -> num_rows ( $result );
}
2014-05-01 08:58:19 +02:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2014-03-06 21:21:16 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
$i = 0 ;
$total = 0 ;
2014-05-01 08:58:19 +02:00
$param = '' ;
2016-06-07 14:06:00 +02:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . $contextpage ;
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . $limit ;
2014-05-01 08:58:19 +02:00
if ( $typeid ) $param .= '&typeid=' . $typeid ;
2015-10-04 11:30:28 +02:00
if ( $optioncss != '' ) $param .= '&optioncss=' . $optioncss ;
2014-05-10 18:57:04 +02:00
2018-04-15 17:37:49 +02:00
$newcardbutton = '' ;
2018-09-07 13:32:56 +02:00
if ( ! empty ( $user -> rights -> salaries -> write ))
2018-04-15 17:37:49 +02:00
{
2018-06-13 22:57:41 +02:00
$newcardbutton = '<a class="butActionNew" href="' . DOL_URL_ROOT . '/compta/salaries/card.php?action=create"><span class="valignmiddle">' . $langs -> trans ( 'NewSalaryPayment' ) . '</span>' ;
2018-04-18 03:26:15 +02:00
$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>' ;
$newcardbutton .= '</a>' ;
2018-04-15 17:37:49 +02:00
}
2018-03-30 16:54:38 +02:00
2018-04-15 17:37:49 +02:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2016-02-16 17:43:05 +01:00
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ '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 . '">' ;
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-06-09 09:25:15 +02:00
2018-03-30 16:54:38 +02:00
print_barre_liste ( $langs -> trans ( " SalariesPayments " ), $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $totalnboflines , 'title_accountancy.png' , 0 , $newcardbutton , '' , $limit );
2017-06-09 09:25:15 +02:00
2016-11-27 13:49:46 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre_filter">' ;
2014-11-01 14:59:39 +01:00
// Ref
print '<td class="liste_titre" align="left">' ;
2017-07-01 02:22:08 +02:00
print '<input class="flat" type="text" size="3" name="search_ref" value="' . $db -> escape ( $search_ref ) . '">' ;
2014-11-01 14:59:39 +01:00
print '</td>' ;
2016-08-29 21:14:11 +02:00
// Employee
2015-05-13 08:57:00 +02:00
print '<td class="liste_titre">' ;
2017-07-01 02:22:08 +02:00
print '<input class="flat" type="text" size="6" name="search_user" value="' . $db -> escape ( $search_user ) . '">' ;
2015-05-13 08:57:00 +02:00
print '</td>' ;
2014-11-01 14:59:39 +01:00
// Label
2017-07-01 02:22:08 +02:00
print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="' . $db -> escape ( $search_label ) . '"></td>' ;
2015-05-13 08:57:00 +02:00
// Date
2014-05-01 08:58:19 +02:00
print '<td class="liste_titre"> </td>' ;
// Type
print '<td class="liste_titre" align="left">' ;
2018-03-07 19:00:38 +01:00
$form -> select_types_paiements ( $typeid , 'typeid' , '' , 0 , 1 , 1 , 16 );
2014-05-01 08:58:19 +02:00
print '</td>' ;
2016-08-11 18:41:31 +02:00
// Account
if ( ! empty ( $conf -> banque -> enabled ))
{
2016-12-11 16:11:42 +01:00
print '<td class="liste_titre">' ;
2016-08-11 18:41:31 +02:00
$form -> select_comptes ( $search_account , 'search_account' , 0 , '' , 1 );
print '</td>' ;
}
2014-11-01 14:59:39 +01:00
// Amount
2017-07-01 02:22:08 +02:00
print '<td class="liste_titre" align="right"><input name="search_amount" class="flat" type="text" size="8" value="' . $db -> escape ( $search_amount ) . '"></td>' ;
2016-02-07 15:50:48 +01:00
print '<td class="liste_titre" align="right">' ;
2017-05-14 21:06:33 +02:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
print $searchpicto ;
2016-02-07 15:50:48 +01:00
print '</td>' ;
2017-06-09 09:25:15 +02:00
2017-04-01 12:46:47 +02:00
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " Ref " , $_SERVER [ " PHP_SELF " ], " s.rowid " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Employee " , $_SERVER [ " PHP_SELF " ], " u.rowid " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Label " , $_SERVER [ " PHP_SELF " ], " s.label " , " " , $param , 'align="left"' , $sortfield , $sortorder );
2018-04-28 19:54:41 +02:00
print_liste_field_titre ( " DatePayment " , $_SERVER [ " PHP_SELF " ], " s.datep,s.rowid " , " " , $param , 'align="center"' , $sortfield , $sortorder );
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " PaymentMode " , $_SERVER [ " PHP_SELF " ], " type " , " " , $param , 'align="left"' , $sortfield , $sortorder );
if ( ! empty ( $conf -> banque -> enabled )) print_liste_field_titre ( " BankAccount " , $_SERVER [ " PHP_SELF " ], " ba.label " , " " , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( " PayedByThisPayment " , $_SERVER [ " PHP_SELF " ], " s.amount " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2017-04-01 12:46:47 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'maxwidthsearch ' );
print " </tr> \n " ;
2017-06-09 09:25:15 +02:00
2016-02-07 15:50:48 +01:00
print " </tr> \n " ;
2014-05-10 18:57:04 +02:00
2014-05-01 08:58:19 +02:00
while ( $i < min ( $num , $limit ))
2014-03-06 21:21:16 +01:00
{
$obj = $db -> fetch_object ( $result );
2017-06-09 09:25:15 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2014-03-06 21:21:16 +01:00
$userstatic -> id = $obj -> uid ;
$userstatic -> lastname = $obj -> lastname ;
$userstatic -> firstname = $obj -> firstname ;
2015-03-10 10:11:51 +01:00
$userstatic -> admin = $obj -> admin ;
$userstatic -> login = $obj -> login ;
$userstatic -> email = $obj -> email ;
$userstatic -> societe_id = $obj -> fk_soc ;
2017-12-18 11:55:34 +01:00
$userstatic -> statut = $obj -> status ;
2015-05-13 08:57:00 +02:00
2014-03-06 21:21:16 +01:00
$salstatic -> id = $obj -> rowid ;
2014-03-25 21:35:52 +01:00
$salstatic -> ref = $obj -> rowid ;
2018-11-08 10:04:25 +01:00
2015-03-10 09:29:24 +01:00
// Ref
print " <td> " . $salstatic -> getNomUrl ( 1 ) . " </td> \n " ;
2016-08-29 21:14:11 +02:00
// Employee
2014-03-25 21:35:52 +01:00
print " <td> " . $userstatic -> getNomUrl ( 1 ) . " </td> \n " ;
2015-03-10 09:29:24 +01:00
// Label payment
2014-03-06 21:21:16 +01:00
print " <td> " . dol_trunc ( $obj -> label , 40 ) . " </td> \n " ;
2015-05-13 08:57:00 +02:00
// Date payment
print '<td align="center">' . dol_print_date ( $db -> jdate ( $obj -> datep ), 'day' ) . " </td> \n " ;
2014-03-25 21:35:52 +01:00
// Type
print '<td>' . $langs -> trans ( " PaymentTypeShort " . $obj -> payment_code ) . ' ' . $obj -> num_payment . '</td>' ;
2016-08-11 18:41:31 +02:00
// Account
if ( ! empty ( $conf -> banque -> enabled ))
{
print '<td>' ;
if ( $obj -> fk_bank > 0 )
{
//$accountstatic->fetch($obj->fk_bank);
$accountstatic -> id = $obj -> bid ;
2016-11-12 12:40:06 +01:00
$accountstatic -> ref = $obj -> bref ;
$accountstatic -> number = $obj -> bnumber ;
2017-06-09 09:25:15 +02:00
2017-05-14 08:07:34 +02:00
if ( ! empty ( $conf -> accounting -> enabled ))
{
$accountstatic -> account_number = $obj -> account_number ;
2017-06-09 09:25:15 +02:00
2017-05-14 08:07:34 +02:00
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $obj -> fk_accountancy_journal );
$accountstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
}
2016-08-11 18:41:31 +02:00
$accountstatic -> label = $obj -> blabel ;
2016-11-12 12:40:06 +01:00
print $accountstatic -> getNomUrl ( 1 );
2016-08-11 18:41:31 +02:00
}
else print ' ' ;
print '</td>' ;
}
// Amount
2015-08-27 16:10:02 +02:00
print " <td align= \" right \" > " . price ( $obj -> amount ) . " </td> " ;
2015-08-30 21:20:50 +02:00
print " <td></td> " ;
2014-03-06 21:21:16 +01:00
print " </tr> \n " ;
2014-03-25 21:35:52 +01:00
$total = $total + $obj -> amount ;
2014-05-10 18:57:04 +02:00
2014-03-06 21:21:16 +01:00
$i ++ ;
}
2016-08-29 21:21:10 +02:00
$colspan = 5 ;
2016-08-11 18:41:31 +02:00
if ( ! empty ( $conf -> banque -> enabled )) $colspan ++ ;
print '<tr class="liste_total"><td colspan="' . $colspan . '" class="liste_total">' . $langs -> trans ( " Total " ) . '</td>' ;
2016-07-29 23:52:49 +02:00
print '<td class="liste_total" align="right">' . price ( $total ) . " </td> " ;
2015-08-30 21:20:50 +02:00
print " <td></td></tr> " ;
2014-03-06 21:21:16 +01:00
print " </table> " ;
2016-11-27 13:49:46 +01:00
print '</div>' ;
2014-05-01 08:58:19 +02:00
print '</form>' ;
2014-05-10 18:57:04 +02:00
2014-03-06 21:21:16 +01:00
$db -> free ( $result );
}
else
{
dol_print_error ( $db );
}
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 ();