dolibarr 24.0.0-beta
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-2024 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
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 $object->update($user);
120 }
121
122 // date of upload
123 if ($action == 'setdate_trans' && $permissiontosend) {
124 $result = $object->setValueFrom('date_trans', $date_trans, '', null, 'date');
125 if ($result < 0) {
126 setEventMessages($object->error, $object->errors, 'errors');
127 }
128 }
129
130 if ($action == 'infotrans' && $permissiontosend) {
131 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
132
133 $dt = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
134
135 /*
136 if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
137 {
138 $dir = $conf->prelevement->dir_output.'/receipts';
139
140 if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
141 {
142 $object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
143 }
144
145 header("Location: card.php?id=".$id);
146 exit;
147 }
148 else
149 {
150 dol_syslog("File invalid",LOG_WARNING);
151 $mesg='BadFile';
152 }*/
153
154 $error = $object->set_infotrans($user, $dt, GETPOSTINT('methode'));
155
156 if ($error) {
157 header("Location: card.php?id=".$id."&error=$error");
158 exit;
159 }
160 }
161
162 // Set direct debit order to credited, create payment and close invoices
163 if ($action == 'setinfocredit' && $permissiontocreditdebit) {
164 $dt = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
165
166 if (($object->type != 'bank-transfer' && $object->status == BonPrelevement::STATUS_CREDITED) || ($object->type == 'bank-transfer' && $object->statut == BonPrelevement::STATUS_DEBITED)) {
167 $error = 1;
168 setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
169 } else {
170 $error = $object->set_infocredit($user, $dt, ($salaryBonPl ? 'salary' : ''));
171 }
172
173 if ($error) {
174 setEventMessages($object->error, $object->errors, 'errors');
175 }
176 }
177
178 if ($action == 'reopen' && $permissiontocreditdebit) {
179 $savtype = $object->type;
180 $res = $object->setStatut(BonPrelevement::STATUS_TRANSFERED);
181 if ($res <= 0) {
182 setEventMessages($object->error, $object->errors, 'errors');
183 }
184 }
185
186 if ($action == 'setcancel' && $permissiontocreditdebit) {
187 $savtype = $object->type;
188 $res = $object->setStatut(BonPrelevement::STATUS_CANCELED);
189 if ($res <= 0) {
190 setEventMessages($object->error, $object->errors, 'errors');
191 }
192 }
193
194 if ($action == 'confirm_delete' && $permissiontodelete) {
195 $savtype = $object->type;
196 $res = $object->delete($user);
197 if ($res > 0) {
198 if ($savtype == 'bank-transfer') {
199 header("Location: ".DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php');
200 } else {
201 header("Location: ".DOL_URL_ROOT.'/compta/prelevement/index.php');
202 }
203 exit;
204 }
205 }
206}
207
208
209/*
210 * View
211 */
212
213$form = new Form($db);
214
215llxHeader('', $langs->trans("WithdrawalsReceipts"));
216
217if ($id > 0 || $ref) {
218 $head = prelevement_prepare_head($object);
219
220 print dol_get_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
221
222 if (GETPOST('error', 'alpha') != '') {
223 print '<div class="error">'.$object->getErrorString(GETPOSTINT('error')).'</div>';
224 }
225
226 $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>';
227
228 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
229
230 print '<div class="fichecenter">';
231 print '<div class="underbanner clearboth"></div>';
232 print '<table class="border centpercent tableforfield">';
233
234 // Date for payment
235 print '<tr><td class="titlefieldcreate">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
236
237 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount).'</span></td></tr>';
238
239 // Upload file
240 if (!empty($object->date_trans)) {
241 $muser = new User($db);
242 $muser->fetch($object->user_trans);
243
244 // Date upload
245 print '<tr><td>';
246 print '<table class="nobordernopadding centpercent"><tr><td>';
247 print $langs->trans('TransData');
248 print '</td>';
249 if ($action != 'editdate_trans' && $permissiontosend) {
250 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>';
251 }
252 print '</tr></table>';
253 print '</td><td>';
254 if ($action == 'editdate_trans' && $permissiontosend) {
255 print '<form name="setdate_trans" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
256 print '<input type="hidden" name="token" value="'.newToken().'">';
257 print '<input type="hidden" name="action" value="setdate_trans">';
258 print $form->selectDate($object->date_trans ? $object->date_trans : -1, 'date_trans', 0, 0, 0, "setdate_trans");
259 print '<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans('Modify').'">';
260 print '</form>';
261 } else {
262 print $object->date_trans ? dol_print_date($object->date_trans, 'day') : '';
263 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getNomUrl(-1).'</td>';
264 }
265 print '</td>';
266 print '</tr>';
267
268 // Method upload
269 print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
270 print $object->methodes_trans[$object->method_trans];
271 print '</td></tr>';
272 }
273
274 // Date real payment
275 if (!empty($object->date_credit)) {
276 print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
277 print dol_print_date($object->date_credit, 'day');
278 print '</td></tr>';
279 }
280
281 print '</table>';
282
283 print '<br>';
284
285 print '<div class="underbanner clearboth"></div>';
286 print '<table class="border centpercent tableforfield">';
287
288 // Get bank account for the payment
289 $acc = new Account($db);
290 $fk_bank_account = $object->fk_bank_account;
291 if (empty($fk_bank_account)) {
292 $fk_bank_account = ($object->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
293 }
294 if ($fk_bank_account > 0) {
295 $result = $acc->fetch($fk_bank_account);
296 }
297
298 // Bank account
299 $labelofbankfield = "BankToReceiveWithdraw";
300 if ($object->type == 'bank-transfer') {
301 $labelofbankfield = 'BankToPayCreditTransfer';
302 }
303 //print $langs->trans($labelofbankfield);
304 $caneditbank = $permissiontoadd;
305 if ($object->status != $object::STATUS_DRAFT) {
306 $caneditbank = 0;
307 }
308 /*
309 print '<tr><td class="titlefieldcreate">';
310 print $form->editfieldkey($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $object, $caneditbank);
311 print '</td>';
312 print '<td>';
313 print $form->editfieldval($langs->trans($labelofbankfield), 'fk_bank_account', $acc->id, $acc, $caneditbank, 'string', '', null, null, '', 1, 'getNomUrl');
314 print '</td>';
315 print '</tr>';
316 */
317 print '<tr><td class="titlefieldcreate">';
318 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
319 print $form->textwithpicto($langs->trans("BankAccount"), $langs->trans($labelofbankfield));
320 print '<td>';
321 if (($action != 'editbankaccount') && $caneditbank) {
322 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>';
323 }
324 print '</tr></table>';
325 print '</td><td>';
326 if ($action == 'editfkbankaccount') {
327 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $fk_bank_account, 'fk_bank_account', 0);
328 } else {
329 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $fk_bank_account, 'none');
330 }
331 print "</td>";
332 print '</tr>';
333
334 // Download file
335 print '<tr><td class="titlefieldcreate">';
336 $labelfororderfield = 'WithdrawalFile';
337 if ($object->type == 'bank-transfer') {
338 $labelfororderfield = 'CreditTransferFile';
339 }
340 print $langs->trans($labelfororderfield).'</td><td>';
341
342 $modulepart = 'prelevement';
343 if ($object->type == 'bank-transfer') {
344 $modulepart = 'paymentbybanktransfer';
345 }
346
347 if (isModEnabled('multicompany')) {
348 $labelentity = $conf->entity;
349 $relativepath = 'receipts/'.$object->ref.'-'.$labelentity.'.xml';
350
351 if ($type != 'bank-transfer') {
352 $dir = $conf->prelevement->dir_output;
353 } else {
354 $dir = $conf->paymentbybanktransfer->dir_output;
355 }
356 if (!dol_is_file($dir.'/'.$relativepath)) { // For backward compatibility
357 $relativepath = 'receipts/'.$object->ref.'.xml';
358 }
359 } else {
360 $relativepath = 'receipts/'.$object->ref.'.xml';
361 }
362
363 print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath;
364 print img_picto('', 'download', 'class="paddingleft"');
365 print '</a>';
366 print '</td></tr>';
367
368 // Other attributes
369 $parameters = array();
370 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
371 print $hookmanager->resPrint;
372
373 print '</table>';
374
375 print '</div>';
376
377 print dol_get_fiche_end();
378
379
380 $formconfirm = '';
381
382 // Confirmation to delete
383 if ($action == 'delete') {
384 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
385 }
386
387 // Call Hook formConfirm
388 /*$parameters = array('formConfirm' => $formconfirm);
389 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
390 if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
391 elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;*/
392
393 // Print form confirm
394 print $formconfirm;
395
396
397 if (empty($object->date_trans) && (($user->hasRight('prelevement', 'bons', 'send') && $object->type != 'bank-transfer') || ($user->hasRight('paymentbybanktransfer', 'send') && $object->type == 'bank-transfer')) && $action == 'settransmitted') {
398 print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
399 print '<input type="hidden" name="token" value="'.newToken().'">';
400 print '<input type="hidden" name="action" value="infotrans">';
401 print '<table class="noborder centpercent">';
402 print '<tr class="liste_titre">';
403 print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
404 print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
405 print $form->selectDate('', '', 0, 0, 0, "userfile", 1, 1);
406 print '</td></tr>';
407 print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
408 print $form->selectarray("methode", $object->methodes_trans);
409 print '</td></tr>';
410 print '</table>';
411 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
412 print '</form>';
413 print '<br>';
414 }
415
416 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') {
417 $btnLabel = ($object->type == 'bank-transfer') ? $langs->trans("ClassDebited") : $langs->trans("ClassCredited");
418 print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
419 print '<input type="hidden" name="token" value="'.newToken().'">';
420 print '<input type="hidden" name="action" value="setinfocredit">';
421 print '<table class="noborder centpercent">';
422 print '<tr class="liste_titre">';
423 print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
424 print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
425 print $form->selectDate(-1, '', 0, 0, 0, "infocredit", 1, 1, 0, '', '', array(array('adddateof' => $object->date_trans, 'labeladddateof' => $langs->transnoentitiesnoconv('TransData'))));
426 print '</td></tr>';
427 print '</table>';
428 print '<br><div class="center"><span class="opacitymedium">'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'</span></div>';
429 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($btnLabel).'"></div>';
430 print '</form>';
431 print '<br>';
432 }
433
434 // Actions
435 if ($action != 'settransmitted' && $action != 'setcredited') {
436 print "\n".'<div class="tabsAction">'."\n";
437 $parameters = array();
438 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
439 if (empty($reshook)) {
440 if (empty($object->date_trans)) {
441 if ($object->type == 'bank-transfer') {
442 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'send'));
443 } else {
444 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'send'));
445 }
446 }
447
448 if (getDolGlobalString('BANK_CAN_REOPEN_DIRECT_DEBIT_OR_CREDIT_TRANSFER')) {
449 if ($object->status == BonPrelevement::STATUS_DEBITED || $object->status == BonPrelevement::STATUS_CREDITED) {
450 if ($object->type == 'bank-transfer') {
451 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'card.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
452 } else {
453 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'card.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
454 }
455 }
456 }
457
458 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
459 if ($object->type == 'bank-transfer') {
460 print dolGetButtonAction($langs->trans("ClassDebited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
461 } else {
462 print dolGetButtonAction($langs->trans("ClassCredited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
463 }
464 }
465
466 // Cancel
467 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
468 if ($object->type == 'bank-transfer') {
469 print dolGetButtonAction($langs->trans("Cancel"), '', 'cancel', 'card.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
470 } else {
471 print dolGetButtonAction($langs->trans("Cancel"), '', 'cancel', 'card.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
472 }
473 }
474
475 if ($object->type == 'bank-transfer') {
476 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'create'));
477 } else {
478 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'creer'));
479 }
480 }
481 print '</div>';
482 }
483
484
485 $ligne = new LignePrelevement($db);
486
487 // Lines into withdraw request
488 if ($salaryBonPl) {
489 $sql = "SELECT pl.rowid, pl.statut as status, pl.amount,";
490 $sql .= " u.rowid as parentid, u.login as name";
491 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
492 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
493 $sql .= ", ".MAIN_DB_PREFIX."user as u";
494 $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id);
495 $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
496 $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
497 $sql .= " AND pl.fk_user = u.rowid";
498 if ($socid) {
499 $sql .= " AND u.rowid = ".((int) $socid);
500 }
501 $sql .= $db->order($sortfield, $sortorder);
502 } else {
503 $sql = "SELECT pl.rowid, pl.statut as status, pl.amount,";
504 $sql .= " s.rowid as parentid, s.nom as name";
505 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
506 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
507 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
508 $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id);
509 $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
510 $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
511 $sql .= " AND pl.fk_soc = s.rowid";
512 if ($socid) {
513 $sql .= " AND s.rowid = ".((int) $socid);
514 }
515 $sql .= $db->order($sortfield, $sortorder);
516 }
517 // Count total nb of records
518 $nbtotalofrecords = '';
519 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
520 $result = $db->query($sql);
521 $nbtotalofrecords = $db->num_rows($result);
522 if (($page * $limit) > (int) $nbtotalofrecords) {
523 // if total resultset is smaller then paging size (filtering), goto and load page 0
524 $page = 0;
525 $offset = 0;
526 }
527 }
528
529 $sql .= $db->plimit($limit + 1, $offset);
530
531 $result = $db->query($sql);
532
533 if ($result) {
534 $num = $db->num_rows($result);
535 $i = 0;
536
537 $urladd = "&id=".urlencode((string) ($id));
538 if ($limit > 0 && $limit != $conf->liste_limit) {
539 $urladd .= '&limit='.((int) $limit);
540 }
541
542 print '<form method="POST" action="'.$_SERVER ['PHP_SELF'].'" name="search_form">'."\n";
543 print '<input type="hidden" name="token" value="'.newToken().'"/>';
544 print '<input type="hidden" name="id" value="'.$id.'"/>';
545 print '<input type="hidden" name="socid" value="'.$socid.'"/>';
546 if (!empty($page)) {
547 print '<input type="hidden" name="page" value="'.$page.'"/>';
548 }
549 if (!empty($limit)) {
550 print '<input type="hidden" name="limit" value="'.$limit.'"/>';
551 }
552 if (!empty($sortfield)) {
553 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
554 }
555 if (!empty($sortorder)) {
556 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
557 }
558 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
559 print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
560
561 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
562 print '<table class="noborder liste centpercent">';
563 print '<tr class="liste_titre">';
564 print_liste_field_titre("Lines", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd, '', $sortfield, $sortorder);
565 print_liste_field_titre((!$salaryBonPl ? "ThirdParty" : "Employee"), $_SERVER["PHP_SELF"], "s.nom", '', $urladd, '', $sortfield, $sortorder);
566 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $urladd, 'class="right"', $sortfield, $sortorder);
568 print "</tr>\n";
569
570 $total = 0;
571
572 while ($i < min($num, $limit)) {
573 $obj = $db->fetch_object($result);
574
575 print '<tr class="oddeven">';
576
577 // Status of line
578 print "<td>";
579 print '<a class="valignmiddle" href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'&type='.$object->type.'&token='.newToken().'">';
580 print $ligne->LibStatut($obj->status, 2);
581 print '<span class="paddingleft">'.$obj->rowid.'</span>';
582 print '</a></td>';
583 if (!$salaryBonPl) {
584 $thirdparty = new Societe($db);
585 $thirdparty->fetch($obj->parentid);
586 $name = $thirdparty->getNomUrl(1);
587 } else {
588 $userSalary = new User($db);
589 $userSalary->fetch($obj->parentid);
590 $name = $userSalary->getNomUrl(-1);
591 }
592 print '<td class="tdoverflowmax150">';
593 print($name);
594 print "</td>\n";
595
596 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
597
598 print '<td class="right">';
599
600 if ($obj->status == 3) {
601 print '<span class="error">'.$langs->trans("StatusRefused").'</span>';
602 } else {
603 if ($object->status == BonPrelevement::STATUS_CREDITED) {
604 if ($obj->status == LignePrelevement::STATUS_CREDITED) {
605 if ($user->hasRight('prelevement', 'bons', 'credit')) {
606 //print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
607 print '<a href="line.php?action=rejet&type='.$object->type.'&id='.$obj->rowid.'&token='.newToken().'">'.$langs->trans("StandingOrderReject").'</a>';
608 } else {
609 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
610 }
611 }
612 } else {
613 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
614 }
615 }
616
617 print '</td></tr>';
618
619 $total += $obj->amount;
620
621 $i++;
622 }
623
624 if ($num > 0) {
625 $total = price2num($total, 'MT');
626
627 print '<tr class="liste_total">';
628 print '<td>'.$langs->trans("Total").'</td>';
629 print '<td>&nbsp;</td>';
630 print '<td class="right">';
631 if (empty($offset) && $num <= $limit) {
632 // If we have all record on same page, then the following test/warning can be done
633 if ($total != $object->amount) {
634 print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"));
635 }
636 }
637 print price($total);
638 print "</td>\n";
639 print '<td>&nbsp;</td>';
640 print "</tr>\n";
641 }
642
643 print "</table>";
644 print '</div>';
645 print '</form>';
646
647 $db->free($result);
648 } else {
650 }
651}
652
653// End of page
654llxFooter();
655$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 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_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).
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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, $mode=0)
Check permissions of a user to show a page and an object.