dolibarr 25.0.0-alpha
requests.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
40require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.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', 'bills', 'companies', 'withdrawals'));
45
46// Get supervariables
47$action = GETPOST('action', 'aZ09');
48
49$id = GETPOSTINT('id');
50$ref = GETPOST('ref', 'alpha');
51$socid = GETPOSTINT('socid');
52$type = GETPOST('type', 'aZ09');
53$date_trans = dol_mktime(GETPOSTINT('date_transhour'), GETPOSTINT('date_transmin'), GETPOSTINT('date_transsec'), GETPOSTINT('date_transmonth'), GETPOSTINT('date_transday'), GETPOSTINT('date_transyear'));
54
55// Load variable for pagination
56$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
57$sortfield = GETPOST('sortfield', 'aZ09comma');
58$sortorder = GETPOST('sortorder', 'aZ09comma');
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$pageprev = $page - 1;
65$pagenext = $page + 1;
66
67if (!$sortfield) {
68 $sortfield = 'pd.rowid';
69}
70if (!$sortorder) {
71 $sortorder = 'ASC';
72}
73
74$object = new BonPrelevement($db);
75
76// Load object
77include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
78
79$hookmanager->initHooks(array('directdebitprevcard', 'globalcard', 'directdebitprevlist'));
80
81$type = $object->type;
82
83// Check if salary or invoice
84$salaryBonPl = $object->checkIfSalaryBonPrelevement();
85
86// Security check
87if ($type == 'bank-transfer') {
88 $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
89
90 $permissiontoadd = $user->hasRight('paymentbybanktransfer', 'create');
91 $permissiontosend = $user->hasRight('paymentbybanktransfer', 'send');
92 $permissiontocreditdebit = $user->hasRight('paymentbybanktransfer', 'debit');
93 $permissiontodelete = $user->hasRight('paymentbybanktransfer', 'read');
94} else {
95 $result = restrictedArea($user, 'prelevement', '', '', 'bons');
96
97 $permissiontoadd = $user->hasRight('prelevement', 'bons', 'creer');
98 $permissiontosend = $user->hasRight('prelevement', 'bons', 'send');
99 $permissiontocreditdebit = $user->hasRight('prelevement', 'bons', 'credit');
100 $permissiontodelete = $user->hasRight('prelevement', 'bons', 'read');
101}
102
103
104/*
105 * Actions
106 */
107
108$parameters = array('socid' => $socid);
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 == 'setbankaccount' && $permissiontoadd) {
116 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
117 $object->fk_bank_account = GETPOSTINT('fk_bank_account');
118
119 $result = $object->update($user);
120 if ($result < 0) {
121 setEventMessages($object->error, $object->errors, 'errors');
122 }
123 }
124
125 // date of upload
126 if ($action == 'setdate_trans' && $permissiontosend) {
127 $result = $object->setValueFrom('date_trans', $date_trans, '', null, 'date');
128 if ($result < 0) {
129 setEventMessages($object->error, $object->errors, 'errors');
130 }
131 }
132
133 if ($action == 'infotrans' && $permissiontosend) {
134 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
135
136 $dt = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
137
138 /*
139 if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
140 {
141 $dir = $conf->prelevement->dir_output.'/receipts';
142
143 if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
144 {
145 $object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
146 }
147
148 header("Location: card.php?id=".$id);
149 exit;
150 }
151 else
152 {
153 dol_syslog("File invalid",LOG_WARNING);
154 $mesg='BadFile';
155 }*/
156
157 $error = $object->set_infotrans($user, $dt, GETPOSTINT('methode'));
158
159 if ($error) {
160 header("Location: card.php?id=".$id."&error=$error");
161 exit;
162 }
163 }
164
165 // Set direct debit order to credited, create payment and close invoices
166 if ($action == 'setinfocredit' && $permissiontocreditdebit) {
167 $dt = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
168
169 if (($object->type != 'bank-transfer' && $object->statut == BonPrelevement::STATUS_CREDITED) || ($object->type == 'bank-transfer' && $object->statut == BonPrelevement::STATUS_DEBITED)) {
170 $error = 1;
171 setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
172 } else {
173 $error = $object->set_infocredit($user, $dt, ($salaryBonPl ? 'salary' : ''));
174 }
175
176 if ($error) {
177 setEventMessages($object->error, $object->errors, 'errors');
178 }
179 }
180
181 if ($action == 'reopen' && $permissiontocreditdebit) {
182 $savtype = $object->type;
183 $res = $object->setStatut(BonPrelevement::STATUS_TRANSFERED);
184 if ($res <= 0) {
185 setEventMessages($object->error, $object->errors, 'errors');
186 }
187 }
188
189 if ($action == 'setcancel' && $permissiontocreditdebit) {
190 $savtype = $object->type;
191 $res = $object->setStatut(BonPrelevement::STATUS_CANCELED);
192 if ($res <= 0) {
193 setEventMessages($object->error, $object->errors, 'errors');
194 }
195 }
196
197 if ($action == 'confirm_delete' && $permissiontodelete) {
198 $savtype = $object->type;
199 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
200 $res = $object->delete($user);
201 if ($res > 0) {
202 if ($savtype == 'bank-transfer') {
203 header("Location: ".DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php');
204 } else {
205 header("Location: ".DOL_URL_ROOT.'/compta/prelevement/index.php');
206 }
207 exit;
208 } else {
209 setEventMessages($object->error, $object->errors, 'errors');
210 }
211 }
212}
213
214
215/*
216 * View
217 */
218
219$form = new Form($db);
220
221llxHeader('', $langs->trans("WithdrawalsReceipts"));
222
223if ($id > 0 || $ref) {
224 $head = prelevement_prepare_head($object);
225
226 print dol_get_fiche_head($head, 'requests', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
227
228 if (GETPOST('error', 'alpha') != '') {
229 print '<div class="error">'.$object->getErrorString(GETPOSTINT('error')).'</div>';
230 }
231
232 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
233
234 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
235
236 print '<div class="fichecenter">';
237 print '<div class="underbanner clearboth"></div>';
238 print '<table class="border centpercent tableforfield">';
239
240 // Date for payment
241 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
242
243 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
244
245 // Upload file
246 if (!empty($object->date_trans)) {
247 $muser = new User($db);
248 $muser->fetch($object->user_trans);
249
250 // Date upload
251 print '<tr><td>';
252 print '<table class="nobordernopadding centpercent"><tr><td>';
253 print $langs->trans('TransData');
254 print '</td>';
255 if ($action != 'editdate_trans' && $permissiontosend) {
256 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_trans&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetTransDate'), 1).'</a></td>';
257 }
258 print '</tr></table>';
259 print '</td><td>';
260 if ($action == 'editdate_trans' && $permissiontosend) {
261 print '<form name="setdate_trans" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
262 print '<input type="hidden" name="token" value="'.newToken().'">';
263 print '<input type="hidden" name="action" value="setdate_trans">';
264 print $form->selectDate($object->date_trans, 'date_trans', 0, 0, 0, "setdate_trans"); // $object->date_trans can't be empty due to test some lines ago
265 print '<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans('Modify').'">';
266 print '</form>';
267 } else {
268 print dol_print_date($object->date_trans, 'day'); // $object->date_trans can't be empty due to test some lines ago
269 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td>';
270 }
271 print '</td>';
272 print '</tr>';
273
274 // Method upload
275 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
276 print $object->methodes_trans[$object->method_trans];
277 print '</td></tr>';
278 }
279
280 // Date real payment
281 if (!empty($object->date_credit)) {
282 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
283 print dol_print_date($object->date_credit, 'day');
284 print '</td></tr>';
285 }
286
287 print '</table>';
288
289 print '<br>';
290
291 print '<div class="underbanner clearboth"></div>';
292 print '<table class="border centpercent tableforfield">';
293
294 // Get bank account for the payment
295 $acc = new Account($db);
296 $fk_bank_account = $object->fk_bank_account;
297 if (empty($fk_bank_account)) {
298 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
299 }
300 if ($fk_bank_account > 0) {
301 $result = $acc->fetch($fk_bank_account);
302 }
303
304 // Bank account
305 $labelofbankfield = "BankToReceiveWithdraw";
306 if ($object->type == 'bank-transfer') {
307 $labelofbankfield = 'BankToPayCreditTransfer';
308 }
309 //print $langs->trans($labelofbankfield);
310 $caneditbank = $permissiontoadd;
311 if ($object->status != $object::STATUS_DRAFT) {
312 $caneditbank = 0;
313 }
314 /*
315 print '<tr><td class="titlefieldcreate">';
316 print $form->editfieldkey($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $object, $caneditbank);
317 print '</td>';
318 print '<td>';
319 print $form->editfieldval($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $acc, $caneditbank, 'string', '', null, null, '', 1, 'getNomUrl');
320 print '</td>';
321 print '</tr>';
322 */
323 print '<tr><td class="titlefieldcreate">';
324 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
325 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
326 print '<td>';
327 if (($action != 'editbankaccount') && $caneditbank) {
328 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editfkbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
329 }
330 print '</tr></table>';
331 print '</td><td>';
332 if ($action == 'editfkbankaccount') {
333 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $fk_bank_account, 'fk_bank_account', 0);
334 } else {
335 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $fk_bank_account, 'none');
336 }
337 print "</td>";
338 print '</tr>';
339
340 // Download file
341 print '<tr><td class="titlefieldcreate">';
342 $labelfororderfield = 'WithdrawalFile';
343 if ($object->type == 'bank-transfer') {
344 $labelfororderfield = 'CreditTransferFile';
345 }
346 print $langs->trans($labelfororderfield).'</td><td>';
347
348 $modulepart = 'prelevement';
349 if ($object->type == 'bank-transfer') {
350 $modulepart = 'paymentbybanktransfer';
351 }
352
353 if (isModEnabled('multicompany')) {
354 $labelentity = $conf->entity;
355 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
356
357 if ($type != 'bank-transfer') {
358 $dir = $conf->prelevement->dir_output;
359 } else {
360 $dir = $conf->paymentbybanktransfer->dir_output;
361 }
362 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
363 $relativepath = 'receipts/'.$object->ref.'.xml';
364 }
365 } else {
366 $relativepath = 'receipts/'.$object->ref.'.xml';
367 }
368
369 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
370 print img_picto('', 'download', 'class="paddingleft"');
371 print '</a>';
372 print '</td></tr>';
373
374 // Other attributes
375 $parameters = array();
376 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
377 print $hookmanager->resPrint;
378
379 print '</table>';
380
381 print '</div>';
382
383 print dol_get_fiche_end();
384
385
386 $formconfirm = '';
387
388 // Confirmation to delete
389 if ($action == 'delete') {
390 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
391 }
392
393 // Call Hook formConfirm
394 /*$parameters = array('formConfirm' => $formconfirm);
395 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
396 if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
397 elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;*/
398
399 // Print form confirm
400 print $formconfirm;
401
402
403 if (empty($object->date_trans) && (($user->hasRight('prelevement', 'bons', 'send') && $object->type != 'bank-transfer') || ($user->hasRight('paymentbybanktransfer', 'send') && $object->type == 'bank-transfer')) && $action == 'settransmitted') {
404 print '<form method="post" name="userfile" action="requests.php?id='.$object->id.'" enctype="multipart/form-data">';
405 print '<input type="hidden" name="token" value="'.newToken().'">';
406 print '<input type="hidden" name="action" value="infotrans">';
407 print '<table class="noborder centpercent">';
408 print '<tr class="liste_titre">';
409 print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
410 print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
411 print $form->selectDate('', '', 0, 0, 0, "userfile", 1, 1);
412 print '</td></tr>';
413 print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
414 print $form->selectarray("methode", $object->methodes_trans);
415 print '</td></tr>';
416 print '</table>';
417 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
418 print '</form>';
419 print '<br>';
420 }
421
422 if ($object->status == BonPrelevement::STATUS_TRANSFERED && (($user->hasRight('prelevement', 'bons', 'credit') && $object->type != 'bank-transfer') || ($user->hasRight('paymentbybanktransfer', 'debit') && $object->type == 'bank-transfer')) && $action == 'setcredited') {
423 $btnLabel = ($object->type == 'bank-transfer') ? $langs->trans("ClassDebited") : $langs->trans("ClassCredited");
424 print '<form name="infocredit" method="post" action="requests.php?id='.$object->id.'">';
425 print '<input type="hidden" name="token" value="'.newToken().'">';
426 print '<input type="hidden" name="action" value="setinfocredit">';
427 print '<table class="noborder centpercent">';
428 print '<tr class="liste_titre">';
429 print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
430 print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
431 print $form->selectDate(-1, '', 0, 0, 0, "infocredit", 1, 1, 0, '', '', array(array('adddateof' => $object->date_trans, 'labeladddateof' => $langs->transnoentitiesnoconv('TransData'))));
432 print '</td></tr>';
433 print '</table>';
434 print '<br><div class="center"><span class="opacitymedium">'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'</span></div>';
435 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($btnLabel).'"></div>';
436 print '</form>';
437 print '<br>';
438 }
439
440 // Actions
441 if ($action != 'settransmitted' && $action != 'setcredited') {
442 print "\n".'<div class="tabsAction">'."\n";
443 $parameters = array();
444 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
445 if (empty($reshook)) {
446 if (empty($object->date_trans)) {
447 if ($object->type == 'bank-transfer') {
448 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'requests.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'send'));
449 } else {
450 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'requests.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'send'));
451 }
452 }
453
454 if (getDolGlobalString('BANK_CAN_REOPEN_DIRECT_DEBIT_OR_CREDIT_TRANSFER')) {
455 if ($object->status == BonPrelevement::STATUS_DEBITED || $object->status == BonPrelevement::STATUS_CREDITED) {
456 if ($object->type == 'bank-transfer') {
457 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'requests.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
458 } else {
459 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'requests.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
460 }
461 }
462 }
463
464 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
465 if ($object->type == 'bank-transfer') {
466 print dolGetButtonAction($langs->trans("ClassDebited"), '', 'default', 'requests.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
467 } else {
468 print dolGetButtonAction($langs->trans("ClassCredited"), '', 'default', 'requests.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
469 }
470 }
471
472 // Cancel
473 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
474 if ($object->type == 'bank-transfer') {
475 print dolGetButtonAction($langs->trans("Cancel"), '', 'default', 'requests.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'), array('attr' => array('classOverride' => 'butAction butActionDanger')))."\n";
476 } else {
477 print dolGetButtonAction($langs->trans("Cancel"), '', 'default', 'requests.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'), array('attr' => array('classOverride' => 'butAction butActionDanger')))."\n";
478 }
479 }
480
481 if ($object->type == 'bank-transfer') {
482 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', 'requests.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'create'), array('attr' => array('class' => 'reposition')))."\n";
483 } else {
484 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', 'requests.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'creer'), array('attr' => array('class' => 'reposition')))."\n";
485 }
486 }
487 print '</div>';
488 }
489
490
491 $ligne = new LignePrelevement($db);
492
493 // Lines into withdraw request
494 $sql = "SELECT pd.rowid, pd.type, pd.ext_payment_id, pd.ext_payment_site, pd.amount, pd.fk_facture, pd.fk_user_demande, pd.date_demande, pd.traite, ";
495 $sql .= " s.rowid as socid, s.nom as name";
496 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pd";
497 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
498 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
499 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
500 $sql .= " WHERE pd.fk_prelevement_bons = ".((int) $id);
501 $sql .= " AND pd.fk_prelevement_bons = pb.rowid";
502 $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
503 $sql .= " AND pd.fk_facture = f.rowid AND f.fk_soc = s.rowid";
504 if ($socid) {
505 $sql .= " AND s.rowid = ".((int) $socid);
506 }
507 $sql .= $db->order($sortfield, $sortorder);
508
509 // Count total nb of records
510 $nbtotalofrecords = '';
511 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
512 $result = $db->query($sql);
513 $nbtotalofrecords = $db->num_rows($result);
514 if (($page * $limit) > (int) $nbtotalofrecords) {
515 // if total resultset is smaller then paging size (filtering), goto and load page 0
516 $page = 0;
517 $offset = 0;
518 }
519 }
520
521 $sql .= $db->plimit($limit + 1, $offset);
522
523 $result = $db->query($sql);
524
525 if ($result) {
526 $num = $db->num_rows($result);
527 $i = 0;
528
529 $urladd = "&id=".urlencode((string) ($id));
530 if ($limit > 0 && $limit != $conf->liste_limit) {
531 $urladd .= '&limit='.((int) $limit);
532 }
533
534 print '<form method="POST" action="'.$_SERVER ['PHP_SELF'].'" name="search_form">'."\n";
535 print '<input type="hidden" name="token" value="'.newToken().'"/>';
536 print '<input type="hidden" name="id" value="'.$id.'"/>';
537 print '<input type="hidden" name="socid" value="'.$socid.'"/>';
538 if (!empty($page)) {
539 print '<input type="hidden" name="page" value="'.$page.'"/>';
540 }
541 if (!empty($limit)) {
542 print '<input type="hidden" name="limit" value="'.$limit.'"/>';
543 }
544 if (!empty($sortfield)) {
545 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
546 }
547 if (!empty($sortorder)) {
548 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
549 }
550 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
551 print_barre_liste($langs->trans("Requests"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
552
553 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
554 print '<table class="noborder liste centpercent">';
555 print '<tr class="liste_titre">';
556 print_liste_field_titre("ID", $_SERVER["PHP_SELF"], "pd.rowid", '', $urladd, '', $sortfield, $sortorder);
557 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "pd.date_demande", '', $urladd, '', $sortfield, $sortorder);
558 print_liste_field_titre("User", $_SERVER["PHP_SELF"], "pd.fk_user_demande", "", $urladd, '', $sortfield, $sortorder);
559 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pd.amount", "", $urladd, 'class="right"', $sortfield, $sortorder);
560 print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "pd.fk_facture", '', $urladd, '', $sortfield, $sortorder);
562 print "</tr>\n";
563
564 $total = 0;
565
566 while ($i < min($num, $limit)) {
567 $obj = $db->fetch_object($result);
568
569 print '<tr class="oddeven">';
570
571 // Status of line
572 print "<td>";
573 print $obj->rowid;
574 print '</td>';
575
576 print '<td class="tdoverflowmax150">';
577 print dol_print_date($obj->date_demande, 'dayhour', 'tzuserrel');
578 print "</td>\n";
579
580 print '<td>';
581 $tmpuser = new User($db);
582 $tmpuser->fetch($obj->fk_user_demande);
583 print $tmpuser->getNomUrl(1);
584 print '</td>';
585
586 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
587
588 print '<td>';
589 $tmpinvoice = new Facture($db);
590 $tmpinvoice->fetch($obj->fk_facture);
591 print $tmpinvoice->getNomUrl(1);
592 print '</td>';
593
594 print '<td class="right">';
595 print $obj->ext_payment_id;
596 print '</td>';
597
598 print '</tr>';
599
600 $total += $obj->amount;
601
602 $i++;
603 }
604
605 if ($num > 0) {
606 $total = price2num($total, 'MT');
607
608 print '<tr class="liste_total">';
609 print '<td>'.$langs->trans("Total").'</td>';
610 print '<td>&nbsp;</td>';
611 print '<td>&nbsp;</td>';
612 print '<td class="right">';
613 if (empty($offset) && $num <= $limit) {
614 // If we have all record on same page, then the following test/warning can be done
615 if ($total != $object->amount) {
616 print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"));
617 }
618 }
619 print price($total);
620 print "</td>\n";
621 print '<td>&nbsp;</td>';
622 print '<td>&nbsp;</td>';
623 print "</tr>\n";
624 }
625
626 print "</table>";
627 print '</div>';
628 print '</form>';
629
630 $db->free($result);
631 } else {
632 dol_print_error($db);
633 }
634}
635
636// End of page
637llxFooter();
638$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage withdrawals.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_is_file($pathoffile)
Return if path is a file.
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.