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