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');
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';
118 if (empty($bank->ics) && $type !==
'bank-transfer') {
119 $errormessage = str_replace(
'{url}', $bank->getNomUrl(1,
'',
'', -1, 1), $langs->trans(
"ErrorICSmissing",
'{url}'));
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);
189 $langs->load(
"errors");
190 $modulenametoshow =
"Withdraw";
191 if ($type ==
'bank-transfer') {
192 $modulenametoshow =
"PaymentByBankTransfer";
194 setEventMessages($langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv($modulenametoshow)),
null,
'errors');
198 $title = $langs->trans(
"NewStandingOrder");
199 if ($type ==
'bank-transfer') {
200 $title = $langs->trans(
"NewPaymentByBankTransfer");
209 $nb = $bprev->nbOfInvoiceToPay($type);
210 $pricetowithdraw = $bprev->SommeAPrelever($type);
214 print
'<table class="border centpercent tableforfield">';
216 $labeltoshow = $langs->trans(
"NbOfInvoiceToWithdraw");
217 if ($type ==
'bank-transfer') {
218 $labeltoshow = $langs->trans(
"NbOfInvoiceToPayByBankTransfer");
221 print
'<tr><td class="titlefield">'.$labeltoshow.
'</td>';
222 print
'<td class="nowraponall">';
226 print
'<tr><td>'.$langs->trans(
"AmountTotal").
'</td>';
227 print
'<td class="amount nowraponall">';
228 print
price($pricetowithdraw, 0, $langs, 1, -1, -1, $conf->currency);
239 print
'<div class="tabsAction">'.
"\n";
241 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?action=create" method="POST">';
242 print
'<input type="hidden" name="token" value="'.newToken().
'">';
243 print
'<input type="hidden" name="type" value="'.$type.
'">';
245 if ($pricetowithdraw) {
246 $title = $langs->trans(
'BankToReceiveWithdraw').
': ';
247 if ($type ==
'bank-transfer') {
248 $title = $langs->trans(
'BankToPayCreditTransfer').
': ';
250 print
'<span class="hideonsmartphone">'.$title.
'</span>';
253 $default_account = ($type ==
'bank-transfer' ?
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' :
'PRELEVEMENT_ID_BANKACCOUNT');
255 print
$form->select_comptes(
getDolGlobalInt($default_account),
'id_bankaccount', 0,
"courant=1", 0,
'', 0,
'widthcentpercentminusx maxwidth300', 1);
256 print
' ';
258 if (empty($executiondate)) {
260 if ($type !=
'bank-transfer') {
269 print $langs->trans(
'ExecutionDate').
' ';
270 $datere = $executiondate;
271 print
$form->selectDate($datere,
're');
274 if ($mysoc->isInEEC()) {
275 $title = $langs->trans(
"CreateForSepa");
276 if ($type ==
'bank-transfer') {
277 $title = $langs->trans(
"CreateSepaFileForPaymentByBankTransfer");
280 if ($type !=
'bank-transfer') {
281 print
'<select name="format">';
282 print
'<option value="FRST"'.($format ==
'FRST' ?
' selected="selected"' :
'').
'>'.$langs->trans(
'SEPAFRST').
'</option>';
283 print
'<option value="RCUR"'.($format ==
'RCUR' ?
' selected="selected"' :
'').
'>'.$langs->trans(
'SEPARCUR').
'</option>';
286 print
'<input type="submit" class="butAction margintoponly maringbottomonly" value="'.$title.
'"/>';
288 $title = $langs->trans(
"CreateAll");
289 if ($type ==
'bank-transfer') {
290 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
292 print
'<input type="hidden" name="format" value="ALL">'.
"\n";
293 print
'<input type="submit" class="butAction margintoponly maringbottomonly" value="'.$title.
'">'.
"\n";
296 if ($mysoc->isInEEC()) {
297 $title = $langs->trans(
"CreateForSepaFRST");
298 if ($type ==
'bank-transfer') {
299 $title = $langs->trans(
"CreateSepaFileForPaymentByBankTransfer");
301 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.$langs->trans(
"AmountMustBePositive").
'">'.$title.
"</a>\n";
303 if ($type !=
'bank-transfer') {
304 $title = $langs->trans(
"CreateForSepaRCUR");
305 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.$langs->trans(
"AmountMustBePositive").
'">'.$title.
"</a>\n";
308 $title = $langs->trans(
"CreateAll");
309 if ($type ==
'bank-transfer') {
310 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
312 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#">'.$title.
"</a>\n";
316 $titlefortab = $langs->transnoentitiesnoconv(
"StandingOrders");
317 $title = $langs->trans(
"CreateAll");
318 if ($type ==
'bank-transfer') {
319 $titlefortab = $langs->transnoentitiesnoconv(
"PaymentByBankTransfers");
320 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
322 print
'<a class="butActionRefused classfortooltip margintoponly maringbottomonly" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoInvoiceToWithdraw", $titlefortab, $titlefortab)).
'">';
338 $sql =
"SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
339 if ($type ==
'bank-transfer') {
340 $sql .=
" f.ref_supplier,";
342 $sql .=
" pfd.rowid as request_row_id, pfd.date_demande, pfd.amount";
343 if ($type ==
'bank-transfer') {
344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f,";
346 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f,";
348 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s,";
349 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
350 $sql .=
" WHERE s.rowid = f.fk_soc";
351 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
352 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
353 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
356 $sql .=
" AND f.total_ttc > 0";
357 $sql .=
" AND pfd.traite = 0";
358 $sql .=
" AND pfd.ext_payment_id IS NULL";
359 if ($type ==
'bank-transfer') {
360 $sql .=
" AND pfd.fk_facture_fourn = f.rowid";
362 $sql .=
" AND pfd.fk_facture = f.rowid";
365 $sql .=
" AND f.fk_soc = ".((int) $socid);
368 $nbtotalofrecords =
'';
370 $result = $db->query(
$sql);
371 $nbtotalofrecords = $db->num_rows($result);
372 if (($page * $limit) > $nbtotalofrecords) {
379 $sql .= $db->plimit($limit + 1, $offset);
381 $resql = $db->query(
$sql);
383 $num = $db->num_rows($resql);
387 if ($limit > 0 && $limit != $conf->liste_limit) {
388 $param .=
'&limit='.((int) $limit);
391 $param .=
'&socid='.urlencode($socid);
394 $param .=
"&option=".urlencode($option);
397 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
398 print
'<input type="hidden" name="token" value="'.newToken().
'">';
399 print
'<input type="hidden" name="page" value="'.$page.
'">';
400 if (!empty($limit)) {
401 print
'<input type="hidden" name="limit" value="'.$limit.
'"/>';
404 print
'<input type="hidden" name="type" value="'.$type.
'">';
407 $title = $langs->trans(
"InvoiceWaitingWithdraw");
408 if ($type ==
'bank-transfer') {
409 $title = $langs->trans(
"InvoiceWaitingPaymentByBankTransfer");
411 print_barre_liste($title, $page, $_SERVER[
'PHP_SELF'], $param,
'',
'', $massactionbutton, $num, $nbtotalofrecords,
'bill', 0,
'',
'', $limit);
413 $tradinvoice =
"Invoice";
414 if ($type ==
'bank-transfer') {
415 $tradinvoice =
"SupplierInvoice";
418 print
'<div class="div-table-responsive-no-min">';
419 print
'<table class="noborder centpercent">';
420 print
'<tr class="liste_titre">';
421 print
'<td>'.$langs->trans($tradinvoice).
'</td>';
422 if ($type ==
'bank-transfer') {
423 print
'<td>'.$langs->trans(
"RefSupplier").
'</td>';
425 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
426 print
'<td>'.$langs->trans(
"RIB").
'</td>';
427 print
'<td>'.$langs->trans(
"RUM").
'</td>';
428 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
429 print
'<td class="right">'.$langs->trans(
"DateRequest").
'</td>';
430 if ($massactionbutton || $massaction) {
431 print
'<td align="center">'.$form->showCheckAddButtons(
'checkforselect', 1).
'</td>';
436 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
438 while ($i < $num && $i < $limit) {
439 $obj = $db->fetch_object($resql);
442 $bac->fetch(0, $obj->socid);
444 $invoicestatic->id = $obj->rowid;
445 $invoicestatic->ref = $obj->ref;
446 $invoicestatic->ref_supplier = $obj->ref_supplier;
448 print
'<tr class="oddeven">';
451 print
'<td class="tdoverflowmax150">';
452 print $invoicestatic->getNomUrl(1,
'withdraw');
455 if ($type ==
'bank-transfer') {
456 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($invoicestatic->ref_supplier).
'">';
462 print
'<td class="tdoverflowmax100">';
463 $thirdpartystatic->fetch($obj->socid);
464 print $thirdpartystatic->getNomUrl(1,
'ban');
470 if (!empty($bac->iban) || !empty($bac->bic)) {
471 print $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
472 if ($bac->verif() <= 0) {
473 print
img_warning(
'Error on default bank number for IBAN : '.$langs->trans($bac->error_message));
476 print
img_warning($langs->trans(
"IBANNotDefined"));
479 print
img_warning($langs->trans(
"NoBankAccountDefined"));
485 $rumtoshow = $thirdpartystatic->display_rib(
'rum');
488 $format = $thirdpartystatic->display_rib(
'format');
489 if ($type !=
'bank-transfer') {
491 print
' ('.$format.
')';
495 print
img_warning($langs->trans(
"NoBankAccountDefined"));
499 print
'<td class="right amount">';
500 print
price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
503 print
'<td class="right">';
507 if ($massactionbutton || $massaction) {
508 print
'<td class="nowrap center">';
510 if (in_array($obj->request_row_id, $arrayofselected)) {
513 print
'<input id="cb'.$obj->request_row_id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
520 print
'<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';