dolibarr 18.0.6
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
7 * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
8 * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36
37// Load translation files required by the page
38$langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'compta'));
39
40$id = GETPOST('id', 'int');
41$ref = GETPOST('ref', 'alpha');
42$action = GETPOST('action', 'aZ09');
43$confirm = GETPOST('confirm', 'alpha');
44
45$type = GETPOST('type');
46if (empty($type)) {
47 $type = 'CHQ';
48}
49
50$object = new RemiseCheque($db);
51
52$sortfield = GETPOST('sortfield', 'aZ09comma');
53$sortorder = GETPOST('sortorder', 'aZ09comma');
54$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
55if (!$sortorder) {
56 $sortorder = "ASC";
57}
58if (!$sortfield) {
59 $sortfield = "b.dateo,b.rowid";
60}
61if (empty($page) || $page == -1) {
62 $page = 0;
63}
64$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
65$offset = $limit * $page;
66
67$upload_dir = $conf->bank->multidir_output[$object->entity ? $object->entity : $conf->entity]."/checkdeposits";
68
69// filter by dates from / to
70$search_date_start_day = GETPOST('search_date_start_day', 'int');
71$search_date_start_month = GETPOST('search_date_start_month', 'int');
72$search_date_start_year = GETPOST('search_date_start_year', 'int');
73$search_date_end_day = GETPOST('search_date_end_day', 'int');
74$search_date_end_month = GETPOST('search_date_end_month', 'int');
75$search_date_end_year = GETPOST('search_date_end_year', 'int');
76$search_date_start = dol_mktime(0, 0, 0, $search_date_start_month, $search_date_start_day, $search_date_start_year);
77$search_date_end = dol_mktime(23, 59, 59, $search_date_end_month, $search_date_end_day, $search_date_end_year);
78$filteraccountid = GETPOST('accountid', 'int');
79
80// Security check
81$fieldname = (!empty($ref) ? 'ref' : 'rowid');
82if ($user->socid) {
83 $socid = $user->socid;
84}
85$result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque', '', 'fk_user_author', $fieldname);
86
87$usercanread = $user->rights->banque->cheque;
88$usercancreate = $user->rights->banque->cheque;
89$usercandelete = $user->rights->banque->cheque;
90
91$permissiontodelete = $user->rights->banque->cheque;
92
93// List of payment mode to support
94// Example: BANK_PAYMENT_MODES_FOR_DEPOSIT_MANAGEMENT = 'CHQ','TRA'
95$arrayofpaymentmodetomanage = explode(',', getDolGlobalString('BANK_PAYMENT_MODES_FOR_DEPOSIT_MANAGEMENT', 'CHQ'));
96
97
98/*
99 * Actions
100 */
101
102if ($action == 'setdate' && $user->rights->banque->cheque) {
103 $result = $object->fetch(GETPOST('id', 'int'));
104 if ($result > 0) {
105 $date = dol_mktime(0, 0, 0, GETPOST('datecreate_month', 'int'), GETPOST('datecreate_day', 'int'), GETPOST('datecreate_year', 'int'));
106
107 $result = $object->set_date($user, $date);
108 if ($result < 0) {
109 setEventMessages($object->error, $object->errors, 'errors');
110 }
111 } else {
112 setEventMessages($object->error, $object->errors, 'errors');
113 }
114}
115
116if ($action == 'setrefext' && $user->rights->banque->cheque) {
117 $result = $object->fetch(GETPOST('id', 'int'));
118 if ($result > 0) {
119 $ref_ext = GETPOST('ref_ext');
120
121 $result = $object->setValueFrom('ref_ext', $ref_ext, '', null, 'text', '', $user, 'CHECKDEPOSIT_MODIFY');
122 if ($result < 0) {
123 setEventMessages($object->error, $object->errors, 'errors');
124 }
125 } else {
126 setEventMessages($object->error, $object->errors, 'errors');
127 }
128}
129
130if ($action == 'setref' && $user->rights->banque->cheque) {
131 $result = $object->fetch(GETPOST('id', 'int'));
132 if ($result > 0) {
133 $ref = GETPOST('ref');
134
135 $result = $object->set_number($user, $ref);
136 if ($result < 0) {
137 setEventMessages($object->error, $object->errors, 'errors');
138 }
139 } else {
140 setEventMessages($object->error, $object->errors, 'errors');
141 }
142}
143
144if ($action == 'create' && GETPOST("accountid", "int") > 0 && $user->rights->banque->cheque) {
145 if (GETPOSTISARRAY('toRemise')) {
146 $object->type = $type;
147 $arrayofid = GETPOST('toRemise', 'array:int');
148
149 $result = $object->create($user, GETPOST("accountid", "int"), 0, $arrayofid);
150 if ($result > 0) {
151 if ($object->statut == 1) { // If statut is validated, we build doc
152 $object->fetch($object->id); // To force to reload all properties in correct property name
153 // Define output language
154 $outputlangs = $langs;
155 $newlang = '';
156 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
157 $newlang = GETPOST('lang_id', 'aZ09');
158 }
159 //if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang=$object->client->default_lang;
160 if (!empty($newlang)) {
161 $outputlangs = new Translate("", $conf);
162 $outputlangs->setDefaultLang($newlang);
163 }
164 $result = $object->generatePdf(GETPOST("model"), $outputlangs);
165 }
166
167 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
168 exit;
169 } else {
170 setEventMessages($object->error, $object->errors, 'errors');
171 }
172 } else {
173 setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'mesgs');
174 $action = 'new';
175 }
176}
177
178if ($action == 'remove' && $id > 0 && GETPOST("lineid", 'int') > 0 && $user->rights->banque->cheque) {
179 $object->id = $id;
180 $result = $object->removeCheck(GETPOST("lineid", "int"));
181 if ($result === 0) {
182 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
183 exit;
184 } else {
185 setEventMessages($object->error, $object->errors, 'errors');
186 }
187}
188
189if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->cheque) {
190 $object->id = $id;
191 $result = $object->delete();
192 if ($result == 0) {
193 header("Location: index.php");
194 exit;
195 } else {
196 setEventMessages($paiement->error, $paiement->errors, 'errors');
197 }
198}
199
200if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->banque->cheque) {
201 $result = $object->fetch($id);
202 $result = $object->validate($user);
203 if ($result >= 0) {
204 // Define output language
205 $outputlangs = $langs;
206 $newlang = '';
207 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
208 $newlang = GETPOST('lang_id', 'aZ09');
209 }
210 //if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang=$object->client->default_lang;
211 if (!empty($newlang)) {
212 $outputlangs = new Translate("", $conf);
213 $outputlangs->setDefaultLang($newlang);
214 }
215 $result = $object->generatePdf(GETPOST('model'), $outputlangs);
216
217 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
218 exit;
219 } else {
220 setEventMessages($object->error, $object->errors, 'errors');
221 }
222}
223
224if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->banque->cheque) {
225 $reject_date = dol_mktime(0, 0, 0, GETPOST('rejectdate_month'), GETPOST('rejectdate_day'), GETPOST('rejectdate_year'));
226 $rejected_check = GETPOST('bankid', 'int');
227
228 $object->fetch($id);
229 $paiement_id = $object->rejectCheck($rejected_check, $reject_date);
230 if ($paiement_id > 0) {
231 setEventMessages($langs->trans("CheckRejectedAndInvoicesReopened"), null, 'mesgs');
232 //header("Location: ".DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id);
233 //exit;
234 $action = '';
235 } else {
236 setEventMessages($object->error, $object->errors, 'errors');
237 $action = '';
238 }
239}
240
241if ($action == 'builddoc' && $user->rights->banque->cheque) {
242 $result = $object->fetch($id);
243
244 // Save last template used to generate document
245 //if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
246
247 $outputlangs = $langs;
248 $newlang = '';
249 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
250 $newlang = GETPOST('lang_id', 'aZ09');
251 }
252 //if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang=$object->client->default_lang;
253 if (!empty($newlang)) {
254 $outputlangs = new Translate("", $conf);
255 $outputlangs->setDefaultLang($newlang);
256 }
257 $result = $object->generatePdf(GETPOST("model"), $outputlangs);
258 if ($result <= 0) {
259 dol_print_error($db, $object->error);
260 exit;
261 } else {
262 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
263 exit;
264 }
265} elseif ($action == 'remove_file' && $user->rights->banque->cheque) {
266 // Remove file in doc form
267 if ($object->fetch($id) > 0) {
268 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
269
270 $langs->load("other");
271
272 $filetodelete = GETPOST('file', 'alpha');
273 $file = $upload_dir.'/'.$filetodelete;
274
275 $ret = dol_delete_file($file, 0, 0, 0, $object);
276 if ($ret) {
277 setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
278 } else {
279 setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
280 }
281 }
282}
283
284
285/*
286 * View
287 */
288
289if (GETPOST('removefilter')) {
290 // filter by dates from / to
291 $search_date_start_day = '';
292 $search_date_start_month = '';
293 $search_date_start_year = '';
294 $search_date_end_day = '';
295 $search_date_end_month = '';
296 $search_date_end_year = '';
297 $search_date_start = '';
298 $search_date_end = '';
299 $filteraccountid = 0;
300}
301
302if ($action == 'new') {
303 $title = $langs->trans("NewChequeDeposit");
304} else {
305 if ($type == 'CHQ') {
306 $title = $langs->trans("Cheques");
307 } else {
308 $title = ($langs->trans("PaymentType".$type) != "PaymentType".$type ? $langs->trans("PaymentType".$type) : $langs->trans("PaymentMode").' '.$type);
309 }
310}
311
312$helpurl = "";
313llxHeader("", $title, $helpurl);
314
315$form = new Form($db);
316$formfile = new FormFile($db);
317
318
319if ($action == 'new') {
320 $head = array();
321 $h = 0;
322 $head[$h][0] = $_SERVER["PHP_SELF"].'?action=new';
323 $head[$h][1] = $langs->trans("MenuChequeDeposits");
324 $hselected = $h;
325 $h++;
326
327 print load_fiche_titre($title, '', 'bank_account');
328} else {
329 $result = $object->fetch($id, $ref);
330 if ($result < 0) {
331 dol_print_error($db, $object->error);
332 exit;
333 }
334
335 $h = 0;
336 $head[$h][0] = $_SERVER["PHP_SELF"].'?id='.$object->id;
337 $head[$h][1] = $langs->trans("CheckReceipt");
338 $hselected = $h;
339 $h++;
340 // $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/cheque/info.php?id='.$object->id;
341 // $head[$h][1] = $langs->trans("Info");
342 // $h++;
343
344 print dol_get_fiche_head($head, $hselected, $langs->trans("Cheques"), -1, 'payment');
345
346 /*
347 * Confirmation of slip's delete
348 */
349 if ($action == 'delete') {
350 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteCheckReceipt"), $langs->trans("ConfirmDeleteCheckReceipt"), 'confirm_delete', '', '', 1);
351 }
352
353 /*
354 * Confirmation of slip's validation
355 */
356 if ($action == 'valide') {
357 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_validate', '', '', 1);
358 }
359
360 /*
361 * Confirm check rejection
362 */
363 if ($action == 'reject_check') {
364 $formquestion = array(
365 array('type' => 'hidden', 'name' => 'bankid', 'value' => GETPOST('lineid', 'int')),
366 array('type' => 'date', 'name' => 'rejectdate_', 'label' => $langs->trans("RejectCheckDate"), 'value' => dol_now())
367 );
368 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("RejectCheck"), $langs->trans("ConfirmRejectCheck"), 'confirm_reject_check', $formquestion, '', 1);
369 }
370}
371
372$accounts = array();
373
374if ($action == 'new') {
375 $paymentstatic = new Paiement($db);
376 $accountlinestatic = new AccountLine($db);
377
378 $lines = array();
379
380 $now = dol_now();
381
382 $labeltype = ($langs->trans("PaymentType".$type) != "PaymentType".$type ? $langs->trans("PaymentType".$type) : $type);
383 if ($type == 'CHQ') {
384 print '<span class="opacitymedium">'.$langs->trans("SelectChequeTransactionAndGenerate").'</span><br><br>'."\n";
385 } else {
386 print '<span class="opacitymedium">'.$langs->trans("SelectPaymentTransactionAndGenerate", $labeltype).'</span><br><br>'."\n";
387 }
388
389 print '<form class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
390 print '<input type="hidden" name="token" value="'.newToken().'">';
391 print '<input type="hidden" name="action" value="new">';
392
393 print dol_get_fiche_head();
394
395 print '<table class="border centpercent">';
396
397 if (count($arrayofpaymentmodetomanage) > 1) {
398 $arrayoflabels = array();
399 foreach ($arrayofpaymentmodetomanage as $key => $val) {
400 $labelval = ($langs->trans("PaymentType".$val) != "PaymentType".$val ? $langs->trans("PaymentType".$val) : $val);
401 $arrayoflabels[$key] = $labelval;
402 }
403 // Type
404 print '<tr><td>';
405 print $langs->trans("Type");
406 print '</td><td>';
407 print $form->selectarray('type', $arrayoflabels, $type);
408 print '</td></tr>';
409 }
410 // Date
411 print '<tr><td class="titlefieldcreate">';
412 if ($type == 'CHQ') {
413 print $langs->trans("DateChequeReceived");
414 } else {
415 print $langs->trans("DatePaymentReceived");
416 }
417 print '</td><td>';
418 // filter by dates from / to
419 print '<div class="nowrap">';
420 print $form->selectDate($search_date_start, 'search_date_start_', 0, 0, 1, '', 1, 1, 0, '', '', '', '', 1, '', $langs->trans('From'));
421 print '</div>';
422 print '<div class="nowrap">';
423 print $form->selectDate($search_date_end, 'search_date_end_', 0, 0, 1, '', 1, 1, 0, '', '', '', '', 1, '', $langs->trans('to'));
424 print '</div>';
425 print '</td></tr>';
426 print '<tr><td>'.$langs->trans("BankAccount").'</td><td>';
427 $form->select_comptes($filteraccountid, 'accountid', 0, 'courant <> 2', 1);
428 print '</td></tr>';
429 print '</table>';
430
431 print dol_get_fiche_end();
432
433 print '<div class="center">';
434 print '<input type="submit" class="button small" name="filter" value="'.dol_escape_htmltag($langs->trans("ToFilter")).'">';
435 if ($search_date_start || $search_date_end || $filteraccountid > 0) {
436 print ' &nbsp; ';
437 print '<input type="submit" class="button" name="removefilter small" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
438 }
439 print '</div>';
440 print '</form>';
441 print '<br>';
442 print '<br>';
443
444 $sql = "SELECT ba.rowid as bid, ba.label,";
445 $sql .= " b.rowid as transactionid, b.label as transactionlabel, b.datec as datec, b.dateo as date, ";
446 $sql .= " b.amount, b.emetteur, b.num_chq, b.banque,";
447 $sql .= " p.rowid as paymentid, p.ref as paymentref";
448 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
449 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
450 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (b.fk_account = ba.rowid)";
451 $sql .= " WHERE b.fk_type = '".$db->escape($type)."'";
452 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
453 $sql .= " AND b.fk_bordereau = 0";
454 $sql .= " AND b.amount > 0";
455 if ($search_date_start) {
456 $sql .= " AND b.dateo >= '".$db->idate($search_date_start)."'";
457 }
458 if ($search_date_end) {
459 $sql .= " AND b.dateo <= '".$db->idate($search_date_end)."'";
460 }
461 if ($filteraccountid > 0) {
462 $sql .= " AND ba.rowid = ".((int) $filteraccountid);
463 }
464 $sql .= $db->order("b.dateo,b.rowid", "ASC");
465
466 $resql = $db->query($sql);
467 if ($resql) {
468 $i = 0;
469 while ($obj = $db->fetch_object($resql)) {
470 $accounts[$obj->bid] = $obj->label;
471 $lines[$obj->bid][$i]["date"] = $db->jdate($obj->datec);
472 $lines[$obj->bid][$i]["amount"] = $obj->amount;
473 $lines[$obj->bid][$i]["emetteur"] = $obj->emetteur;
474 $lines[$obj->bid][$i]["numero"] = $obj->num_chq;
475 $lines[$obj->bid][$i]["banque"] = $obj->banque;
476 $lines[$obj->bid][$i]["id"] = $obj->transactionid;
477 $lines[$obj->bid][$i]["ref"] = $obj->transactionid;
478 $lines[$obj->bid][$i]["label"] = $obj->transactionlabel;
479 $lines[$obj->bid][$i]["paymentid"] = $obj->paymentid;
480 $lines[$obj->bid][$i]["paymentref"] = $obj->paymentref;
481 $lines[$obj->bid][$i]["paymentdate"] = $db->jdate($obj->date);
482 $i++;
483 }
484
485 if ($i == 0) {
486 if ($type == 'CHQ') {
487 print '<div class="opacitymedium">'.$langs->trans("NoWaitingChecks").'</div><br>';
488 } else {
489 print '<div class="opacitymedium">'.$langs->trans("NoWaitingPaymentForDeposit", $labeltype).'</div><br>';
490 }
491 }
492 }
493
494 foreach ($accounts as $bid => $account_label) {
495 print '
496 <script type="text/javascript">
497 jQuery(document).ready(function()
498 {
499 jQuery("#checkall_'.$bid.'").click(function()
500 {
501 jQuery(".checkforremise_'.$bid.'").prop(\'checked\', true);
502 });
503 jQuery("#checknone_'.$bid.'").click(function()
504 {
505 jQuery(".checkforremise_'.$bid.'").prop(\'checked\', false);
506 });
507 });
508 </script>
509 ';
510
511 $num = $db->num_rows($resql);
512
513 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
514 print '<input type="hidden" name="token" value="'.newToken().'">';
515 print '<input type="hidden" name="action" value="create">';
516 print '<input type="hidden" name="type" value="'.$type.'">';
517 print '<input type="hidden" name="accountid" value="'.$bid.'">';
518
519 $moreforfilter = '';
520 print '<div class="div-table-responsive-no-min">';
521 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
522
523 print '<tr class="liste_titre">';
524 print '<td>';
525 if ($type == 'CHQ') {
526 print $langs->trans("DateChequeReceived");
527 } else {
528 print $langs->trans("DatePaymentForDepositReceived", $type);
529 }
530 print '</td>'."\n";
531 print '<td>'.$langs->trans("ChequeNumber")."</td>\n";
532 print '<td>'.$langs->trans("CheckTransmitter")."</td>\n";
533 print '<td>'.$langs->trans("Bank")."</td>\n";
534 print '<td class="right">'.$langs->trans("Amount")."</td>\n";
535 print '<td class="center">'.$langs->trans("Payment")."</td>\n";
536 print '<td class="center">'.$langs->trans("LineRecord")."</td>\n";
537 print '<td class="center">'.$langs->trans("Select")."<br>";
538 if ($conf->use_javascript_ajax) {
539 print '<a href="#" id="checkall_'.$bid.'">'.$langs->trans("All").'</a> / <a href="#" id="checknone_'.$bid.'">'.$langs->trans("None").'</a>';
540 }
541 print '</td>';
542 print "</tr>\n";
543
544 if (count($lines[$bid])) {
545 foreach ($lines[$bid] as $lid => $value) {
546 print '<tr class="oddeven">';
547 print '<td>'.dol_print_date($value["date"], 'day').'</td>';
548 print '<td>'.$value["numero"]."</td>\n";
549 print '<td>'.$value["emetteur"]."</td>\n";
550 print '<td>'.$value["banque"]."</td>\n";
551 print '<td class="right"><span class="amount">'.price($value["amount"], 0, $langs, 1, -1, -1, $conf->currency).'</span></td>';
552
553 // Link to payment
554 print '<td class="center">';
555 $paymentstatic->id = $value["paymentid"];
556 $paymentstatic->ref = $value["paymentref"];
557 $paymentstatic->date = $value["paymentdate"];
558 if ($paymentstatic->id) {
559 print $paymentstatic->getNomUrl(1);
560 } else {
561 print '&nbsp;';
562 }
563 print '</td>';
564 // Link to bank transaction
565 print '<td class="center">';
566 $accountlinestatic->id = $value["id"];
567 $accountlinestatic->ref = $value["ref"];
568 if ($accountlinestatic->id > 0) {
569 print $accountlinestatic->getNomUrl(1);
570 } else {
571 print '&nbsp;';
572 }
573 print '</td>';
574
575 print '<td class="center">';
576 print '<input id="'.$value["id"].'" class="flat checkforremise_'.$bid.'" checked type="checkbox" name="toRemise[]" value="'.$value["id"].'">';
577 print '</td>';
578 print '</tr>';
579 }
580 }
581 print "</table>";
582 print '</div>';
583
584 print '<div class="tabsAction">';
585 if ($user->rights->banque->cheque) {
586 print '<input type="submit" class="button" value="'.$langs->trans('NewCheckDepositOn', $account_label).'">';
587 } else {
588 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('NewCheckDepositOn', $account_label).'</a>';
589 }
590 print '</div><br>';
591 print '</form>';
592 }
593} else {
594 $paymentstatic = new Paiement($db);
595 $accountlinestatic = new AccountLine($db);
596 $accountstatic = new Account($db);
597 $accountstatic->fetch($object->account_id);
598
599 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/paiement/cheque/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
600
601 $morehtmlref = '';
602 $morehtmlleft = '';
603 $moreghtmlright = '';
604
605 $labelval = ($langs->trans("PaymentType".$object->type) != "PaymentType".$object->type ? $langs->trans("PaymentType".$object->type) : $object->type);
606 $morehtmlref = '<br><div class="refidno">'.$langs->trans("Type").' : '.$labelval.'</div>';
607
608 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, $morehtmlleft, '', 0, $moreghtmlright);
609
610
611 print '<div class="fichecenter">';
612 print '<div class="underbanner clearboth"></div>';
613
614 print '<table class="border centpercent">';
615
616 print '<tr><td class="titlefield">';
617
618 print '<table class="nobordernopadding centpercent"><tr><td>';
619 print $langs->trans('Date');
620 print '</td>';
621 if ($action != 'editdate') {
622 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
623 }
624 print '</tr></table>';
625
626 print '</td><td>';
627 if ($action == 'editdate') {
628 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
629 print '<input type="hidden" name="token" value="'.newToken().'">';
630 print '<input type="hidden" name="action" value="setdate">';
631 print $form->selectDate($object->date_bordereau, 'datecreate_', '', '', '', "setdate");
632 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
633 print '</form>';
634 } else {
635 print $object->date_bordereau ? dol_print_date($object->date_bordereau, 'day') : '&nbsp;';
636 }
637
638 print '</td>';
639 print '</tr>';
640
641 // External ref - Ext ref are not visible field on standard usage
642 if (getDolGlobalString('MAIN_SHOW_EXTREF')) {
643 print '<tr><td>';
644 print '<table class="nobordernopadding" width="100%"><tr><td>';
645 print $langs->trans('RefExt');
646 print '</td>';
647 if ($action != 'editrefext') {
648 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrefext&token='.newToken().'&id='.((int) $object->id).'">'.img_edit($langs->trans('SetRefExt'), 1).'</a></td>';
649 }
650 print '</tr></table>';
651 print '</td><td>';
652 if ($action == 'editrefext') {
653 print '<form name="setrefext" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
654 print '<input type="hidden" name="token" value="'.newToken().'">';
655 print '<input type="hidden" name="action" value="setrefext">';
656 print '<input type="text" name="ref_ext" value="'.$object->ref_ext.'">';
657 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
658 print '</form>';
659 } else {
660 print $object->ref_ext;
661 }
662 print '</td></tr>';
663 }
664
665 print '<tr><td>'.$langs->trans('Account').'</td><td>';
666 print $accountstatic->getNomUrl(1);
667 print '</td></tr>';
668
669 // Number of bank checks
670 print '<tr><td>'.$langs->trans('NbOfCheques').'</td><td>';
671 print $object->nbcheque;
672 print '</td></tr>';
673
674 print '<tr><td>'.$langs->trans('Total').'</td><td>';
675 print '<span class="amount">'.price($object->amount).'</span>';
676 print '</td></tr>';
677
678 print '</table><br>';
679
680 print '</div>';
681
682
683 // List of bank checks
684 $sql = "SELECT b.rowid, b.rowid as ref, b.label, b.amount, b.num_chq, b.emetteur,";
685 $sql .= " b.dateo as date, b.datec as datec, b.banque,";
686 $sql .= " p.rowid as pid, p.ref as pref, ba.rowid as bid, p.statut";
687 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
688 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)";
689 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
690 $sql .= " WHERE ba.entity IN (".getEntity('bank_account').")";
691 $sql .= " AND b.fk_type= '".$db->escape($object->type)."'";
692 $sql .= " AND b.fk_bordereau = ".((int) $object->id);
693 $sql .= $db->order($sortfield, $sortorder);
694
695 $resql = $db->query($sql);
696 if ($resql) {
697 $num = $db->num_rows($resql);
698
699 print '<div class="div-table-responsive">';
700 print '<table class="noborder centpercent">';
701
702 $param = "&amp;id=".$object->id;
703
704 print '<tr class="liste_titre">';
705 print_liste_field_titre("Cheques", '', '', '', '', 'width="30"');
706 print_liste_field_titre("DateChequeReceived", $_SERVER["PHP_SELF"], "b.dateo,b.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
707 print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "b.num_chq", "", $param, 'align="center"', $sortfield, $sortorder);
708 print_liste_field_titre("CheckTransmitter", $_SERVER["PHP_SELF"], "b.emetteur", "", $param, "", $sortfield, $sortorder);
709 print_liste_field_titre("Bank", $_SERVER["PHP_SELF"], "b.banque", "", $param, "", $sortfield, $sortorder);
710 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "b.amount", "", $param, 'class="right"', $sortfield, $sortorder);
711 print_liste_field_titre("Payment", $_SERVER["PHP_SELF"], "p.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
712 print_liste_field_titre("LineRecord", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
714 print "</tr>\n";
715
716 $i = 1;
717 if ($num > 0) {
718 while ($objp = $db->fetch_object($resql)) {
719 $paymentstatic->id = $objp->pid;
720 $paymentstatic->ref = $objp->pref;
721
722 $accountlinestatic->id = $objp->rowid;
723 $accountlinestatic->ref = $objp->ref;
724
725 print '<tr class="oddeven">';
726 print '<td class="center">'.$i.'</td>';
727 print '<td class="center">'.dol_print_date($db->jdate($objp->date), 'day').'</td>'; // Operation date
728 print '<td class="center">'.($objp->num_chq ? $objp->num_chq : '&nbsp;').'</td>';
729 print '<td>'.dol_trunc($objp->emetteur, 24).'</td>';
730 print '<td>'.dol_trunc($objp->banque, 24).'</td>';
731 print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
732 // Link to payment
733 print '<td class="center">';
734 if ($paymentstatic->id) {
735 print $paymentstatic->getNomUrl(1);
736 } else {
737 print '&nbsp;';
738 }
739 print '</td>';
740 // Link to bank transaction
741 print '<td class="center">';
742 if ($accountlinestatic->id > 0) {
743 print $accountlinestatic->getNomUrl(1);
744 } else {
745 print '&nbsp;';
746 }
747 print '</td>';
748 // Action button
749 print '<td class="right">';
750 if ($object->statut == 0) {
751 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&token='.newToken().'&lineid='.$objp->rowid.'">'.img_delete().'</a>';
752 }
753 if ($object->statut == 1 && $objp->statut != 2) {
754 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reject_check&token='.newToken().'&lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"), 'disable').'</a>';
755 }
756 if ($objp->statut == 2) {
757 print ' &nbsp; '.img_picto($langs->trans('CheckRejected'), 'statut8').'</a>';
758 }
759 print '</td>';
760 print '</tr>';
761
762 $i++;
763 }
764 } else {
765 print '<td colspan="9"><span class="opacitymedium">';
766 print $langs->trans("None");
767 print '</span></td>';
768 }
769
770 print "</table>";
771
772 // Cheque denormalized data nbcheque is similar to real number of bank check
773 if ($num > 0 && $i < ($object->nbcheque + 1)) {
774 // Show warning that some records were removed.
775 $langs->load("errors");
776 print info_admin($langs->trans("WarningSomeBankTransactionByChequeWereRemovedAfter"), 0, 0, 'warning');
777 // TODO Fix data ->nbcheque and ->amount
778 }
779
780 print "</div>";
781 } else {
782 dol_print_error($db);
783 }
784
785 print dol_get_fiche_end();
786}
787
788
789
790
791/*
792 * Actions Buttons
793 */
794
795print '<div class="tabsAction">';
796
797if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) {
798 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valide&token='.newToken().'&sortfield='.$sortfield.'&sortorder='.$sortorder.'">'.$langs->trans('Validate').'</a>';
799}
800
801if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) {
802 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
803}
804print '</div>';
805
806
807
808if ($action != 'new') {
809 if ($object->statut == 1) {
810 // Documents
811 $objref = dol_sanitizeFileName($object->ref);
812 $filedir = $upload_dir.'/'.$objref;
813 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
814 $genallowed = $usercancreate;
815 $delallowed = $usercandelete;
816 print $formfile->showdocuments('remisecheque', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
817
818 print '<br>';
819 }
820}
821
822// End of page
823llxFooter();
824$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of customer invoices.
Class to manage cheque delivery receipts.
Class to manage translations.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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.