dolibarr 21.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-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();
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}
266print '<table class="border centpercent tableforfield">';
267
268$labeltoshow = $langs->trans("NbOfInvoiceToWithdraw");
269if ($type == 'bank-transfer') {
270 $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransfer");
271}
272if ($sourcetype == 'salary') {
273 $labeltoshow = $langs->trans("NbOfInvoiceToPayByBankTransferForSalaries");
274}
275
276print '<tr><td class="titlefield">'.$labeltoshow.'</td>';
277print '<td class="nowraponall">';
278print dol_escape_htmltag((string) $nb);
279print '</td></tr>';
280
281print '<tr><td>'.$langs->trans("AmountTotal").'</td>';
282print '<td class="amount nowraponall">';
283print price($pricetowithdraw, 0, $langs, 1, -1, -1, $conf->currency);
284print '</td>';
285print '</tr>';
286
287print '</table>';
288print '</div>';
289
290print '<div class="tabsAction">'."\n";
291
292print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
293print '<input type="hidden" name="action" value="create">';
294print '<input type="hidden" name="token" value="'.newToken().'">';
295print '<input type="hidden" name="type" value="'.$type.'">';
296print '<input type="hidden" name="sourcetype" value="'.$sourcetype.'">';
297
298if ($nb) {
299 if ($pricetowithdraw) {
300 $title = $langs->trans('BankToReceiveWithdraw').': ';
301 if ($type == 'bank-transfer') {
302 $title = $langs->trans('BankToPayCreditTransfer').': ';
303 }
304 print '<span class="hideonsmartphone">'.$title.'</span>';
305 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
306
307 $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
308
309 print $form->select_comptes(getDolGlobalInt($default_account), 'id_bankaccount', 0, "courant=1", 0, '', 0, 'widthcentpercentminusx maxwidth300', 1);
310 print ' &nbsp; &nbsp; ';
311
312 if (empty($executiondate)) {
313 $delayindays = 0;
314 if ($type != 'bank-transfer') {
315 $delayindays = getDolGlobalInt('PRELEVEMENT_ADDDAYS');
316 } else {
317 $delayindays = getDolGlobalInt('PAYMENTBYBANKTRANSFER_ADDDAYS');
318 }
319
320 $executiondate = dol_time_plus_duree(dol_now(), $delayindays, 'd');
321 }
322
323 print $langs->trans('ExecutionDate').' ';
324 $datere = $executiondate;
325 print $form->selectDate($datere, 're');
326
327
328 if ($mysoc->isInEEC()) {
329 $title = $langs->trans("CreateForSepa");
330 if ($type == 'bank-transfer') {
331 $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
332 }
333
334 if ($type != 'bank-transfer') {
335 print '<select name="format">';
336 print '<option value="FRST"'.($format == 'FRST' ? ' selected="selected"' : '').'>'.$langs->trans('SEPAFRST').'</option>';
337 print '<option value="RCUR"'.($format == 'RCUR' ? ' selected="selected"' : '').'>'.$langs->trans('SEPARCUR').'</option>';
338 print '</select>';
339 }
340 print '<input type="submit" class="butAction margintoponly marginbottomonly" value="'.$title.'"/>';
341 } else {
342 $title = $langs->trans("CreateAll");
343 if ($type == 'bank-transfer') {
344 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
345 }
346 print '<input type="hidden" name="format" value="ALL">'."\n";
347 print '<input type="submit" class="butAction margintoponly marginbottomonly" value="'.$title.'">'."\n";
348 }
349 } else {
350 if ($mysoc->isInEEC()) {
351 $title = $langs->trans("CreateForSepaFRST");
352 if ($type == 'bank-transfer') {
353 $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer");
354 }
355 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
356
357 if ($type != 'bank-transfer') {
358 $title = $langs->trans("CreateForSepaRCUR");
359 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.$langs->trans("AmountMustBePositive").'">'.$title."</a>\n";
360 }
361 } else {
362 $title = $langs->trans("CreateAll");
363 if ($type == 'bank-transfer') {
364 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
365 }
366 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#">'.$title."</a>\n";
367 }
368 }
369} else {
370 $titlefortab = $langs->transnoentitiesnoconv("StandingOrders");
371 $title = $langs->trans("CreateAll");
372 if ($type == 'bank-transfer') {
373 $titlefortab = $langs->transnoentitiesnoconv("PaymentByBankTransfers");
374 $title = $langs->trans("CreateFileForPaymentByBankTransfer");
375 }
376 print '<a class="butActionRefused classfortooltip margintoponly marginbottomonly" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoInvoiceToWithdraw", $titlefortab, $titlefortab)).'">';
377 print $title;
378 print "</a>\n";
379}
380
381print "</form>\n";
382
383print "</div>\n";
384
385// Show errors or warnings
386if ($mesg) {
387 print $mesg;
388 print '<br>';
389}
390
391print '<br>';
392
393
394/*
395 * Invoices waiting for withdraw
396 */
397if ($sourcetype != 'salary') {
398 $sql = "SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
399 if ($type == 'bank-transfer') {
400 $sql .= " f.ref_supplier,";
401 }
402 $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount, pd.fk_societe_rib as soc_rib_id";
403 if ($type == 'bank-transfer') {
404 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
405 } else {
406 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
407 }
408 $sql .= " ".MAIN_DB_PREFIX."societe as s,";
409 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
410 $sql .= " WHERE s.rowid = f.fk_soc";
411 $sql .= " AND f.entity IN (".getEntity('invoice').")";
412 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
413 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
414 }
415 //$sql .= " AND pd.amount > 0";
416 $sql .= " AND f.total_ttc > 0"; // Avoid credit notes
417 $sql .= " AND pd.traite = 0";
418 $sql .= " AND pd.ext_payment_id IS NULL";
419 if ($type == 'bank-transfer') {
420 $sql .= " AND pd.fk_facture_fourn = f.rowid";
421 } else {
422 $sql .= " AND pd.fk_facture = f.rowid";
423 }
424 if ($socid > 0) {
425 $sql .= " AND f.fk_soc = ".((int) $socid);
426 }
427} else {
428 $sql = "SELECT s.ref, s.rowid, s.amount, CONCAT(u.lastname, ' ', u.firstname) as name, u.rowid as uid,";
429 $sql .= " pd.rowid as request_row_id, pd.date_demande, pd.amount, pd.fk_societe_rib as soc_rib_id";
430 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s,";
431 $sql .= " ".MAIN_DB_PREFIX."user as u,";
432 $sql .= " ".MAIN_DB_PREFIX."prelevement_demande as pd";
433 $sql .= " WHERE s.fk_user = u.rowid";
434 $sql .= " AND s.entity IN (".getEntity('salary').")";
435 /*if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
436 $sql .= " AND s.fk_statut = ".Facture::STATUS_VALIDATED;
437 }*/
438 $sql .= " AND s.amount > 0";
439 $sql .= " AND pd.traite = 0";
440 $sql .= " AND pd.ext_payment_id IS NULL";
441 $sql .= " AND s.rowid = pd.fk_salary AND s.paye = ".Salary::STATUS_UNPAID;
442 $sql .= " AND pd.traite = 0";
443}
444
445$nbtotalofrecords = '';
446if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
447 $result = $db->query($sql);
448 $nbtotalofrecords = $db->num_rows($result);
449 if (($page * $limit) > $nbtotalofrecords) {
450 // if total resultset is smaller then paging size (filtering), goto and load page 0
451 $page = 0;
452 $offset = 0;
453 }
454}
455
456$sql .= $db->plimit($limit + 1, $offset);
457
458$resql = $db->query($sql);
459if ($resql) {
460 $num = $db->num_rows($resql);
461 $i = 0;
462
463 $param = '';
464 if ($type) {
465 $param .= '&type=' . urlencode((string) $type);
466 }
467 if ($limit > 0 && $limit != $conf->liste_limit) {
468 $param .= '&limit='.((int) $limit);
469 }
470 if ($socid) {
471 $param .= '&socid='.urlencode((string) ($socid));
472 }
473 if ($option) {
474 $param .= "&option=".urlencode($option);
475 }
476
477 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
478 print '<input type="hidden" name="token" value="'.newToken().'">';
479 print '<input type="hidden" name="page" value="'.$page.'">';
480 if (!empty($limit)) {
481 print '<input type="hidden" name="limit" value="'.$limit.'"/>';
482 }
483 if ($type != '') {
484 print '<input type="hidden" name="type" value="'.$type.'">';
485 }
486 $title = $langs->trans("InvoiceWaitingWithdraw");
487 $picto = 'bill';
488 if ($type == 'bank-transfer') {
489 if ($sourcetype != 'salary') {
490 $title = $langs->trans("InvoiceWaitingPaymentByBankTransfer");
491 } else {
492 $title = $langs->trans("SalaryWaitingWithdraw");
493 $picto = 'salary';
494 }
495 }
496 print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, '', '', $massactionbutton, $num, $nbtotalofrecords, $picto, 0, '', '', $limit);
497
498
499 $tradinvoice = "Invoice";
500 if ($type == 'bank-transfer') {
501 if ($sourcetype != 'salary') {
502 $tradinvoice = "SupplierInvoice";
503 } else {
504 $tradinvoice = "RefSalary";
505 }
506 }
507
508 print '<div class="div-table-responsive-no-min">';
509 print '<table class="noborder centpercent">';
510 print '<tr class="liste_titre">';
511 // Action column
512 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
513 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
514 print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
515 }
516 }
517 // Ref invoice or salary
518 print '<td>'.$langs->trans($tradinvoice).'</td>';
519 // Ref supplier
520 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
521 print '<td>'.$langs->trans("RefSupplier").'</td>';
522 }
523 // Thirdparty or user
524 if ($sourcetype != 'salary') {
525 print '<td>'.$langs->trans("ThirdParty").'</td>';
526 } else {
527 print '<td>'.$langs->trans("Employee").'</td>';
528 }
529 // BAN
530 print '<td>'.$langs->trans("RIB").'</td>';
531 // RUM
532 if (empty($type) || $type == 'direc-debit') {
533 print '<td>'.$langs->trans("RUM").'</td>';
534 }
535 print '<td class="right">';
536 if ($sourcetype == 'salary') {
537 print $langs->trans("Amount");
538 } else {
539 print $langs->trans("AmountTTC");
540 }
541 print '</td>';
542 print '<td class="right">'.$langs->trans("PendingSince").'</td>';
543 // Action column
544 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
545 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
546 print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
547 }
548 }
549 print '</tr>';
550
551 if ($num) {
552 if ($sourcetype != 'salary') {
553 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
554 } else {
555 require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
556 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
557 }
558
559 while ($i < $num && $i < $limit) {
560 $obj = $db->fetch_object($resql);
561 if ($sourcetype != 'salary') {
562 $bac = new CompanyBankAccount($db); // Must include the new in loop so the fetch is clean
563 $bac->fetch($obj->soc_rib_id ?? 0, '', $obj->socid);
564
565 $invoicestatic->id = $obj->rowid;
566 $invoicestatic->ref = $obj->ref;
567 if ($type == 'bank-transfer') {
568 $invoicestatic->ref_supplier = $obj->ref_supplier;
569 }
570 $salary = null;
571 } else {
572 $bac = new UserBankAccount($db);
573 $bac->fetch($obj->soc_rib_id ?? 0, '', $obj->uid);
574
575 $salary = new Salary($db);
576 $salary->fetch($obj->rowid);
577 }
578 print '<tr class="oddeven">';
579
580 // Action column
581 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
582 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
583 print '<td class="nowrap center">';
584 $selected = 0;
585 if (in_array($obj->request_row_id, $arrayofselected)) {
586 $selected = 1;
587 }
588 print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
589 print '</td>';
590 }
591 }
592
593 // Ref invoice
594 print '<td class="tdoverflowmax150">';
595 if ($sourcetype != 'salary' || $salary === null) {
596 print $invoicestatic->getNomUrl(1, 'withdraw');
597 } else {
598 print $salary->getNomUrl(1, 'withdraw');
599 }
600 print '</td>';
601
602 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
603 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($invoicestatic->ref_supplier).'">';
604 print dol_escape_htmltag($invoicestatic->ref_supplier);
605 print '</td>';
606 }
607
608 // Thirdparty
609 if ($sourcetype != 'salary') {
610 print '<td class="tdoverflowmax100">';
611 $thirdpartystatic->fetch($obj->socid);
612 print $thirdpartystatic->getNomUrl(1, 'ban');
613 print '</td>';
614 } else {
615 print '<td class="tdoverflowmax100">';
616 $user->fetch($obj->uid);
617 print $user->getNomUrl(-1);
618 print '</td>';
619 }
620
621 // BAN
622 print '<td>';
623 if ($bac->id > 0) {
624 if (!empty($bac->iban) || !empty($bac->bic)) {
625 print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
626 if ($bac->verif() <= 0) {
627 print img_warning('Error on default bank number for IBAN : '.$langs->trans($bac->error));
628 }
629 } else {
630 print img_warning($langs->trans("IBANNotDefined"));
631 }
632 } else {
633 $langs->load("banks");
634 print img_warning($langs->trans("NoBankAccountDefined"));
635 }
636 print '</td>';
637
638 // RUM
639 if (empty($type) || $type == 'direct-debit') {
640 print '<td>';
641 if (!empty($bac->rum)) {
642 print $bac->rum;
643 } else {
644 $rumToShow = $thirdpartystatic->display_rib('rum');
645 if ($rumToShow) {
646 print $rumToShow;
647 $format = $thirdpartystatic->display_rib('format');
648 if ($type != 'bank-transfer') {
649 if ($format) {
650 print ' ('.$format.')';
651 }
652 }
653 } else {
654 $langs->load("banks");
655 print img_warning($langs->trans("NoBankAccountDefined"));
656 }
657 }
658 print '</td>';
659 }
660
661 // Amount
662 print '<td class="right amount">';
663 print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
664 print '</td>';
665 // Date
666 print '<td class="right">';
667 print dol_print_date($db->jdate($obj->date_demande), 'day');
668 print '</td>';
669 // Action column
670 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
671 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
672 print '<td class="nowrap center">';
673 $selected = 0;
674 if (in_array($obj->request_row_id, $arrayofselected)) {
675 $selected = 1;
676 }
677 print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
678 print '</td>';
679 }
680 }
681 print '</tr>';
682 $i++;
683 }
684 } else {
685 $colspan = 6;
686 if ($type == 'bank-transfer') {
687 $colspan++;
688 }
689 if ($massactionbutton || $massaction) {
690 $colspan++;
691 }
692 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
693 }
694 print "</table>";
695 print "</div>";
696
697 print "</form>";
698 print "<br>\n";
699} else {
700 dol_print_error($db);
701}
702
703
704/*
705 * List of latest withdraws
706 */
707/*
708$limit=5;
709
710print load_fiche_titre($langs->trans("LastWithdrawalReceipts",$limit),'','');
711
712$sql = "SELECT p.rowid, p.ref, p.amount, p.statut";
713$sql.= ", p.datec";
714$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
715$sql.= " WHERE p.entity IN (".getEntity('invoice').")";
716$sql.= " ORDER BY datec DESC";
717$sql.=$db->plimit($limit);
718
719$result = $db->query($sql);
720if ($result)
721{
722 $num = $db->num_rows($result);
723 $i = 0;
724
725 print"\n<!-- debut table -->\n";
726 print '<table class="noborder centpercent">';
727 print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
728 print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
729 print '</tr>';
730
731 while ($i < min($num,$limit))
732 {
733 $obj = $db->fetch_object($result);
734
735
736 print '<tr class="oddeven">';
737
738 print "<td>";
739 $bprev->id=$obj->rowid;
740 $bprev->ref=$obj->ref;
741 print $bprev->getNomUrl(1);
742 print "</td>\n";
743
744 print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
745
746 print '<td class="right"><span class="amount">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</span></td>\n";
747
748 print "</tr>\n";
749 $i++;
750 }
751 print "</table><br>";
752 $db->free($result);
753}
754else
755{
756 dol_print_error($db);
757}
758*/
759
760// End of page
761llxFooter();
762$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).
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
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...
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.