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