dolibarr  17.0.4
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
4  * Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
5  * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
6  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array("accountancy", "compta"));
43 
44 $socid = GETPOST('socid', 'int');
45 
46 $action = GETPOST('action', 'aZ09');
47 $massaction = GETPOST('massaction', 'alpha');
48 $confirm = GETPOST('confirm', 'alpha');
49 $toselect = GETPOST('toselect', 'array');
50 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bookkeepinglist';
51 $search_mvt_num = GETPOST('search_mvt_num', 'int');
52 $search_doc_type = GETPOST("search_doc_type", 'alpha');
53 $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
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_creation_startyear = GETPOST('search_date_creation_startyear', 'int');
64 $search_date_creation_startmonth = GETPOST('search_date_creation_startmonth', 'int');
65 $search_date_creation_startday = GETPOST('search_date_creation_startday', 'int');
66 $search_date_creation_endyear = GETPOST('search_date_creation_endyear', 'int');
67 $search_date_creation_endmonth = GETPOST('search_date_creation_endmonth', 'int');
68 $search_date_creation_endday = GETPOST('search_date_creation_endday', 'int');
69 $search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear);
70 $search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear);
71 $search_date_modification_startyear = GETPOST('search_date_modification_startyear', 'int');
72 $search_date_modification_startmonth = GETPOST('search_date_modification_startmonth', 'int');
73 $search_date_modification_startday = GETPOST('search_date_modification_startday', 'int');
74 $search_date_modification_endyear = GETPOST('search_date_modification_endyear', 'int');
75 $search_date_modification_endmonth = GETPOST('search_date_modification_endmonth', 'int');
76 $search_date_modification_endday = GETPOST('search_date_modification_endday', 'int');
77 $search_date_modification_start = dol_mktime(0, 0, 0, $search_date_modification_startmonth, $search_date_modification_startday, $search_date_modification_startyear);
78 $search_date_modification_end = dol_mktime(23, 59, 59, $search_date_modification_endmonth, $search_date_modification_endday, $search_date_modification_endyear);
79 $search_date_export_startyear = GETPOST('search_date_export_startyear', 'int');
80 $search_date_export_startmonth = GETPOST('search_date_export_startmonth', 'int');
81 $search_date_export_startday = GETPOST('search_date_export_startday', 'int');
82 $search_date_export_endyear = GETPOST('search_date_export_endyear', 'int');
83 $search_date_export_endmonth = GETPOST('search_date_export_endmonth', 'int');
84 $search_date_export_endday = GETPOST('search_date_export_endday', 'int');
85 $search_date_export_start = dol_mktime(0, 0, 0, $search_date_export_startmonth, $search_date_export_startday, $search_date_export_startyear);
86 $search_date_export_end = dol_mktime(23, 59, 59, $search_date_export_endmonth, $search_date_export_endday, $search_date_export_endyear);
87 $search_date_validation_startyear = GETPOST('search_date_validation_startyear', 'int');
88 $search_date_validation_startmonth = GETPOST('search_date_validation_startmonth', 'int');
89 $search_date_validation_startday = GETPOST('search_date_validation_startday', 'int');
90 $search_date_validation_endyear = GETPOST('search_date_validation_endyear', 'int');
91 $search_date_validation_endmonth = GETPOST('search_date_validation_endmonth', 'int');
92 $search_date_validation_endday = GETPOST('search_date_validation_endday', 'int');
93 $search_date_validation_start = dol_mktime(0, 0, 0, $search_date_validation_startmonth, $search_date_validation_startday, $search_date_validation_startyear);
94 $search_date_validation_end = dol_mktime(23, 59, 59, $search_date_validation_endmonth, $search_date_validation_endday, $search_date_validation_endyear);
95 $search_import_key = GETPOST("search_import_key", 'alpha');
96 
97 //var_dump($search_date_start);exit;
98 if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
99  $action = 'delbookkeepingyear';
100 }
101 if (GETPOST("button_export_file_x") || GETPOST("button_export_file.x") || GETPOST("button_export_file")) {
102  $action = 'export_file';
103 }
104 
105 $search_accountancy_code = GETPOST("search_accountancy_code");
106 $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
107 if ($search_accountancy_code_start == - 1) {
108  $search_accountancy_code_start = '';
109 }
110 $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
111 if ($search_accountancy_code_end == - 1) {
112  $search_accountancy_code_end = '';
113 }
114 
115 $search_accountancy_aux_code = GETPOST("search_accountancy_aux_code", 'alpha');
116 $search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha');
117 if ($search_accountancy_aux_code_start == - 1) {
118  $search_accountancy_aux_code_start = '';
119 }
120 $search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha');
121 if ($search_accountancy_aux_code_end == - 1) {
122  $search_accountancy_aux_code_end = '';
123 }
124 $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
125 $search_direction = GETPOST('search_direction', 'alpha');
126 $search_debit = GETPOST('search_debit', 'alpha');
127 $search_credit = GETPOST('search_credit', 'alpha');
128 $search_ledger_code = GETPOST('search_ledger_code', 'array');
129 $search_lettering_code = GETPOST('search_lettering_code', 'alpha');
130 $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha');
131 
132 // Load variable for pagination
133 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
134 $sortfield = GETPOST('sortfield', 'aZ09comma');
135 $sortorder = GETPOST('sortorder', 'aZ09comma');
136 $optioncss = GETPOST('optioncss', 'alpha');
137 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
138 if (empty($page) || $page < 0) {
139  $page = 0;
140 }
141 $offset = $limit * $page;
142 $pageprev = $page - 1;
143 $pagenext = $page + 1;
144 if ($sortorder == "") {
145  $sortorder = "ASC";
146 }
147 if ($sortfield == "") {
148  $sortfield = "t.piece_num,t.rowid";
149 }
150 
151 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
152 $object = new BookKeeping($db);
153 $hookmanager->initHooks(array('bookkeepinglist'));
154 
155 $formaccounting = new FormAccounting($db);
156 $form = new Form($db);
157 
158 if (!in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && !GETPOSTISSET('begin') && !GETPOSTISSET('formfilteraction') && GETPOST('page', 'int') == '' && !GETPOST('noreset', 'int') && $user->hasRight('accounting', 'mouvements', 'export')) {
159  if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('restore_lastsearch_values') && !GETPOST('search_accountancy_code_start')) {
160  $query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
161  $query .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1";
162  $res = $db->query($query);
163 
164  if ($res->num_rows > 0) {
165  $fiscalYear = $db->fetch_object($res);
166  $search_date_start = strtotime($fiscalYear->date_start);
167  $search_date_end = strtotime($fiscalYear->date_end);
168  } else {
169  $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
170  $year_start = dol_print_date(dol_now(), '%Y');
171  if (dol_print_date(dol_now(), '%m') < $month_start) {
172  $year_start--; // If current month is lower that starting fiscal month, we start last year
173  }
174  $year_end = $year_start + 1;
175  $month_end = $month_start - 1;
176  if ($month_end < 1) {
177  $month_end = 12;
178  $year_end--;
179  }
180  $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
181  $search_date_end = dol_get_last_day($year_end, $month_end);
182  }
183  }
184 }
185 
186 
187 $arrayfields = array(
188  't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1),
189  't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
190  't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1),
191  't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1),
192  't.numero_compte'=>array('label'=>$langs->trans("AccountAccountingShort"), 'checked'=>1),
193  't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
194  't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
195  't.debit'=>array('label'=>$langs->trans("AccountingDebit"), 'checked'=>1),
196  't.credit'=>array('label'=>$langs->trans("AccountingCredit"), 'checked'=>1),
197  't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1),
198  't.date_creation'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0),
199  't.tms'=>array('label'=>$langs->trans("DateModification"), 'checked'=>0),
200  't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1),
201  't.date_validated'=>array('label'=>$langs->trans("DateValidationAndLock"), 'checked'=>1, 'enabled'=>!getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")),
202  't.import_key'=>array('label'=>$langs->trans("ImportId"), 'checked'=>0, 'position'=>1100),
203 );
204 
205 if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) {
206  unset($arrayfields['t.lettering_code']);
207 }
208 
209 $accountancyexport = new AccountancyExport($db);
210 $listofformat = $accountancyexport->getType();
211 $formatexportset = getDolGlobalString('ACCOUNTING_EXPORT_MODELCSV');
212 if (empty($listofformat[$formatexportset])) {
213  $formatexportset = 1;
214 }
215 
216 $error = 0;
217 
218 if (!isModEnabled('accounting')) {
219  accessforbidden();
220 }
221 if ($user->socid > 0) {
222  accessforbidden();
223 }
224 if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
225  accessforbidden();
226 }
227 
228 
229 /*
230  * Actions
231  */
232 
233 $param = '';
234 
235 if (GETPOST('cancel', 'alpha')) {
236  $action = 'list'; $massaction = '';
237 }
238 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunletteringauto' && $massaction != 'preunletteringmanual' && $massaction != 'predeletebookkeepingwriting') {
239  $massaction = '';
240 }
241 
242 $parameters = array('socid'=>$socid);
243 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
244 if ($reshook < 0) {
245  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
246 }
247 
248 if (empty($reshook)) {
249  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
250 
251  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
252  $search_mvt_num = '';
253  $search_doc_type = '';
254  $search_doc_ref = '';
255  $search_doc_date = '';
256  $search_accountancy_code = '';
257  $search_accountancy_code_start = '';
258  $search_accountancy_code_end = '';
259  $search_accountancy_aux_code = '';
260  $search_accountancy_aux_code_start = '';
261  $search_accountancy_aux_code_end = '';
262  $search_mvt_label = '';
263  $search_direction = '';
264  $search_ledger_code = array();
265  $search_date_startyear = '';
266  $search_date_startmonth = '';
267  $search_date_startday = '';
268  $search_date_endyear = '';
269  $search_date_endmonth = '';
270  $search_date_endday = '';
271  $search_date_start = '';
272  $search_date_end = '';
273  $search_date_creation_startyear = '';
274  $search_date_creation_startmonth = '';
275  $search_date_creation_startday = '';
276  $search_date_creation_endyear = '';
277  $search_date_creation_endmonth = '';
278  $search_date_creation_endday = '';
279  $search_date_creation_start = '';
280  $search_date_creation_end = '';
281  $search_date_modification_startyear = '';
282  $search_date_modification_startmonth = '';
283  $search_date_modification_startday = '';
284  $search_date_modification_endyear = '';
285  $search_date_modification_endmonth = '';
286  $search_date_modification_endday = '';
287  $search_date_modification_start = '';
288  $search_date_modification_end = '';
289  $search_date_export_startyear = '';
290  $search_date_export_startmonth = '';
291  $search_date_export_startday = '';
292  $search_date_export_endyear = '';
293  $search_date_export_endmonth = '';
294  $search_date_export_endday = '';
295  $search_date_export_start = '';
296  $search_date_export_end = '';
297  $search_date_validation_startyear = '';
298  $search_date_validation_startmonth = '';
299  $search_date_validation_startday = '';
300  $search_date_validation_endyear = '';
301  $search_date_validation_endmonth = '';
302  $search_date_validation_endday = '';
303  $search_date_validation_start = '';
304  $search_date_validation_end = '';
305  $search_debit = '';
306  $search_credit = '';
307  $search_lettering_code = '';
308  $search_not_reconciled = '';
309  $search_import_key = '';
310  $toselect = array();
311  }
312 
313  // Must be after the remove filter action, before the export.
314  $filter = array();
315  if (!empty($search_date_start)) {
316  $filter['t.doc_date>='] = $search_date_start;
317  $tmp = dol_getdate($search_date_start);
318  $param .= '&search_date_startmonth='.urlencode($tmp['mon']).'&search_date_startday='.urlencode($tmp['mday']).'&search_date_startyear='.urlencode($tmp['year']);
319  }
320  if (!empty($search_date_end)) {
321  $filter['t.doc_date<='] = $search_date_end;
322  $tmp = dol_getdate($search_date_end);
323  $param .= '&search_date_endmonth='.urlencode($tmp['mon']).'&search_date_endday='.urlencode($tmp['mday']).'&search_date_endyear='.urlencode($tmp['year']);
324  }
325  if (!empty($search_doc_date)) {
326  $filter['t.doc_date'] = $search_doc_date;
327  $tmp = dol_getdate($search_doc_date);
328  $param .= '&doc_datemonth='.urlencode($tmp['mon']).'&doc_dateday='.urlencode($tmp['mday']).'&doc_dateyear='.urlencode($tmp['year']);
329  }
330  if (!empty($search_doc_type)) {
331  $filter['t.doc_type'] = $search_doc_type;
332  $param .= '&search_doc_type='.urlencode($search_doc_type);
333  }
334  if (!empty($search_doc_ref)) {
335  $filter['t.doc_ref'] = $search_doc_ref;
336  $param .= '&search_doc_ref='.urlencode($search_doc_ref);
337  }
338  if (!empty($search_accountancy_code)) {
339  $filter['t.numero_compte'] = $search_accountancy_code;
340  $param .= '&search_accountancy_code='.urlencode($search_accountancy_code);
341  }
342  if (!empty($search_accountancy_code_start)) {
343  $filter['t.numero_compte>='] = $search_accountancy_code_start;
344  $param .= '&search_accountancy_code_start='.urlencode($search_accountancy_code_start);
345  }
346  if (!empty($search_accountancy_code_end)) {
347  $filter['t.numero_compte<='] = $search_accountancy_code_end;
348  $param .= '&search_accountancy_code_end='.urlencode($search_accountancy_code_end);
349  }
350  if (!empty($search_accountancy_aux_code)) {
351  $filter['t.subledger_account'] = $search_accountancy_aux_code;
352  $param .= '&search_accountancy_aux_code='.urlencode($search_accountancy_aux_code);
353  }
354  if (!empty($search_accountancy_aux_code_start)) {
355  $filter['t.subledger_account>='] = $search_accountancy_aux_code_start;
356  $param .= '&search_accountancy_aux_code_start='.urlencode($search_accountancy_aux_code_start);
357  }
358  if (!empty($search_accountancy_aux_code_end)) {
359  $filter['t.subledger_account<='] = $search_accountancy_aux_code_end;
360  $param .= '&search_accountancy_aux_code_end='.urlencode($search_accountancy_aux_code_end);
361  }
362  if (!empty($search_mvt_label)) {
363  $filter['t.label_operation'] = $search_mvt_label;
364  $param .= '&search_mvt_label='.urlencode($search_mvt_label);
365  }
366  if (!empty($search_direction)) {
367  $filter['t.sens'] = $search_direction;
368  $param .= '&search_direction='.urlencode($search_direction);
369  }
370  if (!empty($search_ledger_code)) {
371  $filter['t.code_journal'] = $search_ledger_code;
372  foreach ($search_ledger_code as $code) {
373  $param .= '&search_ledger_code[]='.urlencode($code);
374  }
375  }
376  if (!empty($search_mvt_num)) {
377  $filter['t.piece_num'] = $search_mvt_num;
378  $param .= '&search_mvt_num='.urlencode($search_mvt_num);
379  }
380  if (!empty($search_date_creation_start)) {
381  $filter['t.date_creation>='] = $search_date_creation_start;
382  $tmp = dol_getdate($search_date_creation_start);
383  $param .= '&search_date_creation_startmonth='.urlencode($tmp['mon']).'&search_date_creation_startday='.urlencode($tmp['mday']).'&search_date_creation_startyear='.urlencode($tmp['year']);
384  }
385  if (!empty($search_date_creation_end)) {
386  $filter['t.date_creation<='] = $search_date_creation_end;
387  $tmp = dol_getdate($search_date_creation_end);
388  $param .= '&search_date_creation_endmonth='.urlencode($tmp['mon']).'&search_date_creation_endday='.urlencode($tmp['mday']).'&search_date_creation_endyear='.urlencode($tmp['year']);
389  }
390  if (!empty($search_date_modification_start)) {
391  $filter['t.tms>='] = $search_date_modification_start;
392  $tmp = dol_getdate($search_date_modification_start);
393  $param .= '&search_date_modification_startmonth='.urlencode($tmp['mon']).'&search_date_modification_startday='.urlencode($tmp['mday']).'&search_date_modification_startyear='.urlencode($tmp['year']);
394  }
395  if (!empty($search_date_modification_end)) {
396  $filter['t.tms<='] = $search_date_modification_end;
397  $tmp = dol_getdate($search_date_modification_end);
398  $param .= '&search_date_modification_endmonth='.urlencode($tmp['mon']).'&search_date_modification_endday='.urlencode($tmp['mday']).'&search_date_modification_endyear='.urlencode($tmp['year']);
399  }
400  if (!empty($search_date_export_start)) {
401  $filter['t.date_export>='] = $search_date_export_start;
402  $tmp = dol_getdate($search_date_export_start);
403  $param .= '&search_date_export_startmonth='.urlencode($tmp['mon']).'&search_date_export_startday='.urlencode($tmp['mday']).'&search_date_export_startyear='.urlencode($tmp['year']);
404  }
405  if (!empty($search_date_export_end)) {
406  $filter['t.date_export<='] = $search_date_export_end;
407  $tmp = dol_getdate($search_date_export_end);
408  $param .= '&search_date_export_endmonth='.urlencode($tmp['mon']).'&search_date_export_endday='.urlencode($tmp['mday']).'&search_date_export_endyear='.urlencode($tmp['year']);
409  }
410  if (!empty($search_date_validation_start)) {
411  $filter['t.date_validated>='] = $search_date_validation_start;
412  $tmp = dol_getdate($search_date_validation_start);
413  $param .= '&search_date_validation_startmonth='.urlencode($tmp['mon']).'&search_date_validation_startday='.urlencode($tmp['mday']).'&search_date_validation_startyear='.urlencode($tmp['year']);
414  }
415  if (!empty($search_date_validation_end)) {
416  $filter['t.date_validated<='] = $search_date_validation_end;
417  $tmp = dol_getdate($search_date_validation_end);
418  $param .= '&search_date_validation_endmonth='.urlencode($tmp['mon']).'&search_date_validation_endday='.urlencode($tmp['mday']).'&search_date_validation_endyear='.urlencode($tmp['year']);
419  }
420  if (!empty($search_debit)) {
421  $filter['t.debit'] = $search_debit;
422  $param .= '&search_debit='.urlencode($search_debit);
423  }
424  if (!empty($search_credit)) {
425  $filter['t.credit'] = $search_credit;
426  $param .= '&search_credit='.urlencode($search_credit);
427  }
428  if (!empty($search_lettering_code)) {
429  $filter['t.lettering_code'] = $search_lettering_code;
430  $param .= '&search_lettering_code='.urlencode($search_lettering_code);
431  }
432  if (!empty($search_not_reconciled)) {
433  $filter['t.reconciled_option'] = $search_not_reconciled;
434  $param .= '&search_not_reconciled='.urlencode($search_not_reconciled);
435  }
436  if (!empty($search_import_key)) {
437  $filter['t.import_key'] = $search_import_key;
438  $param .= '&search_import_key='.urlencode($search_import_key);
439  }
440 
441  //if ($action == 'delbookkeepingyearconfirm' && !$user->hasRight('accounting', 'mouvements', 'supprimer_tous')) {
442  // $delmonth = GETPOST('delmonth', 'int');
443  // $delyear = GETPOST('delyear', 'int');
444  // if ($delyear == -1) {
445  // $delyear = 0;
446  // }
447  // $deljournal = GETPOST('deljournal', 'alpha');
448  // if ($deljournal == -1) {
449  // $deljournal = 0;
450  // }
451  //
452  // if (!empty($delmonth) || !empty($delyear) || !empty($deljournal)) {
453  // $result = $object->deleteByYearAndJournal($delyear, $deljournal, '', ($delmonth > 0 ? $delmonth : 0));
454  // if ($result < 0) {
455  // setEventMessages($object->error, $object->errors, 'errors');
456  // } else {
457  // setEventMessages("RecordDeleted", null, 'mesgs');
458  // }
459  //
460  // // Make a redirect to avoid to launch the delete later after a back button
461  // header("Location: list.php".($param ? '?'.$param : ''));
462  // exit;
463  // } else {
464  // setEventMessages("NoRecordDeleted", null, 'warnings');
465  // }
466  //}
467  if ($action == 'setreexport') {
468  $setreexport = GETPOST('value', 'int');
469  if (!dolibarr_set_const($db, "ACCOUNTING_REEXPORT", $setreexport, 'yesno', 0, '', $conf->entity)) {
470  $error++;
471  }
472 
473  if (!$error) {
474  if ($conf->global->ACCOUNTING_REEXPORT == 1) {
475  setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsEnable"), null, 'mesgs');
476  } else {
477  setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsDisable"), null, 'warnings');
478  }
479  } else {
480  setEventMessages($langs->trans("Error"), null, 'errors');
481  }
482  }
483 
484  // Mass actions
485  $objectclass = 'Bookkeeping';
486  $objectlabel = 'Bookkeeping';
487  $permissiontoread = $user->hasRight('societe', 'lire');
488  $permissiontodelete = $user->hasRight('societe', 'supprimer');
489  $permissiontoadd = $user->rights->societe->creer;
490  $uploaddir = $conf->societe->dir_output;
491  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
492 
493  if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'supprimer')) {
494  $db->begin();
495 
496  if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
497  $lettering = new Lettering($db);
498  $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
499  if ($nb_lettering < 0) {
500  setEventMessages('', $lettering->errors, 'errors');
501  $error++;
502  }
503  }
504 
505  $nbok = 0;
506  if (!$error) {
507  foreach ($toselect as $toselectid) {
508  $result = $object->fetch($toselectid);
509  if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
510  $result = $object->deleteMvtNum($object->piece_num);
511  if ($result > 0) {
512  $nbok++;
513  } else {
514  setEventMessages($object->error, $object->errors, 'errors');
515  $error++;
516  break;
517  }
518  } elseif ($result < 0) {
519  setEventMessages($object->error, $object->errors, 'errors');
520  $error++;
521  break;
522  } elseif (isset($object->date_validation) || $object->date_validation != '') {
523  setEventMessages($langs->trans("ValidatedRecordWhereFound"), null, 'errors');
524  $error++;
525  break;
526  }
527  }
528  }
529 
530  if (!$error) {
531  $db->commit();
532 
533  // Message for elements well deleted
534  if ($nbok > 1) {
535  setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
536  } elseif ($nbok > 0) {
537  setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
538  } else {
539  setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
540  }
541 
542  header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
543  exit;
544  } else {
545  $db->rollback();
546  }
547  }
548 
549  // others mass actions
550  if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) {
551  if ($massaction == 'letteringauto') {
552  $lettering = new Lettering($db);
553  $nb_lettering = $lettering->bookkeepingLetteringAll($toselect);
554  if ($nb_lettering < 0) {
555  setEventMessages('', $lettering->errors, 'errors');
556  $error++;
557  $nb_lettering = max(0, abs($nb_lettering) - 2);
558  } elseif ($nb_lettering == 0) {
559  $nb_lettering = 0;
560  setEventMessages($langs->trans('AccountancyNoLetteringModified'), array(), 'mesgs');
561  }
562  if ($nb_lettering == 1) {
563  setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
564  } elseif ($nb_lettering > 1) {
565  setEventMessages($langs->trans('AccountancyLetteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
566  }
567 
568  if (!$error) {
569  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
570  exit();
571  }
572  } elseif ($massaction == 'letteringmanual') {
573  $lettering = new Lettering($db);
574  $result = $lettering->updateLettering($toselect);
575  if ($result < 0) {
576  setEventMessages('', $lettering->errors, 'errors');
577  } else {
578  setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
579  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
580  exit();
581  }
582  } elseif ($action == 'unletteringauto' && $confirm == "yes") {
583  $lettering = new Lettering($db);
584  $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
585  if ($nb_lettering < 0) {
586  setEventMessages('', $lettering->errors, 'errors');
587  $error++;
588  $nb_lettering = max(0, abs($nb_lettering) - 2);
589  } elseif ($nb_lettering == 0) {
590  $nb_lettering = 0;
591  setEventMessages($langs->trans('AccountancyNoUnletteringModified'), array(), 'mesgs');
592  }
593  if ($nb_lettering == 1) {
594  setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
595  } elseif ($nb_lettering > 1) {
596  setEventMessages($langs->trans('AccountancyUnletteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
597  }
598 
599  if (!$error) {
600  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
601  exit();
602  }
603  } elseif ($action == 'unletteringmanual' && $confirm == "yes") {
604  $lettering = new Lettering($db);
605  $nb_lettering = $lettering->deleteLettering($toselect);
606  if ($result < 0) {
607  setEventMessages('', $lettering->errors, 'errors');
608  } else {
609  setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
610  header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
611  exit();
612  }
613  }
614  }
615 }
616 
617 // Build and execute select (used by page and export action)
618 // must de set after the action that set $filter
619 // --------------------------------------------------------------------
620 
621 $sql = 'SELECT';
622 $sql .= ' t.rowid,';
623 $sql .= " t.doc_date,";
624 $sql .= " t.doc_type,";
625 $sql .= " t.doc_ref,";
626 $sql .= " t.fk_doc,";
627 $sql .= " t.fk_docdet,";
628 $sql .= " t.thirdparty_code,";
629 $sql .= " t.subledger_account,";
630 $sql .= " t.subledger_label,";
631 $sql .= " t.numero_compte,";
632 $sql .= " t.label_compte,";
633 $sql .= " t.label_operation,";
634 $sql .= " t.debit,";
635 $sql .= " t.credit,";
636 $sql .= " t.lettering_code,";
637 $sql .= " t.montant as amount,";
638 $sql .= " t.sens,";
639 $sql .= " t.fk_user_author,";
640 $sql .= " t.import_key,";
641 $sql .= " t.code_journal,";
642 $sql .= " t.journal_label,";
643 $sql .= " t.piece_num,";
644 $sql .= " t.date_creation,";
645 $sql .= " t.tms as date_modification,";
646 $sql .= " t.date_export,";
647 $sql .= " t.date_validated as date_validation,";
648 $sql .= " t.import_key";
649 $sql .= ' FROM '.MAIN_DB_PREFIX.$object->table_element.' as t';
650 // Manage filter
651 $sqlwhere = array();
652 if (count($filter) > 0) {
653  foreach ($filter as $key => $value) {
654  if ($key == 't.doc_date') {
655  $sqlwhere[] = $key."='".$db->idate($value)."'";
656  } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') {
657  $sqlwhere[] = $key."'".$db->idate($value)."'";
658  } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
659  $sqlwhere[] = $key."'".$db->escape($value)."'";
660  } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
661  $sqlwhere[] = $key.'='.((int) $value);
662  } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
663  $sqlwhere[] = $key." LIKE '".$db->escape($value)."%'";
664  } elseif ($key == 't.subledger_account') {
665  $sqlwhere[] = natural_search($key, $value, 0, 1);
666  } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') {
667  $sqlwhere[] = $key."'".$db->idate($value)."'";
668  } elseif ($key == 't.tms>=' || $key == 't.tms<=') {
669  $sqlwhere[] = $key."'".$db->idate($value)."'";
670  } elseif ($key == 't.date_export>=' || $key == 't.date_export<=') {
671  $sqlwhere[] = $key."'".$db->idate($value)."'";
672  } elseif ($key == 't.date_validated>=' || $key == 't.date_validated<=') {
673  $sqlwhere[] = $key."'".$db->idate($value)."'";
674  } elseif ($key == 't.credit' || $key == 't.debit') {
675  $sqlwhere[] = natural_search($key, $value, 1, 1);
676  } elseif ($key == 't.reconciled_option') {
677  $sqlwhere[] = 't.lettering_code IS NULL';
678  } elseif ($key == 't.code_journal' && !empty($value)) {
679  $sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1);
680  } else {
681  $sqlwhere[] = natural_search($key, $value, 0, 1);
682  }
683  }
684 }
685 $sql .= ' WHERE t.entity IN ('.getEntity('accountancy').')';
686 if (empty($conf->global->ACCOUNTING_REEXPORT)) {
687  $sql .= " AND t.date_export IS NULL";
688 }
689 if (count($sqlwhere) > 0) {
690  $sql .= ' AND '.implode(' AND ', $sqlwhere);
691 }
692 if (!empty($sortfield)) {
693  $sql .= $db->order($sortfield, $sortorder);
694 }
695 //print $sql;
696 
697 
698 // Export into a file with format defined into setup (FEC, CSV, ...)
699 // Must be after definition of $sql
700 if ($action == 'export_fileconfirm' && $user->hasRight('accounting', 'mouvements', 'export')) {
701  // TODO Replace the fetchAll to get all ->line followed by call to ->export(). It currently consumes too much memory on large export.
702  // Replace this with the query($sql) and loop on each line to export them.
703  $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', (empty($conf->global->ACCOUNTING_REEXPORT) ? 0 : 1));
704 
705  if ($result < 0) {
706  setEventMessages($object->error, $object->errors, 'errors');
707  } else {
708  // Export files then exit
709  $accountancyexport = new AccountancyExport($db);
710 
711  $notexportlettering = GETPOST('notexportlettering', 'alpha');
712 
713  if (!empty($notexportlettering)) {
714  if (is_array($object->lines)) {
715  foreach ($object->lines as $k => $movement) {
716  unset($object->lines[$k]->lettering_code);
717  unset($object->lines[$k]->date_lettering);
718  }
719  }
720  }
721 
722  $mimetype = $accountancyexport->getMimeType($formatexportset);
723 
724  top_httphead($mimetype, 1);
725 
726  // Output data on screen
727  $accountancyexport->export($object->lines, $formatexportset);
728 
729  $notifiedexportdate = GETPOST('notifiedexportdate', 'alpha');
730  $notifiedvalidationdate = GETPOST('notifiedvalidationdate', 'alpha');
731 
732  if (!empty($accountancyexport->errors)) {
733  dol_print_error('', '', $accountancyexport->errors);
734  } elseif (!empty($notifiedexportdate) || !empty($notifiedvalidationdate)) {
735  // Specify as export : update field date_export or date_validated
736  $error = 0;
737  $db->begin();
738 
739  if (is_array($object->lines)) {
740  foreach ($object->lines as $movement) {
741  $now = dol_now();
742 
743  $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping";
744  $sql .= " SET";
745  if (!empty($notifiedexportdate) && !empty($notifiedvalidationdate)) {
746  $sql .= " date_export = '".$db->idate($now)."'";
747  $sql .= ", date_validated = '".$db->idate($now)."'";
748  } elseif (!empty($notifiedexportdate)) {
749  $sql .= " date_export = '".$db->idate($now)."'";
750  } elseif (!empty($notifiedvalidationdate)) {
751  $sql .= " date_validated = '".$db->idate($now)."'";
752  }
753  $sql .= " WHERE rowid = ".((int) $movement->id);
754 
755  dol_syslog("/accountancy/bookkeeping/list.php Function export_file Specify movements as exported", LOG_DEBUG);
756 
757  $result = $db->query($sql);
758  if (!$result) {
759  $error++;
760  break;
761  }
762  }
763  }
764 
765  if (!$error) {
766  $db->commit();
767  } else {
768  $error++;
769  $db->rollback();
770  dol_print_error('', $langs->trans("NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated"));
771  }
772  }
773  exit;
774  }
775 }
776 
777 
778 /*
779  * View
780  */
781 
782 $formother = new FormOther($db);
783 $formfile = new FormFile($db);
784 
785 $title_page = $langs->trans("Operations").' - '.$langs->trans("Journals");
786 
787 // Count total nb of records
788 $nbtotalofrecords = '';
789 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
790  $resql = $db->query($sql);
791  $nbtotalofrecords = $db->num_rows($resql);
792  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
793  $page = 0;
794  $offset = 0;
795  }
796 }
797 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
798 if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
799  $num = $nbtotalofrecords;
800 } else {
801  $sql .= $db->plimit($limit + 1, $offset);
802 
803  $resql = $db->query($sql);
804  if (!$resql) {
805  dol_print_error($db);
806  exit;
807  }
808 
809  $num = $db->num_rows($resql);
810 }
811 
812 $arrayofselected = is_array($toselect) ? $toselect : array();
813 
814 // Output page
815 // --------------------------------------------------------------------
816 
817 llxHeader('', $title_page);
818 
819 $formconfirm = '';
820 
821 if ($action == 'export_file') {
822  $form_question = array();
823 
824  $form_question['notexportlettering'] = array(
825  'name' => 'notexportlettering',
826  'type' => 'other',
827  'label' => '', // TODO Use Selectmodelcsv and show a select combo
828  'value' => $langs->trans('Modelcsv').' : <b>'.$listofformat[$formatexportset].'</b>'
829  );
830 
831  $form_question['separator0'] = array('name'=>'separator0', 'type'=>'separator');
832 
833  if (getDolGlobalInt("ACCOUNTING_ENABLE_LETTERING")) {
834  // If 1, we check by default.
835  $checked = !empty($conf->global->ACCOUNTING_DEFAULT_NOT_EXPORT_LETTERING) ? 'true' : 'false';
836  $form_question['notexportlettering'] = array(
837  'name' => 'notexportlettering',
838  'type' => 'checkbox',
839  'label' => $langs->trans('NotExportLettering'),
840  'value' => $checked,
841  );
842 
843  $form_question['separator1'] = array('name'=>'separator1', 'type'=>'separator');
844  }
845 
846  // If 1 or not set, we check by default.
847  $checked = (!isset($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE) || !empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE));
848  $form_question['notifiedexportdate'] = array(
849  'name' => 'notifiedexportdate',
850  'type' => 'checkbox',
851  'label' => $langs->trans('NotifiedExportDate'),
852  'value' => (!empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE) ? 'false' : 'true'),
853  );
854 
855  $form_question['separator2'] = array('name'=>'separator2', 'type'=>'separator');
856 
857  if (!getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")) {
858  // If 0 or not set, we NOT check by default.
859  $checked = (isset($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE) || !empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE));
860  $form_question['notifiedvalidationdate'] = array(
861  'name' => 'notifiedvalidationdate',
862  'type' => 'checkbox',
863  'label' => $langs->trans('NotifiedValidationDate', $langs->transnoentitiesnoconv("MenuAccountancyClosure")),
864  'value' => $checked,
865  );
866 
867  $form_question['separator3'] = array('name'=>'separator3', 'type'=>'separator');
868  }
869 
870  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans("ExportFilteredList").'...', $langs->trans('ConfirmExportFile'), 'export_fileconfirm', $form_question, '', 1, 350, 600);
871 }
872 
873 //if ($action == 'delbookkeepingyear') {
874 // $form_question = array();
875 // $delyear = GETPOST('delyear', 'int');
876 // $deljournal = GETPOST('deljournal', 'alpha');
877 //
878 // if (empty($delyear)) {
879 // $delyear = dol_print_date(dol_now(), '%Y');
880 // }
881 // $month_array = array();
882 // for ($i = 1; $i <= 12; $i++) {
883 // $month_array[$i] = $langs->trans("Month".sprintf("%02d", $i));
884 // }
885 // $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
886 // $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1);
887 //
888 // $form_question['delmonth'] = array(
889 // 'name' => 'delmonth',
890 // 'type' => 'select',
891 // 'label' => $langs->trans('DelMonth'),
892 // 'values' => $month_array,
893 // 'morecss' => 'minwidth150',
894 // 'default' => ''
895 // );
896 // $form_question['delyear'] = array(
897 // 'name' => 'delyear',
898 // 'type' => 'select',
899 // 'label' => $langs->trans('DelYear'),
900 // 'values' => $year_array,
901 // 'default' => $delyear
902 // );
903 // $form_question['deljournal'] = array(
904 // 'name' => 'deljournal',
905 // 'type' => 'other', // We don't use select here, the journal_array is already a select html component
906 // 'label' => $langs->trans('DelJournal'),
907 // 'value' => $journal_array,
908 // 'default' => $deljournal
909 // );
910 //
911 // $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'delbookkeepingyearconfirm', $form_question, '', 1, 320);
912 //}
913 
914 // Print form confirm
915 print $formconfirm;
916 
917 //$param=''; param started before
918 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
919  $param .= '&contextpage='.urlencode($contextpage);
920 }
921 if ($limit > 0 && $limit != $conf->liste_limit) {
922  $param .= '&limit='.urlencode($limit);
923 }
924 
925 // List of mass actions available
926 $arrayofmassactions = array();
927 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) {
928  $arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringAuto');
929  $arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringAuto');
930  $arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringManual');
931  $arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringManual');
932 }
933 if ($user->hasRight('accounting', 'mouvements', 'supprimer')) {
934  $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
935 }
936 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunletteringauto', 'preunletteringmanual', 'predeletebookkeepingwriting'))) {
937  $arrayofmassactions = array();
938 }
939 $massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions);
940 
941 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
942 print '<input type="hidden" name="token" value="'.newToken().'">';
943 print '<input type="hidden" name="action" value="list">';
944 if ($optioncss != '') {
945  print '<input type="hidden" name="optioncss" value="'.urlencode($optioncss).'">';
946 }
947 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
948 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
949 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
950 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
951 
952 if (count($filter)) {
953  $buttonLabel = $langs->trans("ExportFilteredList");
954 } else {
955  $buttonLabel = $langs->trans("ExportList");
956 }
957 
958 $parameters = array('param' => $param);
959 $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
960 if ($reshook < 0) {
961  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
962 }
963 
964 $newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint;
965 
966 if (empty($reshook)) {
967  // Button re-export
968  if (!empty($conf->global->ACCOUNTING_REEXPORT)) {
969  $newcardbutton .= '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=0'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("ClickToHideAlreadyExportedLines"), 'switch_off', 'class="small size15x valignmiddle"');
970  $newcardbutton .= '<span class="valignmiddle marginrightonly paddingleft">'.$langs->trans("ClickToHideAlreadyExportedLines").'</span>';
971  $newcardbutton .= '</a>';
972  } else {
973  $newcardbutton .= '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=1'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("DocsAlreadyExportedAreExcluded"), 'switch_on', 'class="warning size15x valignmiddle"');
974  $newcardbutton .= '<span class="valignmiddle marginrightonly paddingleft">'.$langs->trans("DocsAlreadyExportedAreExcluded").'</span>';
975  $newcardbutton .= '</a>';
976  }
977 
978  if ($user->hasRight('accounting', 'mouvements', 'export')) {
979  $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file&token='.newToken().($param ? '&'.$param : ''), $user->hasRight('accounting', 'mouvements', 'export'));
980  }
981 
982  $newcardbutton .= dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
983  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly'));
984  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?type=sub'.$param, '', 1, array('morecss' => 'marginleftonly'));
985 
986  $url = './card.php?action=create';
987  if (!empty($socid)) {
988  $url .= '&socid='.$socid;
989  }
990  $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', $url, '', $user->hasRight('accounting', 'mouvements', 'creer'));
991 }
992 
993 print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
994 
995 if ($massaction == 'preunletteringauto') {
996  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringAuto"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringauto", null, '', 0, 200, 500, 1);
997 } elseif ($massaction == 'preunletteringmanual') {
998  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringManual"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringmanual", null, '', 0, 200, 500, 1);
999 } elseif ($massaction == 'predeletebookkeepingwriting') {
1000  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
1001 }
1002 
1003 //$topicmail = "Information";
1004 //$modelmail = "accountingbookkeeping";
1005 //$objecttmp = new BookKeeping($db);
1006 //$trackid = 'bk'.$object->id;
1007 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1008 
1009 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1010 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
1011 if ($massactionbutton && $contextpage != 'poslist') {
1012  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
1013 }
1014 
1015 $moreforfilter = '';
1016 
1017 $parameters = array();
1018 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // Note that $action and $object may have been modified by hook
1019 if (empty($reshook)) {
1020  $moreforfilter .= $hookmanager->resPrint;
1021 } else {
1022  $moreforfilter = $hookmanager->resPrint;
1023 }
1024 
1025 print '<div class="div-table-responsive">';
1026 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
1027 
1028 // Filters lines
1029 print '<tr class="liste_titre_filter">';
1030 // Action column
1031 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1032  print '<td class="liste_titre center">';
1033  $searchpicto = $form->showFilterButtons('left');
1034  print $searchpicto;
1035  print '</td>';
1036 }
1037 // Movement number
1038 if (!empty($arrayfields['t.piece_num']['checked'])) {
1039  print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
1040 }
1041 // Code journal
1042 if (!empty($arrayfields['t.code_journal']['checked'])) {
1043  print '<td class="liste_titre center">';
1044  print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1, 'small maxwidth75');
1045  print '</td>';
1046 }
1047 // Date document
1048 if (!empty($arrayfields['t.doc_date']['checked'])) {
1049  print '<td class="liste_titre center">';
1050  print '<div class="nowrap">';
1051  print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1052  print '</div>';
1053  print '<div class="nowrap">';
1054  print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1055  print '</div>';
1056  print '</td>';
1057 }
1058 // Ref document
1059 if (!empty($arrayfields['t.doc_ref']['checked'])) {
1060  print '<td class="liste_titre"><input type="text" name="search_doc_ref" size="8" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
1061 }
1062 // Accountancy account
1063 if (!empty($arrayfields['t.numero_compte']['checked'])) {
1064  print '<td class="liste_titre">';
1065  print '<div class="nowrap">';
1066  print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth150', 'account');
1067  print '</div>';
1068  print '<div class="nowrap">';
1069  print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth150', 'account');
1070  print '</div>';
1071  print '</td>';
1072 }
1073 // Subledger account
1074 if (!empty($arrayfields['t.subledger_account']['checked'])) {
1075  print '<td class="liste_titre">';
1076  // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
1077  // use setup of keypress to select thirdparty and this hang browser on large database.
1078  if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
1079  print '<div class="nowrap">';
1080  //print $langs->trans('From').' ';
1081  print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', $langs->trans('From'), 'maxwidth250', 'subledgeraccount');
1082  print '</div>';
1083  print '<div class="nowrap">';
1084  print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', $langs->trans('to'), 'maxwidth250', 'subledgeraccount');
1085  print '</div>';
1086  } else {
1087  print '<input type="text" class="maxwidth75" name="search_accountancy_aux_code" value="'.dol_escape_htmltag($search_accountancy_aux_code).'">';
1088  }
1089  print '</td>';
1090 }
1091 // Label operation
1092 if (!empty($arrayfields['t.label_operation']['checked'])) {
1093  print '<td class="liste_titre">';
1094  print '<input type="text" size="7" class="flat" name="search_mvt_label" value="'.dol_escape_htmltag($search_mvt_label).'"/>';
1095  print '</td>';
1096 }
1097 // Debit
1098 if (!empty($arrayfields['t.debit']['checked'])) {
1099  print '<td class="liste_titre right">';
1100  print '<input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'">';
1101  print '</td>';
1102 }
1103 // Credit
1104 if (!empty($arrayfields['t.credit']['checked'])) {
1105  print '<td class="liste_titre right">';
1106  print '<input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'">';
1107  print '</td>';
1108 }
1109 // Lettering code
1110 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1111  print '<td class="liste_titre center">';
1112  print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.dol_escape_htmltag($search_lettering_code).'"/>';
1113  print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
1114  print '</td>';
1115 }
1116 
1117 // Fields from hook
1118 $parameters = array('arrayfields'=>$arrayfields);
1119 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1120 print $hookmanager->resPrint;
1121 
1122 // Date creation
1123 if (!empty($arrayfields['t.date_creation']['checked'])) {
1124  print '<td class="liste_titre center">';
1125  print '<div class="nowrap">';
1126  print $form->selectDate($search_date_creation_start, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1127  print '</div>';
1128  print '<div class="nowrap">';
1129  print $form->selectDate($search_date_creation_end, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1130  print '</div>';
1131  print '</td>';
1132 }
1133 // Date modification
1134 if (!empty($arrayfields['t.tms']['checked'])) {
1135  print '<td class="liste_titre center">';
1136  print '<div class="nowrap">';
1137  print $form->selectDate($search_date_modification_start, 'search_date_modification_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1138  print '</div>';
1139  print '<div class="nowrap">';
1140  print $form->selectDate($search_date_modification_end, 'search_date_modification_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1141  print '</div>';
1142  print '</td>';
1143 }
1144 // Date export
1145 if (!empty($arrayfields['t.date_export']['checked'])) {
1146  print '<td class="liste_titre center">';
1147  print '<div class="nowrap">';
1148  print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1149  print '</div>';
1150  print '<div class="nowrap">';
1151  print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1152  print '</div>';
1153  print '</td>';
1154 }
1155 // Date validation
1156 if (!empty($arrayfields['t.date_validated']['checked'])) {
1157  print '<td class="liste_titre center">';
1158  print '<div class="nowrap">';
1159  print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1160  print '</div>';
1161  print '<div class="nowrap">';
1162  print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1163  print '</div>';
1164  print '</td>';
1165 }
1166 if (!empty($arrayfields['t.import_key']['checked'])) {
1167  print '<td class="liste_titre center">';
1168  print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
1169  print '</td>';
1170 }
1171 // Action column
1172 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1173  print '<td class="liste_titre center">';
1174  $searchpicto = $form->showFilterButtons();
1175  print $searchpicto;
1176  print '</td>';
1177 }
1178 print "</tr>\n";
1179 
1180 print '<tr class="liste_titre">';
1181 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1182  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn ');}
1183 if (!empty($arrayfields['t.piece_num']['checked'])) {
1184  print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, "", $sortfield, $sortorder);
1185 }
1186 if (!empty($arrayfields['t.code_journal']['checked'])) {
1187  print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
1188 }
1189 if (!empty($arrayfields['t.doc_date']['checked'])) {
1190  print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
1191 }
1192 if (!empty($arrayfields['t.doc_ref']['checked'])) {
1193  print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
1194 }
1195 if (!empty($arrayfields['t.numero_compte']['checked'])) {
1196  print_liste_field_titre($arrayfields['t.numero_compte']['label'], $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder);
1197 }
1198 if (!empty($arrayfields['t.subledger_account']['checked'])) {
1199  print_liste_field_titre($arrayfields['t.subledger_account']['label'], $_SERVER['PHP_SELF'], "t.subledger_account", "", $param, "", $sortfield, $sortorder);
1200 }
1201 if (!empty($arrayfields['t.label_operation']['checked'])) {
1202  print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
1203 }
1204 if (!empty($arrayfields['t.debit']['checked'])) {
1205  print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
1206 }
1207 if (!empty($arrayfields['t.credit']['checked'])) {
1208  print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
1209 }
1210 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1211  print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
1212 }
1213 // Hook fields
1214 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1215 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1216 print $hookmanager->resPrint;
1217 if (!empty($arrayfields['t.date_creation']['checked'])) {
1218  print_liste_field_titre($arrayfields['t.date_creation']['label'], $_SERVER['PHP_SELF'], "t.date_creation", "", $param, '', $sortfield, $sortorder, 'center ');
1219 }
1220 if (!empty($arrayfields['t.tms']['checked'])) {
1221  print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER['PHP_SELF'], "t.tms", "", $param, '', $sortfield, $sortorder, 'center ');
1222 }
1223 if (!empty($arrayfields['t.date_export']['checked'])) {
1224  print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export,t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
1225 }
1226 if (!empty($arrayfields['t.date_validated']['checked'])) {
1227  print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated,t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
1228 }
1229 if (!empty($arrayfields['t.import_key']['checked'])) {
1230  print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER["PHP_SELF"], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1231 }
1232 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1233  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1234 }
1235 print "</tr>\n";
1236 
1237 
1238 $line = new BookKeepingLine();
1239 
1240 // Loop on record
1241 // --------------------------------------------------------------------
1242 $i = 0;
1243 $totalarray = array();
1244 $totalarray['nbfield'] = 0;
1245 $total_debit = 0;
1246 $total_credit = 0;
1247 $totalarray['val'] = array ();
1248 $totalarray['val']['totaldebit'] = 0;
1249 $totalarray['val']['totalcredit'] = 0;
1250 
1251 while ($i < min($num, $limit)) {
1252  $obj = $db->fetch_object($resql);
1253  if (empty($obj)) {
1254  break; // Should not happen
1255  }
1256 
1257  $line->id = $obj->rowid;
1258  $line->doc_date = $db->jdate($obj->doc_date);
1259  $line->doc_type = $obj->doc_type;
1260  $line->doc_ref = $obj->doc_ref;
1261  $line->fk_doc = $obj->fk_doc;
1262  $line->fk_docdet = $obj->fk_docdet;
1263  $line->thirdparty_code = $obj->thirdparty_code;
1264  $line->subledger_account = $obj->subledger_account;
1265  $line->subledger_label = $obj->subledger_label;
1266  $line->numero_compte = $obj->numero_compte;
1267  $line->label_compte = $obj->label_compte;
1268  $line->label_operation = $obj->label_operation;
1269  $line->debit = $obj->debit;
1270  $line->credit = $obj->credit;
1271  $line->montant = $obj->amount; // deprecated
1272  $line->amount = $obj->amount;
1273  $line->sens = $obj->sens;
1274  $line->lettering_code = $obj->lettering_code;
1275  $line->fk_user_author = $obj->fk_user_author;
1276  $line->import_key = $obj->import_key;
1277  $line->code_journal = $obj->code_journal;
1278  $line->journal_label = $obj->journal_label;
1279  $line->piece_num = $obj->piece_num;
1280  $line->date_creation = $db->jdate($obj->date_creation);
1281  $line->date_modification = $db->jdate($obj->date_modification);
1282  $line->date_export = $db->jdate($obj->date_export);
1283  $line->date_validation = $db->jdate($obj->date_validation);
1284 
1285  $total_debit += $line->debit;
1286  $total_credit += $line->credit;
1287 
1288  print '<tr class="oddeven">';
1289  // Action column
1290  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1291  print '<td class="nowraponall center">';
1292  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
1293  $selected = 0;
1294  if (in_array($line->id, $arrayofselected)) {
1295  $selected = 1;
1296  }
1297  print '<input id="cb'.$line->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$line->id.'"'.($selected ? ' checked="checked"' : '').' />';
1298  }
1299  print '</td>';
1300  }
1301 
1302  // Piece number
1303  if (!empty($arrayfields['t.piece_num']['checked'])) {
1304  print '<td>';
1305  $object->id = $line->id;
1306  $object->piece_num = $line->piece_num;
1307  print $object->getNomUrl(1, '', 0, '', 1);
1308  print '</td>';
1309  if (!$i) {
1310  $totalarray['nbfield']++;
1311  }
1312  }
1313 
1314  // Journal code
1315  if (!empty($arrayfields['t.code_journal']['checked'])) {
1316  $accountingjournal = new AccountingJournal($db);
1317  $result = $accountingjournal->fetch('', $line->code_journal);
1318  $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
1319  print '<td class="center tdoverflowmax150">'.$journaltoshow.'</td>';
1320  if (!$i) {
1321  $totalarray['nbfield']++;
1322  }
1323  }
1324 
1325  // Document date
1326  if (!empty($arrayfields['t.doc_date']['checked'])) {
1327  print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
1328  if (!$i) {
1329  $totalarray['nbfield']++;
1330  }
1331  }
1332 
1333  // Document ref
1334  if (!empty($arrayfields['t.doc_ref']['checked'])) {
1335  if ($line->doc_type == 'customer_invoice') {
1336  $langs->loadLangs(array('bills'));
1337 
1338  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1339  $objectstatic = new Facture($db);
1340  $objectstatic->fetch($line->fk_doc);
1341  //$modulepart = 'facture';
1342 
1343  $filename = dol_sanitizeFileName($line->doc_ref);
1344  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1345  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1346  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1347  } elseif ($line->doc_type == 'supplier_invoice') {
1348  $langs->loadLangs(array('bills'));
1349 
1350  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1351  $objectstatic = new FactureFournisseur($db);
1352  $objectstatic->fetch($line->fk_doc);
1353  //$modulepart = 'invoice_supplier';
1354 
1355  $filename = dol_sanitizeFileName($line->doc_ref);
1356  $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1357  $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1358  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
1359  } elseif ($line->doc_type == 'expense_report') {
1360  $langs->loadLangs(array('trips'));
1361 
1362  require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1363  $objectstatic = new ExpenseReport($db);
1364  $objectstatic->fetch($line->fk_doc);
1365  //$modulepart = 'expensereport';
1366 
1367  $filename = dol_sanitizeFileName($line->doc_ref);
1368  $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1369  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1370  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1371  } elseif ($line->doc_type == 'bank') {
1372  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1373  $objectstatic = new AccountLine($db);
1374  $objectstatic->fetch($line->fk_doc);
1375  } else {
1376  // Other type
1377  }
1378 
1379  $labeltoshow = '';
1380  $labeltoshowalt = '';
1381  if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
1382  $labeltoshow .= $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1383  $labeltoshow .= $documentlink;
1384  $labeltoshowalt .= $objectstatic->ref;
1385  } elseif ($line->doc_type == 'bank') {
1386  $labeltoshow .= $objectstatic->getNomUrl(1);
1387  $labeltoshowalt .= $objectstatic->ref;
1388  $bank_ref = strstr($line->doc_ref, '-');
1389  $labeltoshow .= " " . $bank_ref;
1390  $labeltoshowalt .= " " . $bank_ref;
1391  } else {
1392  $labeltoshow .= $line->doc_ref;
1393  $labeltoshowalt .= $line->doc_ref;
1394  }
1395 
1396  print '<td class="nowraponall tdoverflowmax200" title="'.dol_escape_htmltag($labeltoshowalt).'">';
1397  print $labeltoshow;
1398  print "</td>\n";
1399  if (!$i) {
1400  $totalarray['nbfield']++;
1401  }
1402  }
1403 
1404  // Account number
1405  if (!empty($arrayfields['t.numero_compte']['checked'])) {
1406  print '<td>'.length_accountg($line->numero_compte).'</td>';
1407  if (!$i) {
1408  $totalarray['nbfield']++;
1409  }
1410  }
1411 
1412  // Subledger account
1413  if (!empty($arrayfields['t.subledger_account']['checked'])) {
1414  print '<td>'.length_accounta($line->subledger_account).'</td>';
1415  if (!$i) {
1416  $totalarray['nbfield']++;
1417  }
1418  }
1419 
1420  // Label operation
1421  if (!empty($arrayfields['t.label_operation']['checked'])) {
1422  print '<td class="small tdoverflowmax200" title="'.dol_escape_htmltag($line->label_operation).'">'.dol_escape_htmltag($line->label_operation).'</td>';
1423  if (!$i) {
1424  $totalarray['nbfield']++;
1425  }
1426  }
1427 
1428  // Amount debit
1429  if (!empty($arrayfields['t.debit']['checked'])) {
1430  print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
1431  if (!$i) {
1432  $totalarray['nbfield']++;
1433  }
1434  if (!$i) {
1435  $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
1436  }
1437  $totalarray['val']['totaldebit'] += $line->debit;
1438  }
1439 
1440  // Amount credit
1441  if (!empty($arrayfields['t.credit']['checked'])) {
1442  print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
1443  if (!$i) {
1444  $totalarray['nbfield']++;
1445  }
1446  if (!$i) {
1447  $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
1448  }
1449  $totalarray['val']['totalcredit'] += $line->credit;
1450  }
1451 
1452  // Lettering code
1453  if (!empty($arrayfields['t.lettering_code']['checked'])) {
1454  print '<td class="center">'.$line->lettering_code.'</td>';
1455  if (!$i) {
1456  $totalarray['nbfield']++;
1457  }
1458  }
1459 
1460  // Fields from hook
1461  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1462  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1463  print $hookmanager->resPrint;
1464 
1465  // Creation operation date
1466  if (!empty($arrayfields['t.date_creation']['checked'])) {
1467  print '<td class="center">'.dol_print_date($line->date_creation, 'dayhour', 'tzuserrel').'</td>';
1468  if (!$i) {
1469  $totalarray['nbfield']++;
1470  }
1471  }
1472 
1473  // Modification operation date
1474  if (!empty($arrayfields['t.tms']['checked'])) {
1475  print '<td class="center">'.dol_print_date($line->date_modification, 'dayhour', 'tzuserrel').'</td>';
1476  if (!$i) {
1477  $totalarray['nbfield']++;
1478  }
1479  }
1480 
1481  // Exported operation date
1482  if (!empty($arrayfields['t.date_export']['checked'])) {
1483  print '<td class="center nowraponall">'.dol_print_date($line->date_export, 'dayhour', 'tzuserrel').'</td>';
1484  if (!$i) {
1485  $totalarray['nbfield']++;
1486  }
1487  }
1488 
1489  // Validated operation date
1490  if (!empty($arrayfields['t.date_validated']['checked'])) {
1491  print '<td class="center nowraponall">'.dol_print_date($line->date_validation, 'dayhour', 'tzuserrel').'</td>';
1492  if (!$i) {
1493  $totalarray['nbfield']++;
1494  }
1495  }
1496 
1497  if (!empty($arrayfields['t.import_key']['checked'])) {
1498  print '<td class="tdoverflowmax100">'.$obj->import_key."</td>\n";
1499  if (!$i) {
1500  $totalarray['nbfield']++;
1501  }
1502  }
1503 
1504  // Action column
1505  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1506  print '<td class="nowraponall center">';
1507  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
1508  $selected = 0;
1509  if (in_array($line->id, $arrayofselected)) {
1510  $selected = 1;
1511  }
1512  print '<input id="cb'.$line->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$line->id.'"'.($selected ? ' checked="checked"' : '').' />';
1513  }
1514  print '</td>';
1515  }
1516 
1517  if (!$i) {
1518  $totalarray['nbfield']++;
1519  }
1520 
1521  print "</tr>\n";
1522 
1523  $i++;
1524 }
1525 
1526 // Show total line
1527 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1528 
1529 // If no record found
1530 if ($num == 0) {
1531  $colspan = 1;
1532  foreach ($arrayfields as $key => $val) {
1533  if (!empty($val['checked'])) {
1534  $colspan++;
1535  }
1536  }
1537  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1538 }
1539 
1540 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1541 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1542 print $hookmanager->resPrint;
1543 
1544 print "</table>";
1545 print '</div>';
1546 
1547 // TODO Replace this with mass delete action
1548 //if ($user->rights->accounting->mouvements->supprimer_tous) {
1549 // print '<div class="tabsAction tabsActionNoBottom">'."\n";
1550 // print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear&token='.newToken().($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>';
1551 // print '</div>';
1552 //}
1553 
1554 print '</form>';
1555 
1556 // End of page
1557 llxFooter();
1558 
1559 $db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:632
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage bank transaction lines.
Manage the different format accountancy export.
Class to manage accounting accounts.
Class to manage Ledger (General Ledger and Subledger)
Class BookKeepingLine.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components for accounting management.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Class Lettering.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:594
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...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
$formconfirm
if ($action == 'delbookkeepingyear') {
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.