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