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 print '<br>';
418
419 $btnLabel = ($object->type == 'bank-transfer') ? $langs->trans("ClassDebited") : $langs->trans("ClassCredited");
420 print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
421 print '<input type="hidden" name="token" value="'.newToken().'">';
422 print '<input type="hidden" name="action" value="setinfocredit">';
423 print '<table class="noborder centpercent">';
424 print '<tr class="liste_titre">';
425 print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
426 print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
427 print $form->selectDate(-1, '', 0, 0, 0, "infocredit", 1, 1, 0, '', '', array(array('adddateof' => $object->date_trans, 'labeladddateof' => $langs->transnoentitiesnoconv('TransData'))));
428 print '</td></tr>';
429 print '</table>';
430 print '<br><div class="center"><span class="opacitymedium">'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'</span></div>';
431 print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($btnLabel).'"></div>';
432 print '</form>';
433 print '<br>';
434 }
435
436 // Actions
437 if ($action != 'settransmitted' && $action != 'setcredited') {
438 print "\n".'<div class="tabsAction">'."\n";
439 $parameters = array();
440 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
441 if (empty($reshook)) {
442 if (empty($object->date_trans)) {
443 if ($object->type == 'bank-transfer') {
444 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'send'));
445 } else {
446 print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'send'));
447 }
448 }
449
450 if (getDolGlobalString('BANK_CAN_REOPEN_DIRECT_DEBIT_OR_CREDIT_TRANSFER')) {
451 if ($object->status == BonPrelevement::STATUS_DEBITED || $object->status == BonPrelevement::STATUS_CREDITED) {
452 if ($object->type == 'bank-transfer') {
453 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'card.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
454 } else {
455 print dolGetButtonAction($langs->trans("ReOpen"), '', 'default', 'card.php?action=reopen&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
456 }
457 }
458 }
459
460 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
461 if ($object->type == 'bank-transfer') {
462 print dolGetButtonAction($langs->trans("ClassDebited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
463 } else {
464 print dolGetButtonAction($langs->trans("ClassCredited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
465 }
466 }
467
468 // Cancel
469 if ($object->status == BonPrelevement::STATUS_TRANSFERED) {
470 if ($object->type == 'bank-transfer') {
471 print dolGetButtonAction($langs->trans("Cancel"), '', 'cancel', 'card.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'debit'));
472 } else {
473 print dolGetButtonAction($langs->trans("Cancel"), '', 'cancel', 'card.php?action=setcancel&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'credit'));
474 }
475 }
476
477 if ($object->type == 'bank-transfer') {
478 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('paymentbybanktransfer', 'create'));
479 } else {
480 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->hasRight('prelevement', 'bons', 'creer'));
481 }
482 }
483 print '</div>';
484 }
485
486
487 $ligne = new LignePrelevement($db);
488
489 // Lines into withdraw request
490 if ($salaryBonPl) {
491 $sql = "SELECT pl.rowid, pl.statut as status, pl.amount,";
492 $sql .= " u.rowid as parentid, u.login as name";
493 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
494 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
495 $sql .= ", ".MAIN_DB_PREFIX."user as u";
496 $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id);
497 $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
498 $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
499 $sql .= " AND pl.fk_user = u.rowid";
500 if ($socid) {
501 $sql .= " AND u.rowid = ".((int) $socid);
502 }
503 $sql .= $db->order($sortfield, $sortorder);
504 } else {
505 $sql = "SELECT pl.rowid, pl.statut as status, pl.amount,";
506 $sql .= " s.rowid as parentid, s.nom as name";
507 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
508 $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
509 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
510 $sql .= " WHERE pl.fk_prelevement_bons = ".((int) $id);
511 $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
512 $sql .= " AND pb.entity = ".((int) $conf->entity); // No sharing of entity here
513 $sql .= " AND pl.fk_soc = s.rowid";
514 if ($socid) {
515 $sql .= " AND s.rowid = ".((int) $socid);
516 }
517 $sql .= $db->order($sortfield, $sortorder);
518 }
519 // Count total nb of records
520 $nbtotalofrecords = '';
521 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
522 $result = $db->query($sql);
523 $nbtotalofrecords = $db->num_rows($result);
524 if (($page * $limit) > (int) $nbtotalofrecords) {
525 // if total resultset is smaller then paging size (filtering), goto and load page 0
526 $page = 0;
527 $offset = 0;
528 }
529 }
530
531 $sql .= $db->plimit($limit + 1, $offset);
532
533 $result = $db->query($sql);
534
535 if ($result) {
536 $num = $db->num_rows($result);
537 $i = 0;
538
539 $urladd = "&id=".urlencode((string) ($id));
540 if ($limit > 0 && $limit != $conf->liste_limit) {
541 $urladd .= '&limit='.((int) $limit);
542 }
543
544 print '<form method="POST" action="'.$_SERVER ['PHP_SELF'].'" name="search_form">'."\n";
545 print '<input type="hidden" name="token" value="'.newToken().'"/>';
546 print '<input type="hidden" name="id" value="'.$id.'"/>';
547 print '<input type="hidden" name="socid" value="'.$socid.'"/>';
548 if (!empty($page)) {
549 print '<input type="hidden" name="page" value="'.$page.'"/>';
550 }
551 if (!empty($limit)) {
552 print '<input type="hidden" name="limit" value="'.$limit.'"/>';
553 }
554 if (!empty($sortfield)) {
555 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
556 }
557 if (!empty($sortorder)) {
558 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
559 }
560 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
561 print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
562
563 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
564 print '<table class="noborder liste centpercent">';
565 print '<tr class="liste_titre">';
566 print_liste_field_titre("LineID", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd, '', $sortfield, $sortorder);
567 print_liste_field_titre((!$salaryBonPl ? "ThirdParty" : "Employee"), $_SERVER["PHP_SELF"], "s.nom", '', $urladd, '', $sortfield, $sortorder);
568 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $urladd, 'class="right"', $sortfield, $sortorder);
570 print "</tr>\n";
571
572 $total = 0;
573
574 while ($i < min($num, $limit)) {
575 $obj = $db->fetch_object($result);
576
577 print '<tr class="oddeven">';
578
579 // Status of line
580 print "<td>";
581 print '<a class="valignmiddle" href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'&type='.$object->type.'&token='.newToken().'">';
582 print $ligne->LibStatut($obj->status, 2);
583 print '<span class="paddingleft">'.$obj->rowid.'</span>';
584 print '</a></td>';
585 if (!$salaryBonPl) {
586 $thirdparty = new Societe($db);
587 $thirdparty->fetch($obj->parentid);
588 $name = $thirdparty->getNomUrl(1);
589 } else {
590 $userSalary = new User($db);
591 $userSalary->fetch($obj->parentid);
592 $name = $userSalary->getNomUrl(-1);
593 }
594 print '<td class="tdoverflowmax150">';
595 print($name);
596 print "</td>\n";
597
598 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
599
600 print '<td class="right">';
601
602 if ($obj->status == 3) {
603 print '<span class="error">'.$langs->trans("StatusRefused").'</span>';
604 } else {
605 if ($object->status == BonPrelevement::STATUS_CREDITED) {
606 if ($obj->status == LignePrelevement::STATUS_CREDITED) {
607 if ($user->hasRight('prelevement', 'bons', 'credit')) {
608 //print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
609 print '<a href="line.php?action=rejet&type='.$object->type.'&id='.$obj->rowid.'&token='.newToken().'">'.$langs->trans("StandingOrderReject").'</a>';
610 } else {
611 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
612 }
613 }
614 } else {
615 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
616 }
617 }
618
619 print '</td></tr>';
620
621 $total += $obj->amount;
622
623 $i++;
624 }
625
626 if ($num > 0) {
627 $total = price2num($total, 'MT');
628
629 print '<tr class="liste_total">';
630 print '<td>'.$langs->trans("Total").'</td>';
631 print '<td>&nbsp;</td>';
632 print '<td class="right">';
633 if (empty($offset) && $num <= $limit) {
634 // If we have all record on same page, then the following test/warning can be done
635 if ($total != $object->amount) {
636 print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"));
637 }
638 }
639 print price($total);
640 print "</td>\n";
641 print '<td>&nbsp;</td>';
642 print "</tr>\n";
643 }
644
645 print "</table>";
646 print '</div>';
647 print '</form>';
648
649 $db->free($result);
650 } else {
652 }
653}
654
655// End of page
656llxFooter();
657$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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.