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