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