31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/prelevement.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
42 $langs->loadLangs(array(
'banks',
'categories',
'withdrawals',
'companies',
'bills'));
44 $type =
GETPOST(
'type',
'aZ09');
47 $action =
GETPOST(
'action',
'aZ09');
48 $massaction =
GETPOST(
'massaction',
'alpha');
49 $toselect =
GETPOST(
'toselect',
'array');
51 $mode =
GETPOST(
'mode',
'alpha') ?
GETPOST(
'mode',
'alpha') :
'real';
52 $format =
GETPOST(
'format',
'aZ09');
53 $id_bankaccount =
GETPOST(
'id_bankaccount',
'int');
56 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
58 if (empty($page) || $page == -1) {
61 $offset = $limit * $page;
63 $hookmanager->initHooks(array(
'directdebitcreatecard',
'globalcard'));
66 $socid =
GETPOST(
'socid',
'int');
68 $socid = $user->socid;
70 if ($type ==
'bank-transfer') {
71 $result =
restrictedArea($user,
'paymentbybanktransfer',
'',
'',
'');
85 if (
GETPOST(
'cancel',
'alpha')) {
89 $parameters = array(
'mode' => $mode,
'format' => $format,
'limit' => $limit,
'page' => $page,
'offset' => $offset);
90 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
95 if (empty($reshook)) {
97 if ($action ==
'modify') {
98 for ($i = 1; $i < 9; $i++) {
102 if ($action ==
'create') {
103 $default_account = ($type ==
'bank-transfer' ?
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' :
'PRELEVEMENT_ID_BANKACCOUNT');
107 if ($id_bankaccount != $conf->global->$default_account) {
108 $res =
dolibarr_set_const($db, $default_account, $id_bankaccount,
'chaine', 0,
'', $conf->entity);
111 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
113 $bank->fetch($conf->global->{$default_account});
118 if (empty($bank->ics) && $type !==
'bank-transfer') {
119 $errormessage = str_replace(
'{url}', $bank->getNomUrl(1,
'',
'', -1, 1), $langs->trans(
"ErrorICSmissing",
'{url}'));
130 $result = $bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $mode, $format, $executiondate, 0, $type);
133 } elseif ($result == 0) {
134 $mesg = $langs->trans(
"NoInvoiceCouldBeWithdrawed", $format);
136 $mesg .=
'<br>'.
"\n";
137 foreach ($bprev->invoice_in_error as $key => $val) {
138 $mesg .=
'<span class="warning">'.$val.
"</span><br>\n";
141 if ($type !=
'bank-transfer') {
142 $texttoshow = $langs->trans(
"DirectDebitOrderCreated",
'{s}');
143 $texttoshow = str_replace(
'{s}', $bprev->getNomUrl(1), $texttoshow);
146 $texttoshow = $langs->trans(
"CreditTransferOrderCreated",
'{s}');
147 $texttoshow = str_replace(
'{s}', $bprev->getNomUrl(1), $texttoshow);
151 header(
"Location: ".DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.urlencode($bprev->id).
'&type='.urlencode($type));
156 $objectclass =
"BonPrelevement";
157 if ($type ==
'bank-transfer') {
158 $uploaddir = $conf->paymentbybanktransfer->dir_output;
160 $uploaddir = $conf->prelevement->dir_output;
162 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
172 $thirdpartystatic =
new Societe($db);
173 if ($type !=
'bank-transfer') {
174 $invoicestatic =
new Facture($db);
179 $arrayofselected = is_array($toselect) ? $toselect : array();
181 $arrayofmassactions = array(
183 if (
GETPOST(
'nomassaction',
'int') || in_array($massaction, array(
'presend',
'predelete'))) {
184 $arrayofmassactions = array();
186 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
188 llxHeader(
'', $langs->trans(
"NewStandingOrder"));
191 $langs->load(
"errors");
192 $modulenametoshow =
"Withdraw";
193 if ($type ==
'bank-transfer') {
194 $modulenametoshow =
"PaymentByBankTransfer";
196 setEventMessages($langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv($modulenametoshow)),
null,
'errors');
210 $title = $langs->trans(
"NewStandingOrder");
211 if ($type ==
'bank-transfer') {
212 $title = $langs->trans(
"NewPaymentByBankTransfer");
219 $nb = $bprev->nbOfInvoiceToPay($type);
220 $pricetowithdraw = $bprev->SommeAPrelever($type);
224 print
'<table class="border centpercent tableforfield">';
226 $title = $langs->trans(
"NbOfInvoiceToWithdraw");
227 if ($type ==
'bank-transfer') {
228 $title = $langs->trans(
"NbOfInvoiceToPayByBankTransfer");
231 print
'<tr><td class="titlefield">'.$title.
'</td>';
232 print
'<td class="nowraponall">';
236 print
'<tr><td>'.$langs->trans(
"AmountTotal").
'</td>';
237 print
'<td class="amount nowraponall">';
238 print
price($pricetowithdraw, 0, $langs, 1, -1, -1, $conf->currency);
249 print
'<div class="tabsAction">'.
"\n";
251 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?action=create" method="POST">';
252 print
'<input type="hidden" name="token" value="'.newToken().
'">';
253 print
'<input type="hidden" name="type" value="'.$type.
'">';
255 if ($pricetowithdraw) {
256 $title = $langs->trans(
'BankToReceiveWithdraw').
': ';
257 if ($type ==
'bank-transfer') {
258 $title = $langs->trans(
'BankToPayCreditTransfer').
': ';
260 print
'<span class="hideonsmartphone">'.$title.
'</span>';
263 $default_account = ($type ==
'bank-transfer' ?
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' :
'PRELEVEMENT_ID_BANKACCOUNT');
265 print
$form->select_comptes(
getDolGlobalInt($default_account),
'id_bankaccount', 0,
"courant=1", 0,
'', 0,
'widthcentpercentminusx maxwidth300', 1);
266 print
' ';
268 if (empty($executiondate)) {
270 if ($type !=
'bank-transfer') {
279 print $langs->trans(
'ExecutionDate').
' ';
280 $datere = $executiondate;
281 print
$form->selectDate($datere,
're');
284 if ($mysoc->isInEEC()) {
285 $title = $langs->trans(
"CreateForSepa");
286 if ($type ==
'bank-transfer') {
287 $title = $langs->trans(
"CreateSepaFileForPaymentByBankTransfer");
290 if ($type !=
'bank-transfer') {
291 print
'<select name="format">';
292 print
'<option value="FRST"'.($format ==
'FRST' ?
' selected="selected"' :
'').
'>'.$langs->trans(
'SEPAFRST').
'</option>';
293 print
'<option value="RCUR"'.($format ==
'RCUR' ?
' selected="selected"' :
'').
'>'.$langs->trans(
'SEPARCUR').
'</option>';
296 print
'<input type="submit" class="butAction margintoponly maringbottomonly" value="'.$title.
'"/>';
298 $title = $langs->trans(
"CreateAll");
299 if ($type ==
'bank-transfer') {
300 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
302 print
'<input type="hidden" name="format" value="ALL">'.
"\n";
303 print
'<input type="submit" class="butAction margintoponly maringbottomonly" value="'.$title.
'">'.
"\n";
306 if ($mysoc->isInEEC()) {
307 $title = $langs->trans(
"CreateForSepaFRST");
308 if ($type ==
'bank-transfer') {
309 $title = $langs->trans(
"CreateSepaFileForPaymentByBankTransfer");
311 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.$langs->trans(
"AmountMustBePositive").
'">'.$title.
"</a>\n";
313 if ($type !=
'bank-transfer') {
314 $title = $langs->trans(
"CreateForSepaRCUR");
315 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.$langs->trans(
"AmountMustBePositive").
'">'.$title.
"</a>\n";
318 $title = $langs->trans(
"CreateAll");
319 if ($type ==
'bank-transfer') {
320 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
322 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#">'.$title.
"</a>\n";
326 $titlefortab = $langs->transnoentitiesnoconv(
"StandingOrders");
327 $title = $langs->trans(
"CreateAll");
328 if ($type ==
'bank-transfer') {
329 $titlefortab = $langs->transnoentitiesnoconv(
"PaymentByBankTransfers");
330 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
332 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoInvoiceToWithdraw", $titlefortab, $titlefortab)).
'">';
348 $sql =
"SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
349 if ($type ==
'bank-transfer') {
350 $sql .=
" f.ref_supplier,";
352 $sql .=
" pfd.rowid as request_row_id, pfd.date_demande, pfd.amount";
353 if ($type ==
'bank-transfer') {
354 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f,";
356 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f,";
358 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s,";
359 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
360 $sql .=
" WHERE s.rowid = f.fk_soc";
361 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
362 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
363 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
366 $sql .=
" AND f.total_ttc > 0";
367 $sql .=
" AND pfd.traite = 0";
368 $sql .=
" AND pfd.ext_payment_id IS NULL";
369 if ($type ==
'bank-transfer') {
370 $sql .=
" AND pfd.fk_facture_fourn = f.rowid";
372 $sql .=
" AND pfd.fk_facture = f.rowid";
375 $sql .=
" AND f.fk_soc = ".((int) $socid);
379 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
380 $result = $db->query(
$sql);
389 $sql .= $db->plimit($limit + 1, $offset);
391 $resql = $db->query(
$sql);
393 $num = $db->num_rows($resql);
397 if ($limit > 0 && $limit != $conf->liste_limit) {
398 $param .=
'&limit='.urlencode($limit);
401 $param .=
'&socid='.urlencode($socid);
404 $param .=
"&option=".urlencode($option);
407 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
408 print
'<input type="hidden" name="token" value="'.newToken().
'">';
409 print
'<input type="hidden" name="page" value="'.$page.
'">';
410 if (!empty($limit)) {
411 print
'<input type="hidden" name="limit" value="'.$limit.
'"/>';
414 print
'<input type="hidden" name="type" value="'.$type.
'">';
417 $title = $langs->trans(
"InvoiceWaitingWithdraw");
418 if ($type ==
'bank-transfer') {
419 $title = $langs->trans(
"InvoiceWaitingPaymentByBankTransfer");
421 print_barre_liste($title, $page, $_SERVER[
'PHP_SELF'], $param,
'',
'', $massactionbutton, $num,
$nbtotalofrecords,
'bill', 0,
'',
'', $limit);
423 $tradinvoice =
"Invoice";
424 if ($type ==
'bank-transfer') {
425 $tradinvoice =
"SupplierInvoice";
428 print
'<div class="div-table-responsive-no-min">';
429 print
'<table class="noborder centpercent">';
430 print
'<tr class="liste_titre">';
431 print
'<td>'.$langs->trans($tradinvoice).
'</td>';
432 if ($type ==
'bank-transfer') {
433 print
'<td>'.$langs->trans(
"RefSupplier").
'</td>';
435 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
436 print
'<td>'.$langs->trans(
"RIB").
'</td>';
437 print
'<td>'.$langs->trans(
"RUM").
'</td>';
438 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
439 print
'<td class="right">'.$langs->trans(
"DateRequest").
'</td>';
440 if ($massactionbutton || $massaction) {
441 print
'<td align="center">'.$form->showCheckAddButtons(
'checkforselect', 1).
'</td>';
446 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
449 while ($i < $num && $i < $limit) {
450 $obj = $db->fetch_object($resql);
452 $bac->fetch(0, $obj->socid);
454 $invoicestatic->id = $obj->rowid;
455 $invoicestatic->ref = $obj->ref;
456 $invoicestatic->ref_supplier = $obj->ref_supplier;
458 print
'<tr class="oddeven">';
461 print
'<td class="tdoverflowmax150">';
462 print $invoicestatic->getNomUrl(1,
'withdraw');
465 if ($type ==
'bank-transfer') {
466 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($invoicestatic->ref_supplier).
'">';
472 print
'<td class="tdoverflowmax100">';
473 $thirdpartystatic->fetch($obj->socid);
474 print $thirdpartystatic->getNomUrl(1,
'ban');
480 if (!empty($bac->iban) || !empty($bac->bic)) {
481 print $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
482 if ($bac->verif() <= 0) {
483 print
img_warning(
'Error on default bank number for IBAN : '.$langs->trans($bac->error_message));
486 print
img_warning($langs->trans(
"IBANNotDefined"));
489 print
img_warning($langs->trans(
"NoBankAccountDefined"));
495 $rumtoshow = $thirdpartystatic->display_rib(
'rum');
498 $format = $thirdpartystatic->display_rib(
'format');
499 if ($type !=
'bank-transfer') {
501 print
' ('.$format.
')';
505 print
img_warning($langs->trans(
"NoBankAccountDefined"));
509 print
'<td class="right amount">';
510 print
price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
513 print
'<td class="right">';
517 if ($massactionbutton || $massaction) {
518 print
'<td class="nowrap center">';
520 if (in_array($obj->request_row_id, $arrayofselected)) {
523 print
'<input id="cb'.$obj->request_row_id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
530 print
'<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';