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