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