dolibarr 21.0.3
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-2024 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';
33require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
36require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
42
52// Load translation files required by the page
53$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills'));
54
55// Get supervariables
56$action = GETPOST('action', 'aZ09');
57$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
58$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
59$mode = GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : 'real';
60
61$type = GETPOST('type', 'aZ09');
62$sourcetype = GETPOST('sourcetype', 'aZ09');
63$format = GETPOST('format', 'aZ09');
64$id_bankaccount = GETPOSTINT('id_bankaccount');
65$executiondate = dol_mktime(0, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
66
67$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
68$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
69if (empty($page) || $page == -1) {
70 $page = 0;
71} // If $page is not defined, or '' or -1
72$offset = $limit * $page;
73
74$hookmanager->initHooks(array('directdebitcreatecard', 'globalcard'));
75
76// Security check
77$socid = GETPOSTINT('socid');
78if ($user->socid) {
79 $socid = $user->socid;
80}
81if ($type == 'bank-transfer') {
82 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
83
84 $permissiontoread = $user->hasRight('paymentbybanktransfer', 'read');
85 $permissiontocreate = $user->hasRight('paymentbybanktransfer', 'create');
86} else {
87 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
88
89 $permissiontoread = $user->hasRight('prelevement', 'bons', 'lire');
90 $permissiontocreate = $user->hasRight('prelevement', 'bons', 'creer');
91}
92
93
94$error = 0;
95$option = "";
96$mesg = '';
97
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) {
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
136
137 $bprev = new BonPrelevement($db);
138
139 if (!$error) {
140 // getDolGlobalString('PRELEVEMENT_CODE_BANQUE') and getDolGlobalString('PRELEVEMENT_CODE_GUICHET') should be empty (we don't use them anymore)
141 $result = $bprev->create(getDolGlobalString('PRELEVEMENT_CODE_BANQUE'), getDolGlobalString('PRELEVEMENT_CODE_GUICHET'), $mode, $format, $executiondate, 0, $type, 0, 0, $sourcetype);
142 if ($result < 0) {
143 $mesg = '';
144
145 if ($bprev->error || !empty($bprev->errors)) {
146 setEventMessages($bprev->error, $bprev->errors, 'errors');
147 } else {
148 $langs->load("errors");
149 setEventMessages($langs->trans("ErrorsOnXLines", count($bprev->invoice_in_error)), null, 'warnings');
150 }
151
152 if (!empty($bprev->invoice_in_error)) {
153 foreach ($bprev->invoice_in_error as $key => $val) {
154 $mesg .= '<span class="warning">'.$val."</span><br>\n";
155 }
156 }
157 } elseif ($result == 0 || !empty($bprev->invoice_in_error)) {
158 $mesg = '';
159
160 if ($result == 0) {
161 if ($type != 'bank-transfer') {
162 $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format);
163 }
164 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
165 $mesg = $langs->trans("NoInvoiceCouldBeWithdrawedSupplier", $format);
166 }
167 if ($type == 'bank-transfer' && $sourcetype == 'salary') {
168 $mesg = $langs->trans("NoSalariesCouldBeWithdrawed", $format);
169 }
170 setEventMessages($mesg, null, 'errors');
171 }
172
173 if (!empty($bprev->invoice_in_error)) {
174 $mesg .= '<br>'."\n";
175 foreach ($bprev->invoice_in_error as $key => $val) {
176 $mesg .= '<span class="warning">'.$val."</span><br>\n";
177 }
178 }
179 } else {
180 if ($type != 'bank-transfer') {
181 $texttoshow = $langs->trans("DirectDebitOrderCreated", '{s}');
182 $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
183 setEventMessages($texttoshow, null);
184 } else {
185 $texttoshow = $langs->trans("CreditTransferOrderCreated", '{s}');
186 $texttoshow = str_replace('{s}', $bprev->getNomUrl(1), $texttoshow);
187 setEventMessages($texttoshow, null);
188 }
189
190 header("Location: ".DOL_URL_ROOT.'/compta/prelevement/card.php?id='.urlencode((string) ($bprev->id)).'&type='.urlencode((string) ($type)));
191 exit;
192 }
193 }
194 }
195
196 $objectclass = "BonPrelevement";
197 if ($type == 'bank-transfer') {
198 $uploaddir = $conf->paymentbybanktransfer->dir_output;
199 } else {
200 $uploaddir = $conf->prelevement->dir_output;
201 }
202 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
203}
204
205
206/*
207 * View
208 */
209
210$form = new Form($db);
211
212$thirdpartystatic = new Societe($db);
213if ($type != 'bank-transfer') {
214 $invoicestatic = new Facture($db);
215} else {
216 $invoicestatic = new FactureFournisseur($db);
217}
218$bprev = new BonPrelevement($db);
219$arrayofselected = is_array($toselect) ? $toselect : array();
220// List of mass actions available
221$arrayofmassactions = array(
222);
223if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
224 $arrayofmassactions = array();
225}
226$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
227
228if (prelevement_check_config($type) < 0) {
229 $langs->load("errors");
230 $modulenametoshow = "Withdraw";
231 if ($type == 'bank-transfer') {
232 $modulenametoshow = "PaymentByBankTransfer";
233 }
234 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv($modulenametoshow)), null, 'errors');
235}
236
237
238$title = $langs->trans("NewStandingOrder");
239if ($type == 'bank-transfer') {
240 $title = $langs->trans("NewPaymentByBankTransfer");
241}
242
243llxHeader('', $title);
244
245
246// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
247$head = bon_prelevement_prepare_head($bprev, $bprev->nbOfInvoiceToPay($type), $bprev->nbOfInvoiceToPay($type, 'salary'));
248if ($type) {
249 print dol_get_fiche_head($head, (!GETPOSTISSET('sourcetype') ? 'invoice' : 'salary'), $langs->trans("Invoices"), -1, $bprev->picto);
250} else {
251 print load_fiche_titre($title);
252 print dol_get_fiche_head(array(), '', '', -1);
253}
254
255
256if ($sourcetype != 'salary') {
257 $nb = $bprev->nbOfInvoiceToPay($type); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
258 $pricetowithdraw = $bprev->SommeAPrelever($type); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
259} else {
260 $nb = $bprev->nbOfInvoiceToPay($type, 'salary'); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
261 $pricetowithdraw = $bprev->SommeAPrelever($type, 'salary'); // @phan-suppress-current-line PhanPluginSuspiciousParamPosition
262}
263if ($nb < 0) {
264 dol_print_error($db, $bprev->error);
265}
266
267print '<div class="fichecenter">';
268
269print '<table class="border centpercent tableforfield">';
270
271$labeltoshow = $langs->trans("NbOfInvoiceToWithdraw");
272if ($type == 'bank-transfer') {
273 $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransfer");
274}
275if ($sourcetype == 'salary') {
276 $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransferForSalaries");
277}
278
279print '<tr><td class="titlefield">'.$labeltoshow.'</td>';
280print '<td class="nowraponall">';
281print dol_escape_htmltag((string) $nb);
282print '</td></tr>';
283
284print '<tr><td>'.$langs->trans("AmountTotal").'</td>';
285print '<td class="amount nowraponall">';
286print price($pricetowithdraw, 0, $langs, 1, -1, -1, $conf->currency);
287print '</td>';
288print '</tr>';
289
290print '</table>';
291
292print '</div>';
293print '<div class="clearboth"></div>';
294
295print dol_get_fiche_end();
296
297print '<div class="tabsAction">'."\n";
298
299print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
300print '<input type="hidden" name="action" value="create">';
301print '<input type="hidden" name="token" value="'.newToken().'">';
302print '<input type="hidden" name="type" value="'.$type.'">';
303print '<input type="hidden" name="sourcetype" value="'.$sourcetype.'">';
304
305if ($nb) {
306 if ($pricetowithdraw) {
307 $title = $langs->trans('BankToReceiveWithdraw').': ';
308 if ($type == 'bank-transfer') {
309 $title = $langs->trans('BankToPayCreditTransfer').': ';
310 }
311 print '<span class="hideonsmartphone">'.$title.'</span>';
312 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
313
314 $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
315
316 print $form->select_comptes(getDolGlobalInt($default_account), 'id_bankaccount', 0, "courant=1", 0, '', 0, 'widthcentpercentminusx maxwidth300', 1);
317 print ' &nbsp; &nbsp; ';
318
319 if (empty($executiondate)) {
320 $delayindays = 0;
321 if ($type != 'bank-transfer') {
322 $delayindays = getDolGlobalInt('PRELEVEMENT_ADDDAYS');
323 } else {
324 $delayindays = getDolGlobalInt('PAYMENTBYBANKTRANSFER_ADDDAYS');
325 }
326
327 $executiondate = dol_time_plus_duree(dol_now(), $delayindays, 'd');
328 }
329
330 print $langs->trans('ExecutionDate').' ';
331 $datere = $executiondate;
332 print $form->selectDate($datere, 're');
333
334
335 if ($mysoc->isInEEC()) {
336 $title = $langs->trans("CreateForSepa");
337 if ($type == 'bank-transfer') {
338 $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
339 }
340
341 if ($type != 'bank-transfer') {
342 print '<select name="format">';
343 print '<option value="FRST"'.($format == 'FRST' ? ' selected="selected"' : '').'>'.$langs->trans('SEPAFRST').'</option>';
344 print '<option value="RCUR"'.($format == 'RCUR' ? ' selected="selected"' : '').'>'.$langs->trans('SEPARCUR').'</option>';
345 print '</select>';
346 }
347 print '<input type="submit" class="butAction margintoponly marginbottomonly" value="'.$title.'"/>';
348 } else {
349 $title = $langs->trans("CreateAll");
350 if ($type == 'bank-transfer') {
351 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
352 }
353 print '<input type="hidden" name="format" value="ALL">'."\n";
354 print '<input type="submit" class="butAction margintoponly marginbottomonly" value="'.$title.'">'."\n";
355 }
356 } else {
357 if ($mysoc->isInEEC()) {
358 $title = $langs->trans("CreateForSepaFRST");
359 if ($type == 'bank-transfer') {
360 $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
361 }
362 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
363
364 if ($type != 'bank-transfer') {
365 $title = $langs->trans("CreateForSepaRCUR");
366 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
367 }
368 } else {
369 $title = $langs->trans("CreateAll");
370 if ($type == 'bank-transfer') {
371 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
372 }
373 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#">'.$title."</a>\n";
374 }
375 }
376} else {
377 $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
378 $title = $langs->trans("CreateAll");
379 if ($type == 'bank-transfer') {
380 $titlefortab = $langs->transnoentitiesnoconv("PaymentByBankTransfers");
381 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
382 }
383 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoInvoiceToWithdraw", $titlefortab, $titlefortab)).'">';
384 print $title;
385 print "</a>\n";
386}
387
388print "</form>\n";
389
390print "</div>\n";
391
392// Show errors or warnings
393if ($mesg) {
394 print $mesg;
395 print '<br>';
396}
397
398print '<br>';
399
400
401/*
402 * Invoices waiting for withdraw
403 */
404if ($sourcetype != 'salary') {
405 $sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
406 if ($type == 'bank-transfer') {
407 $sql .= " f.ref_supplier,";
408 }
409 $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount, pd.fk_societe_rib as soc_rib_id";
410 if ($type == 'bank-transfer') {
411 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
412 } else {
413 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
414 }
415 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
416 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
417 $sql .= " WHERE s.rowid = f.fk_soc";
418 $sql .= " AND f.entity IN (".getEntity('invoice').")";
419 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
420 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
421 }
422 //$sql .= " AND pd.amount > 0";
423 $sql .= " AND f.total_ttc > 0"; // Avoid credit notes
424 $sql .= " AND pd.traite = 0";
425 $sql .= " AND pd.ext_payment_id IS NULL";
426 if ($type == 'bank-transfer') {
427 $sql .= " AND pd.fk_facture_fourn = f.rowid";
428 } else {
429 $sql .= " AND pd.fk_facture = f.rowid";
430 }
431 if ($socid > 0) {
432 $sql .= " AND f.fk_soc = ".((int) $socid);
433 }
434} else {
435 $sql = "SELECT s.ref, s.rowid, s.amount, CONCAT(u.lastname, ' ', u.firstname) as name, u.rowid as uid,";
436 $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount, pd.fk_societe_rib as soc_rib_id";
437 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s,";
438 $sql .= " ".MAIN_DB_PREFIX."user as u,";
439 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
440 $sql .= " WHERE s.fk_user = u.rowid";
441 $sql .= " AND s.entity IN (".getEntity('salary').")";
442 /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
443 $sql .= " AND s.fk_statut = ".Facture::STATUS_VALIDATED;
444 }*/
445 $sql .= " AND s.amount > 0";
446 $sql .= " AND pd.traite = 0";
447 $sql .= " AND pd.ext_payment_id IS NULL";
448 $sql .= " AND s.rowid = pd.fk_salary AND s.paye = ".Salary::STATUS_UNPAID;
449 $sql .= " AND pd.traite = 0";
450}
451
452$nbtotalofrecords = '';
453if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
454 $result = $db->query($sql);
455 $nbtotalofrecords = $db->num_rows($result);
456 if (($page * $limit) > $nbtotalofrecords) {
457 // if total resultset is smaller then paging size (filtering), goto and load page 0
458 $page = 0;
459 $offset = 0;
460 }
461}
462
463$sql .= $db->plimit($limit + 1, $offset);
464
465$resql = $db->query($sql);
466if ($resql) {
467 $num = $db->num_rows($resql);
468 $i = 0;
469
470 $param = '';
471 if ($type) {
472 $param .= '&type=' . urlencode((string) $type);
473 }
474 if ($limit > 0 && $limit != $conf->liste_limit) {
475 $param .= '&limit='.((int) $limit);
476 }
477 if ($socid) {
478 $param .= '&socid='.urlencode((string) ($socid));
479 }
480 if ($option) {
481 $param .= "&option=".urlencode($option);
482 }
483
484 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
485 print '<input type="hidden" name="token" value="'.newToken().'">';
486 print '<input type="hidden" name="page" value="'.$page.'">';
487 if (!empty($limit)) {
488 print '<input type="hidden" name="limit" value="'.$limit.'"/>';
489 }
490 if ($type != '') {
491 print '<input type="hidden" name="type" value="'.$type.'">';
492 }
493 $title = $langs->trans("InvoiceWaitingWithdraw");
494 $picto = 'bill';
495 if ($type == 'bank-transfer') {
496 if ($sourcetype != 'salary') {
497 $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer");
498 } else {
499 $title = $langs->trans("SalaryWaitingWithdraw");
500 $picto = 'salary';
501 }
502 }
503 print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', $massactionbutton, $num, $nbtotalofrecords, $picto, 0, '', '', $limit);
504
505
506 $tradinvoice = "Invoice";
507 if ($type == 'bank-transfer') {
508 if ($sourcetype != 'salary') {
509 $tradinvoice = "SupplierInvoice";
510 } else {
511 $tradinvoice = "RefSalary";
512 }
513 }
514
515 print '<div class="div-table-responsive-no-min">';
516 print '<table class="noborder centpercent">';
517 print '<tr class="liste_titre">';
518 // Action column
519 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
520 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
521 print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
522 }
523 }
524 // Ref invoice or salary
525 print '<td>'.$langs->trans($tradinvoice).'</td>';
526 // Ref supplier
527 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
528 print '<td>'.$langs->trans("RefSupplier").'</td>';
529 }
530 // Thirdparty or user
531 if ($sourcetype != 'salary') {
532 print '<td>'.$langs->trans("ThirdParty").'</td>';
533 } else {
534 print '<td>'.$langs->trans("Employee").'</td>';
535 }
536 // BAN
537 print '<td>'.$langs->trans("RIB").'</td>';
538 // RUM
539 if (empty($type) || $type == 'direc-debit') {
540 print '<td>'.$langs->trans("RUM").'</td>';
541 }
542 print '<td class="right">';
543 if ($sourcetype == 'salary') {
544 print $langs->trans("Amount");
545 } else {
546 print $langs->trans("AmountTTC");
547 }
548 print '</td>';
549 print '<td class="right">'.$langs->trans("PendingSince").'</td>';
550 // Action column
551 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
552 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
553 print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
554 }
555 }
556 print '</tr>';
557
558 if ($num) {
559 if ($sourcetype != 'salary') {
560 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
561 } else {
562 require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
563 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
564 }
565
566 while ($i < $num && $i < $limit) {
567 $obj = $db->fetch_object($resql);
568 if ($sourcetype != 'salary') {
569 $bac = new CompanyBankAccount($db); // Must include the new in loop so the fetch is clean
570 $bac->fetch($obj->soc_rib_id ?? 0, '', $obj->socid);
571
572 $invoicestatic->id = $obj->rowid;
573 $invoicestatic->ref = $obj->ref;
574 if ($type == 'bank-transfer') {
575 $invoicestatic->ref_supplier = $obj->ref_supplier;
576 }
577 $salary = null;
578 } else {
579 $bac = new UserBankAccount($db);
580 $bac->fetch($obj->soc_rib_id ?? 0, '', $obj->uid);
581
582 $salary = new Salary($db);
583 $salary->fetch($obj->rowid);
584 }
585 print '<tr class="oddeven">';
586
587 // Action column
588 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
589 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
590 print '<td class="nowrap center">';
591 $selected = 0;
592 if (in_array($obj->request_row_id, $arrayofselected)) {
593 $selected = 1;
594 }
595 print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
596 print '</td>';
597 }
598 }
599
600 // Ref invoice
601 print '<td class="tdoverflowmax150">';
602 if ($sourcetype != 'salary' || $salary === null) {
603 print $invoicestatic->getNomUrl(1, 'withdraw');
604 } else {
605 print $salary->getNomUrl(1, 'withdraw');
606 }
607 print '</td>';
608
609 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
610 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($invoicestatic->ref_supplier).'">';
611 print dol_escape_htmltag($invoicestatic->ref_supplier);
612 print '</td>';
613 }
614
615 // Thirdparty
616 if ($sourcetype != 'salary') {
617 print '<td class="tdoverflowmax100">';
618 $thirdpartystatic->fetch($obj->socid);
619 print $thirdpartystatic->getNomUrl(1, 'ban');
620 print '</td>';
621 } else {
622 print '<td class="tdoverflowmax100">';
623 $user->fetch($obj->uid);
624 print $user->getNomUrl(-1);
625 print '</td>';
626 }
627
628 // BAN
629 print '<td>';
630 if ($bac->id > 0) {
631 if (!empty($bac->iban) || !empty($bac->bic)) {
632 print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
633 if ($bac->verif() <= 0) {
634 print img_warning('Error on default bank number for IBAN : '.$langs->trans($bac->error));
635 }
636 } else {
637 print img_warning($langs->trans("IBANNotDefined"));
638 }
639 } else {
640 $langs->load("banks");
641 print img_warning($langs->trans("NoBankAccountDefined"));
642 }
643 print '</td>';
644
645 // RUM
646 if (empty($type) || $type == 'direct-debit') {
647 print '<td>';
648 if (!empty($bac->rum)) {
649 print $bac->rum;
650 } else {
651 $rumToShow = $thirdpartystatic->display_rib('rum');
652 if ($rumToShow) {
653 print $rumToShow;
654 $format = $thirdpartystatic->display_rib('format');
655 if ($type != 'bank-transfer') {
656 if ($format) {
657 print ' ('.$format.')';
658 }
659 }
660 } else {
661 $langs->load("banks");
662 print img_warning($langs->trans("NoBankAccountDefined"));
663 }
664 }
665 print '</td>';
666 }
667
668 // Amount
669 print '<td class="right amount">';
670 print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
671 print '</td>';
672 // Date
673 print '<td class="right">';
674 print dol_print_date($db->jdate($obj->date_demande), 'day');
675 print '</td>';
676 // Action column
677 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
678 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
679 print '<td class="nowrap center">';
680 $selected = 0;
681 if (in_array($obj->request_row_id, $arrayofselected)) {
682 $selected = 1;
683 }
684 print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
685 print '</td>';
686 }
687 }
688 print '</tr>';
689 $i++;
690 }
691 } else {
692 $colspan = 6;
693 if ($type == 'bank-transfer') {
694 $colspan++;
695 }
696 if ($massactionbutton || $massaction) {
697 $colspan++;
698 }
699 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
700 }
701 print "</table>";
702 print "</div>";
703
704 print "</form>";
705 print "<br>\n";
706} else {
707 dol_print_error($db);
708}
709
710
711/*
712 * List of latest withdraws
713 */
714/*
715$limit=5;
716
717print load_fiche_titre($langs->trans("LastWithdrawalReceipts",$limit),'','');
718
719$sql = "SELECT p.rowid, p.ref, p.amount, p.statut";
720$sql.= ", p.datec";
721$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
722$sql.= " WHERE p.entity IN (".getEntity('invoice').")";
723$sql.= " ORDER BY datec DESC";
724$sql.=$db->plimit($limit);
725
726$result = $db->query($sql);
727if ($result)
728{
729 $num = $db->num_rows($result);
730 $i = 0;
731
732 print"\n<!-- debut table -->\n";
733 print '<table class="noborder centpercent">';
734 print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
735 print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
736 print '</tr>';
737
738 while ($i < min($num,$limit))
739 {
740 $obj = $db->fetch_object($result);
741
742
743 print '<tr class="oddeven">';
744
745 print "<td>";
746 $bprev->id=$obj->rowid;
747 $bprev->ref=$obj->ref;
748 print $bprev->getNomUrl(1);
749 print "</td>\n";
750
751 print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
752
753 print '<td class="right"><span class="amount">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</span></td>\n";
754
755 print "</tr>\n";
756 $i++;
757 }
758 print "</table><br>";
759 $db->free($result);
760}
761else
762{
763 dol_print_error($db);
764}
765*/
766
767// End of page
768llxFooter();
769$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:87
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:71
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.