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