dolibarr 25.0.0-alpha
card.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 = 'pl.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->status == 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) && $object->id <= 0) {
224 recordNotFound('', 0);
225}
226
227if ($id > 0 || $ref) {
228 $head = prelevement_prepare_head($object);
229
230 print dol_get_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
231
232 if (GETPOST('error', 'alpha') != '') {
233 print '<div class="error">'.$object->getErrorString(GETPOSTINT('error')).'</div>';
234 }
235
236 $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>';
237
238 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
239
240 print '<div class="fichecenter">';
241 print '<div class="underbanner clearboth"></div>';
242 print '<table class="border centpercent tableforfield">';
243
244 // Date for payment
245 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
246
247 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
248
249 // Upload file
250 if (!empty($object->date_trans)) {
251 $muser = new User($db);
252 $muser->fetch($object->user_trans);
253
254 // Date upload
255 print '<tr><td>';
256 print '<table class="nobordernopadding centpercent"><tr><td>';
257 print $langs->trans('TransData');
258 print '</td>';
259 if ($action != 'editdate_trans' && $permissiontosend) {
260 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>';
261 }
262 print '</tr></table>';
263 print '</td><td>';
264 if ($action == 'editdate_trans' && $permissiontosend) {
265 print '<form name="setdate_trans" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
266 print '<input type="hidden" name="token" value="'.newToken().'">';
267 print '<input type="hidden" name="action" value="setdate_trans">';
268 print $form->selectDate($object->date_trans ? $object->date_trans : -1, 'date_trans', 0, 0, 0, "setdate_trans");
269 print '<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans('Modify').'">';
270 print '</form>';
271 } else {
272 print $object->date_trans ? dol_print_date($object->date_trans, 'day') : '';
273 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td>';
274 }
275 print '</td>';
276 print '</tr>';
277
278 // Method upload
279 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
280 print $object->methodes_trans[$object->method_trans];
281 print '</td></tr>';
282 }
283
284 // Date real payment
285 if (!empty($object->date_credit)) {
286 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
287 print dol_print_date($object->date_credit, 'day');
288 print '</td></tr>';
289 }
290
291 print '</table>';
292
293 print '<br>';
294
295 print '<div class="underbanner clearboth"></div>';
296 print '<table class="border centpercent tableforfield">';
297
298 // Get bank account for the payment
299 $acc = new Account($db);
300 $fk_bank_account = $object->fk_bank_account;
301 if (empty($fk_bank_account)) {
302 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
303 }
304 if ($fk_bank_account > 0) {
305 $result = $acc->fetch($fk_bank_account);
306 }
307
308 // Bank account
309 $labelofbankfield = "BankToReceiveWithdraw";
310 if ($object->type == 'bank-transfer') {
311 $labelofbankfield = 'BankToPayCreditTransfer';
312 }
313 //print $langs->trans($labelofbankfield);
314 $caneditbank = $permissiontoadd;
315 if ($object->status != $object::STATUS_DRAFT) {
316 $caneditbank = 0;
317 }
318 /*
319 print '<tr><td class="titlefieldcreate">';
320 print $form->editfieldkey($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $object, $caneditbank);
321 print '</td>';
322 print '<td>';
323 print $form->editfieldval($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $acc, $caneditbank, 'string', '', null, null, '', 1, 'getNomUrl');
324 print '</td>';
325 print '</tr>';
326 */
327 print '<tr><td class="titlefieldcreate">';
328 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
329 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
330 print '<td>';
331 if (($action != 'editbankaccount') && $caneditbank) {
332 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>';
333 }
334 print '</tr></table>';
335 print '</td><td>';
336 if ($action == 'editfkbankaccount') {
337 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $fk_bank_account, 'fk_bank_account', 0);
338 } else {
339 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $fk_bank_account, 'none');
340 }
341 print "</td>";
342 print '</tr>';
343
344 // Download file
345 print '<tr><td class="titlefieldcreate">';
346 $labelfororderfield = 'WithdrawalFile';
347 if ($object->type == 'bank-transfer') {
348 $labelfororderfield = 'CreditTransferFile';
349 }
350 print $langs->trans($labelfororderfield).'</td><td>';
351
352 $modulepart = 'prelevement';
353 if ($object->type == 'bank-transfer') {
354 $modulepart = 'paymentbybanktransfer';
355 }
356
357 if (isModEnabled('multicompany')) {
358 $labelentity = $conf->entity;
359 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
360
361 if ($type != 'bank-transfer') {
362 $dir = $conf->prelevement->dir_output;
363 } else {
364 $dir = $conf->paymentbybanktransfer->dir_output;
365 }
366 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
367 $relativepath = 'receipts/'.$object->ref.'.xml';
368 }
369 } else {
370 $relativepath = 'receipts/'.$object->ref.'.xml';
371 }
372
373 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
374 print img_picto('', 'download', 'class="paddingleft"');
375 print '</a>';
376 print '</td></tr>';
377
378 // Other attributes
379 $parameters = array();
380 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
381 print $hookmanager->resPrint;
382
383 print '</table>';
384
385 print '</div>';
386
387 print dol_get_fiche_end();
388
389
390 $formconfirm = '';
391
392 // Confirmation to delete
393 if ($action == 'delete') {
394 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
395 }
396
397 // Call Hook formConfirm
398 /*$parameters = array('formConfirm' => $formconfirm);
399 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
400 if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
401 elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;*/
402
403 // Print form confirm
404 print $formconfirm;
405
406
407 if (empty($object->date_trans) && (($user->hasRight('prelevement', 'bons', 'send') && $object->type != 'bank-transfer') || ($user->hasRight('paymentbybanktransfer', 'send') && $object->type == 'bank-transfer')) && $action == 'settransmitted') {
408 print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
409 print '<input type="hidden" name="token" value="'.newToken().'">';
410 print '<input type="hidden" name="action" value="infotrans">';
411 print '<table class="noborder centpercent">';
412 print '<tr class="liste_titre">';
413 print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
414 print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
415 print $form->selectDate('', '', 0, 0, 0, "userfile", 1, 1);
416 print '</td></tr>';
417 print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
418 print $form->selectarray("methode", $object->methodes_trans);
419 print '</td></tr>';
420 print '</table>';
421 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
422 print '</form>';
423 print '<br>';
424 }
425
426 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') {
427 print '<br>';
428
429 $btnLabel = ($object->type == 'bank-transfer') ? $langs->trans("ClassDebited") : $langs->trans("ClassCredited");
430 print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
431 print '<input type="hidden" name="token" value="'.newToken().'">';
432 print '<input type="hidden" name="action" value="setinfocredit">';
433 print '<table class="noborder centpercent">';
434 print '<tr class="liste_titre">';
435 print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
436 print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
437 print $form->selectDate(-1, '', 0, 0, 0, "infocredit", 1, 1, 0, '', '', array(array('adddateof' => $object->date_trans, 'labeladddateof' => $langs->transnoentitiesnoconv('TransData'))));
438 print '</td></tr>';
439 print '</table>';
440 print '<br><div class="center"><span class="opacitymedium">'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'</span></div>';
441 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($btnLabel).'"></div>';
442 print '</form>';
443 print '<br>';
444 }
445
446 // Actions
447 if ($action != 'settransmitted' && $action != 'setcredited') {
448 print "\n".'<div class="tabsAction">'."\n";
449 $parameters = array();
450 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
451 if (empty($reshook)) {
452 if (empty($object->date_trans)) {
453 if ($object->type == 'bank-transfer') {
454 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'send'));
455 } else {
456 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'send'));
457 }
458 }
459
460 if (getDolGlobalString('BANK_CAN_REOPEN_DIRECT_DEBIT_OR_CREDIT_TRANSFER')) {
461 if ($object->status == BonPrelevement::STATUS_DEBITED || $object->status == BonPrelevement::STATUS_CREDITED) {
462 if ($object->type == 'bank-transfer') {
463 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'card.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
464 } else {
465 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'card.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
466 }
467 }
468 }
469
470 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
471 if ($object->type == 'bank-transfer') {
472 print dolGetButtonAction($langs->trans("ClassDebited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
473 } else {
474 print dolGetButtonAction($langs->trans("ClassCredited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
475 }
476 }
477
478 // Cancel
479 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
480 if ($object->type == 'bank-transfer') {
481 print dolGetButtonAction($langs->trans("Cancel"), '', 'default', 'card.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'), array('attr' => array('classOverride' => 'butAction butActionDanger')))."\n";
482 } else {
483 print dolGetButtonAction($langs->trans("Cancel"), '', 'default', 'card.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'), array('attr' => array('classOverride' => 'butAction butActionDanger')))."\n";
484 }
485 }
486
487 if ($object->type == 'bank-transfer') {
488 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'create'), array('attr' => array('class' => 'reposition')))."\n";
489 } else {
490 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'creer'), array('attr' => array('class' => 'reposition')))."\n";
491 }
492 }
493 print '</div>';
494 }
495
496
497 $ligne = new LignePrelevement($db);
498
499 // Lines into withdraw request
500 if ($salaryBonPl) {
501 $sql = "SELECT pl.rowid, pl.statut as status, pl.amount,";
502 $sql .= " u.rowid as parentid, u.login as name";
503 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
504 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
505 $sql .= ", ".MAIN_DB_PREFIX."user as u";
506 $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id);
507 $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
508 $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
509 $sql .= " AND pl.fk_user = u.rowid";
510 if ($socid) {
511 $sql .= " AND u.rowid = ".((int) $socid);
512 }
513 $sql .= $db->order($sortfield, $sortorder);
514 } else {
515 $sql = "SELECT pl.rowid, pl.statut as status, pl.amount,";
516 $sql .= " s.rowid as parentid, s.nom as name";
517 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
518 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
519 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
520 $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id);
521 $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
522 $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
523 $sql .= " AND pl.fk_soc = s.rowid";
524 if ($socid) {
525 $sql .= " AND s.rowid = ".((int) $socid);
526 }
527 $sql .= $db->order($sortfield, $sortorder);
528 }
529 // Count total nb of records
530 $nbtotalofrecords = '';
531 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
532 $result = $db->query($sql);
533 $nbtotalofrecords = $db->num_rows($result);
534 if (($page * $limit) > (int) $nbtotalofrecords) {
535 // if total resultset is smaller then paging size (filtering), goto and load page 0
536 $page = 0;
537 $offset = 0;
538 }
539 }
540
541 $sql .= $db->plimit($limit + 1, $offset);
542
543 $result = $db->query($sql);
544
545 if ($result) {
546 $num = $db->num_rows($result);
547 $i = 0;
548
549 $urladd = "&id=".urlencode((string) ($id));
550 if ($limit > 0 && $limit != $conf->liste_limit) {
551 $urladd .= '&limit='.((int) $limit);
552 }
553
554 print '<form method="POST" action="'.$_SERVER ['PHP_SELF'].'" name="search_form">'."\n";
555 print '<input type="hidden" name="token" value="'.newToken().'"/>';
556 print '<input type="hidden" name="id" value="'.$id.'"/>';
557 print '<input type="hidden" name="socid" value="'.$socid.'"/>';
558 if (!empty($page)) {
559 print '<input type="hidden" name="page" value="'.$page.'"/>';
560 }
561 if (!empty($limit)) {
562 print '<input type="hidden" name="limit" value="'.$limit.'"/>';
563 }
564 if (!empty($sortfield)) {
565 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
566 }
567 if (!empty($sortorder)) {
568 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
569 }
570 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
571 print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
572
573 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
574 print '<table class="noborder liste centpercent">';
575 print '<tr class="liste_titre">';
576 print_liste_field_titre("LineID", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd, '', $sortfield, $sortorder);
577 print_liste_field_titre((!$salaryBonPl ? "ThirdParty" : "Employee"), $_SERVER["PHP_SELF"], "s.nom", '', $urladd, '', $sortfield, $sortorder);
578 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $urladd, 'class="right"', $sortfield, $sortorder);
580 print "</tr>\n";
581
582 $total = 0;
583
584 while ($i < min($num, $limit)) {
585 $obj = $db->fetch_object($result);
586
587 print '<tr class="oddeven">';
588
589 // Status of line
590 print "<td>";
591 print '<a class="valignmiddle" href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'&type='.$object->type.'&token='.newToken().'">';
592 print $ligne->LibStatut($obj->status, 2);
593 print '<span class="paddingleft">'.$obj->rowid.'</span>';
594 print '</a></td>';
595 if (!$salaryBonPl) {
596 $thirdparty = new Societe($db);
597 $thirdparty->fetch($obj->parentid);
598 $name = $thirdparty->getNomUrl(1);
599 } else {
600 $userSalary = new User($db);
601 $userSalary->fetch($obj->parentid);
602 $name = $userSalary->getNomUrl(-1);
603 }
604 print '<td class="tdoverflowmax150">';
605 print($name);
606 print "</td>\n";
607
608 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
609
610 print '<td class="right">';
611
612 if ($obj->status == 3) {
613 print '<span class="error">'.$langs->trans("StatusRefused").'</span>';
614 } else {
615 if ($object->status == BonPrelevement::STATUS_CREDITED) {
616 if ($obj->status == LignePrelevement::STATUS_CREDITED) {
617 if ($user->hasRight('prelevement', 'bons', 'credit')) {
618 //print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
619 print '<a href="line.php?action=rejet&type='.$object->type.'&id='.$obj->rowid.'&token='.newToken().'">'.$langs->trans("StandingOrderReject").'</a>';
620 } else {
621 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
622 }
623 }
624 } else {
625 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
626 }
627 }
628
629 print '</td></tr>';
630
631 $total += $obj->amount;
632
633 $i++;
634 }
635
636 if ($num > 0) {
637 $total = price2num($total, 'MT');
638
639 print '<tr class="liste_total">';
640 print '<td>'.$langs->trans("Total").'</td>';
641 print '<td>&nbsp;</td>';
642 print '<td class="right">';
643 if (empty($offset) && $num <= $limit) {
644 // If we have all record on same page, then the following test/warning can be done
645 if ($total != $object->amount) {
646 print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"));
647 }
648 }
649 print price($total);
650 print "</td>\n";
651 print '<td>&nbsp;</td>';
652 print "</tr>\n";
653 }
654
655 print "</table>";
656 print '</div>';
657 print '</form>';
658
659 $db->free($result);
660 } else {
661 dol_print_error($db);
662 }
663}
664
665// End of page
666llxFooter();
667$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage withdrawal receipts.
Class to manage generation of HTML components Only common components must be here.
Class to manage withdrawals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_is_file($pathoffile)
Return if path is a file.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
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, $currencycode='')
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:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
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.