2012-08-22 23:27:53 +02:00
< ? php
2022-07-16 06:34:52 +02:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2010 - 2018 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2022 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2005-01-07 16:12:08 +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-07 16:12:08 +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-07 16:12:08 +01:00
*/
2005-08-15 18:51:36 +02:00
/**
2014-09-18 20:33:37 +02:00
* \file htdocs / compta / prelevement / list . php
2010-09-05 15:24:59 +02:00
* \ingroup prelevement
2020-06-08 11:43:20 +02:00
* \brief Page list of direct debit orders or credit transfers orders
2010-09-05 15:24:59 +02:00
*/
2017-01-22 13:19:07 +01: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' ;
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/ligneprelevement.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
$langs -> loadLangs ( array ( 'banks' , 'withdrawals' , 'companies' , 'categories' ));
2005-09-10 14:13:47 +02:00
2020-04-28 02:10:26 +02: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
2020-09-25 10:27:30 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'directdebitcredittransferlinelist' ; // To manage different context of search
2020-04-28 02:10:26 +02:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
2020-05-27 20:14:11 +02:00
$type = GETPOST ( 'type' , 'aZ09' );
2020-10-31 14:32:18 +01: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
2019-01-27 11:55:16 +01:00
$search_line = GETPOST ( 'search_line' , 'alpha' );
$search_bon = GETPOST ( 'search_bon' , 'alpha' );
$search_code = GETPOST ( 'search_code' , 'alpha' );
$search_company = GETPOST ( 'search_company' , 'alpha' );
$statut = GETPOST ( 'statut' , 'int' );
2011-05-06 16:20:20 +02:00
2020-05-07 12:14:45 +02:00
$bon = new BonPrelevement ( $db );
$line = new LignePrelevement ( $db );
2020-04-28 02:10:26 +02:00
$company = new Societe ( $db );
2010-09-05 15:24:59 +02:00
2020-05-05 10:02:36 +02:00
$hookmanager -> initHooks ( array ( 'withdrawalsreceiptslineslist' ));
2011-01-05 10:57:55 +01:00
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' );
}
2010-09-05 15:24:59 +02:00
2017-01-22 13:19:07 +01:00
/*
* Actions
*/
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
2019-11-14 12:09:46 +01:00
$search_line = " " ;
$search_bon = " " ;
$search_code = " " ;
2020-10-31 14:32:18 +01:00
$search_company = " " ;
2019-11-14 12:09:46 +01:00
$statut = " " ;
2014-11-02 21:44:03 +01:00
}
2005-09-10 14:13:47 +02:00
2017-01-22 13:19:07 +01:00
2005-01-07 16:12:08 +01:00
/*
2010-09-05 15:24:59 +02:00
* View
2005-01-07 16:12:08 +01:00
*/
2019-11-14 12:09:46 +01:00
$form = new Form ( $db );
2017-01-22 13:19:07 +01:00
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " WithdrawalsLines " ));
2005-09-10 14:13:47 +02:00
2020-04-28 02:10:26 +02:00
$sql = " SELECT p.rowid, p.ref, p.statut as status, p.datec " ;
2020-06-08 11:43:20 +02:00
$sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc " ;
2022-07-16 06:34:52 +02:00
$sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email " ;
2019-11-14 12:09:46 +01:00
$sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_bons as p " ;
$sql .= " , " . MAIN_DB_PREFIX . " prelevement_lignes as pl " ;
$sql .= " , " . MAIN_DB_PREFIX . " prelevement_facture as pf " ;
2020-06-08 11:43:20 +02:00
if ( $type == 'bank-transfer' ) {
$sql .= " , " . MAIN_DB_PREFIX . " facture_fourn as f " ;
} else {
$sql .= " , " . MAIN_DB_PREFIX . " facture as f " ;
}
2019-11-14 12:09:46 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " WHERE pl.fk_prelevement_bons = p.rowid " ;
$sql .= " AND pf.fk_prelevement_lignes = pl.rowid " ;
2020-06-08 11:43:20 +02:00
if ( $type == 'bank-transfer' ) {
$sql .= " AND pf.fk_facture_fourn = f.rowid " ;
} else {
$sql .= " AND pf.fk_facture = f.rowid " ;
}
2019-11-14 12:09:46 +01:00
$sql .= " AND f.fk_soc = s.rowid " ;
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2021-02-23 21:09:01 +01:00
if ( $socid ) {
2021-04-24 20:18:11 +02:00
$sql .= " AND s.rowid = " . (( int ) $socid );
2021-02-23 21:09:01 +01:00
}
if ( $search_line ) {
$sql .= " AND pl.rowid = ' " . $db -> escape ( $search_line ) . " ' " ;
}
if ( $search_bon ) {
$sql .= natural_search ( " p.ref " , $search_bon );
}
2020-06-08 11:43:20 +02:00
if ( $type == 'bank-transfer' ) {
2021-02-23 21:09:01 +01:00
if ( $search_code ) {
2022-07-16 06:34:52 +02:00
$sql .= natural_search ( " s.code_fournisseur " , $search_code );
2021-02-23 21:09:01 +01:00
}
2020-06-08 11:43:20 +02:00
} else {
2021-02-23 21:09:01 +01:00
if ( $search_code ) {
$sql .= natural_search ( " s.code_client " , $search_code );
}
}
if ( $search_company ) {
$sql .= natural_search ( " s.nom " , $search_company );
2020-06-08 11:43:20 +02:00
}
2019-11-14 12:09:46 +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 ;
}
2005-01-07 16:12:08 +01:00
}
2017-01-22 13:19:07 +01:00
2019-11-14 12:09:46 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2005-01-07 16:12:08 +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 ;
2010-09-05 15:24:59 +02:00
2020-10-31 14:32:18 +01:00
$param = " &statut= " . urlencode ( $statut );
$param .= " &search_bon= " . urlencode ( $search_bon );
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 );
}
2010-09-05 15:24:59 +02:00
2020-10-31 14:32:18 +01:00
print " \n <!-- debut table --> \n " ;
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
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="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 . '">' ;
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
$title = $langs -> trans ( " WithdrawalsLines " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " CreditTransferLines " );
}
2020-06-08 11:43:20 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $nbtotalofrecords , 'generic' , 0 , '' , '' , $limit , 0 , 0 , 1 );
2018-02-06 18:49:29 +01:00
2019-11-14 12:09:46 +01:00
$moreforfilter = '' ;
2017-06-07 16:44:04 +02:00
2020-10-31 14:32:18 +01:00
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" name="search_line" value="' . dol_escape_htmltag ( $search_line ) . '" size="6"></td>' ;
print '<td class="liste_titre"><input type="text" class="flat" name="search_bon" value="' . dol_escape_htmltag ( $search_bon ) . '" size="6"></td>' ;
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre"><input type="text" class="flat" name="search_company" value="' . dol_escape_htmltag ( $search_company ) . '" size="6"></td>' ;
2022-07-16 06:34:52 +02:00
print '<td class="liste_titre center"><input type="text" class="flat" name="search_code" value="' . dol_escape_htmltag ( $search_code ) . '" size="6"></td>' ;
2020-10-31 14:32:18 +01:00
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre maxwidthsearch">' ;
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
2020-10-31 18:51:30 +01:00
$columntitle = " WithdrawalsReceipts " ;
2022-07-16 06:34:52 +02:00
$columntitlethirdparty = " CustomerCode " ;
$columncodethirdparty = " s.code_client " ;
2020-10-31 14:32:18 +01:00
if ( $type == 'bank-transfer' ) {
2020-10-31 18:51:30 +01:00
$columntitle = " BankTransferReceipts " ;
2022-07-16 06:34:52 +02:00
$columntitlethirdparty = " SupplierCode " ;
$columncodethirdparty = " s.code_fournisseur " ;
2020-10-31 14:32:18 +01:00
}
print '<tr class="liste_titre">' ;
print_liste_field_titre ( $columntitle , $_SERVER [ " PHP_SELF " ], " p.ref " , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Line " , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Bill " , $_SERVER [ " PHP_SELF " ], " f.ref " , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( " Company " , $_SERVER [ " PHP_SELF " ], " s.nom " , '' , $param , '' , $sortfield , $sortorder );
2022-07-16 06:34:52 +02:00
print_liste_field_titre ( $columntitlethirdparty , $_SERVER [ " PHP_SELF " ], $columncodethirdparty , '' , $param , '' , $sortfield , $sortorder , 'center ' );
2020-10-31 14:32:18 +01:00
print_liste_field_titre ( " Date " , $_SERVER [ " PHP_SELF " ], " p.datec " , " " , $param , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( " Amount " , $_SERVER [ " PHP_SELF " ], " pl.amount " , " " , $param , '' , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( '' );
2017-06-07 16:44:04 +02:00
print " </tr> \n " ;
2020-06-08 11:43:20 +02:00
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 );
$bon -> id = $obj -> rowid ;
$bon -> ref = $obj -> ref ;
$bon -> statut = $obj -> status ;
$company -> id = $obj -> socid ;
$company -> name = $obj -> name ;
$company -> email = $obj -> email ;
$company -> code_client = $obj -> code_client ;
print '<tr class="oddeven">' ;
print '<td>' ;
print $bon -> getNomUrl ( 1 );
print " </td> \n " ;
print '<td>' ;
print $line -> LibStatut ( $obj -> statut_ligne , 2 );
print " " ;
print '<a href="' . DOL_URL_ROOT . '/compta/prelevement/line.php?id=' . $obj -> rowid_ligne . '">' ;
print substr ( '000000' . $obj -> rowid_ligne , - 6 );
print '</a></td>' ;
print '<td>' ;
2022-07-15 17:31:30 +02:00
$link_to_bill = '/compta/facture/card.php?facid=' ;
$link_title = 'Invoice' ;
$link_picto = 'bill' ;
if ( $type == 'bank-transfer' ) {
$link_to_bill = '/fourn/facture/card.php?facid=' ;
$link_title = 'SupplierInvoice' ;
$link_picto = 'supplier_invoice' ;
}
print '<a href="' . DOL_URL_ROOT . $link_to_bill . $obj -> facid . '">' ;
print img_object ( $langs -> trans ( $link_title ), $link_picto );
print ' ' . $obj -> invoiceref . " </td> \n " ;
2020-10-31 14:32:18 +01:00
print '</a>' ;
print '</td>' ;
print '<td>' ;
print $company -> getNomUrl ( 1 );
2020-06-08 11:43:20 +02:00
print " </td> \n " ;
2005-01-07 16:12:08 +01:00
2022-07-16 06:34:52 +02:00
print '<td class="center">' ;
$link_to_tab = '/comm/card.php?socid=' ;
$link_code = $obj -> code_client ;
if ( $type == 'bank-transfer' ) {
2022-07-18 07:23:25 +02:00
$link_to_tab = '/fourn/card.php?socid=' ;
2022-07-16 06:34:52 +02:00
$link_code = $obj -> code_fournisseur ;
}
print '<a href="' . DOL_URL_ROOT . $link_to_tab . $company -> id . '">' . $link_code . " </a></td> \n " ;
2005-01-07 16:12:08 +01:00
2020-10-31 14:32:18 +01:00
print '<td class="center">' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' ) . " </td> \n " ;
2005-01-07 16:12:08 +01:00
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $obj -> amount ) . " </span></td> \n " ;
2005-01-31 15:24:45 +01:00
2020-10-31 14:32:18 +01:00
print '<td> </td>' ;
2009-07-22 19:13:59 +02:00
2020-10-31 14:32:18 +01:00
print " </tr> \n " ;
$i ++ ;
}
2020-06-08 11:43:20 +02:00
} else {
2021-10-04 04:14:31 +02:00
print '<tr><td colspan="8"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2020-06-08 11:43:20 +02:00
}
2020-10-31 14:32:18 +01:00
print " </table> " ;
print '</div>' ;
2017-06-07 16:44:04 +02:00
2020-10-31 14:32:18 +01:00
print '</form>' ;
2017-06-07 16:44:04 +02:00
2020-10-31 14:32:18 +01:00
$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-07 16:12:08 +01:00
}
2018-08-08 12:29:36 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2015-12-11 14:19:38 +01:00
$db -> close ();