dolibarr  13.0.2
bankentries_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Vinícius Nogueira <viniciusvgn@gmail.com>
6  * Copyright (C) 2014 Florian Henry <florian.henry@open-cooncept.pro>
7  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8  * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2017-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
10  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
11  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
41 
42 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
52 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
53 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
54 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
55 
56 // Load translation files required by the page
57 $langs->loadLangs(array("banks", "bills", "categories", "companies", "margins", "salaries", "loan", "donations", "trips", "members", "compta", "accountancy"));
58 
59 $id = GETPOST('id', 'int');
60 $ref = GETPOST('ref', 'alpha');
61 $action = GETPOST('action', 'aZ09');
62 $cancel = GETPOST('cancel', 'alpha');
63 $confirm = GETPOST('confirm', 'alpha');
64 $contextpage = 'banktransactionlist'.(empty($object->ref) ? '' : '-'.$object->id);
65 
66 // Security check
67 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
68 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
69 if ($fielvalue)
70 {
71  if ($user->socid) $socid = $user->socid;
72  $result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account&bank_account', '', '', $fieldtype);
73 } else {
74  if ($user->socid) $socid = $user->socid;
75  $result = restrictedArea($user, 'banque');
76 }
77 
78 $dateop = dol_mktime(12, 0, 0, GETPOST("opmonth", 'int'), GETPOST("opday", 'int'), GETPOST("opyear", 'int'));
79 $search_debit = GETPOST("search_debit", 'alpha');
80 $search_credit = GETPOST("search_credit", 'alpha');
81 $search_type = GETPOST("search_type", 'alpha');
82 $search_account = GETPOST("search_account", 'int') ?GETPOST("search_account", 'int') : GETPOST("account", 'int');
83 $search_accountancy_code = GETPOST('search_accountancy_code', 'alpha') ?GETPOST('search_accountancy_code', 'alpha') : GETPOST('accountancy_code', 'alpha');
84 $search_bid = GETPOST("search_bid", "int") ?GETPOST("search_bid", "int") : GETPOST("bid", "int");
85 $search_ref = GETPOST('search_ref', 'alpha');
86 $search_description = GETPOST("search_description", 'alpha');
87 $search_dt_start = dol_mktime(0, 0, 0, GETPOST('search_start_dtmonth', 'int'), GETPOST('search_start_dtday', 'int'), GETPOST('search_start_dtyear', 'int'));
88 $search_dt_end = dol_mktime(0, 0, 0, GETPOST('search_end_dtmonth', 'int'), GETPOST('search_end_dtday', 'int'), GETPOST('search_end_dtyear', 'int'));
89 $search_dv_start = dol_mktime(0, 0, 0, GETPOST('search_start_dvmonth', 'int'), GETPOST('search_start_dvday', 'int'), GETPOST('search_start_dvyear', 'int'));
90 $search_dv_end = dol_mktime(0, 0, 0, GETPOST('search_end_dvmonth', 'int'), GETPOST('search_end_dvday', 'int'), GETPOST('search_end_dvyear', 'int'));
91 $search_thirdparty = GETPOST("search_thirdparty", 'alpha') ?GETPOST("search_thirdparty", 'alpha') : GETPOST("thirdparty", 'alpha');
92 $search_req_nb = GETPOST("req_nb", 'alpha');
93 $search_num_releve = GETPOST("search_num_releve", 'alpha');
94 $search_conciliated = GETPOST("search_conciliated", 'int');
95 $num_releve = GETPOST("num_releve", "alpha");
96 if (empty($dateop)) $dateop = -1;
97 
98 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
99 $sortfield = GETPOST("sortfield", 'alpha');
100 $sortorder = GETPOST("sortorder", 'alpha');
101 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
102 $pageplusone = GETPOST("pageplusone", 'int');
103 if ($pageplusone) $page = $pageplusone - 1;
104 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
105 $offset = $limit * $page;
106 $pageprev = $page - 1;
107 $pagenext = $page + 1;
108 if (!$sortorder) $sortorder = 'desc,desc,desc';
109 if (!$sortfield) $sortfield = 'b.datev,b.dateo,b.rowid';
110 
111 $object = new Account($db);
112 if ($id > 0 || !empty($ref))
113 {
114  $result = $object->fetch($id, $ref);
115  $search_account = $object->id; // Force the search field on id of account
116 
117  if (!($object->id > 0))
118  {
119  $langs->load("errors");
120  print($langs->trans('ErrorRecordNotFound'));
121  exit;
122  }
123 }
124 
125 $mode_balance_ok = false;
126 //if (($sortfield == 'b.datev' || $sortfield == 'b.datev,b.dateo,b.rowid')) // TODO Manage balance when account not selected
127 if (($sortfield == 'b.datev' || $sortfield == 'b.datev,b.dateo,b.rowid'))
128 {
129  $sortfield = 'b.datev,b.dateo,b.rowid';
130  if ($id > 0 || !empty($ref) || $search_account > 0) $mode_balance_ok = true;
131 }
132 
133 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
134 $hookmanager->initHooks(array('banktransactionlist', $contextpage));
135 $extrafields = new ExtraFields($db);
136 
137 // fetch optionals attributes and labels
138 $extrafields->fetch_name_optionals_label('banktransaction');
139 $search_array_options = $extrafields->getOptionalsFromPost('banktransaction', '', 'search_');
140 
141 $arrayfields = array(
142  'b.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
143  'b.label'=>array('label'=>$langs->trans("Description"), 'checked'=>1),
144  'b.dateo'=>array('label'=>$langs->trans("DateOperationShort"), 'checked'=>1),
145  'b.datev'=>array('label'=>$langs->trans("DateValueShort"), 'checked'=>1),
146  'type'=>array('label'=>$langs->trans("Type"), 'checked'=>1),
147  'b.num_chq'=>array('label'=>$langs->trans("Numero"), 'checked'=>1),
148  'bu.label'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>500),
149  'ba.ref'=>array('label'=>$langs->trans("BankAccount"), 'checked'=>(($id > 0 || !empty($ref)) ? 0 : 1), 'position'=>1000),
150  'b.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1, 'position'=>600),
151  'b.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1, 'position'=>605),
152  'balancebefore'=>array('label'=>$langs->trans("BalanceBefore"), 'checked'=>0, 'position'=>1000),
153  'balance'=>array('label'=>$langs->trans("Balance"), 'checked'=>1, 'position'=>1001),
154  'b.num_releve'=>array('label'=>$langs->trans("AccountStatement"), 'checked'=>1, 'position'=>1010),
155  'b.conciliated'=>array('label'=>$langs->trans("Conciliated"), 'enabled'=> $object->rappro, 'checked'=>($action == 'reconcile' ? 1 : 0), 'position'=>1020),
156 );
157 // Extra fields
158 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
159 
160 $object->fields = dol_sort_array($object->fields, 'position');
161 $arrayfields = dol_sort_array($arrayfields, 'position');
162 
163 
164 
165 /*
166  * Actions
167  */
168 
169 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
170 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
171 
172 $parameters = array();
173 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
174 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
175 
176 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
177 
178 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
179 {
180  $search_dt_start = '';
181  $search_dt_end = '';
182  $search_dv_start = '';
183  $search_dv_end = '';
184  $search_type = "";
185  $search_debit = "";
186  $search_credit = "";
187  $search_bid = "";
188  $search_ref = "";
189  $search_req_nb = '';
190  $search_description = '';
191  $search_thirdparty = '';
192  $search_num_releve = '';
193  $search_conciliated = '';
194  $thirdparty = '';
195 
196  $search_account = "";
197  if ($id > 0 || !empty($ref)) $search_account = $object->id;
198 }
199 
200 if (empty($reshook))
201 {
202  $objectclass = 'Account';
203  $objectlabel = 'BankTransaction';
204  $permissiontoread = $user->rights->banque->lire;
205  $permissiontodelete = $user->rights->banque->supprimer;
206  $uploaddir = $conf->bank->dir_output;
207  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
208 }
209 
210 // Conciliation
211 if ((GETPOST('confirm_savestatement', 'alpha') || GETPOST('confirm_reconcile', 'alpha')) && $user->rights->banque->consolidate
212  && (!GETPOSTISSET('pageplusone') || (GETPOST('pageplusone') == GETPOST('pageplusoneold'))))
213 {
214  $error = 0;
215 
216  // Definition, nettoyage parametres
217  $num_releve = GETPOST("num_releve", "alpha");
218 
219  if ($num_releve)
220  {
221  $bankline = new AccountLine($db);
222 
223  $rowids = GETPOST('rowid', 'array');
224 
225  if (!empty($rowids) && is_array($rowids)) {
226  foreach ($rowids as $row) {
227  if ($row > 0) {
228  $result = $bankline->fetch($row);
229  $bankline->num_releve = $num_releve; //$_POST["num_releve"];
230  $result = $bankline->update_conciliation($user, GETPOST("cat"), GETPOST('confirm_reconcile', 'alpha') ? 1 : 0); // If we confirm_reconcile, we set flag 'rappro' to 1.
231  if ($result < 0) {
232  setEventMessages($bankline->error, $bankline->errors, 'errors');
233  $error++;
234  break;
235  }
236  }
237  }
238  } else {
239  $error++;
240  $langs->load("errors");
241  setEventMessages($langs->trans("NoRecordSelected"), null, 'errors');
242  }
243  } else {
244  $error++;
245  $langs->load("errors");
246  setEventMessages($langs->trans("ErrorPleaseTypeBankTransactionReportName"), null, 'errors');
247  }
248 
249  if (!$error)
250  {
251  $param = 'action=reconcile&contextpage=banktransactionlist&id='.$id.'&search_account='.$id;
252  $param .= '&search_conciliated='.urlencode($search_conciliated);
253  if ($page) $param .= '&page='.urlencode($page);
254  if ($offset) $param .= '&offset='.urlencode($offset);
255  if ($search_thirdparty) $param .= '&search_thirdparty='.urlencode($search_thirdparty);
256  if ($search_num_releve) $param .= '&search_num_releve='.urlencode($search_num_releve);
257  if ($search_description) $param .= '&search_description='.urlencode($search_description);
258  if ($search_start_dt) $param .= '&search_start_dt='.urlencode($search_start_dt);
259  if ($search_end_dt) $param .= '&search_end_dt='.urlencode($search_end_dt);
260  if ($search_start_dv) $param .= '&search_start_dv='.urlencode($search_start_dv);
261  if ($search_end_dv) $param .= '&search_end_dv='.urlencode($search_end_dv);
262  if ($search_type) $param .= '&search_type='.urlencode($search_type);
263  if ($search_debit) $param .= '&search_debit='.urlencode($search_debit);
264  if ($search_credit) $param .= '&search_credit='.urlencode($search_credit);
265  $param .= '&sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder);
266  header('Location: '.$_SERVER["PHP_SELF"].'?'.$param); // To avoid to submit twice and allow the back button
267  exit;
268  }
269 }
270 
271 
272 if (GETPOST('save') && !$cancel && $user->rights->banque->modifier)
273 {
274  $error = 0;
275 
276  if (price2num(GETPOST("addcredit")) > 0)
277  {
278  $amount = price2num(GETPOST("addcredit"));
279  } else {
280  $amount = - price2num(GETPOST("adddebit"));
281  }
282 
283  $operation = GETPOST("operation", 'alpha');
284  $num_chq = GETPOST("num_chq", 'alpha');
285  $label = GETPOST("label", 'alpha');
286  $cat1 = GETPOST("cat1", 'alpha');
287 
288  $bankaccountid = $id;
289  if (GETPOST('add_account', 'int') > 0) $bankaccountid = GETPOST('add_account', 'int');
290 
291  if (!$dateop) {
292  $error++;
293  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
294  }
295  if (!$operation) {
296  $error++;
297  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
298  }
299  if (!$label) {
300  $error++;
301  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
302  }
303  if (!$amount) {
304  $error++;
305  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
306  }
307  if (!$bankaccountid > 0)
308  {
309  $error++;
310  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
311  }
312  /*if (! empty($conf->accounting->enabled) && (empty($search_accountancy_code) || $search_accountancy_code == '-1'))
313  {
314  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
315  $error++;
316  }*/
317 
318  if (!$error && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT))
319  {
320  $objecttmp = new Account($db);
321  $objecttmp->fetch($bankaccountid);
322  $insertid = $objecttmp->addline($dateop, $operation, $label, $amount, $num_chq, ($cat1 > 0 ? $cat1 : 0), $user, '', '', $search_accountancy_code);
323  if ($insertid > 0)
324  {
325  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
326  header("Location: ".$_SERVER['PHP_SELF'].($id ? "?id=".$id : ''));
327  exit;
328  } else {
329  setEventMessages($object->error, $object->errors, 'errors');
330  }
331  } else {
332  $action = 'addline';
333  }
334 }
335 
336 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->modifier)
337 {
338  $accline = new AccountLine($db);
339  $result = $accline->fetch(GETPOST("rowid", "int"));
340  $result = $accline->delete($user);
341  if ($result <= 0) {
342  setEventMessages($accline->error, $accline->errors, 'errors');
343  } else {
344  setEventMessages('RecordDeleted', null, 'mesgs');
345  }
346 }
347 
348 
349 
350 /*
351  * View
352  */
353 
354 $form = new Form($db);
355 $formother = new FormOther($db);
356 $formaccounting = new FormAccounting($db);
357 
358 $companystatic = new Societe($db);
359 $bankaccountstatic = new Account($db);
360 
361 $banktransferstatic = new BonPrelevement($db);
362 $societestatic = new Societe($db);
363 $userstatic = new User($db);
364 $chargestatic = new ChargeSociales($db);
365 $loanstatic = new Loan($db);
366 $memberstatic = new Adherent($db);
367 $donstatic = new Don($db);
368 $paymentstatic = new Paiement($db);
369 $paymentsupplierstatic = new PaiementFourn($db);
370 $paymentscstatic = new PaymentSocialContribution($db);
371 $paymentvatstatic = new TVA($db);
372 $paymentsalstatic = new PaymentSalary($db);
373 $paymentdonationstatic = new PaymentDonation($db);
374 $paymentvariousstatic = new PaymentVarious($db);
375 $paymentexpensereportstatic = new PaymentExpenseReport($db);
376 $bankstatic = new Account($db);
377 $banklinestatic = new AccountLine($db);
378 
379 $now = dol_now();
380 
381 
382 // Must be before button action
383 $param = '';
384 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
385 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
386 if ($id > 0) $param .= '&id='.urlencode($id);
387 if (!empty($ref)) $param .= '&ref='.urlencode($ref);
388 if (!empty($search_ref)) $param .= '&search_ref='.urlencode($search_ref);
389 if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description);
390 if (!empty($search_type)) $param .= '&type='.urlencode($search_type);
391 if (!empty($search_thirdparty)) $param .= '&search_thirdparty='.urlencode($search_thirdparty);
392 if (!empty($search_debit)) $param .= '&search_debit='.urlencode($search_debit);
393 if (!empty($search_credit)) $param .= '&search_credit='.urlencode($search_credit);
394 if (!empty($search_account)) $param .= '&search_account='.urlencode($search_account);
395 if (!empty($search_num_releve)) $param .= '&search_num_releve='.urlencode($search_num_releve);
396 if ($search_conciliated != '' && $search_conciliated != '-1') $param .= '&search_conciliated='.urlencode($search_conciliated);
397 if ($search_bid > 0) $param .= '&search_bid='.urlencode($search_bid);
398 if (dol_strlen($search_dt_start) > 0) $param .= '&search_start_dtmonth='.GETPOST('search_start_dtmonth', 'int').'&search_start_dtday='.GETPOST('search_start_dtday', 'int').'&search_start_dtyear='.GETPOST('search_start_dtyear', 'int');
399 if (dol_strlen($search_dt_end) > 0) $param .= '&search_end_dtmonth='.GETPOST('search_end_dtmonth', 'int').'&search_end_dtday='.GETPOST('search_end_dtday', 'int').'&search_end_dtyear='.GETPOST('search_end_dtyear', 'int');
400 if (dol_strlen($search_dv_start) > 0) $param .= '&search_start_dvmonth='.GETPOST('search_start_dvmonth', 'int').'&search_start_dvday='.GETPOST('search_start_dvday', 'int').'&search_start_dvyear='.GETPOST('search_start_dvyear', 'int');
401 if (dol_strlen($search_dv_end) > 0) $param .= '&search_end_dvmonth='.GETPOST('search_end_dvmonth', 'int').'&search_end_dvday='.GETPOST('search_end_dvday', 'int').'&search_end_dvyear='.GETPOST('search_end_dvyear', 'int');
402 if ($search_req_nb) $param .= '&req_nb='.urlencode($search_req_nb);
403 if (GETPOST("search_thirdparty", 'int')) $param .= '&thirdparty='.urlencode(GETPOST("search_thirdparty", 'int'));
404 if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
405 if ($action == 'reconcile') $param .= '&action=reconcile';
406 // Add $param from extra fields
407 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
408 
409 $options = array();
410 
411 $buttonreconcile = '';
412 $morehtmlref = '';
413 
414 if ($id > 0 || !empty($ref))
415 {
416  $title = $langs->trans("FinancialAccount").' - '.$langs->trans("Transactions");
417  $helpurl = "";
418  llxHeader('', $title, $helpurl);
419 
420  // Load bank groups
421  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
422  $bankcateg = new BankCateg($db);
423 
424  foreach ($bankcateg->fetchAll() as $bankcategory) {
425  $options[$bankcategory->id] = $bankcategory->label;
426  }
427 
428  // Bank card
429  $head = bank_prepare_head($object);
430  print dol_get_fiche_head($head, 'journal', $langs->trans("FinancialAccount"), 0, 'account');
431 
432  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
433 
434  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
435 
437 
438 
439  /*
440  * Buttons actions
441  */
442 
443  if ($action != 'reconcile')
444  {
445  if ($object->canBeConciliated() > 0)
446  {
447  // If not cash account and can be reconciliate
448  if ($user->rights->banque->consolidate) {
449  $newparam = $param;
450  $newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam);
451  $buttonreconcile = '<a class="butAction" style="margin-bottom: 5px !important; margin-top: 5px !important" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&amp;sortorder=asc,asc,asc&search_conciliated=0'.$newparam.'">'.$langs->trans("Conciliate").'</a>';
452  } else {
453  $buttonreconcile = '<a class="butActionRefused" style="margin-bottom: 5px !important; margin-top: 5px !important" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$langs->trans("Conciliate").'</a>';
454  }
455  }
456  }
457 } else {
458  llxHeader('', $langs->trans("BankTransactions"), '', '', 0, 0, array(), array(), $param);
459 }
460 
461 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro as conciliated, b.num_releve, b.num_chq,";
462 $sql .= " b.fk_account, b.fk_type,";
463 $sql .= " ba.rowid as bankid, ba.ref as bankref,";
464 $sql .= " bu.url_id,";
465 $sql .= " s.nom, s.name_alias, s.client, s.fournisseur, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
466 // Add fields from extrafields
467 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
468  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
469 }
470 // Add fields from hooks
471 $parameters = array();
472 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
473 $sql .= $hookmanager->resPrint;
474 $sql .= " FROM ";
475 if ($search_bid > 0) $sql .= MAIN_DB_PREFIX."bank_class as l,";
476 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba,";
477 $sql .= " ".MAIN_DB_PREFIX."bank as b";
478 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)";
479 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND type = 'company'";
480 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid";
481 $sql .= " WHERE b.fk_account = ba.rowid";
482 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
483 if ($search_account > 0) $sql .= " AND b.fk_account = ".$search_account;
484 // Search period criteria
485 if (dol_strlen($search_dt_start) > 0) $sql .= " AND b.dateo >= '".$db->idate($search_dt_start)."'";
486 if (dol_strlen($search_dt_end) > 0) $sql .= " AND b.dateo <= '".$db->idate($search_dt_end)."'";
487 // Search period criteria
488 if (dol_strlen($search_dv_start) > 0) $sql .= " AND b.datev >= '".$db->idate($search_dv_start)."'";
489 if (dol_strlen($search_dv_end) > 0) $sql .= " AND b.datev <= '".$db->idate($search_dv_end)."'";
490 if ($search_ref) $sql .= natural_search("b.rowid", $search_ref, 1);
491 if ($search_req_nb) $sql .= natural_search("b.num_chq", $search_req_nb);
492 if ($search_num_releve) $sql .= natural_search("b.num_releve", $search_num_releve);
493 if ($search_conciliated != '' && $search_conciliated != '-1') $sql .= " AND b.rappro = ".urlencode($search_conciliated);
494 if ($search_thirdparty) $sql .= natural_search("s.nom", $search_thirdparty);
495 if ($search_description)
496 {
497  $search_description_to_use = $search_description;
498  $arrayoffixedlabels = array(
499  'payment_salary',
500  'CustomerInvoicePayment', 'CustomerInvoicePaymentBack',
501  'SupplierInvoicePayment', 'SupplierInvoicePaymentBack',
502  'DonationPayment',
503  'ExpenseReportPayment',
504  'SocialContributionPayment',
505  'SubscriptionPayment',
506  'WithdrawalPayment'
507  );
508  foreach ($arrayoffixedlabels as $keyforlabel)
509  {
510  $translatedlabel = $langs->transnoentitiesnoconv($keyforlabel);
511  if (preg_match('/'.$search_description.'/i', $translatedlabel))
512  {
513  $search_description_to_use .= "|".$keyforlabel;
514  }
515  }
516  $sql .= natural_search("b.label", $search_description_to_use); // Warning some text are just translation keys, not translated strings
517 }
518 if ($search_bid > 0) $sql .= " AND b.rowid=l.lineid AND l.fk_categ=".$search_bid;
519 if (!empty($search_type)) $sql .= " AND b.fk_type = '".$db->escape($search_type)."' ";
520 // Search criteria amount
521 $search_debit = price2num(str_replace('-', '', $search_debit));
522 $search_credit = price2num(str_replace('-', '', $search_credit));
523 if ($search_debit) $sql .= natural_search('- b.amount', $search_debit, 1);
524 if ($search_credit) $sql .= natural_search('b.amount', $search_credit, 1);
525 // Add where from extra fields
526 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
527 
528 // Add where from hooks
529 $parameters = array();
530 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
531 $sql .= $hookmanager->resPrint;
532 
533 $sql .= $db->order($sortfield, $sortorder);
534 
535 $nbtotalofrecords = '';
536 $nbtotalofpages = 0;
537 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
538 {
539  $result = $db->query($sql);
540  $nbtotalofrecords = $db->num_rows($result);
541  $nbtotalofpages = ceil($nbtotalofrecords / $limit);
542 }
543 
544 if (($id > 0 || !empty($ref)) && ((string) $page == ''))
545 {
546  // We open a list of transaction of a dedicated account and no page was set by defaut
547  // We force on last page.
548  $page = ($nbtotalofpages - 1);
549  $offset = $limit * $page;
550  if ($page < 0) $page = 0;
551 }
552 if ($page >= $nbtotalofpages)
553 {
554  // If we made a search and result has low page than the page number we were on
555  $page = ($nbtotalofpages - 1);
556  $offset = $limit * $page;
557  if ($page < 0) $page = 0;
558 }
559 
560 
561 // If not account defined $mode_balance_ok=false
562 if (empty($search_account)) $mode_balance_ok = false;
563 // If a search is done $mode_balance_ok=false
564 if (!empty($search_ref)) $mode_balance_ok = false;
565 if (!empty($search_description)) $mode_balance_ok = false;
566 if (!empty($search_type)) $mode_balance_ok = false;
567 if (!empty($search_debit)) $mode_balance_ok = false;
568 if (!empty($search_credit)) $mode_balance_ok = false;
569 if (!empty($search_thirdparty)) $mode_balance_ok = false;
570 if ($search_conciliated != '' && $search_conciliated != '-1') $mode_balance_ok = false;
571 if (!empty($search_num_releve)) $mode_balance_ok = false;
572 
573 $sql .= $db->plimit($limit + 1, $offset);
574 //print $sql;
575 dol_syslog('compta/bank/bankentries_list.php', LOG_DEBUG);
576 $resql = $db->query($sql);
577 if ($resql)
578 {
579  $num = $db->num_rows($resql);
580 
581  $arrayofselected = is_array($toselect) ? $toselect : array();
582 
583  // List of mass actions available
584  $arrayofmassactions = array(
585  //'presend'=>$langs->trans("SendByMail"),
586  //'builddoc'=>$langs->trans("PDFMerge"),
587  );
588  //if ($user->rights->bank->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
589  if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
590  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
591 
592  // Confirmation delete
593  if ($action == 'delete')
594  {
595  $text = $langs->trans('ConfirmDeleteTransaction');
596  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&rowid='.GETPOST("rowid"), $langs->trans('DeleteTransaction'), $text, 'confirm_delete', null, '', 1);
597  }
598 
599  // Lines of title fields
600  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="search_form">'."\n";
601  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
602  print '<input type="hidden" name="token" value="'.newToken().'">';
603  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
604  print '<input type="hidden" name="action" value="'.($action ? $action : 'search').'">';
605  print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
606  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
607  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
608  print '<input type="hidden" name="page" value="'.$page.'">';
609  print '<input type="hidden" name="id" value="'.$id.'">';
610  print '<input type="hidden" name="ref" value="'.$ref.'">';
611  if (GETPOST('bid')) print '<input type="hidden" name="bid" value="'.GETPOST("bid").'">';
612 
613  // Form to reconcile
614  if ($user->rights->banque->consolidate && $action == 'reconcile')
615  {
616  print '<div class="valignmiddle inline-block" style="padding-right: 20px;">';
617  print '<strong>'.$langs->trans("InputReceiptNumber").'</strong>: ';
618  print '<input class="flat" id="num_releve" name="num_releve" type="text" value="'.(GETPOST('num_releve') ?GETPOST('num_releve') : '').'" size="10">'; // The only default value is value we just entered
619  print '</div>';
620  if (is_array($options) && count($options))
621  {
622  print $langs->trans("EventualyAddCategory").': ';
623  print Form::selectarray('cat', $options, GETPOST('cat'), 1);
624  }
625  print '<br><div style="margin-top: 5px;"><span class="opacitymedium">'.$langs->trans("ThenCheckLinesAndConciliate").'</span> ';
626  print '<input class="button" name="confirm_savestatement" type="submit" value="'.$langs->trans("SaveStatementOnly").'">';
627  print ' '.$langs->trans("or").' ';
628  print '<input class="button" name="confirm_reconcile" type="submit" value="'.$langs->trans("Conciliate").'">';
629  print ' '.$langs->trans("or").' ';
630  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
631  print '</div>';
632 
633  // Show last bank statements
634  $nbmax = 12; // We show last 12 receipts (so we can have more than one year)
635  $liste = "";
636  $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank";
637  $sql .= " WHERE fk_account=".$object->id." AND num_releve IS NOT NULL";
638  $sql .= $db->order("num_releve", "DESC");
639  $sql .= $db->plimit($nbmax + 1);
640  print '<br>';
641  print $langs->trans("LastAccountStatements").' : ';
642  $resqlr = $db->query($sql);
643  if ($resqlr)
644  {
645  $numr = $db->num_rows($resqlr);
646  $i = 0;
647  $last_ok = 0;
648  while (($i < $numr) && ($i < $nbmax))
649  {
650  $objr = $db->fetch_object($resqlr);
651  if (!$last_ok) {
652  $last_releve = $objr->num_releve;
653  $last_ok = 1;
654  }
655  $i++;
656  $liste = '<a href="'.DOL_URL_ROOT.'/compta/bank/releve.php?account='.$id.'&amp;num='.$objr->num_releve.'">'.$objr->num_releve.'</a> &nbsp; '.$liste;
657  }
658  if ($numr >= $nbmax) $liste = "... &nbsp; ".$liste;
659  print $liste;
660  if ($numr <= 0) print '<b>'.$langs->trans("None").'</b>';
661  } else {
662  dol_print_error($db);
663  }
664 
665  // Using BANK_REPORT_LAST_NUM_RELEVE to automatically report last num (or not)
666  if (!empty($conf->global->BANK_REPORT_LAST_NUM_RELEVE))
667  {
668  print '
669  <script type="text/javascript">
670  $("#num_releve").val("' . $last_releve.'");
671  </script>
672  ';
673  }
674  print '<br><br>';
675  }
676 
677  // Form to add a transaction with no invoice
678  if ($user->rights->banque->modifier && $action == 'addline' && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT))
679  {
680  print load_fiche_titre($langs->trans("AddBankRecordLong"), '', '');
681 
682  print '<table class="noborder centpercent">';
683 
684  print '<tr class="liste_titre">';
685  print '<td>'.$langs->trans("Description").'</td>';
686  print '<td>'.$langs->trans("Date").'</td>';
687  print '<td>&nbsp;</td>';
688  print '<td>'.$langs->trans("Type").'</td>';
689  print '<td>'.$langs->trans("Numero").'</td>';
690  print '<td class=right>'.$langs->trans("BankAccount").'</td>';
691  print '<td class=right>'.$langs->trans("Debit").'</td>';
692  print '<td class=right>'.$langs->trans("Credit").'</td>';
693  /*if (! empty($conf->accounting->enabled))
694  {
695  print '<td class="center">';
696  print $langs->trans("AccountAccounting");
697  print '</td>';
698  }*/
699  print '<td align="center">&nbsp;</td>';
700  print '</tr>';
701 
702  print '<tr>';
703  print '<td>';
704  print '<input name="label" class="flat minwidth200" type="text" value="'.GETPOST("label", "alpha").'">';
705  if (is_array($options) && count($options))
706  {
707  print '<br>'.$langs->trans("Rubrique").': ';
708  print Form::selectarray('cat1', $options, GETPOST('cat1'), 1);
709  }
710  print '</td>';
711  print '<td class="nowrap">';
712  print $form->selectDate(empty($dateop) ?-1 : $dateop, 'op', 0, 0, 0, 'transaction');
713  print '</td>';
714  print '<td>&nbsp;</td>';
715  print '<td class="nowrap">';
716  $form->select_types_paiements((GETPOST('operation') ?GETPOST('operation') : ($object->courant == Account::TYPE_CASH ? 'LIQ' : '')), 'operation', '1,2', 2, 1);
717  print '</td>';
718  print '<td>';
719  print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq", "alpha").'">';
720  print '</td>';
721  //if (! $search_account > 0)
722  //{
723  print '<td class=right>';
724  $form->select_comptes(GETPOST('add_account', 'int') ?GETPOST('add_account', 'int') : $search_account, 'add_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''));
725  print '</td>';
726  //}
727  print '<td class="right"><input name="adddebit" class="flat" type="text" size="4" value="'.GETPOST("adddebit", "alpha").'"></td>';
728  print '<td class="right"><input name="addcredit" class="flat" type="text" size="4" value="'.GETPOST("addcredit", "alpha").'"></td>';
729  /*if (! empty($conf->accounting->enabled))
730  {
731  print '<td class="center">';
732  print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, null, 1, 1, '');
733  print '</td>';
734  }*/
735  print '<td class="center">';
736  print '<input type="submit" name="save" class="button buttongen marginbottomonly" value="'.$langs->trans("Add").'"><br>';
737  print '<input type="submit" name="cancel" class="button buttongen marginbottomonly button-cancel" value="'.$langs->trans("Cancel").'">';
738  print '</td></tr>';
739 
740  print '</table>';
741  print '<br>';
742  }
743 
745  print '
746  <script type="text/javascript">
747  $(function() {
748  $("a.ajax").each(function(){
749  var current = $(this);
750  current.click(function()
751  {
752  $.get("'.DOL_URL_ROOT.'/core/ajax/bankconciliate.php?"+current.attr("href").split("?")[1], function(data)
753  {
754  console.log(data)
755  current.parent().prev().replaceWith(data);
756  });
757  return false;
758  });
759  });
760  });
761  </script>
762  ';
763 
764  $i = 0;
765 
766  // Title
767  $bankcateg = new BankCateg($db);
768 
769  $newcardbutton = '';
770  if ($action != 'addline' && $action != 'reconcile')
771  {
772  if (empty($conf->global->BANK_DISABLE_DIRECT_INPUT))
773  {
774  if (empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) // Default is to record miscellaneous direct entries using miscellaneous payments
775  {
776  $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&accountid='.$search_account.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.urlencode($search_account)), '', $user->rights->banque->modifier);
777  } else // If direct entries is not done using miscellaneous payments
778  {
779  $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&page='.$page.$param, '', $user->rights->banque->modifier);
780  }
781  } else {
782  $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&page='.$page.$param, '', -1);
783  }
784  }
785 
786  /*$morehtml = '<div class="inline-block '.(($buttonreconcile || $newcardbutton) ? 'marginrightonly' : '').'">';
787  $morehtml .= '<label for="pageplusone">'.$langs->trans("Page")."</label> "; // ' Page ';
788  $morehtml .= '<input type="text" name="pageplusone" id="pageplusone" class="flat right width25 pageplusone" value="'.($page + 1).'">';
789  $morehtml .= '/'.$nbtotalofpages.' ';
790  $morehtml .= '</div>';
791  */
792 
793  if ($action != 'addline' && $action != 'reconcile')
794  {
795  $morehtml .= $buttonreconcile;
796  }
797 
798  $morehtml .= '<!-- Add New button -->'.$newcardbutton;
799 
800  $picto = 'bank_account';
801  if ($id > 0 || !empty($ref)) $picto = '';
802 
803  print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit, 0, 0, 1);
804 
805  // We can add page now to param
806  if ($page != '') $param .= '&page='.urlencode($page);
807 
808  $moreforfilter = '';
809 
810  $moreforfilter .= '<div class="divsearchfield">';
811  $moreforfilter .= $langs->trans('DateOperationShort').' :';
812  $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
813  $moreforfilter .= '<div class="nowrap inline-block">';
814  $moreforfilter .= $form->selectDate($search_dt_start, 'search_start_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')).'</div>';
815  //$moreforfilter .= ' - ';
816  $moreforfilter .= '<div class="nowrap inline-block">'.$form->selectDate($search_dt_end, 'search_end_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')).'</div>';
817  $moreforfilter .= '</div>';
818 
819  $moreforfilter .= '<div class="divsearchfield">';
820  $moreforfilter .= $langs->trans('DateValueShort').' : ';
821  $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
822  $moreforfilter .= '<div class="nowrap inline-block">';
823  $moreforfilter .= $form->selectDate($search_dv_start, 'search_start_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')).'</div>';
824  //$moreforfilter .= ' - ';
825  $moreforfilter .= '<div class="nowrap inline-block">'.$form->selectDate($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')).'</div>';
826  $moreforfilter .= '</div>';
827 
828  if (!empty($conf->categorie->enabled))
829  {
830  // Categories
831  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
832  {
833  $langs->load('categories');
834 
835  // Bank line
836  $moreforfilter .= '<div class="divsearchfield">';
837  $moreforfilter .= $langs->trans('RubriquesTransactions').' : ';
838  $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, $search_bid, 'parent', null, null, 1);
839  $moreforfilter .= $form->selectarray('search_bid', $cate_arbo, $search_bid, 1, 0, 0, '', 0, 0, 0, '', '', 1);
840  $moreforfilter .= '</div>';
841  }
842  }
843 
844  $parameters = array();
845  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
846  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
847  else $moreforfilter = $hookmanager->resPrint;
848 
849  if ($moreforfilter)
850  {
851  print '<div class="liste_titre liste_titre_bydiv centpercent">';
852  print $moreforfilter;
853  print '</div>'."\n";
854  }
855 
856  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
857  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
858  // When action is 'reconcile', we force to have the column num_releve always enabled (otherwise we can't make reconciliation).
859  if ($action == 'reconcile') {
860  $arrayfields['b.num_releve']['checked'] = 1;
861  }
862 
863  print '<div class="div-table-responsive">';
864  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
865 
866 
867  print '<tr class="liste_titre_filter">';
868  if (!empty($arrayfields['b.rowid']['checked']))
869  {
870  print '<td class="liste_titre">';
871  print '<input type="text" class="flat" name="search_ref" size="2" value="'.dol_escape_htmltag($search_ref).'">';
872  print '</td>';
873  }
874  if (!empty($arrayfields['b.label']['checked']))
875  {
876  print '<td class="liste_titre">';
877  print '<input type="text" class="flat maxwidth100" name="search_description" value="'.dol_escape_htmltag($search_description).'">';
878  print '</td>';
879  }
880  if (!empty($arrayfields['b.dateo']['checked']))
881  {
882  print '<td class="liste_titre">&nbsp;</td>';
883  }
884  if (!empty($arrayfields['b.datev']['checked']))
885  {
886  print '<td class="liste_titre">&nbsp;</td>';
887  }
888  if (!empty($arrayfields['type']['checked']))
889  {
890  print '<td class="liste_titre" align="center">';
891  $form->select_types_paiements(empty($search_type) ? '' : $search_type, 'search_type', '', 2, 1, 1, 0, 1, 'maxwidth100');
892  print '</td>';
893  }
894  if (!empty($arrayfields['b.num_chq']['checked']))
895  {
896  // Numero
897  print '<td class="liste_titre" align="center"><input type="text" class="flat" name="req_nb" value="'.dol_escape_htmltag($search_req_nb).'" size="2"></td>';
898  }
899  if (!empty($arrayfields['bu.label']['checked']))
900  {
901  print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_thirdparty" value="'.dol_escape_htmltag($search_thirdparty).'"></td>';
902  }
903  if (!empty($arrayfields['ba.ref']['checked']))
904  {
905  print '<td class="liste_titre">';
906  $form->select_comptes($search_account, 'search_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, 'maxwidth100');
907  print '</td>';
908  }
909  if (!empty($arrayfields['b.debit']['checked']))
910  {
911  print '<td class="liste_titre right">';
912  print '<input type="text" class="flat width50" name="search_debit" value="'.dol_escape_htmltag($search_debit).'">';
913  print '</td>';
914  }
915  if (!empty($arrayfields['b.credit']['checked']))
916  {
917  print '<td class="liste_titre right">';
918  print '<input type="text" class="flat width50" name="search_credit" value="'.dol_escape_htmltag($search_credit).'">';
919  print '</td>';
920  }
921  if (!empty($arrayfields['balancebefore']['checked']))
922  {
923  print '<td class="liste_titre right">';
924  $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
925  print $form->textwithpicto('', $htmltext, 1);
926  print '</td>';
927  }
928  if (!empty($arrayfields['balance']['checked']))
929  {
930  print '<td class="liste_titre right">';
931  $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
932  print $form->textwithpicto('', $htmltext, 1);
933  print '</td>';
934  }
935  // Numero statement
936  if (!empty($arrayfields['b.num_releve']['checked']))
937  {
938  print '<td class="liste_titre" align="center"><input type="text" class="flat" name="search_num_releve" value="'.dol_escape_htmltag($search_num_releve).'" size="3"></td>';
939  }
940  // Conciliated
941  if (!empty($arrayfields['b.conciliated']['checked']))
942  {
943  print '<td class="liste_titre" align="center">';
944  print $form->selectyesno('search_conciliated', $search_conciliated, 1, false, 1, 1);
945  print '</td>';
946  }
947  print '<td class="liste_titre" align="middle">';
948  print '</td>';
949  print '<td class="liste_titre" align="middle">';
950  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
951  print $searchpicto;
952  print '</td>';
953  print "</tr>\n";
954 
955  // Fields title
956  print '<tr class="liste_titre">';
957  if (!empty($arrayfields['b.rowid']['checked'])) print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
958  if (!empty($arrayfields['b.label']['checked'])) print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER['PHP_SELF'], 'b.label', '', $param, '', $sortfield, $sortorder);
959  if (!empty($arrayfields['b.dateo']['checked'])) print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '', $sortfield, $sortorder, "center ");
960  if (!empty($arrayfields['b.datev']['checked'])) print_liste_field_titre($arrayfields['b.datev']['label'], $_SERVER['PHP_SELF'], 'b.datev,b.dateo,b.rowid', '', $param, 'align="center"', $sortfield, $sortorder);
961  if (!empty($arrayfields['type']['checked'])) print_liste_field_titre($arrayfields['type']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="center"', $sortfield, $sortorder);
962  if (!empty($arrayfields['b.num_chq']['checked'])) print_liste_field_titre($arrayfields['b.num_chq']['label'], $_SERVER['PHP_SELF'], 'b.num_chq', '', $param, '', $sortfield, $sortorder, "center ");
963  if (!empty($arrayfields['bu.label']['checked'])) print_liste_field_titre($arrayfields['bu.label']['label'], $_SERVER['PHP_SELF'], 'bu.label', '', $param, '', $sortfield, $sortorder);
964  if (!empty($arrayfields['ba.ref']['checked'])) print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder);
965  if (!empty($arrayfields['b.debit']['checked'])) print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
966  if (!empty($arrayfields['b.credit']['checked'])) print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
967  if (!empty($arrayfields['balancebefore']['checked'])) print_liste_field_titre($arrayfields['balancebefore']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
968  if (!empty($arrayfields['balance']['checked'])) print_liste_field_titre($arrayfields['balance']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
969  if (!empty($arrayfields['b.num_releve']['checked'])) print_liste_field_titre($arrayfields['b.num_releve']['label'], $_SERVER['PHP_SELF'], 'b.num_releve', '', $param, '', $sortfield, $sortorder, "center ");
970  if (!empty($arrayfields['b.conciliated']['checked'])) print_liste_field_titre($arrayfields['b.conciliated']['label'], $_SERVER['PHP_SELF'], 'b.rappro', '', $param, '', $sortfield, $sortorder, "center ");
971  // Extra fields
972  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
973  // Hook fields
974  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
975  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
976  print $hookmanager->resPrint;
977  print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', 'class="right"', $sortfield, $sortorder, 'maxwidthsearch ');
978  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
979  print "</tr>\n";
980 
981  $balance = 0; // For balance
982  $balancebefore = 0; // For balance
983  $balancecalculated = false;
984  $posconciliatecol = 0;
985  $cachebankaccount = array();
986 
987  // Loop on each record
988  $sign = 1;
989 
990  $totalarray = array();
991  while ($i < min($num, $limit))
992  {
993  $objp = $db->fetch_object($resql);
994  // If we are in a situation where we need/can show balance, we calculate the start of balance
995  if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && ($mode_balance_ok || $search_conciliated === '0'))
996  {
997  if (!$search_account)
998  {
999  dol_print_error('', 'account is not defined but $mode_balance_ok is true');
1000  exit;
1001  }
1002 
1003  // Loop on each record before
1004  $sign = 1;
1005  $i = 0;
1006  $sqlforbalance = 'SELECT SUM(b.amount) as previoustotal';
1007  $sqlforbalance .= " FROM ";
1008  $sqlforbalance .= " ".MAIN_DB_PREFIX."bank_account as ba,";
1009  $sqlforbalance .= " ".MAIN_DB_PREFIX."bank as b";
1010  $sqlforbalance .= " WHERE b.fk_account = ba.rowid";
1011  $sqlforbalance .= " AND ba.entity IN (".getEntity('bank_account').")";
1012  $sqlforbalance .= " AND b.fk_account = ".$search_account;
1013  $sqlforbalance .= " AND (b.datev < '".$db->idate($db->jdate($objp->dv))."' OR (b.datev = '".$db->idate($db->jdate($objp->dv))."' AND (b.dateo < '".$db->idate($db->jdate($objp->do))."' OR (b.dateo = '".$db->idate($db->jdate($objp->do))."' AND b.rowid < ".$objp->rowid."))))";
1014  $resqlforbalance = $db->query($sqlforbalance);
1015  //print $sqlforbalance;
1016  if ($resqlforbalance) {
1017  $objforbalance = $db->fetch_object($resqlforbalance);
1018  if ($objforbalance) {
1019  // If sort is desc,desc,desc then total of previous date + amount is the balancebefore of the previous line before the line to show
1020  if ($sortfield == 'b.datev,b.dateo,b.rowid' && $sortorder == 'desc,desc,desc')
1021  {
1022  $balancebefore = $objforbalance->previoustotal + ($sign * $objp->amount);
1023  } // If sort is asc,asc,asc then total of previous date is balance of line before the next line to show
1024  else {
1025  $balance = $objforbalance->previoustotal;
1026  }
1027  }
1028  } else dol_print_error($db);
1029 
1030  $balancecalculated = true;
1031 
1032  // Output a line with start balance
1033  if ($user->rights->banque->consolidate && $action == 'reconcile')
1034  {
1035  $tmpnbfieldbeforebalance = 0;
1036  $tmpnbfieldafterbalance = 0;
1037  $balancefieldfound = 0;
1038  foreach ($arrayfields as $key => $val)
1039  {
1040  if ($key == 'balancebefore' || $key == 'balance')
1041  {
1042  $balancefieldfound++;
1043  continue;
1044  }
1045  if (!empty($arrayfields[$key]['checked']))
1046  {
1047  if (!$balancefieldfound) $tmpnbfieldbeforebalance++;
1048  else $tmpnbfieldafterbalance++;
1049  }
1050  }
1051  // Extra fields
1052  $element = 'banktransaction';
1053  if (is_array($extrafields->attributes[$element]['label']) && count($extrafields->attributes[$element]['label']))
1054  {
1055  foreach ($extrafields->attributes[$element]['label'] as $key => $val)
1056  {
1057  if (!empty($arrayfields["ef.".$key]['checked']))
1058  {
1059  if (!empty($arrayfields[$key]['checked']))
1060  {
1061  if (!$balancefieldfound) $tmpnbfieldbeforebalance++;
1062  else $tmpnbfieldafterbalance++;
1063  }
1064  }
1065  }
1066  }
1067 
1068  print '<tr class="oddeven trforbreak">';
1069  if ($tmpnbfieldbeforebalance)
1070  {
1071  print '<td colspan="'.$tmpnbfieldbeforebalance.'">';
1072  print '&nbsp;';
1073  print '</td>';
1074  }
1075 
1076  if (!empty($arrayfields['balancebefore']['checked']))
1077  {
1078  print '<td class="right">';
1079  if ($search_conciliated !== '0') {
1080  print price(price2num($balance, 'MT'), 1, $langs);
1081  }
1082  print '</td>';
1083  }
1084  if (!empty($arrayfields['balance']['checked']))
1085  {
1086  print '<td class="right">';
1087  if ($search_conciliated !== '0') {
1088  print price(price2num($balance, 'MT'), 1, $langs);
1089  }
1090  print '</td>';
1091  }
1092  if (!empty($arrayfields['b.num_releve']['checked']))
1093  {
1094  print '<td class="center">';
1095  print '<input type="checkbox" id="selectAll" title="'.dol_escape_htmltag($langs->trans("SelectAll")).'" />';
1096  print ' <script type="text/javascript">
1097  $("input#selectAll").change(function() {
1098  $("input[type=checkbox][name^=rowid]").prop("checked", $(this).is(":checked"));
1099  });
1100  </script>';
1101  print '</td>';
1102  }
1103  print '<td colspan="'.($tmpnbfieldafterbalance + 2).'">';
1104  print '&nbsp;';
1105  print '</td>';
1106  print '</tr>';
1107  }
1108  }
1109 
1110 
1111  if ($sortfield == 'b.datev,b.dateo,b.rowid' && $sortorder == 'desc,desc,desc')
1112  {
1113  $balance = price2num($balancebefore, 'MT'); // balance = balancebefore of previous line (sort is desc)
1114  $balancebefore = price2num($balancebefore - ($sign * $objp->amount), 'MT');
1115  } else {
1116  $balancebefore = price2num($balance, 'MT'); // balancebefore = balance of previous line (sort is asc)
1117  $balance = price2num($balance + ($sign * $objp->amount), 'MT');
1118  }
1119 
1120  if (empty($cachebankaccount[$objp->bankid]))
1121  {
1122  $bankaccounttmp = new Account($db);
1123  $bankaccounttmp->fetch($objp->bankid);
1124  $cachebankaccount[$objp->bankid] = $bankaccounttmp;
1125  $bankaccount = $bankaccounttmp;
1126  } else {
1127  $bankaccount = $cachebankaccount[$objp->bankid];
1128  }
1129 
1130  if (empty($conf->global->BANK_COLORIZE_MOVEMENT)) {
1131  $backgroundcolor = "class='oddeven'";
1132  } else {
1133  if ($objp->amount < 0)
1134  {
1135  if (empty($conf->global->BANK_COLORIZE_MOVEMENT_COLOR1)) {
1136  $color = '#fca955';
1137  } else {
1138  $color = '#'.$conf->global->BANK_COLORIZE_MOVEMENT_COLOR1;
1139  }
1140  $backgroundcolor = 'style="background: '.$color.';"';
1141  } else {
1142  if (empty($conf->global->BANK_COLORIZE_MOVEMENT_COLOR2)) {
1143  $color = '#7fdb86';
1144  } else {
1145  $color = '#'.$conf->global->BANK_COLORIZE_MOVEMENT_COLOR2;
1146  }
1147  $backgroundcolor = 'style="background: '.$color.';"';
1148  }
1149  }
1150 
1151  $banklinestatic->id = $objp->rowid;
1152  $banklinestatic->ref = $objp->rowid;
1153 
1154  print '<tr class="oddeven" '.$backgroundcolor.'>';
1155 
1156  // Ref
1157  if (!empty($arrayfields['b.rowid']['checked']))
1158  {
1159  print '<td class="nowrap left">';
1160  print $banklinestatic->getNomUrl(1);
1161  print '</td>';
1162  if (!$i) $totalarray['nbfield']++;
1163  }
1164 
1165  // Description
1166  if (!empty($arrayfields['b.label']['checked']))
1167  {
1168  print "<td>";
1169 
1170  //print "<a href=\"line.php?rowid=".$objp->rowid."&amp;account=".$objp->fk_account."\">";
1171  $reg = array();
1172  preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthee on tente recherche de traduction
1173  if ($reg[1] && $langs->trans($reg[1]) != $reg[1]) print $langs->trans($reg[1]);
1174  else {
1175  if ($objp->label == '(payment_salary)') {
1176  print dol_trunc($langs->trans("SalaryPayment", 40));
1177  } else {
1178  print dol_trunc($objp->label, 40);
1179  }
1180  }
1181  //print "</a>&nbsp;";
1182 
1183  // Add links after description
1184  $links = $bankaccountstatic->get_url($objp->rowid);
1185  $cachebankaccount = array();
1186  foreach ($links as $key=>$val)
1187  {
1188  print '<!-- '.$links[$key]['type'].' -->';
1189  if ($links[$key]['type'] == 'withdraw')
1190  {
1191  $banktransferstatic->id = $links[$key]['url_id'];
1192  $banktransferstatic->ref = $links[$key]['label'];
1193  print ' '.$banktransferstatic->getNomUrl(0);
1194  } elseif ($links[$key]['type'] == 'payment')
1195  {
1196  $paymentstatic->id = $links[$key]['url_id'];
1197  $paymentstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
1198  print ' '.$paymentstatic->getNomUrl(2);
1199  } elseif ($links[$key]['type'] == 'payment_supplier')
1200  {
1201  $paymentsupplierstatic->id = $links[$key]['url_id'];
1202  $paymentsupplierstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
1203  print ' '.$paymentsupplierstatic->getNomUrl(2);
1204  } elseif ($links[$key]['type'] == 'payment_sc')
1205  {
1206  $paymentscstatic->id = $links[$key]['url_id'];
1207  $paymentscstatic->ref = $links[$key]['url_id'];
1208  $paymentscstatic->label = $links[$key]['label'];
1209  print ' '.$paymentscstatic->getNomUrl(2);
1210  } elseif ($links[$key]['type'] == 'payment_vat')
1211  {
1212  $paymentvatstatic->id = $links[$key]['url_id'];
1213  $paymentvatstatic->ref = $links[$key]['url_id'];
1214  print ' '.$paymentvatstatic->getNomUrl(2);
1215  } elseif ($links[$key]['type'] == 'payment_salary')
1216  {
1217  $paymentsalstatic->id = $links[$key]['url_id'];
1218  $paymentsalstatic->ref = $links[$key]['url_id'];
1219  $paymentsalstatic->label = $links[$key]['label'];
1220  print ' '.$paymentsalstatic->getNomUrl(2);
1221  } elseif ($links[$key]['type'] == 'payment_loan')
1222  {
1223  print '<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$links[$key]['url_id'].'">';
1224  print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
1225  print '</a>';
1226  } elseif ($links[$key]['type'] == 'payment_donation')
1227  {
1228  $paymentdonationstatic->id = $links[$key]['url_id'];
1229  $paymentdonationstatic->ref = $links[$key]['url_id'];
1230  print ' '.$paymentdonationstatic->getNomUrl(2);
1231  } elseif ($links[$key]['type'] == 'payment_expensereport')
1232  {
1233  $paymentexpensereportstatic->id = $links[$key]['url_id'];
1234  $paymentexpensereportstatic->ref = $links[$key]['url_id'];
1235  print ' '.$paymentexpensereportstatic->getNomUrl(2);
1236  } elseif ($links[$key]['type'] == 'payment_various')
1237  {
1238  $paymentvariousstatic->id = $links[$key]['url_id'];
1239  $paymentvariousstatic->ref = $links[$key]['url_id'];
1240  print ' '.$paymentvariousstatic->getNomUrl(2);
1241  } elseif ($links[$key]['type'] == 'banktransfert')
1242  {
1243  // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
1244  if ($objp->amount > 0)
1245  {
1246  $banklinestatic->fetch($links[$key]['url_id']);
1247  $bankstatic->id = $banklinestatic->fk_account;
1248  $bankstatic->label = $banklinestatic->bank_account_ref;
1249  print ' ('.$langs->trans("TransferFrom").' ';
1250  print $bankstatic->getNomUrl(1, 'transactions');
1251  print ' '.$langs->trans("toward").' ';
1252  $bankstatic->id = $objp->bankid;
1253  $bankstatic->label = $objp->bankref;
1254  print $bankstatic->getNomUrl(1, '');
1255  print ')';
1256  } else {
1257  $bankstatic->id = $objp->bankid;
1258  $bankstatic->label = $objp->bankref;
1259  print ' ('.$langs->trans("TransferFrom").' ';
1260  print $bankstatic->getNomUrl(1, '');
1261  print ' '.$langs->trans("toward").' ';
1262  $banklinestatic->fetch($links[$key]['url_id']);
1263  $bankstatic->id = $banklinestatic->fk_account;
1264  $bankstatic->label = $banklinestatic->bank_account_ref;
1265  print $bankstatic->getNomUrl(1, 'transactions');
1266  print ')';
1267  }
1268  //var_dump($links);
1269  } elseif ($links[$key]['type'] == 'company')
1270  {
1271  } elseif ($links[$key]['type'] == 'user')
1272  {
1273  } elseif ($links[$key]['type'] == 'member')
1274  {
1275  } elseif ($links[$key]['type'] == 'sc')
1276  {
1277  } else {
1278  // Show link with label $links[$key]['label']
1279  if (!empty($objp->label) && !empty($links[$key]['label'])) print ' - ';
1280  print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
1281  if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg))
1282  {
1283  // Label generique car entre parentheses. On l'affiche en le traduisant
1284  if ($reg[1] == 'paiement') $reg[1] = 'Payment';
1285  print ' '.$langs->trans($reg[1]);
1286  } else {
1287  print ' '.$links[$key]['label'];
1288  }
1289  print '</a>';
1290  }
1291  }
1292  print '</td>';
1293  if (!$i) $totalarray['nbfield']++;
1294  }
1295 
1296  // Date ope
1297  if (!empty($arrayfields['b.dateo']['checked']))
1298  {
1299  print '<td align="center" class="nowrap">';
1300  print '<span id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
1301  print '&nbsp;';
1302  print '<span class="inline-block">';
1303  print '<a class="ajax" href="'.$_SERVER['PHP_SELF'].'?action=doprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1304  print img_edit_remove()."</a> ";
1305  print '<a class="ajax" href="'.$_SERVER['PHP_SELF'].'?action=donext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1306  print img_edit_add()."</a>";
1307  print '</span>';
1308  print "</td>\n";
1309  if (!$i) $totalarray['nbfield']++;
1310  }
1311 
1312  // Date value
1313  if (!empty($arrayfields['b.datev']['checked']))
1314  {
1315  print '<td align="center" class="nowrap">';
1316  print '<span id="datevalue_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->dv), "day")."</span>";
1317  print '&nbsp;';
1318  print '<span class="inline-block">';
1319  print '<a class="ajax" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1320  print img_edit_remove()."</a> ";
1321  print '<a class="ajax" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1322  print img_edit_add()."</a>";
1323  print '</span>';
1324  print "</td>\n";
1325  if (!$i) $totalarray['nbfield']++;
1326  }
1327 
1328  // Payment type
1329  if (!empty($arrayfields['type']['checked']))
1330  {
1331  print '<td align="center" class="nowrap">';
1332  $labeltype = ($langs->trans("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->trans("PaymentTypeShort".$objp->fk_type) : $langs->getLabelFromKey($db, $objp->fk_type, 'c_paiement', 'code', 'libelle', '', 1);
1333  if ($labeltype == 'SOLD') print '&nbsp;'; //$langs->trans("InitialBankBalance");
1334  else print $labeltype;
1335  print "</td>\n";
1336  if (!$i) $totalarray['nbfield']++;
1337  }
1338 
1339  // Num cheque
1340  if (!empty($arrayfields['b.num_chq']['checked']))
1341  {
1342  print '<td class="nowrap" align="center">'.($objp->num_chq ? $objp->num_chq : "")."</td>\n";
1343  if (!$i) $totalarray['nbfield']++;
1344  }
1345 
1346  // Third party
1347  if (!empty($arrayfields['bu.label']['checked']))
1348  {
1349  print '<td class="tdoverflowmax150">';
1350  if ($objp->url_id)
1351  {
1352  $companystatic->id = $objp->url_id;
1353  $companystatic->name = $objp->nom;
1354  $companystatic->name_alias = $objp->name_alias;
1355  $companystatic->client = $objp->client;
1356  $companystatic->email = $objp->email;
1357  $companystatic->fournisseur = $objp->fournisseur;
1358  $companystatic->code_client = $objp->code_client;
1359  $companystatic->code_fournisseur = $objp->code_fournisseur;
1360  $companystatic->code_compta = $objp->code_compta;
1361  $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
1362  print $companystatic->getNomUrl(1);
1363  } else {
1364  print '&nbsp;';
1365  }
1366  print '</td>';
1367  if (!$i) $totalarray['nbfield']++;
1368  }
1369 
1370  // Bank account
1371  if (!empty($arrayfields['ba.ref']['checked']))
1372  {
1373  print '<td class="nowrap">';
1374  print $bankaccount->getNomUrl(1);
1375  print "</td>\n";
1376  if (!$i) $totalarray['nbfield']++;
1377  }
1378 
1379  // Debit
1380  if (!empty($arrayfields['b.debit']['checked']))
1381  {
1382  print '<td class="nowrap right">';
1383  if ($objp->amount < 0)
1384  {
1385  print price($objp->amount * -1);
1386  $totalarray['totaldeb'] += $objp->amount;
1387  }
1388  print "</td>\n";
1389  if (!$i) $totalarray['nbfield']++;
1390  if (!$i) $totalarray['totaldebfield'] = $totalarray['nbfield'];
1391  }
1392 
1393  // Credit
1394  if (!empty($arrayfields['b.credit']['checked']))
1395  {
1396  print '<td class="nowrap right">';
1397  if ($objp->amount > 0)
1398  {
1399  print price($objp->amount);
1400  $totalarray['totalcred'] += $objp->amount;
1401  }
1402  print "</td>\n";
1403  if (!$i) $totalarray['nbfield']++;
1404  if (!$i) $totalarray['totalcredfield'] = $totalarray['nbfield'];
1405  }
1406 
1407  // Balance before
1408  if (!empty($arrayfields['balancebefore']['checked']))
1409  {
1410  if ($mode_balance_ok)
1411  {
1412  if ($balancebefore >= 0)
1413  {
1414  print '<td class="nowrap right">&nbsp;'.price($balancebefore).'</td>';
1415  } else {
1416  print '<td class="error nowrap right">&nbsp;'.price($balancebefore).'</td>';
1417  }
1418  } else {
1419  print '<td class="right">-</td>';
1420  }
1421  if (!$i) $totalarray['nbfield']++;
1422  }
1423  // Balance
1424  if (!empty($arrayfields['balance']['checked']))
1425  {
1426  if ($mode_balance_ok)
1427  {
1428  if ($balance >= 0)
1429  {
1430  print '<td class="nowrap right">&nbsp;'.price($balance).'</td>';
1431  } else {
1432  print '<td class="error nowrap right">&nbsp;'.price($balance).'</td>';
1433  }
1434  } else {
1435  print '<td class="right">-</td>';
1436  }
1437  if (!$i) $totalarray['nbfield']++;
1438  }
1439 
1440  if (!empty($arrayfields['b.num_releve']['checked']))
1441  {
1442  print '<td class="nowraponall" align="center">';
1443  // Transaction reconciliated or edit link
1444  if ($bankaccount->canBeConciliated() > 0)
1445  {
1446  if ($objp->num_releve)
1447  {
1448  print '<a href="releve.php?num='.$objp->num_releve.'&account='.$objp->bankid.'&save_lastsearch_values=1">'.$objp->num_releve.'</a>';
1449  }
1450  if (!$objp->conciliated && $action == 'reconcile')
1451  {
1452  if ($objp->num_releve) print '&nbsp;';
1453  print '<input class="flat" name="rowid['.$objp->rowid.']" type="checkbox" value="'.$objp->rowid.'" size="1"'.(!empty($_POST['rowid'][$objp->rowid]) ? ' checked' : '').'>';
1454  }
1455  }
1456  print '</td>';
1457  if (!$i)
1458  {
1459  $totalarray['nbfield']++;
1460  $posconciliatecol = $totalarray['nbfield'];
1461  }
1462  }
1463 
1464  if (!empty($arrayfields['b.conciliated']['checked']))
1465  {
1466  print '<td class="nowraponall" align="center">';
1467  print $objp->conciliated ? $langs->trans("Yes") : $langs->trans("No");
1468  print '</td>';
1469  if (!$i) $totalarray['nbfield']++;
1470  }
1471 
1472  // Action edit/delete
1473  print '<td class="nowraponall" align="center">';
1474  // Transaction reconciliated or edit link
1475  if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) // If line not conciliated and account can be conciliated
1476  {
1477  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&amp;rowid='.$objp->rowid.'&amp;account='.$objp->bankid.'&amp;page='.$page.'">';
1478  print img_edit();
1479  print '</a>';
1480  } else {
1481  if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
1482  {
1483  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&amp;rowid='.$objp->rowid.'&amp;account='.$objp->bankid.'&amp;page='.$page.'">';
1484  print img_edit();
1485  print '</a>';
1486  } else {
1487  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&amp;rowid='.$objp->rowid.'&amp;account='.$objp->bankid.'&amp;page='.$page.'">';
1488  print img_view();
1489  print '</a>';
1490  }
1491  if ($bankaccount->canBeConciliated() > 0 && empty($objp->conciliated))
1492  {
1493  if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay))
1494  {
1495  print ' '.img_warning($langs->trans("ReconciliationLate"));
1496  }
1497  }
1498  if ($user->rights->banque->modifier)
1499  {
1500  print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;token='.newToken().'&amp;rowid='.$objp->rowid.'&amp;id='.$objp->bankid.'&amp;page='.$page.'">';
1501  print img_delete('', 'class="marginleftonly"');
1502  print '</a>';
1503  }
1504  }
1505  print '</td>';
1506  if (!$i) $totalarray['nbfield']++;
1507 
1508  // Action column
1509  print '<td class="nowrap" align="center">';
1510  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1511  {
1512  $selected = 0;
1513  if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
1514  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1515  }
1516  print '</td>';
1517  if (!$i) $totalarray['nbfield']++;
1518 
1519  print "</tr>";
1520 
1521  $i++;
1522  }
1523 
1524  // Show total line
1525  if (isset($totalarray['totaldebfield']) || isset($totalarray['totalcredfield']))
1526  {
1527  print '<tr class="liste_total">';
1528  $i = 0;
1529  while ($i < $totalarray['nbfield'])
1530  {
1531  $i++;
1532  if ($i == 1)
1533  {
1534  if ($num < $limit && empty($offset)) print '<td class="left">'.$langs->trans("Total").'</td>';
1535  else print '<td class="left tdoverflowmax50" title="'.$langs->trans("Totalforthispage").'">'.$langs->trans("Totalforthispage").'</td>';
1536  } elseif ($totalarray['totaldebfield'] == $i) print '<td class="right">'.price(-1 * $totalarray['totaldeb']).'</td>';
1537  elseif ($totalarray['totalcredfield'] == $i) print '<td class="right">'.price($totalarray['totalcred']).'</td>';
1538  elseif ($i == $posconciliatecol)
1539  {
1540  print '<td class="center">';
1541  if ($user->rights->banque->consolidate && $action == 'reconcile') print '<input class="button" name="confirm_reconcile" type="submit" value="'.$langs->trans("Conciliate").'">';
1542  print '</td>';
1543  } else print '<td></td>';
1544  }
1545  print '</tr>';
1546  }
1547 
1548  // If no record found
1549  if ($num == 0)
1550  {
1551  $colspan = 1;
1552  foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
1553  print '<tr><td colspan="'.($colspan + 1).'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1554  }
1555 
1556  print "</table>";
1557  print "</div>";
1558 
1559  print '</form>';
1560  $db->free($resql);
1561 } else {
1562  dol_print_error($db);
1563 }
1564 
1565 // End of page
1566 llxFooter();
1567 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
static selectarray($htmlname, $array, $id= '', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam= '', $translate=0, $maxlen=0, $disabled=0, $sort= '', $morecss= '', $addjscombo=0, $moreparamonempty= '', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
Loan.
Definition: loan.class.php:30
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...
Class to manage various payments.
Class to manage salary payments.
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:35
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage payments of social contributions.
Class to manage bank transaction lines.
Class to manage bank accounts.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage withdrawal receipts.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
Class to manage payments of customer invoices.
Class to manage bank categories.
Class to manage members of a foundation.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
const TYPE_CASH
Cash account.
Class to manage payments of donations.
print $_SERVER["PHP_SELF"]
Edit parameters.
img_edit_add($titlealt= 'default', $other= '')
Show logo +.
img_edit_remove($titlealt= 'default', $other= '')
Show logo -.
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to manage donations.
Definition: don.class.php:37
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage generation of HTML components for accounting management.
Class to manage payments of expense report.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_view($titlealt= 'default', $float=0, $other= '')
Show logo view card.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
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.
Class to manage payments for supplier invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...