2005-07-25 15:07:22 +02:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2020-07-02 15:45:11 +02:00
* Copyright ( C ) 2010 - 2020 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2010 - 2012 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2018 Nicolas ZABOURI < info @ inovea - conseil . com >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2020-07-01 19:42:28 +02:00
* Copyright ( C ) 2019 Markus Welters < markus @ welters . de >
2005-07-25 15:07:22 +02: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-07-25 15:07:22 +02: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-07-25 15:07:22 +02:00
*/
/**
2010-03-27 15:40:39 +01:00
* \file htdocs / compta / prelevement / create . php
2012-08-05 14:37:45 +02:00
* \ingroup prelevement
2020-07-01 19:42:28 +02:00
* \brief Page to create a direct debit order or a credit transfer order
2008-11-05 23:34:14 +01:00
*/
2005-07-25 15:07:22 +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' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2017-10-12 00:38:59 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/prelevement.lib.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
2019-09-06 14:24:33 +02:00
$langs -> loadLangs ( array ( 'banks' , 'categories' , 'withdrawals' , 'companies' , 'bills' ));
2008-11-04 17:58:26 +01:00
2020-05-27 20:14:11 +02:00
$type = GETPOST ( 'type' , 'aZ09' );
2011-05-06 15:49:34 +02:00
// Get supervariables
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2021-02-10 08:11:28 +01:00
$massaction = GETPOST ( 'massaction' , 'alpha' ); // The bulk action (combo box choice into lists)
$toselect = GETPOST ( 'toselect' , 'array' ); // Array of ids of elements selected into a list
2021-12-09 12:42:04 +01:00
2020-01-30 01:48:28 +01:00
$mode = GETPOST ( 'mode' , 'alpha' ) ? GETPOST ( 'mode' , 'alpha' ) : 'real' ;
2019-01-27 11:55:16 +01:00
$format = GETPOST ( 'format' , 'aZ09' );
2020-12-31 10:49:27 +01:00
$id_bankaccount = GETPOST ( 'id_bankaccount' , 'int' );
2021-12-09 12:42:04 +01:00
$executiondate = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ));
2020-01-30 01:48:28 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
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
2018-08-10 15:05:21 +02:00
$offset = $limit * $page ;
2011-07-29 23:15:39 +02:00
2020-01-30 01:48:28 +01:00
$hookmanager -> initHooks ( array ( 'directdebitcreatecard' , 'globalcard' ));
2019-07-18 16:12:42 +02:00
2021-10-04 04:36:58 +02:00
// Security check
if ( $user -> socid ) {
$socid = $user -> socid ;
}
if ( $type == 'bank-transfer' ) {
$result = restrictedArea ( $user , 'paymentbybanktransfer' , '' , '' , '' );
} else {
$result = restrictedArea ( $user , 'prelevement' , '' , '' , 'bons' );
}
2021-12-09 12:42:04 +01:00
$error = 0 ;
2019-07-18 16:12:42 +02:00
2005-09-10 16:24:10 +02:00
/*
* Actions
*/
2021-08-03 17:03:34 +02:00
2021-02-23 21:09:01 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
$massaction = '' ;
}
2005-09-10 16:24:10 +02:00
2019-07-18 16:12:42 +02:00
$parameters = array ( 'mode' => $mode , 'format' => $format , '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' );
}
2018-03-10 11:23:35 +01:00
2021-01-13 18:09:57 +01:00
if ( empty ( $reshook )) {
2019-07-18 18:09:37 +02:00
// Change customer bank information to withdraw
2021-01-13 18:09:57 +01:00
if ( $action == 'modify' ) {
for ( $i = 1 ; $i < 9 ; $i ++ ) {
2019-07-18 18:09:37 +02:00
dolibarr_set_const ( $db , GETPOST ( " nom $i " ), GETPOST ( " value $i " ), 'chaine' , 0 , '' , $conf -> entity );
2017-10-13 13:28:26 +02:00
}
}
2021-01-13 18:09:57 +01:00
if ( $action == 'create' ) {
2021-10-25 22:07:31 +02:00
$default_account = ( $type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT' );
2020-12-31 10:49:27 +01:00
2021-12-09 12:42:04 +01:00
//var_dump($default_account);var_dump($conf->global->$default_account);var_dump($id_bankaccount);exit;
if ( $id_bankaccount != $conf -> global -> $default_account ) {
$res = dolibarr_set_const ( $db , $default_account , $id_bankaccount , 'chaine' , 0 , '' , $conf -> entity ); // Set as default
2020-11-09 13:17:24 +01:00
}
2020-12-31 10:49:27 +01:00
2020-11-09 13:17:24 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
$bank = new Account ( $db );
$bank -> fetch ( $conf -> global -> { $default_account });
2022-04-15 16:17:03 +02:00
// ICS is not mandatory with payment by bank transfer
/* if (( empty ( $bank -> ics ) && $type !== 'bank-transfer' )
2021-09-06 15:24:22 +02:00
|| ( empty ( $bank -> ics_transfer ) && $type === 'bank-transfer' )
2022-04-15 16:17:03 +02:00
) { */
if ( empty ( $bank -> ics ) && $type !== 'bank-transfer' ) {
2021-08-04 12:43:36 +02:00
$errormessage = str_replace ( '{url}' , $bank -> getNomUrl ( 1 , '' , '' , - 1 , 1 ), $langs -> trans ( " ErrorICSmissing " , '{url}' ));
2021-01-13 18:09:57 +01:00
setEventMessages ( $errormessage , null , 'errors' );
2021-12-09 12:42:04 +01:00
$action = '' ;
$error ++ ;
2020-11-09 13:17:24 +01:00
}
2020-12-31 10:49:27 +01:00
2020-11-09 13:17:24 +01:00
2019-07-18 18:09:37 +02:00
$bprev = new BonPrelevement ( $db );
2021-12-09 12:42:04 +01:00
if ( ! $error ) {
// $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty (we don't use them anymore)
$result = $bprev -> create ( $conf -> global -> PRELEVEMENT_CODE_BANQUE , $conf -> global -> PRELEVEMENT_CODE_GUICHET , $mode , $format , $executiondate , 0 , $type );
if ( $result < 0 ) {
setEventMessages ( $bprev -> error , $bprev -> errors , 'errors' );
} elseif ( $result == 0 ) {
$mesg = $langs -> trans ( " NoInvoiceCouldBeWithdrawed " , $format );
setEventMessages ( $mesg , null , 'errors' );
$mesg .= '<br>' . " \n " ;
foreach ( $bprev -> invoice_in_error as $key => $val ) {
$mesg .= '<span class="warning">' . $val . " </span><br> \n " ;
}
2020-07-27 19:33:24 +02:00
} else {
2021-12-09 12:42:04 +01:00
if ( $type != 'bank-transfer' ) {
$texttoshow = $langs -> trans ( " DirectDebitOrderCreated " , '{s}' );
$texttoshow = str_replace ( '{s}' , $bprev -> getNomUrl ( 1 ), $texttoshow );
setEventMessages ( $texttoshow , null );
} else {
$texttoshow = $langs -> trans ( " CreditTransferOrderCreated " , '{s}' );
$texttoshow = str_replace ( '{s}' , $bprev -> getNomUrl ( 1 ), $texttoshow );
setEventMessages ( $texttoshow , null );
}
header ( " Location: " . DOL_URL_ROOT . '/compta/prelevement/card.php?id=' . urlencode ( $bprev -> id ) . '&type=' . urlencode ( $type ));
exit ;
2020-07-27 19:33:24 +02:00
}
2019-07-18 18:09:37 +02:00
}
2021-02-10 08:15:16 +01:00
}
2021-02-10 08:11:28 +01:00
$objectclass = " BonPrelevement " ;
2021-10-04 04:36:58 +02:00
if ( $type == 'bank-transfer' ) {
$uploaddir = $conf -> paymentbybanktransfer -> dir_output ;
} else {
$uploaddir = $conf -> prelevement -> dir_output ;
}
2021-02-10 08:11:28 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
2005-07-25 15:07:22 +02:00
}
2008-11-04 17:58:26 +01:00
/*
* View
*/
2019-09-06 14:24:33 +02:00
2018-03-10 11:23:35 +01:00
$form = new Form ( $db );
2008-11-04 17:58:26 +01:00
2020-01-30 01:48:28 +01:00
$thirdpartystatic = new Societe ( $db );
2020-07-02 15:45:11 +02:00
if ( $type != 'bank-transfer' ) {
$invoicestatic = new Facture ( $db );
} else {
$invoicestatic = new FactureFournisseur ( $db );
}
2008-11-05 23:34:14 +01:00
$bprev = new BonPrelevement ( $db );
2021-02-10 08:11:28 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
// List of mass actions available
$arrayofmassactions = array (
);
2021-02-23 21:09:01 +01:00
if ( GETPOST ( 'nomassaction' , 'int' ) || in_array ( $massaction , array ( 'presend' , 'predelete' ))) {
$arrayofmassactions = array ();
}
2021-02-10 08:11:28 +01:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2008-11-05 23:34:14 +01:00
2009-04-27 22:37:50 +02:00
llxHeader ( '' , $langs -> trans ( " NewStandingOrder " ));
2005-07-25 15:07:22 +02:00
2021-01-13 18:09:57 +01:00
if ( prelevement_check_config ( $type ) < 0 ) {
2011-02-03 23:19:36 +01:00
$langs -> load ( " errors " );
2021-08-03 17:03:34 +02:00
$modulenametoshow = " Withdraw " ;
if ( $type == 'bank-transfer' ) {
$modulenametoshow = " PaymentByBankTransfer " ;
}
setEventMessages ( $langs -> trans ( " ErrorModuleSetupNotComplete " , $langs -> transnoentitiesnoconv ( $modulenametoshow )), null , 'errors' );
2011-02-03 23:19:36 +01:00
}
2020-11-09 13:17:24 +01:00
2015-06-21 17:05:49 +02:00
/* $h = 0 ;
2005-07-25 15:07:22 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/prelevement/create.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " NewStandingOrder " );
2015-06-21 17:05:49 +02:00
$head [ $h ][ 2 ] = 'payment' ;
$hselected = 'payment' ;
2005-07-25 15:07:22 +02:00
$h ++ ;
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , $hselected , $langs -> trans ( " StandingOrders " ), 0 , 'payment' );
2015-06-21 17:05:49 +02:00
*/
2005-07-25 15:07:22 +02:00
2020-05-27 20:14:11 +02:00
$title = $langs -> trans ( " NewStandingOrder " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " NewPaymentByBankTransfer " );
}
print load_fiche_titre ( $title );
2015-06-21 17:05:49 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ();
2005-07-25 15:07:22 +02:00
2020-06-08 11:43:20 +02:00
$nb = $bprev -> nbOfInvoiceToPay ( $type );
$pricetowithdraw = $bprev -> SommeAPrelever ( $type );
2021-02-23 21:09:01 +01:00
if ( $nb < 0 ) {
2017-10-13 13:28:26 +02:00
dol_print_error ( $bprev -> error );
2005-12-09 00:53:43 +01:00
}
2019-10-14 18:41:46 +02:00
print '<table class="border centpercent tableforfield">' ;
2008-11-05 23:34:14 +01:00
2020-05-27 20:14:11 +02:00
$title = $langs -> trans ( " NbOfInvoiceToWithdraw " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " NbOfInvoiceToPayByBankTransfer " );
}
2020-06-18 03:44:26 +02:00
print '<tr><td class="titlefieldcreate">' . $title . '</td>' ;
2017-02-10 10:47:19 +01:00
print '<td>' ;
2005-09-10 16:24:10 +02:00
print $nb ;
2008-11-05 23:34:14 +01:00
print '</td></tr>' ;
2010-09-05 03:20:53 +02:00
2020-05-27 20:14:11 +02:00
print '<tr><td>' . $langs -> trans ( " AmountTotal " ) . '</td>' ;
2021-08-02 18:23:05 +02:00
print '<td class="amount">' ;
2010-09-05 03:20:53 +02:00
print price ( $pricetowithdraw );
2005-09-10 16:24:10 +02:00
print '</td>' ;
2008-11-05 23:34:14 +01:00
print '</tr>' ;
print '</table>' ;
2005-07-25 15:07:22 +02:00
print '</div>' ;
2021-02-23 21:09:01 +01:00
if ( $mesg ) {
print $mesg ;
}
2005-07-25 15:07:22 +02:00
2020-05-27 20:14:11 +02:00
print '<div class="tabsAction">' . " \n " ;
2019-10-14 18:41:46 +02:00
2020-01-30 01:48:28 +01:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '?action=create" method="POST">' ;
2020-09-14 16:24:02 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2020-07-02 15:45:11 +02:00
print '<input type="hidden" name="type" value="' . $type . '">' ;
2018-03-10 11:23:35 +01:00
if ( $nb ) {
2021-02-23 21:09:01 +01:00
if ( $pricetowithdraw ) {
2021-08-04 12:30:48 +02:00
$title = $langs -> trans ( 'BankToReceiveWithdraw' ) . ': ' ;
2021-08-02 18:23:05 +02:00
if ( $type == 'bank-transfer' ) {
2021-08-04 12:28:13 +02:00
$title = $langs -> trans ( 'BankToPayCreditTransfer' ) . ': ' ;
2021-08-02 18:23:05 +02:00
}
print $title ;
2021-08-04 12:38:28 +02:00
print img_picto ( '' , 'bank_account' );
2021-12-09 12:42:04 +01:00
$default_account = ( $type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT' );
print $form -> select_comptes ( $conf -> global -> $default_account , 'id_bankaccount' , 0 , " courant=1 " , 0 , '' , 0 , '' , 1 );
2021-02-23 21:09:01 +01:00
print ' - ' ;
2020-12-31 10:49:27 +01:00
2021-12-09 12:42:04 +01:00
if ( empty ( $executiondate )) {
$delayindays = 0 ;
if ( $type != 'bank-transfer' ) {
$delayindays = $conf -> global -> PRELEVEMENT_ADDDAYS ;
} else {
$delayindays = $conf -> global -> PAYMENTBYBANKTRANSFER_ADDDAYS ;
}
$executiondate = dol_time_plus_duree ( dol_now (), $delayindays , 'd' );
}
2021-02-23 21:09:01 +01:00
print $langs -> trans ( 'ExecutionDate' ) . ' ' ;
2021-12-09 12:42:04 +01:00
$datere = $executiondate ;
2021-02-23 21:09:01 +01:00
print $form -> selectDate ( $datere , 're' );
2020-11-09 13:17:24 +01:00
2020-09-07 10:18:17 +02:00
if ( $mysoc -> isInEEC ()) {
$title = $langs -> trans ( " CreateForSepa " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " CreateSepaFileForPaymentByBankTransfer " );
}
if ( $type != 'bank-transfer' ) {
print '<select name="format">' ;
print '<option value="FRST"' . ( GETPOST ( 'format' , 'aZ09' ) == 'FRST' ? ' selected="selected"' : '' ) . '>' . $langs -> trans ( 'SEPAFRST' ) . '</option>' ;
print '<option value="RCUR"' . ( GETPOST ( 'format' , 'aZ09' ) == 'RCUR' ? ' selected="selected"' : '' ) . '>' . $langs -> trans ( 'SEPARCUR' ) . '</option>' ;
print '</select>' ;
}
2021-08-24 17:04:17 +02:00
print '<input type="submit" class="butAction" value="' . $title . '"/>' ;
2020-09-07 10:18:17 +02:00
} else {
$title = $langs -> trans ( " CreateAll " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " CreateFileForPaymentByBankTransfer " );
}
2021-12-09 12:42:04 +01:00
print '<input type="hidden" name="format" value="ALL">' . " \n " ;
print '<input type="submit" class="butAction" value="' . $title . '">' . " \n " ;
2018-03-10 11:23:35 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-01-13 18:09:57 +01:00
if ( $mysoc -> isInEEC ()) {
2020-06-08 11:43:20 +02:00
$title = $langs -> trans ( " CreateForSepaFRST " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " CreateSepaFileForPaymentByBankTransfer " );
}
print '<a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " AmountMustBePositive " ) . '">' . $title . " </a> \n " ;
if ( $type != 'bank-transfer' ) {
$title = $langs -> trans ( " CreateForSepaRCUR " );
print '<a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " AmountMustBePositive " ) . '">' . $title . " </a> \n " ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-05-27 20:14:11 +02:00
$title = $langs -> trans ( " CreateAll " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " CreateFileForPaymentByBankTransfer " );
}
print '<a class="butActionRefused classfortooltip" href="#">' . $title . " </a> \n " ;
2017-10-13 13:28:26 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-06-08 11:52:43 +02:00
$titlefortab = $langs -> transnoentitiesnoconv ( " StandingOrders " );
$title = $langs -> trans ( " CreateAll " );
if ( $type == 'bank-transfer' ) {
$titlefortab = $langs -> transnoentitiesnoconv ( " PaymentByBankTransfers " );
$title = $langs -> trans ( " CreateFileForPaymentByBankTransfer " );
}
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NoInvoiceToWithdraw " , $titlefortab , $titlefortab )) . '">' . $title . " </a> \n " ;
2005-09-10 16:24:10 +02:00
}
2005-07-25 15:07:22 +02:00
2019-07-03 10:44:12 +02:00
print " </form> \n " ;
2019-10-14 18:41:46 +02:00
2010-09-05 15:24:59 +02:00
print " </div> \n " ;
2020-01-23 17:45:16 +01:00
print '</form>' ;
2010-09-05 15:24:59 +02:00
print '<br>' ;
2005-07-25 15:07:22 +02:00
2005-08-03 10:36:15 +02:00
2005-07-25 15:07:22 +02:00
/*
2010-09-05 03:20:53 +02:00
* Invoices waiting for withdraw
2005-07-25 15:07:22 +02:00
*/
2010-09-05 03:20:53 +02:00
2018-12-02 14:31:45 +01:00
$sql = " SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid, " ;
2021-02-10 08:11:28 +01:00
$sql .= " pfd.rowid as request_row_id, pfd.date_demande, pfd.amount " ;
2020-05-27 20:14:11 +02:00
if ( $type == 'bank-transfer' ) {
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f, " ;
} else {
$sql .= " FROM " . MAIN_DB_PREFIX . " facture 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 " ;
$sql .= " WHERE s.rowid = f.fk_soc " ;
$sql .= " AND f.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2021-01-13 18:09:57 +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-07-01 19:42:28 +02:00
//$sql .= " AND pfd.amount > 0";
2020-10-31 14:32:18 +01:00
$sql .= " AND f.total_ttc > 0 " ; // Avoid credit notes
2020-01-30 01:48:28 +01:00
$sql .= " AND pfd.traite = 0 " ;
2020-07-01 19:42:28 +02:00
$sql .= " AND pfd.ext_payment_id IS NULL " ;
2020-05-27 20:14:11 +02:00
if ( $type == 'bank-transfer' ) {
$sql .= " AND pfd.fk_facture_fourn = f.rowid " ;
2020-06-08 11:43:20 +02:00
} else {
$sql .= " AND pfd.fk_facture = f.rowid " ;
2020-05-27 20:14:11 +02:00
}
2021-02-23 21:09:01 +01:00
if ( $socid > 0 ) {
2021-03-22 13:31:06 +01:00
$sql .= " AND f.fk_soc = " . (( int ) $socid );
2021-02-23 21:09:01 +01:00
}
2005-07-25 15:07:22 +02:00
2018-08-10 15:05:21 +02:00
$nbtotalofrecords = '' ;
2021-01-13 18:09:57 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2018-08-10 15:05:21 +02:00
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
2021-01-13 18:09:57 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) {
// if total resultset is smaller then paging size (filtering), goto and load page 0
2020-01-23 17:45:16 +01:00
$page = 0 ;
$offset = 0 ;
}
2018-08-10 15:05:21 +02:00
}
2020-01-30 01:48:28 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2018-08-10 15:05:21 +02:00
2020-01-30 01:48:28 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2017-10-13 13:28:26 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2020-09-07 10:18:17 +02:00
$param = '' ;
2021-02-23 21:09:01 +01:00
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $socid ) {
$param .= '&socid=' . urlencode ( $socid );
}
if ( $option ) {
$param .= " &option= " . urlencode ( $option );
}
2018-08-10 15:05:21 +02:00
2020-09-07 10:18:17 +02:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-08-10 15:05:21 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2020-01-30 01:48:28 +01:00
if ( ! empty ( $limit )) {
print '<input type="hidden" name="limit" value="' . $limit . '"/>' ;
2020-01-23 17:45:16 +01:00
}
2018-08-10 15:05:21 +02:00
2020-05-27 20:14:11 +02:00
$title = $langs -> trans ( " InvoiceWaitingWithdraw " );
if ( $type == 'bank-transfer' ) {
$title = $langs -> trans ( " InvoiceWaitingPaymentByBankTransfer " );
}
2021-02-10 08:11:28 +01:00
print_barre_liste ( $title , $page , $_SERVER [ 'PHP_SELF' ], $param , '' , '' , $massactionbutton , $num , $nbtotalofrecords , 'bill' , 0 , '' , '' , $limit );
2017-10-13 13:28:26 +02:00
2020-09-07 10:18:17 +02:00
$tradinvoice = " Invoice " ;
if ( $type == 'bank-transfer' ) {
$tradinvoice = " SupplierInvoice " ;
}
2020-07-01 14:19:47 +02:00
2019-10-14 18:41:46 +02:00
print '<table class="noborder centpercent">' ;
2017-10-13 13:28:26 +02:00
print '<tr class="liste_titre">' ;
2020-07-01 14:19:47 +02:00
print '<td>' . $langs -> trans ( $tradinvoice ) . '</td>' ;
2017-10-13 13:28:26 +02:00
print '<td>' . $langs -> trans ( " ThirdParty " ) . '</td>' ;
print '<td>' . $langs -> trans ( " RIB " ) . '</td>' ;
print '<td>' . $langs -> trans ( " RUM " ) . '</td>' ;
2019-02-10 16:00:59 +01:00
print '<td class="right">' . $langs -> trans ( " AmountTTC " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " DateRequest " ) . '</td>' ;
2021-02-23 21:09:01 +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
2021-02-10 08:11:28 +01:00
print '<td align="center">' . $form -> showCheckAddButtons ( 'checkforselect' , 1 ) . '</td>' ;
}
2017-10-13 13:28:26 +02:00
print '</tr>' ;
2021-02-23 21:09:01 +01:00
if ( $num ) {
2020-01-30 01:48:28 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php' ;
2017-10-13 13:28:26 +02:00
$bac = new CompanyBankAccount ( $db );
2021-02-23 21:09:01 +01:00
while ( $i < $num && $i < $limit ) {
2017-10-13 13:28:26 +02:00
$obj = $db -> fetch_object ( $resql );
2020-06-08 11:43:20 +02:00
$bac -> fetch ( 0 , $obj -> socid );
2017-10-13 13:28:26 +02:00
print '<tr class="oddeven">' ;
2020-06-08 11:43:20 +02:00
// Ref invoice
2017-10-13 13:28:26 +02:00
print '<td>' ;
2020-01-30 01:48:28 +01:00
$invoicestatic -> id = $obj -> rowid ;
$invoicestatic -> ref = $obj -> ref ;
2019-01-27 11:55:16 +01:00
print $invoicestatic -> getNomUrl ( 1 , 'withdraw' );
2017-10-13 13:28:26 +02:00
print '</td>' ;
2020-06-08 11:43:20 +02:00
2017-10-13 13:28:26 +02:00
// Thirdparty
print '<td>' ;
$thirdpartystatic -> fetch ( $obj -> socid );
2019-01-27 11:55:16 +01:00
print $thirdpartystatic -> getNomUrl ( 1 , 'ban' );
2017-10-13 13:28:26 +02:00
print '</td>' ;
2020-06-08 11:43:20 +02:00
2017-10-13 13:28:26 +02:00
// RIB
print '<td>' ;
2022-04-06 16:15:34 +02:00
if ( $bac -> id > 0 ) {
if ( ! empty ( $bac -> iban ) || ! empty ( $bac -> bic )) {
print $bac -> iban . (( $bac -> iban && $bac -> bic ) ? ' / ' : '' ) . $bac -> bic ;
if ( $bac -> verif () <= 0 ) {
print img_warning ( 'Error on default bank number for IBAN : ' . $langs -> trans ( $bac -> error_message ));
}
} else {
print img_warning ( $langs -> trans ( " IBANNotDefined " ));
}
} else {
print img_warning ( $langs -> trans ( " NoBankAccountDefined " ));
2021-02-23 21:09:01 +01:00
}
2017-10-13 13:28:26 +02:00
print '</td>' ;
2020-06-08 11:43:20 +02:00
2017-10-13 13:28:26 +02:00
// RUM
print '<td>' ;
2020-08-03 14:11:15 +02:00
$rumtoshow = $thirdpartystatic -> display_rib ( 'rum' );
if ( $rumtoshow ) {
print $rumtoshow ;
$format = $thirdpartystatic -> display_rib ( 'format' );
if ( $type != 'bank-transfer' ) {
2021-02-23 21:09:01 +01:00
if ( $format ) {
print ' (' . $format . ')' ;
}
2020-08-03 14:11:15 +02:00
}
} else {
2021-01-13 18:09:57 +01:00
print img_warning ( $langs -> trans ( " NoBankAccountDefined " ));
2020-07-02 15:45:11 +02:00
}
2017-10-13 13:28:26 +02:00
print '</td>' ;
// Amount
2021-08-04 12:41:27 +02:00
print '<td class="right amount">' ;
2019-01-27 11:55:16 +01:00
print price ( $obj -> amount , 0 , $langs , 0 , 0 , - 1 , $conf -> currency );
2017-10-13 13:28:26 +02:00
print '</td>' ;
// Date
2019-02-10 16:00:59 +01:00
print '<td class="right">' ;
2019-01-27 11:55:16 +01:00
print dol_print_date ( $db -> jdate ( $obj -> date_demande ), 'day' );
2017-10-13 13:28:26 +02:00
print '</td>' ;
2021-02-10 08:11:28 +01:00
// Action column
2021-02-23 21:09:01 +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
2021-02-10 08:11:28 +01:00
print '<td class="nowrap center">' ;
$selected = 0 ;
2021-02-23 21:09:01 +01:00
if ( in_array ( $obj -> request_row_id , $arrayofselected )) {
$selected = 1 ;
}
2021-02-10 08:11:28 +01:00
print '<input id="cb' . $obj -> request_row_id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $obj -> request_row_id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
print '</td>' ;
}
2017-10-13 13:28:26 +02:00
print '</tr>' ;
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-10-14 18:41:46 +02:00
print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
}
2017-10-13 13:28:26 +02:00
print " </table> " ;
2018-08-10 15:05:21 +02:00
print " </form> " ;
2017-10-13 13:28:26 +02:00
print " <br> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-13 13:28:26 +02:00
dol_print_error ( $db );
2010-09-05 03:20:53 +02:00
}
/*
2017-02-10 10:47:19 +01:00
* List of latest withdraws
2010-09-05 03:20:53 +02:00
*/
2017-02-21 13:16:28 +01:00
/*
2010-09-05 03:20:53 +02:00
$limit = 5 ;
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( " LastWithdrawalReceipts " , $limit ), '' , '' );
2010-09-05 03:20:53 +02:00
$sql = " SELECT p.rowid, p.ref, p.amount, p.statut " ;
$sql .= " , p.datec " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_bons as p " ;
2018-11-13 12:11:21 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2010-09-05 03:20:53 +02:00
$sql .= " ORDER BY datec DESC " ;
$sql .= $db -> plimit ( $limit );
$result = $db -> query ( $sql );
if ( $result )
{
2021-02-23 21:09:01 +01:00
$num = $db -> num_rows ( $result );
$i = 0 ;
2010-09-05 03:20:53 +02:00
2021-02-23 21:09:01 +01:00
print " \n <!-- debut table --> \n " ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre"><td>' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " Date " ) . '</td><td class="right">' . $langs -> trans ( " Amount " ) . '</td>' ;
print '</tr>' ;
2010-09-05 03:20:53 +02:00
2021-02-23 21:09:01 +01:00
while ( $i < min ( $num , $limit ))
{
$obj = $db -> fetch_object ( $result );
2017-06-07 16:44:04 +02:00
2010-09-05 03:20:53 +02:00
2021-02-23 21:09:01 +01:00
print '<tr class="oddeven">' ;
2015-06-21 17:05:49 +02:00
2021-02-23 21:09:01 +01:00
print " <td> " ;
$bprev -> id = $obj -> rowid ;
$bprev -> ref = $obj -> ref ;
print $bprev -> getNomUrl ( 1 );
print " </td> \n " ;
2015-06-21 17:05:49 +02:00
2021-02-23 21:09:01 +01:00
print '<td class="center">' . dol_print_date ( $db -> jdate ( $obj -> datec ), 'day' ) . " </td> \n " ;
2010-09-05 03:20:53 +02:00
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $obj -> amount , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " </span></td> \n " ;
2010-09-05 03:20:53 +02:00
2021-02-23 21:09:01 +01:00
print " </tr> \n " ;
$i ++ ;
}
print " </table><br> " ;
$db -> free ( $result );
2005-07-25 15:07:22 +02:00
}
else
{
2021-02-23 21:09:01 +01:00
dol_print_error ( $db );
2008-11-05 23:34:14 +01:00
}
2017-02-21 13:16:28 +01:00
*/
2005-07-25 15:07:22 +02: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 ();