dolibarr  17.0.3
listbyaccount.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Neil Orley <neil.orley@oeris.fr>
3  * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
4  * Copyright (C) 2013-2020 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../../main.inc.php';
30 
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array("accountancy", "compta"));
42 
43 $action = GETPOST('action', 'aZ09');
44 $socid = GETPOST('socid', 'int');
45 $massaction = GETPOST('massaction', 'alpha');
46 $confirm = GETPOST('confirm', 'alpha');
47 $toselect = GETPOST('toselect', 'array');
48 $type = GETPOST('type', 'alpha');
49 if ($type == 'sub') {
50  $context_default = 'bookkeepingbysubaccountlist';
51 } else {
52  $context_default = 'bookkeepingbyaccountlist';
53 }
54 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : $context_default;
55 $search_date_startyear = GETPOST('search_date_startyear', 'int');
56 $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
57 $search_date_startday = GETPOST('search_date_startday', 'int');
58 $search_date_endyear = GETPOST('search_date_endyear', 'int');
59 $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
60 $search_date_endday = GETPOST('search_date_endday', 'int');
61 $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
62 $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
63 $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
64 $search_date_export_startyear = GETPOST('search_date_export_startyear', 'int');
65 $search_date_export_startmonth = GETPOST('search_date_export_startmonth', 'int');
66 $search_date_export_startday = GETPOST('search_date_export_startday', 'int');
67 $search_date_export_endyear = GETPOST('search_date_export_endyear', 'int');
68 $search_date_export_endmonth = GETPOST('search_date_export_endmonth', 'int');
69 $search_date_export_endday = GETPOST('search_date_export_endday', 'int');
70 $search_date_export_start = dol_mktime(0, 0, 0, $search_date_export_startmonth, $search_date_export_startday, $search_date_export_startyear);
71 $search_date_export_end = dol_mktime(23, 59, 59, $search_date_export_endmonth, $search_date_export_endday, $search_date_export_endyear);
72 $search_date_validation_startyear = GETPOST('search_date_validation_startyear', 'int');
73 $search_date_validation_startmonth = GETPOST('search_date_validation_startmonth', 'int');
74 $search_date_validation_startday = GETPOST('search_date_validation_startday', 'int');
75 $search_date_validation_endyear = GETPOST('search_date_validation_endyear', 'int');
76 $search_date_validation_endmonth = GETPOST('search_date_validation_endmonth', 'int');
77 $search_date_validation_endday = GETPOST('search_date_validation_endday', 'int');
78 $search_date_validation_start = dol_mktime(0, 0, 0, $search_date_validation_startmonth, $search_date_validation_startday, $search_date_validation_startyear);
79 $search_date_validation_end = dol_mktime(23, 59, 59, $search_date_validation_endmonth, $search_date_validation_endday, $search_date_validation_endyear);
80 $search_import_key = GETPOST("search_import_key", 'alpha');
81 
82 $search_accountancy_code = GETPOST("search_accountancy_code");
83 $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
84 if ($search_accountancy_code_start == - 1) {
85  $search_accountancy_code_start = '';
86 }
87 $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
88 if ($search_accountancy_code_end == - 1) {
89  $search_accountancy_code_end = '';
90 }
91 $search_doc_ref = GETPOST('search_doc_ref', 'alpha');
92 $search_label_operation = GETPOST('search_label_operation', 'alpha');
93 $search_mvt_num = GETPOST('search_mvt_num', 'int');
94 $search_direction = GETPOST('search_direction', 'alpha');
95 $search_ledger_code = GETPOST('search_ledger_code', 'array');
96 $search_debit = GETPOST('search_debit', 'alpha');
97 $search_credit = GETPOST('search_credit', 'alpha');
98 $search_lettering_code = GETPOST('search_lettering_code', 'alpha');
99 $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha');
100 
101 if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
102  $action = 'delbookkeepingyear';
103 }
104 
105 // Load variable for pagination
106 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
107 $sortfield = GETPOST('sortfield', 'aZ09comma');
108 $sortorder = GETPOST('sortorder', 'aZ09comma');
109 $optioncss = GETPOST('optioncss', 'alpha');
110 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
111 if (empty($page) || $page < 0) {
112  $page = 0;
113 }
114 $offset = $limit * $page;
115 $pageprev = $page - 1;
116 $pagenext = $page + 1;
117 if ($sortorder == "") {
118  $sortorder = "ASC";
119 }
120 if ($sortfield == "") {
121  $sortfield = "t.doc_date,t.rowid";
122 }
123 
124 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
125 $object = new BookKeeping($db);
126 $formfile = new FormFile($db);
127 $hookmanager->initHooks(array($context_default));
128 
129 $formaccounting = new FormAccounting($db);
130 $form = new Form($db);
131 
132 if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('search_date_startday') && !GETPOSTISSET('search_date_startmonth') && !GETPOSTISSET('search_date_starthour')) {
133  $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
134  $sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'";
135  $sql .= $db->plimit(1);
136  $res = $db->query($sql);
137 
138  if ($res->num_rows > 0) {
139  $fiscalYear = $db->fetch_object($res);
140  $search_date_start = strtotime($fiscalYear->date_start);
141  $search_date_end = strtotime($fiscalYear->date_end);
142  } else {
143  $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
144  $year_start = dol_print_date(dol_now(), '%Y');
145  if (dol_print_date(dol_now(), '%m') < $month_start) {
146  $year_start--; // If current month is lower that starting fiscal month, we start last year
147  }
148  $year_end = $year_start + 1;
149  $month_end = $month_start - 1;
150  if ($month_end < 1) {
151  $month_end = 12;
152  $year_end--;
153  }
154  $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
155  $search_date_end = dol_get_last_day($year_end, $month_end);
156  }
157 }
158 
159 $arrayfields = array(
160  // 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
161  't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1),
162  't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
163  't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1),
164  't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1),
165  't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
166  't.debit'=>array('label'=>$langs->trans("AccountingDebit"), 'checked'=>1),
167  't.credit'=>array('label'=>$langs->trans("AccountingCredit"), 'checked'=>1),
168  't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1),
169  't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1),
170  't.date_validated'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1, 'enabled'=>!getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")),
171  't.import_key'=>array('label'=>$langs->trans("ImportId"), 'checked'=>0, 'position'=>1100),
172 );
173 
174 if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) {
175  unset($arrayfields['t.lettering_code']);
176 }
177 
178 if ($search_date_start && empty($search_date_startyear)) {
179  $tmparray = dol_getdate($search_date_start);
180  $search_date_startyear = $tmparray['year'];
181  $search_date_startmonth = $tmparray['mon'];
182  $search_date_startday = $tmparray['mday'];
183 }
184 if ($search_date_end && empty($search_date_endyear)) {
185  $tmparray = dol_getdate($search_date_end);
186  $search_date_endyear = $tmparray['year'];
187  $search_date_endmonth = $tmparray['mon'];
188  $search_date_endday = $tmparray['mday'];
189 }
190 
191 if (!isModEnabled('accounting')) {
192  accessforbidden();
193 }
194 if ($user->socid > 0) {
195  accessforbidden();
196 }
197 if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
198  accessforbidden();
199 }
200 
201 
202 /*
203  * Action
204  */
205 
206 $param = '';
207 
208 if (GETPOST('cancel', 'alpha')) {
209  $action = 'list';
210  $massaction = '';
211 }
212 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunletteringauto' && $massaction != 'preunletteringmanual' && $massaction != 'predeletebookkeepingwriting') {
213  $massaction = '';
214 }
215 
216 $parameters = array('socid'=>$socid);
217 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
218 if ($reshook < 0) {
219  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
220 }
221 
222 if (empty($reshook)) {
223  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
224 
225  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
226  $search_doc_date = '';
227  $search_accountancy_code = '';
228  $search_accountancy_code_start = '';
229  $search_accountancy_code_end = '';
230  $search_label_account = '';
231  $search_doc_ref = '';
232  $search_label_operation = '';
233  $search_mvt_num = '';
234  $search_direction = '';
235  $search_ledger_code = array();
236  $search_date_start = '';
237  $search_date_end = '';
238  $search_date_startyear = '';
239  $search_date_startmonth = '';
240  $search_date_startday = '';
241  $search_date_endyear = '';
242  $search_date_endmonth = '';
243  $search_date_endday = '';
244  $search_date_export_start = '';
245  $search_date_export_end = '';
246  $search_date_export_startyear = '';
247  $search_date_export_startmonth = '';
248  $search_date_export_startday = '';
249  $search_date_export_endyear = '';
250  $search_date_export_endmonth = '';
251  $search_date_export_endday = '';
252  $search_date_validation_start = '';
253  $search_date_validation_end = '';
254  $search_date_validation_startyear = '';
255  $search_date_validation_startmonth = '';
256  $search_date_validation_startday = '';
257  $search_date_validation_endyear = '';
258  $search_date_validation_endmonth = '';
259  $search_date_validation_endday = '';
260  $search_debit = '';
261  $search_credit = '';
262  $search_lettering_code = '';
263  $search_not_reconciled = '';
264  $search_import_key = '';
265  $toselect = array();
266  }
267 
268  // Must be after the remove filter action, before the export.
269  $filter = array();
270 
271  if (!empty($search_date_start)) {
272  $filter['t.doc_date>='] = $search_date_start;
273  $param .= '&search_date_startmonth='.$search_date_startmonth.'&search_date_startday='.$search_date_startday.'&search_date_startyear='.$search_date_startyear;
274  }
275  if (!empty($search_date_end)) {
276  $filter['t.doc_date<='] = $search_date_end;
277  $param .= '&search_date_endmonth='.$search_date_endmonth.'&search_date_endday='.$search_date_endday.'&search_date_endyear='.$search_date_endyear;
278  }
279  if (!empty($search_doc_date)) {
280  $filter['t.doc_date'] = $search_doc_date;
281  $param .= '&doc_datemonth='.GETPOST('doc_datemonth', 'int').'&doc_dateday='.GETPOST('doc_dateday', 'int').'&doc_dateyear='.GETPOST('doc_dateyear', 'int');
282  }
283  if (!empty($search_accountancy_code_start)) {
284  if ($type == 'sub') {
285  $filter['t.subledger_account>='] = $search_accountancy_code_start;
286  } else {
287  $filter['t.numero_compte>='] = $search_accountancy_code_start;
288  }
289  $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start);
290  }
291  if (!empty($search_accountancy_code_end)) {
292  if ($type == 'sub') {
293  $filter['t.subledger_account<='] = $search_accountancy_code_end;
294  } else {
295  $filter['t.numero_compte<='] = $search_accountancy_code_end;
296  }
297  $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end);
298  }
299  if (!empty($search_label_account)) {
300  $filter['t.label_compte'] = $search_label_account;
301  $param .= '&search_label_compte='.urlencode($search_label_account);
302  }
303  if (!empty($search_mvt_num)) {
304  $filter['t.piece_num'] = $search_mvt_num;
305  $param .= '&search_mvt_num='.urlencode($search_mvt_num);
306  }
307  if (!empty($search_doc_ref)) {
308  $filter['t.doc_ref'] = $search_doc_ref;
309  $param .= '&search_doc_ref='.urlencode($search_doc_ref);
310  }
311  if (!empty($search_label_operation)) {
312  $filter['t.label_operation'] = $search_label_operation;
313  $param .= '&search_label_operation='.urlencode($search_label_operation);
314  }
315  if (!empty($search_direction)) {
316  $filter['t.sens'] = $search_direction;
317  $param .= '&search_direction='.urlencode($search_direction);
318  }
319  if (!empty($search_ledger_code)) {
320  $filter['t.code_journal'] = $search_ledger_code;
321  foreach ($search_ledger_code as $code) {
322  $param .= '&search_ledger_code[]='.urlencode($code);
323  }
324  }
325  if (!empty($search_debit)) {
326  $filter['t.debit'] = $search_debit;
327  $param .= '&search_debit='.urlencode($search_debit);
328  }
329  if (!empty($search_credit)) {
330  $filter['t.credit'] = $search_credit;
331  $param .= '&search_credit='.urlencode($search_credit);
332  }
333  if (!empty($search_lettering_code)) {
334  $filter['t.lettering_code'] = $search_lettering_code;
335  $param .= '&search_lettering_code='.urlencode($search_lettering_code);
336  }
337  if (!empty($search_not_reconciled)) {
338  $filter['t.reconciled_option'] = $search_not_reconciled;
339  $param .= '&search_not_reconciled='.urlencode($search_not_reconciled);
340  }
341  if (!empty($search_date_export_start)) {
342  $filter['t.date_export>='] = $search_date_export_start;
343  $param .= '&search_date_export_startmonth='.$search_date_export_startmonth.'&search_date_export_startday='.$search_date_export_startday.'&search_date_export_startyear='.$search_date_export_startyear;
344  }
345  if (!empty($search_date_export_end)) {
346  $filter['t.date_export<='] = $search_date_export_end;
347  $param .= '&search_date_export_endmonth='.$search_date_export_endmonth.'&search_date_export_endday='.$search_date_export_endday.'&search_date_export_endyear='.$search_date_export_endyear;
348  }
349  if (!empty($search_date_validation_start)) {
350  $filter['t.date_validated>='] = $search_date_validation_start;
351  $param .= '&search_date_validation_startmonth='.$search_date_validation_startmonth.'&search_date_validation_startday='.$search_date_validation_startday.'&search_date_validation_startyear='.$search_date_validation_startyear;
352  }
353  if (!empty($search_date_validation_end)) {
354  $filter['t.date_validated<='] = $search_date_validation_end;
355  $param .= '&search_date_validation_endmonth='.$search_date_validation_endmonth.'&search_date_validation_endday='.$search_date_validation_endday.'&search_date_validation_endyear='.$search_date_validation_endyear;
356  }
357  if (!empty($search_import_key)) {
358  $filter['t.import_key'] = $search_import_key;
359  $param .= '&search_import_key='.urlencode($search_import_key);
360  }
361 
362  // param with type of list
363  $url_param = substr($param, 1); // remove first "&"
364  if (!empty($type)) {
365  $param = '&type='.$type.$param;
366  }
367 
368  //if ($action == 'delbookkeepingyearconfirm' && $user->rights->accounting->mouvements->supprimer_tous) {
369  // $delmonth = GETPOST('delmonth', 'int');
370  // $delyear = GETPOST('delyear', 'int');
371  // if ($delyear == -1) {
372  // $delyear = 0;
373  // }
374  // $deljournal = GETPOST('deljournal', 'alpha');
375  // if ($deljournal == -1) {
376  // $deljournal = 0;
377  // }
378  //
379  // if (!empty($delmonth) || !empty($delyear) || !empty($deljournal)) {
380  // $result = $object->deleteByYearAndJournal($delyear, $deljournal, '', ($delmonth > 0 ? $delmonth : 0));
381  // if ($result < 0) {
382  // setEventMessages($object->error, $object->errors, 'errors');
383  // } else {
384  // setEventMessages("RecordDeleted", null, 'mesgs');
385  // }
386  //
387  // // Make a redirect to avoid to launch the delete later after a back button
388  // header("Location: ".$_SERVER["PHP_SELF"].($param ? '?'.$param : ''));
389  // exit;
390  // } else {
391  // setEventMessages("NoRecordDeleted", null, 'warnings');
392  // }
393  //}
394 
395  // Mass actions
396  $objectclass = 'Bookkeeping';
397  $objectlabel = 'Bookkeeping';
398  $permissiontoread = $user->hasRight('societe', 'lire');
399  $permissiontodelete = $user->hasRight('societe', 'supprimer');
400  $permissiontoadd = $user->rights->societe->creer;
401  $uploaddir = $conf->societe->dir_output;
402  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
403 
404  if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'supprimer')) {
405  $db->begin();
406 
407  if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
408  $lettering = new Lettering($db);
409  $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
410  if ($nb_lettering < 0) {
411  setEventMessages('', $lettering->errors, 'errors');
412  $error++;
413  }
414  }
415 
416  $nbok = 0;
417  if (!$error) {
418  foreach ($toselect as $toselectid) {
419  $result = $object->fetch($toselectid);
420  if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
421  $result = $object->deleteMvtNum($object->piece_num);
422  if ($result > 0) {
423  $nbok++;
424  } else {
425  setEventMessages($object->error, $object->errors, 'errors');
426  $error++;
427  break;
428  }
429  } elseif ($result < 0) {
430  setEventMessages($object->error, $object->errors, 'errors');
431  $error++;
432  break;
433  }
434  }
435  }
436 
437  if (!$error) {
438  $db->commit();
439 
440  // Message for elements well deleted
441  if ($nbok > 1) {
442  setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
443  } elseif ($nbok > 0) {
444  setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
445  } elseif (!$error) {
446  setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
447  }
448 
449  header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
450  exit;
451  } else {
452  $db->rollback();
453  }
454  }
455 
456  // others mass actions
457  if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) {
458  if ($massaction == 'letteringauto') {
459  $lettering = new Lettering($db);
460  $nb_lettering = $lettering->bookkeepingLetteringAll($toselect);
461  if ($nb_lettering < 0) {
462  setEventMessages('', $lettering->errors, 'errors');
463  $error++;
464  $nb_lettering = max(0, abs($nb_lettering) - 2);
465  } elseif ($nb_lettering == 0) {
466  $nb_lettering = 0;
467  setEventMessages($langs->trans('AccountancyNoLetteringModified'), array(), 'mesgs');
468  }
469  if ($nb_lettering == 1) {
470  setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
471  } elseif ($nb_lettering > 1) {
472  setEventMessages($langs->trans('AccountancyLetteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
473  }
474 
475  if (!$error) {
476  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
477  exit();
478  }
479  } elseif ($massaction == 'letteringmanual') {
480  $lettering = new Lettering($db);
481  $result = $lettering->updateLettering($toselect);
482  if ($result < 0) {
483  setEventMessages('', $lettering->errors, 'errors');
484  } else {
485  setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
486  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
487  exit();
488  }
489  } elseif ($action == 'unletteringauto' && $confirm == "yes") {
490  $lettering = new Lettering($db);
491  $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
492  if ($nb_lettering < 0) {
493  setEventMessages('', $lettering->errors, 'errors');
494  $error++;
495  $nb_lettering = max(0, abs($nb_lettering) - 2);
496  } elseif ($nb_lettering == 0) {
497  $nb_lettering = 0;
498  setEventMessages($langs->trans('AccountancyNoUnletteringModified'), array(), 'mesgs');
499  }
500  if ($nb_lettering == 1) {
501  setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
502  } elseif ($nb_lettering > 1) {
503  setEventMessages($langs->trans('AccountancyUnletteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
504  }
505 
506  if (!$error) {
507  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
508  exit();
509  }
510  } elseif ($action == 'unletteringmanual' && $confirm == "yes") {
511  $lettering = new Lettering($db);
512  $nb_lettering = $lettering->deleteLettering($toselect);
513  if ($result < 0) {
514  setEventMessages('', $lettering->errors, 'errors');
515  } else {
516  setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
517  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
518  exit();
519  }
520  }
521  }
522 }
523 
524 
525 /*
526  * View
527  */
528 
529 $formaccounting = new FormAccounting($db);
530 $formfile = new FormFile($db);
531 $formother = new FormOther($db);
532 $form = new Form($db);
533 
534 $title_page = $langs->trans("Operations").' - '.$langs->trans("VueByAccountAccounting").' (';
535 if ($type == 'sub') {
536  $title_page .= $langs->trans("BookkeepingSubAccount");
537 } else {
538  $title_page .= $langs->trans("Bookkeeping");
539 }
540 $title_page .= ')';
541 
542 llxHeader('', $title_page);
543 
544 // List
545 $nbtotalofrecords = '';
546 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
547  if ($type == 'sub') {
548  $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter, 'AND', 1);
549  } else {
550  $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter);
551  }
552 
553  if ($nbtotalofrecords < 0) {
554  setEventMessages($object->error, $object->errors, 'errors');
555  }
556 }
557 
558 if ($type == 'sub') {
559  $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter, 'AND', 1);
560 } else {
561  $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter);
562 }
563 
564 if ($result < 0) {
565  setEventMessages($object->error, $object->errors, 'errors');
566 }
567 
568 $arrayofselected = is_array($toselect) ? $toselect : array();
569 
570 $num = count($object->lines);
571 
572 
574 // $form_question = array();
575 // $delyear = GETPOST('delyear', 'int');
576 // $deljournal = GETPOST('deljournal', 'alpha');
577 //
578 // if (empty($delyear)) {
579 // $delyear = dol_print_date(dol_now(), '%Y');
580 // }
581 // $month_array = array();
582 // for ($i = 1; $i <= 12; $i++) {
583 // $month_array[$i] = $langs->trans("Month".sprintf("%02d", $i));
584 // }
585 // $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
586 // $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1);
587 //
588 // $form_question['delmonth'] = array(
589 // 'name' => 'delmonth',
590 // 'type' => 'select',
591 // 'label' => $langs->trans('DelMonth'),
592 // 'values' => $month_array,
593 // 'default' => ''
594 // );
595 // $form_question['delyear'] = array(
596 // 'name' => 'delyear',
597 // 'type' => 'select',
598 // 'label' => $langs->trans('DelYear'),
599 // 'values' => $year_array,
600 // 'default' => $delyear
601 // );
602 // $form_question['deljournal'] = array(
603 // 'name' => 'deljournal',
604 // 'type' => 'other', // We don't use select here, the journal_array is already a select html component
605 // 'label' => $langs->trans('DelJournal'),
606 // 'value' => $journal_array,
607 // 'default' => $deljournal
608 // );
609 //
610 // $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'delbookkeepingyearconfirm', $form_question, '', 1, 300);
611 //}
612 
613 // Print form confirm
615 print $formconfirm;
616 
617 // List of mass actions available
618 $arrayofmassactions = array();
619 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) {
620  $arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringAuto');
621  $arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringAuto');
622  $arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringManual');
623  $arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringManual');
624 }
625 if ($user->hasRight('accounting', 'mouvements', 'supprimer')) {
626  $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
627 }
628 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunletteringauto', 'preunletteringmanual', 'predeletebookkeepingwriting'))) {
629  $arrayofmassactions = array();
630 }
631 $massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions);
632 
633 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
634 print '<input type="hidden" name="token" value="'.newToken().'">';
635 print '<input type="hidden" name="action" value="list">';
636 if ($optioncss != '') {
637  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
638 }
639 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
640 print '<input type="hidden" name="type" value="'.$type.'">';
641 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
642 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
643 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
644 
645 $parameters = array('param' => $param);
646 $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
647 if ($reshook < 0) {
648  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
649 }
650 
651 $newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint;
652 
653 if (empty($reshook)) {
654  $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param);
655  if ($type == 'sub') {
656  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly'));
657  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?type=sub&' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
658  } else {
659  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
660  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?type=sub&' . $url_param, '', 1, array('morecss' => 'marginleftonly'));
661  }
662  $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=create');
663 }
664 
665 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
666  $param .= '&contextpage='.urlencode($contextpage);
667 }
668 if ($limit > 0 && $limit != $conf->liste_limit) {
669  $param .= '&limit='.urlencode($limit);
670 }
671 
672 print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $result, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
673 
674 if ($massaction == 'preunletteringauto') {
675  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringAuto"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringauto", null, '', 0, 200, 500, 1);
676 } elseif ($massaction == 'preunletteringmanual') {
677  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringManual"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringmanual", null, '', 0, 200, 500, 1);
678 } elseif ($massaction == 'predeletebookkeepingwriting') {
679  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
680 }
681 //DeleteMvt=Supprimer des lignes d'opérations de la comptabilité
682 //DelMonth=Mois à effacer
683 //DelYear=Année à supprimer
684 //DelJournal=Journal à supprimer
685 //ConfirmDeleteMvt=Cette action supprime les lignes des opérations pour l'année/mois et/ou pour le journal sélectionné (au moins un critère est requis). Vous devrez utiliser de nouveau la fonctionnalité '%s' pour retrouver vos écritures dans la comptabilité.
686 //ConfirmDeleteMvtPartial=Cette action supprime l'écriture de la comptabilité (toutes les lignes opérations liées à une même écriture seront effacées).
687 
688 //$topicmail = "Information";
689 //$modelmail = "accountingbookkeeping";
690 //$objecttmp = new BookKeeping($db);
691 //$trackid = 'bk'.$object->id;
692 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
693 
694 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
695 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
696 if ($massactionbutton && $contextpage != 'poslist') {
697  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
698 }
699 
700 // Reverse sort order
701 if (preg_match('/^asc/i', $sortorder)) {
702  $sortorder = "asc";
703 } else {
704  $sortorder = "desc";
705 }
706 
707 // Warning to explain why list of record is not consistent with the other list view (missing a lot of lines)
708 if ($type == 'sub') {
709  print info_admin($langs->trans("WarningRecordWithoutSubledgerAreExcluded"));
710 }
711 
712 $moreforfilter = '';
713 
714 // Accountancy account
715 $moreforfilter .= '<div class="divsearchfield">';
716 $moreforfilter .= $langs->trans('AccountAccounting').': ';
717 $moreforfilter .= '<div class="nowrap inline-block">';
718 if ($type == 'sub') {
719  $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), 'maxwidth200');
720 } else {
721  $moreforfilter .= $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200');
722 }
723 $moreforfilter .= ' ';
724 if ($type == 'sub') {
725  $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), 'maxwidth200');
726 } else {
727  $moreforfilter .= $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200');
728 }
729 $moreforfilter .= '</div>';
730 $moreforfilter .= '</div>';
731 
732 $parameters = array();
733 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
734 if (empty($reshook)) {
735  $moreforfilter .= $hookmanager->resPrint;
736 } else {
737  $moreforfilter = $hookmanager->resPrint;
738 }
739 
740 print '<div class="liste_titre liste_titre_bydiv centpercent">';
741 print $moreforfilter;
742 print '</div>';
743 
744 print '<div class="div-table-responsive">';
745 print '<table class="tagtable liste centpercent">';
746 
747 // Filters lines
748 print '<tr class="liste_titre_filter">';
749 // Action column
750 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
751  print '<td class="liste_titre center">';
752  $searchpicto = $form->showFilterButtons('left');
753  print $searchpicto;
754  print '</td>';
755 }
756 // Movement number
757 if (!empty($arrayfields['t.piece_num']['checked'])) {
758  print '<td class="liste_titre"><input type="text" name="search_mvt_num" class="width50" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
759 }
760 // Code journal
761 if (!empty($arrayfields['t.code_journal']['checked'])) {
762  print '<td class="liste_titre center">';
763  print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1, 'maxwidth75');
764  print '</td>';
765 }
766 // Date document
767 if (!empty($arrayfields['t.doc_date']['checked'])) {
768  print '<td class="liste_titre center">';
769  print '<div class="nowrap">';
770  print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
771  print '</div>';
772  print '<div class="nowrap">';
773  print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
774  print '</div>';
775  print '</td>';
776 }
777 // Ref document
778 if (!empty($arrayfields['t.doc_ref']['checked'])) {
779  print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"/></td>';
780 }
781 // Label operation
782 if (!empty($arrayfields['t.label_operation']['checked'])) {
783  print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_operation" value="'.dol_escape_htmltag($search_label_operation).'"/></td>';
784 }
785 // Debit
786 if (!empty($arrayfields['t.debit']['checked'])) {
787  print '<td class="liste_titre right"><input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'"></td>';
788 }
789 // Credit
790 if (!empty($arrayfields['t.credit']['checked'])) {
791  print '<td class="liste_titre right"><input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'"></td>';
792 }
793 // Lettering code
794 if (!empty($arrayfields['t.lettering_code']['checked'])) {
795  print '<td class="liste_titre center">';
796  print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
797  print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
798  print '</td>';
799 }
800 // Date export
801 if (!empty($arrayfields['t.date_export']['checked'])) {
802  print '<td class="liste_titre center">';
803  print '<div class="nowrap">';
804  print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
805  print '</div>';
806  print '<div class="nowrap">';
807  print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
808  print '</div>';
809  print '</td>';
810 }
811 // Date validation
812 if (!empty($arrayfields['t.date_validated']['checked'])) {
813  print '<td class="liste_titre center">';
814  print '<div class="nowrap">';
815  print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
816  print '</div>';
817  print '<div class="nowrap">';
818  print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
819  print '</div>';
820  print '</td>';
821 }
822 if (!empty($arrayfields['t.import_key']['checked'])) {
823  print '<td class="liste_titre center">';
824  print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
825  print '</td>';
826 }
827 
828 // Fields from hook
829 $parameters = array('arrayfields'=>$arrayfields);
830 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
831 print $hookmanager->resPrint;
832 
833 // Action column
834 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
835  print '<td class="liste_titre center">';
836  $searchpicto = $form->showFilterButtons();
837  print $searchpicto;
838  print '</td>';
839 }
840 print "</tr>\n";
841 
842 print '<tr class="liste_titre">';
843 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
844  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
845 }
846 if (!empty($arrayfields['t.piece_num']['checked'])) {
847  print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax80imp ');
848 }
849 if (!empty($arrayfields['t.code_journal']['checked'])) {
850  print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
851 }
852 if (!empty($arrayfields['t.doc_date']['checked'])) {
853  print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
854 }
855 if (!empty($arrayfields['t.doc_ref']['checked'])) {
856  print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
857 }
858 if (!empty($arrayfields['t.label_operation']['checked'])) {
859  print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
860 }
861 if (!empty($arrayfields['t.debit']['checked'])) {
862  print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
863 }
864 if (!empty($arrayfields['t.credit']['checked'])) {
865  print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
866 }
867 if (!empty($arrayfields['t.lettering_code']['checked'])) {
868  print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
869 }
870 if (!empty($arrayfields['t.date_export']['checked'])) {
871  print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center ');
872 }
873 if (!empty($arrayfields['t.date_validated']['checked'])) {
874  print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated", "", $param, '', $sortfield, $sortorder, 'center ');
875 }
876 if (!empty($arrayfields['t.import_key']['checked'])) {
877  print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER["PHP_SELF"], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
878 }
879 // Hook fields
880 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
881 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
882 print $hookmanager->resPrint;
883 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
884  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
885 }
886 print "</tr>\n";
887 
888 $displayed_account_number = null; // Start with undefined to be able to distinguish with empty
889 
890 // Loop on record
891 // --------------------------------------------------------------------
892 $i = 0;
893 
894 $totalarray = array();
895 $totalarray['val'] = array ();
896 $totalarray['nbfield'] = 0;
897 $total_debit = 0;
898 $total_credit = 0;
899 $sous_total_debit = 0;
900 $sous_total_credit = 0;
901 $totalarray['val']['totaldebit'] = 0;
902 $totalarray['val']['totalcredit'] = 0;
903 
904 while ($i < min($num, $limit)) {
905  $line = $object->lines[$i];
906 
907  $total_debit += $line->debit;
908  $total_credit += $line->credit;
909 
910  if ($type == 'sub') {
911  $accountg = length_accounta($line->subledger_account);
912  } else {
913  $accountg = length_accountg($line->numero_compte);
914  }
915  //if (empty($accountg)) $accountg = '-';
916 
917  $colspan = 0; // colspan before field 'label of operation'
918  $colspanend = 3; // colspan after debit/credit
919  if (!empty($arrayfields['t.piece_num']['checked'])) { $colspan++; }
920  if (!empty($arrayfields['t.code_journal']['checked'])) { $colspan++; }
921  if (!empty($arrayfields['t.doc_date']['checked'])) { $colspan++; }
922  if (!empty($arrayfields['t.doc_ref']['checked'])) { $colspan++; }
923  if (!empty($arrayfields['t.label_operation']['checked'])) { $colspan++; }
924  if (!empty($arrayfields['t.date_export']['checked'])) { $colspanend++; }
925  if (!empty($arrayfields['t.date_validating']['checked'])) { $colspanend++; }
926  if (!empty($arrayfields['t.lettering_code']['checked'])) { $colspanend++; }
927 
928  // Is it a break ?
929  if ($accountg != $displayed_account_number || !isset($displayed_account_number)) {
930  // Show a subtotal by accounting account
931  if (isset($displayed_account_number)) {
932  print '<tr class="liste_total">';
933  if ($type == 'sub') {
934  print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accounta($displayed_account_number) . ':</td>';
935  } else {
936  print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accountg($displayed_account_number) . ':</td>';
937  }
938  print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
939  print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
940  print '<td colspan="'.$colspanend.'"></td>';
941  print '</tr>';
942  // Show balance of last shown account
943  $balance = $sous_total_debit - $sous_total_credit;
944  print '<tr class="liste_total">';
945  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
946  if ($balance > 0) {
947  print '<td class="nowraponall right">';
948  print price($sous_total_debit - $sous_total_credit);
949  print '</td>';
950  print '<td></td>';
951  } else {
952  print '<td></td>';
953  print '<td class="nowraponall right">';
954  print price($sous_total_credit - $sous_total_debit);
955  print '</td>';
956  }
957  print '<td colspan="'.$colspanend.'"></td>';
958  print '</tr>';
959  }
960 
961  // Show the break account
962  print '<tr class="trforbreak">';
963  print '<td colspan="'.($totalarray['nbfield'] ? $totalarray['nbfield'] : count($arrayfields)+1).'" class="tdforbreak">';
964  if ($type == 'sub') {
965  if ($line->subledger_account != "" && $line->subledger_account != '-1') {
966  print $line->subledger_label . ' : ' . length_accounta($line->subledger_account);
967  } else {
968  // Should not happen: subledger account must be null or a non empty value
969  print '<span class="error">' . $langs->trans("Unknown");
970  if ($line->subledger_label) {
971  print ' (' . $line->subledger_label . ')';
972  $htmltext = 'EmptyStringForSubledgerAccountButSubledgerLabelDefined';
973  } else {
974  $htmltext = 'EmptyStringForSubledgerAccountAndSubledgerLabel';
975  }
976  print $form->textwithpicto('', $htmltext);
977  print '</span>';
978  }
979  } else {
980  if ($line->numero_compte != "" && $line->numero_compte != '-1') {
981  print length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte);
982  } else {
983  print '<span class="error">' . $langs->trans("Unknown") . '</span>';
984  }
985  }
986  print '</td>';
987  print '</tr>';
988 
989  $displayed_account_number = $accountg;
990  //if (empty($displayed_account_number)) $displayed_account_number='-';
991  $sous_total_debit = 0;
992  $sous_total_credit = 0;
993 
994  $colspan = 0;
995  }
996 
997  print '<tr class="oddeven">';
998  // Action column
999  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1000  print '<td class="nowraponall center">';
1001  if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1002  $selected = 0;
1003  if (in_array($line->id, $arrayofselected)) {
1004  $selected = 1;
1005  }
1006  print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
1007  }
1008  print '</td>';
1009  }
1010  // Piece number
1011  if (!empty($arrayfields['t.piece_num']['checked'])) {
1012  print '<td>';
1013  $object->id = $line->id;
1014  $object->piece_num = $line->piece_num;
1015  print $object->getNomUrl(1, '', 0, '', 1);
1016  print '</td>';
1017  if (!$i) {
1018  $totalarray['nbfield']++;
1019  }
1020  }
1021 
1022  // Journal code
1023  if (!empty($arrayfields['t.code_journal']['checked'])) {
1024  $accountingjournal = new AccountingJournal($db);
1025  $result = $accountingjournal->fetch('', $line->code_journal);
1026  $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
1027  print '<td class="center tdoverflowmax80">'.$journaltoshow.'</td>';
1028  if (!$i) {
1029  $totalarray['nbfield']++;
1030  }
1031  }
1032 
1033  // Document date
1034  if (!empty($arrayfields['t.doc_date']['checked'])) {
1035  print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
1036  if (!$i) {
1037  $totalarray['nbfield']++;
1038  }
1039  }
1040 
1041  // Document ref
1042  if (!empty($arrayfields['t.doc_ref']['checked'])) {
1043  if ($line->doc_type == 'customer_invoice') {
1044  $langs->loadLangs(array('bills'));
1045 
1046  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1047  $objectstatic = new Facture($db);
1048  $objectstatic->fetch($line->fk_doc);
1049  //$modulepart = 'facture';
1050 
1051  $filename = dol_sanitizeFileName($line->doc_ref);
1052  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1053  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1054  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1055  } elseif ($line->doc_type == 'supplier_invoice') {
1056  $langs->loadLangs(array('bills'));
1057 
1058  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1059  $objectstatic = new FactureFournisseur($db);
1060  $objectstatic->fetch($line->fk_doc);
1061  //$modulepart = 'invoice_supplier';
1062 
1063  $filename = dol_sanitizeFileName($line->doc_ref);
1064  $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1065  $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1066  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
1067  } elseif ($line->doc_type == 'expense_report') {
1068  $langs->loadLangs(array('trips'));
1069 
1070  require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1071  $objectstatic = new ExpenseReport($db);
1072  $objectstatic->fetch($line->fk_doc);
1073  //$modulepart = 'expensereport';
1074 
1075  $filename = dol_sanitizeFileName($line->doc_ref);
1076  $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1077  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1078  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1079  } elseif ($line->doc_type == 'bank') {
1080  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1081  $objectstatic = new AccountLine($db);
1082  $objectstatic->fetch($line->fk_doc);
1083  } else {
1084  // Other type
1085  }
1086 
1087  print '<td class="maxwidth400">';
1088 
1089  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1090  // Picto + Ref
1091  print '<td class="nobordernopadding">';
1092 
1093  if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
1094  print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1095  print $documentlink;
1096  } elseif ($line->doc_type == 'bank') {
1097  print $objectstatic->getNomUrl(1);
1098  $bank_ref = strstr($line->doc_ref, '-');
1099  print " " . $bank_ref;
1100  } else {
1101  print $line->doc_ref;
1102  }
1103  print '</td></tr></table>';
1104 
1105  print "</td>\n";
1106  if (!$i) {
1107  $totalarray['nbfield']++;
1108  }
1109  }
1110 
1111  // Label operation
1112  if (!empty($arrayfields['t.label_operation']['checked'])) {
1113  // Affiche un lien vers la facture client/fournisseur
1114  $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref);
1115  print strlen(length_accounta($line->subledger_account)) == 0 ? '<td>'.$line->label_operation.'</td>' : '<td>'.$line->label_operation.'<br><span style="font-size:0.8em">('.length_accounta($line->subledger_account).')</span></td>';
1116  if (!$i) {
1117  $totalarray['nbfield']++;
1118  }
1119  }
1120 
1121  // Amount debit
1122  if (!empty($arrayfields['t.debit']['checked'])) {
1123  print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
1124  if (!$i) {
1125  $totalarray['nbfield']++;
1126  }
1127  if (!$i) {
1128  $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
1129  }
1130  $totalarray['val']['totaldebit'] += $line->debit;
1131  }
1132 
1133  // Amount credit
1134  if (!empty($arrayfields['t.credit']['checked'])) {
1135  print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
1136  if (!$i) {
1137  $totalarray['nbfield']++;
1138  }
1139  if (!$i) {
1140  $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
1141  }
1142  $totalarray['val']['totalcredit'] += $line->credit;
1143  }
1144 
1145  // Lettering code
1146  if (!empty($arrayfields['t.lettering_code']['checked'])) {
1147  print '<td class="center">'.$line->lettering_code.'</td>';
1148  if (!$i) {
1149  $totalarray['nbfield']++;
1150  }
1151  }
1152 
1153  // Exported operation date
1154  if (!empty($arrayfields['t.date_export']['checked'])) {
1155  print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>';
1156  if (!$i) {
1157  $totalarray['nbfield']++;
1158  }
1159  }
1160 
1161  // Validated operation date
1162  if (!empty($arrayfields['t.date_validated']['checked'])) {
1163  print '<td class="center">'.dol_print_date($line->date_validation, 'dayhour').'</td>';
1164  if (!$i) {
1165  $totalarray['nbfield']++;
1166  }
1167  }
1168 
1169  if (!empty($arrayfields['t.import_key']['checked'])) {
1170  print '<td class="tdoverflowmax100">'.$line->import_key."</td>\n";
1171  if (!$i) {
1172  $totalarray['nbfield']++;
1173  }
1174  }
1175 
1176  // Fields from hook
1177  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$line);
1178  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1179  print $hookmanager->resPrint;
1180 
1181  // Action column
1182  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1183  print '<td class="nowraponall center">';
1184  if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1185  $selected = 0;
1186  if (in_array($line->id, $arrayofselected)) {
1187  $selected = 1;
1188  }
1189  print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
1190  }
1191  print '</td>';
1192  }
1193  if (!$i) {
1194  $totalarray['nbfield']++;
1195  }
1196 
1197  // Comptabilise le sous-total
1198  $sous_total_debit += $line->debit;
1199  $sous_total_credit += $line->credit;
1200 
1201  print "</tr>\n";
1202 
1203  $i++;
1204 }
1205 
1206 if ($num > 0 && $colspan > 0) {
1207  print '<tr class="liste_total">';
1208  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("TotalForAccount").' '.$accountg.':</td>';
1209  print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
1210  print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
1211  print '<td colspan="'.$colspanend.'"></td>';
1212  print '</tr>';
1213  // Show balance of last shown account
1214  $balance = $sous_total_debit - $sous_total_credit;
1215  print '<tr class="liste_total">';
1216  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
1217  if ($balance > 0) {
1218  print '<td class="nowraponall right">';
1219  print price($sous_total_debit - $sous_total_credit);
1220  print '</td>';
1221  print '<td></td>';
1222  } else {
1223  print '<td></td>';
1224  print '<td class="nowraponall right">';
1225  print price($sous_total_credit - $sous_total_debit);
1226  print '</td>';
1227  }
1228  print '<td colspan="'.$colspanend.'"></td>';
1229  print '</tr>';
1230 }
1231 
1232 // Show total line
1233 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1234 
1235 // If no record found
1236 if ($num == 0) {
1237  $colspan = 1;
1238  foreach ($arrayfields as $key => $val) {
1239  if (!empty($val['checked'])) {
1240  $colspan++;
1241  }
1242  }
1243  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1244 }
1245 
1246 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1247 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1248 print $hookmanager->resPrint;
1249 
1250 print "</table>";
1251 print '</div>';
1252 
1253 // TODO Replace this with mass delete action
1254 //if ($user->rights->accounting->mouvements->supprimer_tous) {
1255 // print '<div class="tabsAction tabsActionNoBottom">'."\n";
1256 // print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear&token='.newToken().($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>';
1257 // print '</div>';
1258 //}
1259 
1260 print '</form>';
1261 
1262 // End of page
1263 llxFooter();
1264 $db->close();
length_accounta
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Definition: accounting.lib.php:133
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2820
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:51
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
Facture
Class to manage invoices.
Definition: facture.class.php:60
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6735
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:614
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
AccountingJournal
Class to manage accounting accounts.
Definition: accountingjournal.class.php:27
dolGetButtonTitle
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.
Definition: functions.lib.php:11017
length_accountg
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Definition: accounting.lib.php:94
print_barre_liste
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.
Definition: functions.lib.php:5413
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:594
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4949
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
BookKeeping
Class to manage Ledger (General Ledger and Subledger)
Definition: bookkeeping.class.php:33
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:421
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5178
Lettering
Class Lettering.
Definition: lettering.class.php:34
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1755
ExpenseReport
Class to manage Trips and Expenses.
Definition: expensereport.class.php:36
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5697
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1120
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2863
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
$nbtotalofrecords
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329