dolibarr  x.y.z
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  print '<tr class="oddeven">';
489  print '<td>'.dol_print_date($value["date"], 'day').'</td>';
490  print '<td>'.$value["numero"]."</td>\n";
491  print '<td>'.$value["emetteur"]."</td>\n";
492  print '<td>'.$value["banque"]."</td>\n";
493  print '<td class="right"><span class="amount">'.price($value["amount"], 0, $langs, 1, -1, -1, $conf->currency).'</span></td>';
494 
495  // Link to payment
496  print '<td class="center">';
497  $paymentstatic->id = $value["paymentid"];
498  $paymentstatic->ref = $value["paymentref"];
499  $paymentstatic->date = $value["paymentdate"];
500  if ($paymentstatic->id) {
501  print $paymentstatic->getNomUrl(1);
502  } else {
503  print '&nbsp;';
504  }
505  print '</td>';
506  // Link to bank transaction
507  print '<td class="center">';
508  $accountlinestatic->id = $value["id"];
509  $accountlinestatic->ref = $value["ref"];
510  if ($accountlinestatic->id > 0) {
511  print $accountlinestatic->getNomUrl(1);
512  } else {
513  print '&nbsp;';
514  }
515  print '</td>';
516 
517  print '<td class="center">';
518  print '<input id="'.$value["id"].'" class="flat checkforremise_'.$bid.'" checked type="checkbox" name="toRemise[]" value="'.$value["id"].'">';
519  print '</td>';
520  print '</tr>';
521  }
522  }
523  print "</table>";
524  print '</div>';
525 
526  print '<div class="tabsAction">';
527  if ($user->rights->banque->cheque) {
528  print '<input type="submit" class="button" value="'.$langs->trans('NewCheckDepositOn', $account_label).'">';
529  } else {
530  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('NewCheckDepositOn', $account_label).'</a>';
531  }
532  print '</div><br>';
533  print '</form>';
534  }
535 } else {
536  $paymentstatic = new Paiement($db);
537  $accountlinestatic = new AccountLine($db);
538  $accountstatic = new Account($db);
539  $accountstatic->fetch($object->account_id);
540 
541  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/paiement/cheque/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
542 
543  $morehtmlref = '';
544  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
545 
546 
547  print '<div class="fichecenter">';
548  print '<div class="underbanner clearboth"></div>';
549 
550 
551  print '<table class="border centpercent">';
552 
553  print '<tr><td class="titlefield">';
554 
555  print '<table class="nobordernopadding" width="100%"><tr><td>';
556  print $langs->trans('Date');
557  print '</td>';
558  if ($action != 'editdate') {
559  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>';
560  }
561  print '</tr></table>';
562  print '</td><td colspan="2">';
563  if ($action == 'editdate') {
564  print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
565  print '<input type="hidden" name="token" value="'.newToken().'">';
566  print '<input type="hidden" name="action" value="setdate">';
567  print $form->selectDate($object->date_bordereau, 'datecreate_', '', '', '', "setdate");
568  print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
569  print '</form>';
570  } else {
571  print $object->date_bordereau ? dol_print_date($object->date_bordereau, 'day') : '&nbsp;';
572  }
573 
574  print '</td>';
575  print '</tr>';
576 
577  // External ref
578  /* Ext ref are not visible field on standard usage
579  print '<tr><td>';
580 
581  print '<table class="nobordernopadding" width="100%"><tr><td>';
582  print $langs->trans('RefExt');
583  print '</td>';
584  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>';
585  print '</tr></table>';
586  print '</td><td colspan="2">';
587  if ($action == 'editrefext')
588  {
589  print '<form name="setrefext" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
590  print '<input type="hidden" name="token" value="'.newToken().'">';
591  print '<input type="hidden" name="action" value="setrefext">';
592  print '<input type="text" name="ref_ext" value="'.$object->ref_ext.'">';
593  print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
594  print '</form>';
595  }
596  else
597  {
598  print $object->ref_ext;
599  }
600 
601  print '</td>';
602  print '</tr>';
603  */
604 
605  print '<tr><td>'.$langs->trans('Account').'</td><td colspan="2">';
606  print $accountstatic->getNomUrl(1);
607  print '</td></tr>';
608 
609  // Number of bank checks
610  print '<tr><td>'.$langs->trans('NbOfCheques').'</td><td colspan="2">';
611  print $object->nbcheque;
612  print '</td></tr>';
613 
614  print '<tr><td>'.$langs->trans('Total').'</td><td colspan="2">';
615  print price($object->amount);
616  print '</td></tr>';
617 
618  /*print '<tr><td>'.$langs->trans('Status').'</td><td colspan="2">';
619  print $object->getLibStatut(4);
620  print '</td></tr>';*/
621 
622  print '</table><br>';
623 
624  print '</div>';
625 
626 
627  // List of bank checks
628  $sql = "SELECT b.rowid, b.rowid as ref, b.label, b.amount, b.num_chq, b.emetteur,";
629  $sql .= " b.dateo as date, b.datec as datec, b.banque,";
630  $sql .= " p.rowid as pid, p.ref as pref, ba.rowid as bid, p.statut";
631  $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
632  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)";
633  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
634  $sql .= " WHERE ba.entity IN (".getEntity('bank_account').")";
635  $sql .= " AND b.fk_type= 'CHQ'";
636  $sql .= " AND b.fk_bordereau = ".((int) $object->id);
637  $sql .= $db->order($sortfield, $sortorder);
638 
639  $resql = $db->query($sql);
640  if ($resql) {
641  $num = $db->num_rows($resql);
642 
643  print '<div class="div-table-responsive">';
644  print '<table class="noborder centpercent">';
645 
646  $param = "&amp;id=".$object->id;
647 
648  print '<tr class="liste_titre">';
649  print_liste_field_titre("Cheques", '', '', '', '', 'width="30"');
650  print_liste_field_titre("DateChequeReceived", $_SERVER["PHP_SELF"], "b.dateo,b.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
651  print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "b.num_chq", "", $param, 'align="center"', $sortfield, $sortorder);
652  print_liste_field_titre("CheckTransmitter", $_SERVER["PHP_SELF"], "b.emetteur", "", $param, "", $sortfield, $sortorder);
653  print_liste_field_titre("Bank", $_SERVER["PHP_SELF"], "b.banque", "", $param, "", $sortfield, $sortorder);
654  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "b.amount", "", $param, 'class="right"', $sortfield, $sortorder);
655  print_liste_field_titre("Payment", $_SERVER["PHP_SELF"], "p.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
656  print_liste_field_titre("LineRecord", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
658  print "</tr>\n";
659 
660  $i = 1;
661  if ($num > 0) {
662  while ($objp = $db->fetch_object($resql)) {
663  $paymentstatic->id = $objp->pid;
664  $paymentstatic->ref = $objp->pref;
665 
666  $accountlinestatic->id = $objp->rowid;
667  $accountlinestatic->ref = $objp->ref;
668 
669  print '<tr class="oddeven">';
670  print '<td class="center">'.$i.'</td>';
671  print '<td class="center">'.dol_print_date($db->jdate($objp->date), 'day').'</td>'; // Operation date
672  print '<td class="center">'.($objp->num_chq ? $objp->num_chq : '&nbsp;').'</td>';
673  print '<td>'.dol_trunc($objp->emetteur, 24).'</td>';
674  print '<td>'.dol_trunc($objp->banque, 24).'</td>';
675  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
676  // Link to payment
677  print '<td class="center">';
678  if ($paymentstatic->id) {
679  print $paymentstatic->getNomUrl(1);
680  } else {
681  print '&nbsp;';
682  }
683  print '</td>';
684  // Link to bank transaction
685  print '<td class="center">';
686  if ($accountlinestatic->id > 0) {
687  print $accountlinestatic->getNomUrl(1);
688  } else {
689  print '&nbsp;';
690  }
691  print '</td>';
692  // Action button
693  print '<td class="right">';
694  if ($object->statut == 0) {
695  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&token='.newToken().'&lineid='.$objp->rowid.'">'.img_delete().'</a>';
696  }
697  if ($object->statut == 1 && $objp->statut != 2) {
698  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reject_check&token='.newToken().'&lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"), 'disable').'</a>';
699  }
700  if ($objp->statut == 2) {
701  print ' &nbsp; '.img_picto($langs->trans('CheckRejected'), 'statut8').'</a>';
702  }
703  print '</td>';
704  print '</tr>';
705 
706  $i++;
707  }
708  } else {
709  print '<td colspan="8" class="opacitymedium">';
710  print $langs->trans("None");
711  print '</td>';
712  }
713 
714  print "</table>";
715 
716  // Cheque denormalized data nbcheque is similar to real number of bank check
717  if ($num > 0 && $i < ($object->nbcheque + 1)) {
718  // Show warning that some records were removed.
719  $langs->load("errors");
720  print info_admin($langs->trans("WarningSomeBankTransactionByChequeWereRemovedAfter"), 0, 0, 'warning');
721  // TODO Fix data ->nbcheque and ->amount
722  }
723 
724  print "</div>";
725  } else {
726  dol_print_error($db);
727  }
728 
729  print dol_get_fiche_end();
730 }
731 
732 
733 
734 
735 /*
736  * Actions Buttons
737  */
738 
739 print '<div class="tabsAction">';
740 
741 if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) {
742  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valide&token='.newToken().'&sortfield='.$sortfield.'&sortorder='.$sortorder.'">'.$langs->trans('Validate').'</a>';
743 }
744 
745 if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) {
746  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
747 }
748 print '</div>';
749 
750 
751 
752 if ($action != 'new') {
753  if ($object->statut == 1) {
754  // Documents
755  $objref = dol_sanitizeFileName($object->ref);
756  $filedir = $upload_dir.'/'.$objref;
757  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
758  $genallowed = $usercancreate;
759  $delallowed = $usercandelete;
760  print $formfile->showdocuments('remisecheque', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
761 
762  print '<br>';
763  }
764 }
765 
766 // End of page
767 llxFooter();
768 $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.
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
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:1250
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.