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