2005-01-11 10:37:35 +01:00
< ? php
/* Copyright ( C ) 2004 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2010-09-05 15:24:59 +02:00
* Copyright ( C ) 2005 - 2010 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 ) 2011 - 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
/**
2010-09-05 15:24:59 +02:00
* \file htdocs / compta / prelevement / demandes . php
2012-08-05 14:37:45 +02:00
* \ingroup prelevement
2020-05-27 20:14:11 +02:00
* \brief Page to list bank transfer requests ( debit order or payments of vendors )
2008-11-05 23:34:14 +01:00
*/
2012-08-05 14:37:45 +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 . '/core/modules/modPrelevement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2020-05-27 20:14:11 +02:00
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.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' , 'categories' , 'withdrawals' , 'companies' ));
2005-05-23 13:16:28 +02:00
2008-02-25 17:30:43 +01:00
// Security check
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2019-09-06 13:44:02 +02:00
$status = GETPOST ( 'status' , 'int' );
2008-02-25 17:30:43 +01:00
2020-09-25 10:27:30 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'directdebitcredittransferlist' ; // To manage different context of search
2020-01-30 01:48:28 +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')
2019-01-27 11:55:16 +01:00
2020-05-27 20:14:11 +02:00
$type = GETPOST ( 'type' , 'aZ09' );
2020-01-27 01:50:02 +01:00
$search_facture = GETPOST ( 'search_facture' , 'alpha' );
2020-08-28 21:27:50 +02:00
$search_societe = GETPOST ( 'search_societe' , 'alpha' );
2020-01-27 01:50:02 +01:00
2019-09-06 13:44:02 +02:00
// Load variable for pagination
2020-01-30 01:48:28 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$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 || 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
2017-01-27 01:20:56 +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 = " f.ref " ;
}
2017-01-27 01:20:56 +01:00
2019-09-06 13:44:02 +02:00
$massactionbutton = '' ;
2020-01-24 13:22:04 +01:00
$hookmanager -> initHooks ( array ( 'withdrawalstodolist' ));
2021-10-04 04:36:58 +02:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
if ( $type == 'bank-transfer' ) {
$result = restrictedArea ( $user , 'paymentbybanktransfer' , '' , '' , '' );
} else {
$result = restrictedArea ( $user , 'prelevement' , '' , '' , 'bons' );
}
2020-01-24 13:22:04 +01:00
/*
* Actions
*/
$parameters = array ( 'socid' => $socid , 'limit' => $limit , 'page' => $page , 'offset' => $offset );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 21:09:01 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2017-01-27 01:20:56 +01:00
2020-01-27 01:50:02 +01:00
// Purge search criteria
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-01-27 01:50:02 +01:00
$search_facture = '' ;
$search_societe = '' ;
$search_array_options = array ();
}
2017-01-27 01:20:56 +01:00
2005-01-11 10:37:35 +01:00
/*
2008-11-05 23:34:14 +01:00
* View
2005-01-11 10:37:35 +01:00
*/
2020-05-27 20:14:11 +02:00
if ( $type != 'bank-transfer' ) {
2020-05-27 23:07:18 +02:00
if ( ! $status ) {
2020-05-27 20:14:11 +02:00
$title = $langs -> trans ( " RequestStandingOrderToTreat " );
} else {
$title = $langs -> trans ( " RequestStandingOrderTreated " );
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-27 23:07:18 +02:00
if ( ! $status ) {
2020-05-27 20:14:11 +02:00
$title = $langs -> trans ( " RequestPaymentsByBankTransferToTreat " );
} else {
$title = $langs -> trans ( " RequestPaymentsByBankTransferTreated " );
}
2019-09-06 13:44:02 +02:00
}
llxHeader ( '' , $title );
2008-11-05 23:34:14 +01:00
2020-01-30 01:48:28 +01:00
$thirdpartystatic = new Societe ( $db );
2020-08-04 21:06:38 +02:00
if ( $type == 'bank-transfer' ) {
$invoicestatic = new FactureFournisseur ( $db );
} else {
$invoicestatic = new Facture ( $db );
}
2008-11-05 23:34:14 +01:00
2017-01-27 01:20:56 +01:00
// List of requests
2005-01-11 11:18:24 +01:00
2020-01-30 01:48:28 +01:00
$sql = " SELECT f.ref, f.rowid, f.total_ttc, " ;
$sql .= " s.nom as name, s.rowid as socid, " ;
2020-08-04 21:06:38 +02:00
$sql .= " pfd.date_demande as date_demande, pfd.amount, pfd.fk_user_demande " ;
2020-05-27 20:14:11 +02:00
if ( $type != 'bank-transfer' ) {
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f, " ;
} else {
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f, " ;
}
2020-01-30 01:48:28 +01:00
$sql .= " " . MAIN_DB_PREFIX . " societe as s, " ;
$sql .= " " . MAIN_DB_PREFIX . " prelevement_facture_demande as pfd " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-02-23 21:09:01 +01:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
}
2020-01-30 01:48:28 +01:00
$sql .= " WHERE s.rowid = f.fk_soc " ;
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2021-10-22 22:15:59 +02:00
if ( empty ( $user -> rights -> societe -> client -> voir ) && ! $socid ) {
2021-08-23 17:41:11 +02:00
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2021-02-23 21:09:01 +01:00
}
if ( $socid ) {
2021-03-22 13:31:06 +01:00
$sql .= " AND f.fk_soc = " . (( int ) $socid );
2021-02-23 21:09:01 +01:00
}
if ( ! $status ) {
$sql .= " AND pfd.traite = 0 " ;
}
2020-08-04 21:06:38 +02:00
$sql .= " AND pfd.ext_payment_id IS NULL " ;
2021-02-23 21:09:01 +01:00
if ( $status ) {
2021-03-22 13:31:06 +01:00
$sql .= " AND pfd.traite = " . (( int ) $status );
2021-02-23 21:09:01 +01:00
}
2020-01-30 01:48:28 +01:00
$sql .= " AND f.total_ttc > 0 " ;
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS )) {
2020-01-30 01:48:28 +01:00
$sql .= " AND f.fk_statut = " . Facture :: STATUS_VALIDATED ;
2019-09-06 14:45:55 +02:00
}
2020-05-27 20:14:11 +02:00
if ( $type != 'bank-transfer' ) {
$sql .= " AND pfd.fk_facture = f.rowid " ;
} else {
$sql .= " AND pfd.fk_facture_fourn = f.rowid " ;
}
2021-02-23 21:09:01 +01:00
if ( $search_facture ) {
$sql .= natural_search ( " f.ref " , $search_facture );
}
if ( $search_societe ) {
$sql .= natural_search ( " s.nom " , $search_societe );
}
2020-01-30 01:48:28 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2005-01-11 10:37:35 +01:00
2019-09-06 13:44:02 +02:00
// Count total nb of records
$nbtotalofrecords = '' ;
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2019-09-06 13:44:02 +02:00
$resql = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $resql );
2021-02-23 21:09:01 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total of record found is smaller than page * limit, goto and load page 0
2019-09-06 13:44:02 +02:00
$page = 0 ;
$offset = 0 ;
2008-11-05 23:34:14 +01:00
}
2019-09-06 13:44:02 +02:00
}
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
2021-02-23 21:09:01 +01:00
if ( is_numeric ( $nbtotalofrecords ) && $limit > $nbtotalofrecords ) {
2019-09-06 13:44:02 +02:00
$num = $nbtotalofrecords ;
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2019-09-06 13:44:02 +02:00
2020-01-30 01:48:28 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( ! $resql ) {
2019-09-06 13:44:02 +02:00
dol_print_error ( $db );
exit ;
2005-01-11 10:37:35 +01:00
}
2005-09-10 16:24:10 +02:00
2019-09-06 13:44:02 +02:00
$num = $db -> num_rows ( $resql );
}
2017-08-02 13:31:53 +02:00
2010-09-05 15:24:59 +02:00
2008-11-05 23:34:14 +01:00
2020-08-04 18:50:57 +02:00
$newcardbutton = '<a class="marginrightonly" href="' . DOL_URL_ROOT . '/compta/prelevement/index.php">' . $langs -> trans ( " Back " ) . '</a>' ;
2020-05-27 20:14:11 +02:00
if ( $type == 'bank-transfer' ) {
2020-08-04 18:50:57 +02:00
$newcardbutton = '<a class="marginrightonly" href="' . DOL_URL_ROOT . '/compta/paymentbybanktransfer/index.php">' . $langs -> trans ( " Back " ) . '</a>' ;
2020-05-27 20:14:11 +02:00
}
2008-11-05 23:34:14 +01:00
2020-01-24 13:22:04 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST" id="searchFormList" name="searchFormList">' ;
2021-02-23 21:09:01 +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 () . '">' ;
2019-09-06 13:44:02 +02: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="page" value="' . $page . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2017-08-02 13:31:53 +02:00
2020-05-27 20:14:11 +02:00
$param = '' ;
2020-07-27 19:33:24 +02:00
$label = 'NewStandingOrder' ;
$typefilter = '' ;
if ( $type == 'bank-transfer' ) {
$label = 'NewPaymentByBankTransfer' ;
$typefilter = 'type=' . $type ;
}
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( $label ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/compta/prelevement/create.php' . ( $typefilter ? '?' . $typefilter : '' ));
2020-01-27 01:50:02 +01:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'generic' , 0 , $newcardbutton , '' , $limit );
2008-11-05 23:34:14 +01:00
2019-11-05 21:24:41 +01:00
print '<table class="liste centpercent">' ;
2008-11-05 23:34:14 +01:00
2019-09-06 13:44:02 +02:00
print '<tr class="liste_titre">' ;
print_liste_field_titre ( " Bill " , $_SERVER [ " PHP_SELF " ]);
print_liste_field_titre ( " Company " , $_SERVER [ " PHP_SELF " ]);
2020-08-04 21:06:38 +02:00
print_liste_field_titre ( " AmountRequested " , $_SERVER [ " PHP_SELF " ], " " , " " , $param , '' , '' , '' , 'right ' );
2020-06-08 11:43:20 +02:00
print_liste_field_titre ( " DateRequest " , $_SERVER [ " PHP_SELF " ], " " , " " , $param , '' , '' , '' , 'center ' );
2019-09-06 13:44:02 +02:00
print_liste_field_titre ( '' );
print '</tr>' ;
2008-11-05 23:34:14 +01:00
2019-09-06 13:44:02 +02:00
print '<tr class="liste_titre">' ;
2020-06-08 11:43:20 +02:00
print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_facture" value="' . dol_escape_htmltag ( $search_facture ) . '"></td>' ;
print '<td class="liste_titre"><input type="text" class="flat maxwidth150" name="search_societe" value="' . dol_escape_htmltag ( $search_societe ) . '"></td>' ;
2019-09-06 13:44:02 +02:00
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
// Action column
2020-01-27 01:50:02 +01:00
print '<td class="liste_titre maxwidthsearch">' ;
$searchpicto = $form -> showFilterButtons ();
2019-09-06 13:44:02 +02:00
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
2008-11-05 23:34:14 +01:00
2019-09-06 13:44:02 +02:00
$i = 0 ;
2021-02-23 21:09:01 +01:00
while ( $i < min ( $num , $limit )) {
2019-09-06 13:44:02 +02:00
$obj = $db -> fetch_object ( $resql );
2021-02-23 21:09:01 +01:00
if ( empty ( $obj )) {
break ; // Should not happen
}
2017-08-02 13:31:53 +02:00
2020-08-04 21:06:38 +02:00
$invoicestatic -> fetch ( $obj -> rowid );
2019-09-06 13:44:02 +02:00
print '<tr class="oddeven">' ;
2008-11-05 23:34:14 +01:00
2019-09-06 13:44:02 +02:00
// Ref facture
print '<td>' ;
print $invoicestatic -> getNomUrl ( 1 , 'withdraw' );
print '</td>' ;
2005-01-24 09:34:00 +01:00
2019-09-06 13:44:02 +02:00
print '<td>' ;
2020-01-30 01:48:28 +01:00
$thirdpartystatic -> id = $obj -> socid ;
$thirdpartystatic -> name = $obj -> name ;
2019-09-06 13:44:02 +02:00
print $thirdpartystatic -> getNomUrl ( 1 , 'customer' );
print '</td>' ;
2020-08-04 21:06:38 +02:00
print '<td class="right">' ;
print price ( $obj -> amount , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency ) . ' / ' . price ( $obj -> total_ttc , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency );
print '</td>' ;
2019-09-06 13:44:02 +02:00
print '<td class="center">' . dol_print_date ( $db -> jdate ( $obj -> date_demande ), 'day' ) . '</td>' ;
print '<td class="right"></td>' ;
print '</tr>' ;
$i ++ ;
2008-11-05 23:34:14 +01:00
}
2005-01-11 10:37:35 +01:00
2019-09-06 13:44:02 +02:00
print " </table><br> " ;
print '</form>' ;
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 ();