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