dolibarr 24.0.0-beta
create.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2010-2023 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
7 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2019 Markus Welters <markus@welters.de>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
42require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
43require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
44require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
50
51// Load translation files required by the page
52$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills'));
53
54// Get supervariables
55$action = GETPOST('action', 'aZ09');
56$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
57$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
58$mode = GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : 'real';
59
60$type = GETPOST('type', 'aZ09');
61$sourcetype = GETPOST('sourcetype', 'aZ09');
62$format = GETPOST('format', 'aZ09');
63$id_bankaccount = GETPOSTINT('id_bankaccount');
64$executiondate = dol_mktime(0, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
65
66$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
67$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
68if (empty($page) || $page == -1) {
69 $page = 0;
70} // If $page is not defined, or '' or -1
71$offset = $limit * $page;
72
73$hookmanager->initHooks(array('directdebitcreatecard', 'globalcard'));
74
75// Security check
76$socid = GETPOSTINT('socid');
77if ($user->socid) {
78 $socid = $user->socid;
79}
80if ($type == 'bank-transfer') {
81 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
82
83 $permissiontoread = $user->hasRight('paymentbybanktransfer', 'read');
84 $permissiontocreate = $user->hasRight('paymentbybanktransfer', 'create');
85} else {
86 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
87
88 $permissiontoread = $user->hasRight('prelevement', 'bons', 'lire');
89 $permissiontocreate = $user->hasRight('prelevement', 'bons', 'creer');
90}
91
92
93$error = 0;
94$option = "";
95$mesg = '';
96
98
99/*
100 * Actions
101 */
102
103if (GETPOST('cancel', 'alpha')) {
104 $massaction = '';
105}
106
107$parameters = array('mode' => $mode, 'format' => $format, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
108$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109if ($reshook < 0) {
110 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
111}
112
113if (empty($reshook)) {
114 if ($action == 'create' && $permissiontocreate && GETPOSTISSET('createtransferrequest')) {
115 $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
116 //var_dump($default_account);var_dump(getDolGlobalString($default_account));var_dump($id_bankaccount);exit;
117
118 if ($id_bankaccount != getDolGlobalInt($default_account)) {
119 $res = dolibarr_set_const($db, $default_account, $id_bankaccount, 'chaine', 0, '', $conf->entity); // Set as default
120 }
121 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
122 $bank = new Account($db);
123 $bank->fetch(getDolGlobalInt($default_account));
124 // ICS is not mandatory with payment by bank transfer
125 /*if ((empty($bank->ics) && $type !== 'bank-transfer')
126 || (empty($bank->ics_transfer) && $type === 'bank-transfer')
127 ) {*/
128
129 if (empty($bank->ics) && $type !== 'bank-transfer') {
130 $errormessage = str_replace('{url}', $bank->getNomUrl(1, '', '', -1, 1), $langs->trans("ErrorICSmissing", '{url}'));
131 setEventMessages($errormessage, null, 'errors');
132 $action = '';
133 $error++;
134 }
135 if (empty($toselect)) {
136 $errormessage = $langs->trans('ErrorBankTransferNoPaymentRequestSelected');
137 setEventMessages($errormessage, null, 'errors');
138 $action = '';
139 $error++;
140 }
141
142 $bprev = new BonPrelevement($db);
143
144 if (!$error) {
145 // getDolGlobalString('PRELEVEMENT_CODE_BANQUE') and getDolGlobalString('PRELEVEMENT_CODE_GUICHET') should be empty (we don't use them anymore)
146 $result = $bprev->create(getDolGlobalString('PRELEVEMENT_CODE_BANQUE'), getDolGlobalString('PRELEVEMENT_CODE_GUICHET'), $mode, $format, $executiondate, 0, $type, $toselect, 0, $sourcetype);
147
148 if ($result < 0) {
149 $mesg = '';
150
151 if ($bprev->error || !empty($bprev->errors)) {
152 setEventMessages($bprev->error, $bprev->errors, 'errors');
153 } else {
154 $langs->load("errors");
155 setEventMessages($langs->trans("ErrorsOnXLines", count($bprev->invoice_in_error)), null, 'warnings');
156 }
157
158 if (!empty($bprev->invoice_in_error)) {
159 foreach ($bprev->invoice_in_error as $key => $val) {
160 $mesg .= '<span class="warning">'.$val."</span><br>\n";
161 }
162 }
163 } elseif ($result == 0 || !empty($bprev->invoice_in_error)) {
164 $mesg = '';
165
166 if ($result == 0) {
167 if ($type != 'bank-transfer') {
168 $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format);
169 }
170 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
171 $mesg = $langs->trans("NoInvoiceCouldBeWithdrawedSupplier", $format);
172 }
173 if ($type == 'bank-transfer' && $sourcetype == 'salary') {
174 $mesg = $langs->trans("NoSalariesCouldBeWithdrawed", $format);
175 }
176 setEventMessages($mesg, null, 'errors');
177 }
178
179 if (!empty($bprev->invoice_in_error)) {
180 $mesg .= '<br>'."\n";
181 foreach ($bprev->invoice_in_error as $key => $val) {
182 $mesg .= '<span class="warning">'.$val."</span><br>\n";
183 }
184 }
185 } else {
186 if ($type != 'bank-transfer') {
187 $texttoshow = $langs->trans("DirectDebitOrderCreated", '{s}');
188 $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
189 setEventMessages($texttoshow, null);
190 } else {
191 $texttoshow = $langs->trans("CreditTransferOrderCreated", '{s}');
192 $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
193 setEventMessages($texttoshow, null);
194 }
195
196 header("Location: ".DOL_URL_ROOT.'/compta/prelevement/card.php?id='.urlencode((string) ($bprev->id)).'&type='.urlencode((string) ($type)));
197 exit;
198 }
199 }
200 }
201
202 $objectclass = "BonPrelevement";
203 if ($type == 'bank-transfer') {
204 $uploaddir = $conf->paymentbybanktransfer->dir_output;
205 } else {
206 $uploaddir = $conf->prelevement->dir_output;
207 }
208 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
209}
210
211
212/*
213 * View
214 */
215
216$form = new Form($db);
217
218$thirdpartystatic = new Societe($db);
219if ($type != 'bank-transfer') {
220 $invoicestatic = new Facture($db);
221} else {
222 $invoicestatic = new FactureFournisseur($db);
223}
224$bprev = new BonPrelevement($db);
225
226$arrayofselected = is_array($toselect) ? $toselect : array();
227// List of mass actions available
228$arrayofmassactions = array();
229if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
230 $arrayofmassactions = array();
231}
232$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
233
234if (prelevement_check_config($type) < 0) {
235 $langs->load("errors");
236 $modulenametoshow = "Withdraw";
237 if ($type == 'bank-transfer') {
238 $modulenametoshow = "PaymentByBankTransfer";
239 }
240 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv($modulenametoshow)), null, 'errors');
241}
242
243
244$title = $langs->trans("NewStandingOrder");
245if ($type == 'bank-transfer') {
246 $title = $langs->trans("NewPaymentByBankTransfer");
247}
248
249llxHeader('', $title);
250
251
252// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
253$head = bon_prelevement_prepare_head($bprev, $bprev->nbOfInvoiceToPay($type), $bprev->nbOfInvoiceToPay($type, 'salary'));
254if ($type) {
255 print dol_get_fiche_head($head, ((GETPOSTISSET('sourcetype') && GETPOST('sourcetype') != '') ? 'salary' : 'invoice'), $langs->trans("Invoices"), -1, $bprev->picto);
256} else {
257 print load_fiche_titre($title);
258 print dol_get_fiche_head(array(), '', '', -1);
259}
260
261
262if ($sourcetype != 'salary') {
263 $nb = $bprev->nbOfInvoiceToPay($type); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
264 $pricetowithdraw = $bprev->SommeAPrelever($type); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
265} else {
266 $nb = $bprev->nbOfInvoiceToPay($type, 'salary'); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
267 $pricetowithdraw = $bprev->SommeAPrelever($type, 'salary'); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
268}
269if ($nb < 0) {
270 dol_print_error($db, $bprev->error);
271}
272
273print '<div class="fichecenter">';
274
275print '<table class="border centpercent tableforfield">';
276
277$labeltoshow = $langs->trans("NbOfInvoiceToWithdraw");
278if ($type == 'bank-transfer') {
279 $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransfer");
280}
281if ($sourcetype == 'salary') {
282 $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransferForSalaries");
283}
284
285print '<tr><td class="titlefield">'.$labeltoshow.'</td>';
286print '<td class="nowraponall">';
287print dol_escape_htmltag((string) $nb);
288print '</td></tr>';
289
290print '<tr><td>'.$langs->trans("AmountTotal").'</td>';
291print '<td class="amount nowraponall">';
292print price($pricetowithdraw, 0, $langs, 1, -1, -1, $conf->currency);
293print '</td>';
294print '</tr>';
295
296print '</table>';
297
298print '</div>';
299print '<div class="clearboth"></div>';
300
301print dol_get_fiche_end();
302
303
304print '<form id="createBankTransfer" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
305print '<input type="hidden" name="action" value="create">';
306print '<input type="hidden" name="token" value="'.newToken().'">';
307print '<input type="hidden" name="type" value="'.$type.'">';
308print '<input type="hidden" name="sourcetype" value="'.$sourcetype.'">';
309//print '<input type="hidden" name="listofselectedids" value="'.$sourcetype.'">';
310
311print '<div class="tabsAction">'."\n";
312
313if ($nb) {
314 if ($pricetowithdraw) {
315 $title = $langs->trans('BankToReceiveWithdraw').': ';
316 if ($type == 'bank-transfer') {
317 $title = $langs->trans('BankToPayCreditTransfer').': ';
318 }
319 print '<span class="hideonsmartphone">'.$title.'</span>';
320 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
321
322 $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
323
324 print $form->select_comptes(getDolGlobalInt($default_account), 'id_bankaccount', 0, "(courant:=:1)", 0, '', 0, 'widthcentpercentminusx maxwidth300', 1);
325 print ' &nbsp; &nbsp; ';
326
327 if (empty($executiondate)) {
328 $delayindays = 0;
329 if ($type != 'bank-transfer') {
330 $delayindays = getDolGlobalInt('PRELEVEMENT_ADDDAYS');
331 } else {
332 $delayindays = getDolGlobalInt('PAYMENTBYBANKTRANSFER_ADDDAYS');
333 }
334
335 $executiondate = dol_time_plus_duree(dol_now(), $delayindays, 'd');
336 }
337
338 print $langs->trans('ExecutionDate').' ';
339 $datere = $executiondate;
340 print $form->selectDate($datere, 're');
341
342
343 if ($mysoc->isInSEPA()) {
344 $title = $langs->trans("CreateForSepa");
345 if ($type == 'bank-transfer') {
346 $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
347 }
348
349 if ($type != 'bank-transfer') {
350 print '<select name="format">';
351 print '<option value="FRST"'.($format == 'FRST' ? ' selected="selected"' : '').'>'.$langs->trans('SEPAFRST').'</option>';
352 print '<option value="RCUR"'.($format == 'RCUR' ? ' selected="selected"' : '').'>'.$langs->trans('SEPARCUR').'</option>';
353 print '</select>';
354 }
355 print '<input type="submit" class="butAction margintoponly marginbottomonly" name="createtransferrequest" value="'.$title.'"/>';
356 } else {
357 $title = $langs->trans("CreateAll");
358 if ($type == 'bank-transfer') {
359 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
360 }
361 print '<input type="hidden" name="format" value="ALL">'."\n";
362 print '<input type="submit" class="butAction margintoponly marginbottomonly" name="createtransferrequest" value="'.$title.'">'."\n";
363 }
364 } else {
365 if ($mysoc->isInSEPA()) {
366 $title = $langs->trans("CreateForSepaFRST");
367 if ($type == 'bank-transfer') {
368 $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
369 }
370 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
371
372 if ($type != 'bank-transfer') {
373 $title = $langs->trans("CreateForSepaRCUR");
374 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
375 }
376 } else {
377 $title = $langs->trans("CreateAll");
378 if ($type == 'bank-transfer') {
379 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
380 }
381 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#">'.$title."</a>\n";
382 }
383 }
384} else {
385 $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
386 $title = $langs->trans("CreateAll");
387 if ($type == 'bank-transfer') {
388 $titlefortab = $langs->transnoentitiesnoconv("PaymentByBankTransfers");
389 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
390 }
391 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoInvoiceToWithdraw", $titlefortab, $titlefortab)).'">';
392 print $title;
393 print "</a>\n";
394}
395
396print "</div>\n";
397
398// Show errors or warnings
399if ($mesg) {
400 print '<div class="resultofprocess">'."\n";
401 print $mesg;
402 print '</div>'."\n";
403 print '<br>';
404}
405
406print '<br>';
407
408
409/*
410 * Invoices waiting for withdraw
411 */
412if ($sourcetype != 'salary') {
413 $sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
414 if ($type == 'bank-transfer') {
415 $sql .= " f.ref_supplier,";
416 }
417 $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount, pd.fk_societe_rib as soc_rib_id";
418 if ($type == 'bank-transfer') {
419 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
420 } else {
421 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
422 }
423 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
424 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
425 $sql .= " WHERE s.rowid = f.fk_soc";
426 $sql .= " AND f.entity IN (".getEntity('invoice').")";
427 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
428 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
429 }
430 //$sql .= " AND pd.amount > 0";
431 $sql .= " AND f.total_ttc > 0"; // Avoid credit notes
432 $sql .= " AND pd.traite = 0";
433 $sql .= " AND pd.ext_payment_id IS NULL";
434 if ($type == 'bank-transfer') {
435 $sql .= " AND pd.fk_facture_fourn = f.rowid";
436 } else {
437 $sql .= " AND pd.fk_facture = f.rowid";
438 }
439 if ($socid > 0) {
440 $sql .= " AND f.fk_soc = ".((int) $socid);
441 }
442} else {
443 $sql = "SELECT s.ref, s.rowid, s.amount, CONCAT(u.lastname, ' ', u.firstname) as name, u.rowid as uid,";
444 $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount, pd.fk_societe_rib as soc_rib_id";
445 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s,";
446 $sql .= " ".MAIN_DB_PREFIX."user as u,";
447 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
448 $sql .= " WHERE s.fk_user = u.rowid";
449 $sql .= " AND s.entity IN (".getEntity('salary').")";
450 /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
451 $sql .= " AND s.fk_statut = ".Facture::STATUS_VALIDATED;
452 }*/
453 $sql .= " AND s.amount > 0";
454 $sql .= " AND pd.traite = 0";
455 $sql .= " AND pd.ext_payment_id IS NULL";
456 $sql .= " AND s.rowid = pd.fk_salary AND s.paye = ".Salary::STATUS_UNPAID;
457 $sql .= " AND pd.traite = 0";
458}
459
460$nbtotalofrecords = '';
461if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
462 $result = $db->query($sql);
463 $nbtotalofrecords = $db->num_rows($result);
464 if (($page * $limit) > (int) $nbtotalofrecords) {
465 // if total resultset is smaller then paging size (filtering), goto and load page 0
466 $page = 0;
467 $offset = 0;
468 }
469}
470
471$sql .= $db->plimit($limit + 1, $offset);
472
473$resql = $db->query($sql);
474if ($resql) {
475 $num = $db->num_rows($resql);
476 $i = 0;
477
478 $param = '';
479 if ($type) {
480 $param .= '&type=' . urlencode((string) $type);
481 }
482 if ($limit > 0 && $limit != $conf->liste_limit) {
483 $param .= '&limit='.((int) $limit);
484 }
485 if ($socid) {
486 $param .= '&socid='.urlencode((string) ($socid));
487 }
488 if ($option) {
489 $param .= "&option=".urlencode($option);
490 }
491
492 //print '<form method="POST" id="searchFormList" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
493 //print '<input type="hidden" name="token" value="'.newToken().'">';
494 print '<input type="hidden" name="page" value="'.$page.'">';
495 if (!empty($limit)) {
496 print '<input type="hidden" name="limit" value="'.$limit.'"/>';
497 }
498 if ($type != '') {
499 print '<input type="hidden" name="type" value="'.$type.'">';
500 }
501 $title = $langs->trans("InvoiceWaitingWithdraw");
502 $picto = 'bill';
503 if ($type == 'bank-transfer') {
504 if ($sourcetype != 'salary') {
505 $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer");
506 } else {
507 $title = $langs->trans("SalaryWaitingWithdraw");
508 $picto = 'salary';
509 }
510 }
511 print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', $massactionbutton, $num, $nbtotalofrecords, $picto, 0, '', '', $limit);
512
513
514 $tradinvoice = "Invoice";
515 if ($type == 'bank-transfer') {
516 if ($sourcetype != 'salary') {
517 $tradinvoice = "SupplierInvoice";
518 } else {
519 $tradinvoice = "RefSalary";
520 }
521 }
522
523 print '<div class="div-table-responsive-no-min">';
524 print '<table class="noborder centpercent">';
525 print '<tr class="liste_titre">';
526 // Action column
527 if ($conf->main_checkbox_left_column) {
528 if ($num) {
529 print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
530 }
531 }
532 // Ref invoice or salary
533 print '<td>'.$langs->trans($tradinvoice).'</td>';
534 // Ref supplier
535 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
536 print '<td>'.$langs->trans("RefSupplier").'</td>';
537 }
538 // Thirdparty or user
539 if ($sourcetype != 'salary') {
540 print '<td>'.$langs->trans("ThirdParty").'</td>';
541 } else {
542 print '<td>'.$langs->trans("Employee").'</td>';
543 }
544 // BAN
545 print '<td>'.$langs->trans("RIB").'</td>';
546 // RUM
547 if (empty($type) || $type == 'direc-debit') {
548 print '<td>'.$langs->trans("RUM").'</td>';
549 }
550 print '<td class="right">';
551 if ($sourcetype == 'salary') {
552 print $langs->trans("Amount");
553 } else {
554 print $langs->trans("AmountTTC");
555 }
556 print '</td>';
557 print '<td class="right">'.$langs->trans("PendingSince").'</td>';
558 // Action column
559 if (!$conf->main_checkbox_left_column) {
560 print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
561 }
562 print '</tr>';
563
564 if ($num) {
565 if ($sourcetype != 'salary') {
566 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
567 } else {
568 require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
569 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
570 }
571
572 while ($i < $num && $i < $limit) {
573 $obj = $db->fetch_object($resql);
574 if ($sourcetype != 'salary') {
575 $bac = new CompanyBankAccount($db); // Must include the new in loop so the fetch is clean
576 $bac->fetch($obj->soc_rib_id ?? 0, '', $obj->socid);
577
578 $invoicestatic->id = $obj->rowid;
579 $invoicestatic->ref = $obj->ref;
580 if ($type == 'bank-transfer') {
581 $invoicestatic->ref_supplier = $obj->ref_supplier;
582 }
583 $salary = null;
584 } else {
585 $bac = new UserBankAccount($db);
586 $bac->fetch($obj->soc_rib_id ?? 0, '', $obj->uid);
587
588 $salary = new Salary($db);
589 $salary->fetch($obj->rowid);
590 }
591 print '<tr class="oddeven">';
592
593 // Action column
594 if ($conf->main_checkbox_left_column) {
595 print '<td class="nowrap center">';
596 $selected = 0;
597 if (in_array($obj->request_row_id, $arrayofselected)) {
598 $selected = 1;
599 }
600 print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
601 print '</td>';
602 }
603
604 // Ref invoice
605 print '<td class="tdoverflowmax150">';
606 if ($sourcetype != 'salary' || $salary === null) {
607 print $invoicestatic->getNomUrl(1, 'withdraw');
608 } else {
609 print $salary->getNomUrl(1, 'withdraw');
610 }
611 print '</td>';
612
613 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
614 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($invoicestatic->ref_supplier).'">';
615 print dol_escape_htmltag($invoicestatic->ref_supplier);
616 print '</td>';
617 }
618
619 // Thirdparty
620 if ($sourcetype != 'salary') {
621 print '<td class="tdoverflowmax100">';
622 $thirdpartystatic->fetch($obj->socid);
623 print $thirdpartystatic->getNomUrl(1, 'ban');
624 print '</td>';
625 } else {
626 print '<td class="tdoverflowmax100">';
627 $user->fetch($obj->uid);
628 print $user->getNomUrl(-1);
629 print '</td>';
630 }
631
632 // BAN
633 print '<td>';
634 if ($bac->id > 0) {
635 if (!empty($bac->iban) || !empty($bac->bic)) {
636 print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
637 if ($bac->verif() <= 0) {
638 print img_warning('Error on default bank number for IBAN : '.$langs->trans($bac->error));
639 }
640 if ($obj->soc_rib_id > 0) {
641 print $form->textwithpicto('', $langs->trans("BankAccountForcedOnRequest"));
642 } else {
643 print $form->textwithpicto('', $langs->trans("BankAccountUsedByDefault").'<br><b>'.$langs->trans("Label").'</b> : '.$bac->label.'<br><b>'.$langs->trans("BankName").'</b> : '.$bac->bank, 1, 'help', 'valigmiddle warning');
644 }
645 } else {
646 print img_warning($langs->trans("IBANNotDefined"));
647 }
648 } else {
649 $langs->load("banks");
650 print img_warning($langs->trans("NoBankAccountDefined"));
651 }
652 print '</td>';
653
654 // RUM
655 if (empty($type) || $type == 'direct-debit') {
656 print '<td>';
657 if (!empty($bac->rum)) {
658 print $bac->rum;
659 } else {
660 $rumToShow = $thirdpartystatic->display_rib('rum');
661 if ($rumToShow) {
662 print $rumToShow;
663 $format = $thirdpartystatic->display_rib('format');
664 if ($type != 'bank-transfer') {
665 if ($format) {
666 print ' ('.$format.')';
667 }
668 }
669 } else {
670 $langs->load("banks");
671 print img_warning($langs->trans("NoBankAccountDefined"));
672 }
673 }
674 print '</td>';
675 }
676
677 // Amount
678 print '<td class="right amount">';
679 print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
680 print '</td>';
681 // Date
682 print '<td class="right">';
683 print dol_print_date($db->jdate($obj->date_demande), 'day');
684 print '</td>';
685 // Action column
686 if (!$conf->main_checkbox_left_column) {
687 print '<td class="nowrap center">';
688 $selected = 0;
689 if (in_array($obj->request_row_id, $arrayofselected)) {
690 $selected = 1;
691 }
692 print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
693 print '</td>';
694 }
695 print '</tr>';
696 $i++;
697 }
698 } else {
699 $colspan = 6;
700 if ($type == 'bank-transfer') {
701 $colspan++;
702 }
703 if ($massactionbutton || $massaction) {
704 $colspan++;
705 }
706 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
707 }
708 print "</table>";
709 print "</div>";
710
711 print "</form>";
712 print "<br>\n";
713} else {
715}
716
717
718/*
719 * List of latest withdraws
720 */
721/*
722$limit=5;
723
724print load_fiche_titre($langs->trans("LastWithdrawalReceipts",$limit),'','');
725
726$sql = "SELECT p.rowid, p.ref, p.amount, p.statut";
727$sql.= ", p.datec";
728$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
729$sql.= " WHERE p.entity IN (".getEntity('invoice').")";
730$sql.= " ORDER BY datec DESC";
731$sql.=$db->plimit($limit);
732
733$result = $db->query($sql);
734if ($result)
735{
736 $num = $db->num_rows($result);
737 $i = 0;
738
739 print"\n<!-- debut table -->\n";
740 print '<table class="noborder centpercent">';
741 print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
742 print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
743 print '</tr>';
744
745 while ($i < min($num,$limit))
746 {
747 $obj = $db->fetch_object($result);
748
749
750 print '<tr class="oddeven">';
751
752 print "<td>";
753 $bprev->id=$obj->rowid;
754 $bprev->ref=$obj->ref;
755 print $bprev->getNomUrl(1);
756 print "</td>\n";
757
758 print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
759
760 print '<td class="right"><span class="amount">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</span></td>\n";
761
762 print "</tr>\n";
763 $i++;
764 }
765 print "</table><br>";
766 $db->free($result);
767}
768else
769{
770 dol_print_error($db);
771}
772*/
773
774// End of page
775llxFooter();
776$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank accounts.
Class to manage withdrawal receipts.
Class to manage bank accounts description of third parties.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage bank accounts description of users.
global $mysoc
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
bon_prelevement_prepare_head(BonPrelevement $object, $nbOfInvoices, $nbOfSalaryInvoice)
Return array head with list of tabs to view object information.
prelevement_check_config($type='direct-debit')
Check need data to create standigns orders receipt file.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.