2012-08-22 23:27:53 +02:00
< ? php
2008-11-05 23:34:14 +01:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2017-06-07 16:44:04 +02:00
* Copyright ( C ) 2005 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2012-02-29 18:56:54 +01:00
* Copyright ( C ) 2010 - 2012 Juanjo Menent < jmenent @ 2 byte . es >
2005-01-11 10:37:35 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-01-11 10:37:35 +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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2005-01-11 10:37:35 +01:00
*/
2005-05-23 13:16:28 +02:00
/**
2020-09-25 10:05:59 +02:00
* \file htdocs / compta / prelevement / orders_list . php
2011-08-27 17:14:31 +02:00
* \ingroup prelevement
2020-09-25 10:05:59 +02:00
* \brief Page to list direct debit orders or credit transfer orders
2011-08-27 17:14:31 +02:00
*/
2005-05-23 13:16:28 +02:00
2018-07-26 11:57:25 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php' ;
2013-06-05 16:24:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2021-08-04 13:51:54 +02:00
$langs -> loadLangs ( array ( 'banks' , 'categories' , 'withdrawals' ));
2009-04-27 22:37:50 +02:00
2020-09-25 10:27:30 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'directdebitcredittransferlist' ; // To manage different context of search
2020-04-28 02:10:26 +02:00
2020-05-27 20:14:11 +02:00
$type = GETPOST ( 'type' , 'aZ09' );
2020-04-28 02:10:26 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
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-23 21:09:01 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2017-01-22 13:19:07 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-23 21:09:01 +01:00
if ( ! $sortorder ) {
$sortorder = " DESC " ;
}
if ( ! $sortfield ) {
$sortfield = " p.datec " ;
}
2017-01-22 13:19:07 +01:00
// Get supervariables
2019-01-27 11:55:16 +01:00
$statut = GETPOST ( 'statut' , 'int' );
$search_ref = GETPOST ( 'search_ref' , 'alpha' );
$search_amount = GETPOST ( 'search_amount' , 'alpha' );
2017-09-15 16:40:52 +02:00
2020-05-07 12:14:45 +02:00
$bon = new BonPrelevement ( $db );
2020-05-05 10:02:36 +02:00
$hookmanager -> initHooks ( array ( 'withdrawalsreceiptslist' ));
2005-05-23 13:16:28 +02:00
2020-05-27 20:14:11 +02:00
$usercancreate = $user -> rights -> prelevement -> bons -> creer ;
if ( $type == 'bank-transfer' ) {
$usercancreate = $user -> rights -> paymentbybanktransfer -> create ;
}
2021-10-04 04:36:58 +02:00
// Security check
$socid = GETPOST ( 'socid' , 'int' );
if ( $user -> socid ) {
$socid = $user -> socid ;
}
if ( $type == 'bank-transfer' ) {
$result = restrictedArea ( $user , 'paymentbybanktransfer' , '' , '' , '' );
} else {
$result = restrictedArea ( $user , 'prelevement' , '' , '' , 'bons' );
}
2005-01-11 10:37:35 +01:00
2017-01-22 13:19:07 +01:00
/*
* Actions
*/
2005-01-11 10:37:35 +01:00
2021-02-23 21:09:01 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
2020-10-31 14:32:18 +01:00
$search_ref = " " ;
$search_amount = " " ;
2017-01-22 13:19:07 +01:00
}
2005-01-11 10:37:35 +01:00
2011-01-05 10:57:55 +01:00
2005-01-11 10:37:35 +01:00
/*
2017-01-22 13:19:07 +01:00
* View
2005-01-11 10:37:35 +01:00
*/
2017-01-22 13:19:07 +01:00
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " WithdrawalsReceipts " ));
2017-01-22 13:19:07 +01:00
2018-02-06 10:57:53 +01:00
$sql = " SELECT p.rowid, p.ref, p.amount, p.statut, p.datec " ;
2019-11-13 19:37:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_bons as p " ;
$sql .= " WHERE p.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2020-05-27 20:14:11 +02:00
if ( $type == 'bank-transfer' ) {
$sql .= " AND p.type = 'bank-transfer' " ;
} else {
$sql .= " AND p.type = 'debit-order' " ;
}
2021-02-23 21:09:01 +01:00
if ( $search_ref ) {
$sql .= natural_search ( " p.ref " , $search_ref );
}
if ( $search_amount ) {
$sql .= natural_search ( " p.amount " , $search_amount , 1 );
}
2017-01-22 13:19:07 +01:00
2019-11-13 19:37:08 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2017-01-22 13:19:07 +01:00
// Count total nb of records
$nbtotalofrecords = '' ;
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2020-10-31 14:32:18 +01:00
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
2021-02-23 21:09:01 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2020-10-31 14:32:18 +01:00
$page = 0 ;
$offset = 0 ;
}
2017-01-22 13:19:07 +01:00
}
2019-11-13 19:37:08 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2005-01-11 10:37:35 +01:00
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
$param = '' ;
2021-02-23 21:09:01 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
2022-07-18 07:23:25 +02:00
if ( $type == 'bank-transfer' ) {
$param .= '&type=bank-transfer' ;
}
2021-02-23 21:09:01 +01:00
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
2020-10-31 14:32:18 +01:00
$param .= " &statut= " . urlencode ( $statut );
$selectedfields = '' ;
$newcardbutton = '' ;
2021-02-23 21:09:01 +01:00
if ( $usercancreate ) {
2021-10-04 04:36:58 +02:00
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( 'NewStandingOrder' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/compta/prelevement/create.php?type=' . urlencode ( $type ));
2020-10-31 14:32:18 +01:00
}
// Lines of title fields
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2021-10-04 04:36:58 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-02-23 21:09:01 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2020-10-31 14:32:18 +01:00
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 . '">' ;
2022-11-20 05:33:31 +01:00
if ( $type != '' ) {
print '<input type="hidden" name="type" value="' . $type . '">' ;
}
2020-10-31 14:32:18 +01:00
$titlekey = " WithdrawalsReceipts " ;
$title = $langs -> trans ( " WithdrawalsReceipts " );
if ( $type == 'bank-transfer' ) {
$titlekey = " BankTransferReceipts " ;
$title = $langs -> trans ( " BankTransferReceipts " );
}
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $nbtotalofrecords , 'generic' , 0 , $newcardbutton , '' , $limit , 0 , 0 , 1 );
$moreforfilter = '' ;
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
print '<tr class="liste_titre">' ;
print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_ref" value="' . dol_escape_htmltag ( $search_ref ) . '"></td>' ;
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre right"><input type="text" class="flat maxwidth100" name="search_amount" value="' . dol_escape_htmltag ( $search_amount ) . '"></td>' ;
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre maxwidthsearch">' ;
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $titlekey , $_SERVER [ " PHP_SELF " ], " p.ref " , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Date " , $_SERVER [ " PHP_SELF " ], " p.datec " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( " Amount " , $_SERVER [ " PHP_SELF " ], " p.amount " , " " , $param , '' , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( " Status " , $_SERVER [ " PHP_SELF " ], " " , " " , $param , '' , $sortfield , $sortorder , 'right ' );
print getTitleFieldOfList ( $selectedfields , 0 , $_SERVER [ " PHP_SELF " ], " " , '' , $param , '' , $sortfield , $sortorder , 'maxwidthsearch center ' ) . " \n " ;
print " </tr> \n " ;
$directdebitorder = new BonPrelevement ( $db );
if ( $num ) {
2021-02-23 21:09:01 +01:00
while ( $i < min ( $num , $limit )) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $result );
$directdebitorder -> id = $obj -> rowid ;
$directdebitorder -> ref = $obj -> ref ;
$directdebitorder -> datec = $obj -> datec ;
$directdebitorder -> amount = $obj -> amount ;
$directdebitorder -> statut = $obj -> statut ;
print '<tr class="oddeven">' ;
print '<td>' ;
print $directdebitorder -> getNomUrl ( 1 );
print " </td> \n " ;
print '<td class="center">' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' ) . " </td> \n " ;
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $obj -> amount ) . " </span></td> \n " ;
2020-10-31 14:32:18 +01:00
print '<td class="right">' ;
2021-12-22 18:35:06 +01:00
print $bon -> LibStatut ( $obj -> statut , 5 );
2020-10-31 14:32:18 +01:00
print '</td>' ;
print '<td class="right"></td>' . " \n " ;
print " </tr> \n " ;
$i ++ ;
}
} else {
2021-10-04 04:14:31 +02:00
print '<tr><td colspan="5"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2020-10-31 14:32:18 +01:00
}
print " </table> " ;
print '</div>' ;
print '</form>' ;
$db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db );
2005-01-11 10:37:35 +01:00
}
2018-08-08 12:29:36 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2015-06-21 17:05:49 +02:00
$db -> close ();