dolibarr  16.0.5
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('param' => $param);
606 $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
607 if ($reshook < 0) {
608  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
609 }
610 
611 $newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint;
612 
613 if (empty($reshook)) {
614  $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param);
615  if ($type == 'sub') {
616  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly'));
617  $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'));
618  } else {
619  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
620  $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'));
621  }
622  $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=create');
623 }
624 
625 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
626  $param .= '&contextpage='.urlencode($contextpage);
627 }
628 if ($limit > 0 && $limit != $conf->liste_limit) {
629  $param .= '&limit='.urlencode($limit);
630 }
631 
632 print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $result, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
633 
634 if ($massaction == 'preunlettering') {
635  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnlettering"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unlettering", null, '', 0, 200, 500, 1);
636 } elseif ($massaction == 'predeletebookkeepingwriting') {
637  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
638 }
639 //DeleteMvt=Supprimer des lignes d'opérations de la comptabilité
640 //DelMonth=Mois à effacer
641 //DelYear=Année à supprimer
642 //DelJournal=Journal à supprimer
643 //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é.
644 //ConfirmDeleteMvtPartial=Cette action supprime l'écriture de la comptabilité (toutes les lignes opérations liées à une même écriture seront effacées).
645 
646 //$topicmail = "Information";
647 //$modelmail = "accountingbookkeeping";
648 //$objecttmp = new BookKeeping($db);
649 //$trackid = 'bk'.$object->id;
650 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
651 
652 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
653 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
654 if ($massactionbutton && $contextpage != 'poslist') {
655  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
656 }
657 
658 // Reverse sort order
659 if (preg_match('/^asc/i', $sortorder)) {
660  $sortorder = "asc";
661 } else {
662  $sortorder = "desc";
663 }
664 
665 // Warning to explain why list of record is not consistent with the other list view (missing a lot of lines)
666 if ($type == 'sub') {
667  print info_admin($langs->trans("WarningRecordWithoutSubledgerAreExcluded"));
668 }
669 
670 $moreforfilter = '';
671 
672 // Accountancy account
673 $moreforfilter .= '<div class="divsearchfield">';
674 $moreforfilter .= $langs->trans('AccountAccounting').': ';
675 $moreforfilter .= '<div class="nowrap inline-block">';
676 if ($type == 'sub') {
677  $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), 'maxwidth200');
678 } else {
679  $moreforfilter .= $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200');
680 }
681 $moreforfilter .= ' ';
682 if ($type == 'sub') {
683  $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), 'maxwidth200');
684 } else {
685  $moreforfilter .= $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200');
686 }
687 $moreforfilter .= '</div>';
688 $moreforfilter .= '</div>';
689 
690 $parameters = array();
691 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
692 if (empty($reshook)) {
693  $moreforfilter .= $hookmanager->resPrint;
694 } else {
695  $moreforfilter = $hookmanager->resPrint;
696 }
697 
698 print '<div class="liste_titre liste_titre_bydiv centpercent">';
699 print $moreforfilter;
700 print '</div>';
701 
702 print '<div class="div-table-responsive">';
703 print '<table class="tagtable liste centpercent">';
704 
705 // Filters lines
706 print '<tr class="liste_titre_filter">';
707 
708 // Movement number
709 if (!empty($arrayfields['t.piece_num']['checked'])) {
710  print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
711 }
712 // Code journal
713 if (!empty($arrayfields['t.code_journal']['checked'])) {
714  print '<td class="liste_titre center">';
715  print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1);
716  print '</td>';
717 }
718 // Date document
719 if (!empty($arrayfields['t.doc_date']['checked'])) {
720  print '<td class="liste_titre center">';
721  print '<div class="nowrap">';
722  print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
723  print '</div>';
724  print '<div class="nowrap">';
725  print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
726  print '</div>';
727  print '</td>';
728 }
729 // Ref document
730 if (!empty($arrayfields['t.doc_ref']['checked'])) {
731  print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"/></td>';
732 }
733 // Label operation
734 if (!empty($arrayfields['t.label_operation']['checked'])) {
735  print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_operation" value="'.dol_escape_htmltag($search_label_operation).'"/></td>';
736 }
737 // Debit
738 if (!empty($arrayfields['t.debit']['checked'])) {
739  print '<td class="liste_titre right"><input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'"></td>';
740 }
741 // Credit
742 if (!empty($arrayfields['t.credit']['checked'])) {
743  print '<td class="liste_titre right"><input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'"></td>';
744 }
745 // Lettering code
746 if (!empty($arrayfields['t.lettering_code']['checked'])) {
747  print '<td class="liste_titre center">';
748  print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
749  print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
750  print '</td>';
751 }
752 // Date export
753 if (!empty($arrayfields['t.date_export']['checked'])) {
754  print '<td class="liste_titre center">';
755  print '<div class="nowrap">';
756  print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
757  print '</div>';
758  print '<div class="nowrap">';
759  print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
760  print '</div>';
761  print '</td>';
762 }
763 // Date validation
764 if (!empty($arrayfields['t.date_validated']['checked'])) {
765  print '<td class="liste_titre center">';
766  print '<div class="nowrap">';
767  print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
768  print '</div>';
769  print '<div class="nowrap">';
770  print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
771  print '</div>';
772  print '</td>';
773 }
774 if (!empty($arrayfields['t.import_key']['checked'])) {
775  print '<td class="liste_titre center">';
776  print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
777  print '</td>';
778 }
779 
780 // Fields from hook
781 $parameters = array('arrayfields'=>$arrayfields);
782 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
783 print $hookmanager->resPrint;
784 
785 // Action column
786 print '<td class="liste_titre center">';
787 $searchpicto = $form->showFilterButtons();
788 print $searchpicto;
789 print '</td>';
790 print "</tr>\n";
791 
792 print '<tr class="liste_titre">';
793 if (!empty($arrayfields['t.piece_num']['checked'])) {
794  print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, '', $sortfield, $sortorder);
795 }
796 if (!empty($arrayfields['t.code_journal']['checked'])) {
797  print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
798 }
799 if (!empty($arrayfields['t.doc_date']['checked'])) {
800  print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
801 }
802 if (!empty($arrayfields['t.doc_ref']['checked'])) {
803  print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
804 }
805 if (!empty($arrayfields['t.label_operation']['checked'])) {
806  print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
807 }
808 if (!empty($arrayfields['t.debit']['checked'])) {
809  print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
810 }
811 if (!empty($arrayfields['t.credit']['checked'])) {
812  print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
813 }
814 if (!empty($arrayfields['t.lettering_code']['checked'])) {
815  print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
816 }
817 if (!empty($arrayfields['t.date_export']['checked'])) {
818  print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center ');
819 }
820 if (!empty($arrayfields['t.date_validated']['checked'])) {
821  print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated", "", $param, '', $sortfield, $sortorder, 'center ');
822 }
823 if (!empty($arrayfields['t.import_key']['checked'])) {
824  print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER["PHP_SELF"], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
825 }
826 // Hook fields
827 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
828 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
829 print $hookmanager->resPrint;
830 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
831 print "</tr>\n";
832 
833 $displayed_account_number = null; // Start with undefined to be able to distinguish with empty
834 
835 // Loop on record
836 // --------------------------------------------------------------------
837 $i = 0;
838 
839 $totalarray = array();
840 $totalarray['val'] = array ();
841 $totalarray['nbfield'] = 0;
842 $total_debit = 0;
843 $total_credit = 0;
844 $sous_total_debit = 0;
845 $sous_total_credit = 0;
846 $totalarray['val']['totaldebit'] = 0;
847 $totalarray['val']['totalcredit'] = 0;
848 
849 while ($i < min($num, $limit)) {
850  $line = $object->lines[$i];
851 
852  $total_debit += $line->debit;
853  $total_credit += $line->credit;
854 
855  if ($type == 'sub') {
856  $accountg = length_accounta($line->subledger_account);
857  } else {
858  $accountg = length_accountg($line->numero_compte);
859  }
860  //if (empty($accountg)) $accountg = '-';
861 
862  $colspan = 0; // colspan before field 'label of operation'
863  $colspanend = 3; // colspan after debit/credit
864  if (!empty($arrayfields['t.piece_num']['checked'])) { $colspan++; }
865  if (!empty($arrayfields['t.code_journal']['checked'])) { $colspan++; }
866  if (!empty($arrayfields['t.doc_date']['checked'])) { $colspan++; }
867  if (!empty($arrayfields['t.doc_ref']['checked'])) { $colspan++; }
868  if (!empty($arrayfields['t.label_operation']['checked'])) { $colspan++; }
869  if (!empty($arrayfields['t.date_export']['checked'])) { $colspanend++; }
870  if (!empty($arrayfields['t.date_validating']['checked'])) { $colspanend++; }
871  if (!empty($arrayfields['t.lettering_code']['checked'])) { $colspanend++; }
872 
873  // Is it a break ?
874  if ($accountg != $displayed_account_number || !isset($displayed_account_number)) {
875  // Show a subtotal by accounting account
876  if (isset($displayed_account_number)) {
877  print '<tr class="liste_total">';
878  if ($type == 'sub') {
879  print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accounta($displayed_account_number) . ':</td>';
880  } else {
881  print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accountg($displayed_account_number) . ':</td>';
882  }
883  print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
884  print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
885  print '<td colspan="'.$colspanend.'"></td>';
886  print '</tr>';
887  // Show balance of last shown account
888  $balance = $sous_total_debit - $sous_total_credit;
889  print '<tr class="liste_total">';
890  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
891  if ($balance > 0) {
892  print '<td class="nowraponall right">';
893  print price($sous_total_debit - $sous_total_credit);
894  print '</td>';
895  print '<td></td>';
896  } else {
897  print '<td></td>';
898  print '<td class="nowraponall right">';
899  print price($sous_total_credit - $sous_total_debit);
900  print '</td>';
901  }
902  print '<td colspan="'.$colspanend.'"></td>';
903  print '</tr>';
904  }
905 
906  // Show the break account
907  print '<tr class="trforbreak">';
908  print '<td colspan="'.($totalarray['nbfield'] ? $totalarray['nbfield'] : count($arrayfields)+1).'" class="tdforbreak">';
909  if ($type == 'sub') {
910  if ($line->subledger_account != "" && $line->subledger_account != '-1') {
911  print $line->subledger_label . ' : ' . length_accounta($line->subledger_account);
912  } else {
913  // Should not happen: subledger account must be null or a non empty value
914  print '<span class="error">' . $langs->trans("Unknown");
915  if ($line->subledger_label) {
916  print ' (' . $line->subledger_label . ')';
917  $htmltext = 'EmptyStringForSubledgerAccountButSubledgerLabelDefined';
918  } else {
919  $htmltext = 'EmptyStringForSubledgerAccountAndSubledgerLabel';
920  }
921  print $form->textwithpicto('', $htmltext);
922  print '</span>';
923  }
924  } else {
925  if ($line->numero_compte != "" && $line->numero_compte != '-1') {
926  print length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte);
927  } else {
928  print '<span class="error">' . $langs->trans("Unknown") . '</span>';
929  }
930  }
931  print '</td>';
932  print '</tr>';
933 
934  $displayed_account_number = $accountg;
935  //if (empty($displayed_account_number)) $displayed_account_number='-';
936  $sous_total_debit = 0;
937  $sous_total_credit = 0;
938 
939  $colspan = 0;
940  }
941 
942  print '<tr class="oddeven">';
943 
944  // Piece number
945  if (!empty($arrayfields['t.piece_num']['checked'])) {
946  print '<td>';
947  $object->id = $line->id;
948  $object->piece_num = $line->piece_num;
949  print $object->getNomUrl(1, '', 0, '', 1);
950  print '</td>';
951  if (!$i) {
952  $totalarray['nbfield']++;
953  }
954  }
955 
956  // Journal code
957  if (!empty($arrayfields['t.code_journal']['checked'])) {
958  $accountingjournal = new AccountingJournal($db);
959  $result = $accountingjournal->fetch('', $line->code_journal);
960  $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
961  print '<td class="center">'.$journaltoshow.'</td>';
962  if (!$i) {
963  $totalarray['nbfield']++;
964  }
965  }
966 
967  // Document date
968  if (!empty($arrayfields['t.doc_date']['checked'])) {
969  print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
970  if (!$i) {
971  $totalarray['nbfield']++;
972  }
973  }
974 
975  // Document ref
976  if (!empty($arrayfields['t.doc_ref']['checked'])) {
977  if ($line->doc_type == 'customer_invoice') {
978  $langs->loadLangs(array('bills'));
979 
980  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
981  $objectstatic = new Facture($db);
982  $objectstatic->fetch($line->fk_doc);
983  //$modulepart = 'facture';
984 
985  $filename = dol_sanitizeFileName($line->doc_ref);
986  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
987  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
988  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
989  } elseif ($line->doc_type == 'supplier_invoice') {
990  $langs->loadLangs(array('bills'));
991 
992  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
993  $objectstatic = new FactureFournisseur($db);
994  $objectstatic->fetch($line->fk_doc);
995  //$modulepart = 'invoice_supplier';
996 
997  $filename = dol_sanitizeFileName($line->doc_ref);
998  $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
999  $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1000  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
1001  } elseif ($line->doc_type == 'expense_report') {
1002  $langs->loadLangs(array('trips'));
1003 
1004  require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1005  $objectstatic = new ExpenseReport($db);
1006  $objectstatic->fetch($line->fk_doc);
1007  //$modulepart = 'expensereport';
1008 
1009  $filename = dol_sanitizeFileName($line->doc_ref);
1010  $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1011  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1012  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1013  } elseif ($line->doc_type == 'bank') {
1014  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1015  $objectstatic = new AccountLine($db);
1016  $objectstatic->fetch($line->fk_doc);
1017  } else {
1018  // Other type
1019  }
1020 
1021  print '<td class="maxwidth400">';
1022 
1023  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1024  // Picto + Ref
1025  print '<td class="nobordernopadding">';
1026 
1027  if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
1028  print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1029  print $documentlink;
1030  } elseif ($line->doc_type == 'bank') {
1031  print $objectstatic->getNomUrl(1);
1032  $bank_ref = strstr($line->doc_ref, '-');
1033  print " " . $bank_ref;
1034  } else {
1035  print $line->doc_ref;
1036  }
1037  print '</td></tr></table>';
1038 
1039  print "</td>\n";
1040  if (!$i) {
1041  $totalarray['nbfield']++;
1042  }
1043  }
1044 
1045  // Label operation
1046  if (!empty($arrayfields['t.label_operation']['checked'])) {
1047  // Affiche un lien vers la facture client/fournisseur
1048  $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref);
1049  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>';
1050  if (!$i) {
1051  $totalarray['nbfield']++;
1052  }
1053  }
1054 
1055  // Amount debit
1056  if (!empty($arrayfields['t.debit']['checked'])) {
1057  print '<td class="right nowraponall amount">'.($line->debit ? price($line->debit) : '').'</td>';
1058  if (!$i) {
1059  $totalarray['nbfield']++;
1060  }
1061  if (!$i) {
1062  $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
1063  }
1064  $totalarray['val']['totaldebit'] += $line->debit;
1065  }
1066 
1067  // Amount credit
1068  if (!empty($arrayfields['t.credit']['checked'])) {
1069  print '<td class="right nowraponall amount">'.($line->credit ? price($line->credit) : '').'</td>';
1070  if (!$i) {
1071  $totalarray['nbfield']++;
1072  }
1073  if (!$i) {
1074  $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
1075  }
1076  $totalarray['val']['totalcredit'] += $line->credit;
1077  }
1078 
1079  // Lettering code
1080  if (!empty($arrayfields['t.lettering_code']['checked'])) {
1081  print '<td class="center">'.$line->lettering_code.'</td>';
1082  if (!$i) {
1083  $totalarray['nbfield']++;
1084  }
1085  }
1086 
1087  // Exported operation date
1088  if (!empty($arrayfields['t.date_export']['checked'])) {
1089  print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>';
1090  if (!$i) {
1091  $totalarray['nbfield']++;
1092  }
1093  }
1094 
1095  // Validated operation date
1096  if (!empty($arrayfields['t.date_validated']['checked'])) {
1097  print '<td class="center">'.dol_print_date($line->date_validation, 'dayhour').'</td>';
1098  if (!$i) {
1099  $totalarray['nbfield']++;
1100  }
1101  }
1102 
1103  if (!empty($arrayfields['t.import_key']['checked'])) {
1104  print '<td class="tdoverflowmax100">'.$line->import_key."</td>\n";
1105  if (!$i) {
1106  $totalarray['nbfield']++;
1107  }
1108  }
1109 
1110  // Fields from hook
1111  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$line);
1112  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1113  print $hookmanager->resPrint;
1114 
1115  // Action column
1116  print '<td class="nowraponall center">';
1117  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
1118  $selected = 0;
1119  if (in_array($line->id, $arrayofselected)) {
1120  $selected = 1;
1121  }
1122  print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
1123  }
1124  print '</td>';
1125  if (!$i) {
1126  $totalarray['nbfield']++;
1127  }
1128 
1129  // Comptabilise le sous-total
1130  $sous_total_debit += $line->debit;
1131  $sous_total_credit += $line->credit;
1132 
1133  print "</tr>\n";
1134 
1135  $i++;
1136 }
1137 
1138 if ($num > 0 && $colspan > 0) {
1139  print '<tr class="liste_total">';
1140  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("TotalForAccount").' '.$accountg.':</td>';
1141  print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
1142  print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
1143  print '<td colspan="'.$colspanend.'"></td>';
1144  print '</tr>';
1145  // Show balance of last shown account
1146  $balance = $sous_total_debit - $sous_total_credit;
1147  print '<tr class="liste_total">';
1148  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
1149  if ($balance > 0) {
1150  print '<td class="nowraponall right">';
1151  print price($sous_total_debit - $sous_total_credit);
1152  print '</td>';
1153  print '<td></td>';
1154  } else {
1155  print '<td></td>';
1156  print '<td class="nowraponall right">';
1157  print price($sous_total_credit - $sous_total_debit);
1158  print '</td>';
1159  }
1160  print '<td colspan="'.$colspanend.'"></td>';
1161  print '</tr>';
1162 }
1163 
1164 // Show total line
1165 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1166 
1167 
1168 print "</table>";
1169 print '</div>';
1170 
1171 // TODO Replace this with mass delete action
1172 //if ($user->rights->accounting->mouvements->supprimer_tous) {
1173 // print '<div class="tabsAction tabsActionNoBottom">'."\n";
1174 // print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear&token='.newToken().($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>';
1175 // print '</div>';
1176 //}
1177 
1178 print '</form>';
1179 
1180 // End of page
1181 llxFooter();
1182 $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:2713
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
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:6549
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
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:10605
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:5257
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
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:570
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
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:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
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:52
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1779
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:2845
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59