dolibarr  13.0.2
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-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
5  * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array("accountancy", "compta"));
40 
41 $socid = GETPOST('socid', 'int');
42 
43 $action = GETPOST('action', 'aZ09');
44 $search_mvt_num = GETPOST('search_mvt_num', 'int');
45 $search_doc_type = GETPOST("search_doc_type", 'alpha');
46 $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
47 $search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
48 $search_date_end = dol_mktime(0, 0, 0, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
49 $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
50 $search_date_creation_start = dol_mktime(0, 0, 0, GETPOST('date_creation_startmonth', 'int'), GETPOST('date_creation_startday', 'int'), GETPOST('date_creation_startyear', 'int'));
51 $search_date_creation_end = dol_mktime(0, 0, 0, GETPOST('date_creation_endmonth', 'int'), GETPOST('date_creation_endday', 'int'), GETPOST('date_creation_endyear', 'int'));
52 $search_date_modification_start = dol_mktime(0, 0, 0, GETPOST('date_modification_startmonth', 'int'), GETPOST('date_modification_startday', 'int'), GETPOST('date_modification_startyear', 'int'));
53 $search_date_modification_end = dol_mktime(0, 0, 0, GETPOST('date_modification_endmonth', 'int'), GETPOST('date_modification_endday', 'int'), GETPOST('date_modification_endyear', 'int'));
54 $search_date_export_start = dol_mktime(0, 0, 0, GETPOST('date_export_startmonth', 'int'), GETPOST('date_export_startday', 'int'), GETPOST('date_export_startyear', 'int'));
55 $search_date_export_end = dol_mktime(0, 0, 0, GETPOST('date_export_endmonth', 'int'), GETPOST('date_export_endday', 'int'), GETPOST('date_export_endyear', 'int'));
56 
57 //var_dump($search_date_start);exit;
58 if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
59  $action = 'delbookkeepingyear';
60 }
61 if (GETPOST("button_export_file_x") || GETPOST("button_export_file.x") || GETPOST("button_export_file")) {
62  $action = 'export_file';
63 }
64 
65 $search_accountancy_code = GETPOST("search_accountancy_code");
66 $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
67 if ($search_accountancy_code_start == - 1) {
68  $search_accountancy_code_start = '';
69 }
70 $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
71 if ($search_accountancy_code_end == - 1) {
72  $search_accountancy_code_end = '';
73 }
74 
75 $search_accountancy_aux_code = GETPOST("search_accountancy_aux_code");
76 $search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha');
77 if ($search_accountancy_aux_code_start == - 1) {
78  $search_accountancy_aux_code_start = '';
79 }
80 $search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha');
81 if ($search_accountancy_aux_code_end == - 1) {
82  $search_accountancy_aux_code_end = '';
83 }
84 $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
85 $search_direction = GETPOST('search_direction', 'alpha');
86 $search_debit = GETPOST('search_debit', 'alpha');
87 $search_credit = GETPOST('search_credit', 'alpha');
88 $search_ledger_code = GETPOST('search_ledger_code', 'alpha');
89 $search_lettering_code = GETPOST('search_lettering_code', 'alpha');
90 $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha');
91 
92 // Load variable for pagination
93 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
94 $sortfield = GETPOST('sortfield', 'aZ09comma');
95 $sortorder = GETPOST('sortorder', 'aZ09comma');
96 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
97 if (empty($page) || $page < 0) { $page = 0; }
98 $offset = $limit * $page;
99 $pageprev = $page - 1;
100 $pagenext = $page + 1;
101 if ($sortorder == "") $sortorder = "ASC";
102 if ($sortfield == "") $sortfield = "t.piece_num,t.rowid";
103 
104 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
105 $object = new BookKeeping($db);
106 $hookmanager->initHooks(array('bookkeepinglist'));
107 
108 $formaccounting = new FormAccounting($db);
109 $form = new Form($db);
110 
111 if (!in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && !GETPOSTISSET('begin') && !GETPOSTISSET('formfilteraction') && GETPOST('page', 'int') == '' && !GETPOST('noreset', 'int') && $user->rights->accounting->mouvements->export)
112 {
113  if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('restore_lastsearch_values') && !GETPOST('search_accountancy_code_start'))
114  {
115  $query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
116  $query .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1";
117  $res = $db->query($query);
118 
119  if ($res->num_rows > 0) {
120  $fiscalYear = $db->fetch_object($res);
121  $search_date_start = strtotime($fiscalYear->date_start);
122  $search_date_end = strtotime($fiscalYear->date_end);
123  } else {
124  $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
125  $year_start = dol_print_date(dol_now(), '%Y');
126  if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year
127  $year_end = $year_start + 1;
128  $month_end = $month_start - 1;
129  if ($month_end < 1)
130  {
131  $month_end = 12;
132  $year_end--;
133  }
134  $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
135  $search_date_end = dol_get_last_day($year_end, $month_end);
136  }
137  }
138 }
139 
140 
141 $arrayfields = array(
142  't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1),
143  't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
144  't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1),
145  't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1),
146  't.numero_compte'=>array('label'=>$langs->trans("AccountAccountingShort"), 'checked'=>1),
147  't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
148  't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
149  't.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1),
150  't.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1),
151  't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1),
152  't.date_creation'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0),
153  't.tms'=>array('label'=>$langs->trans("DateModification"), 'checked'=>0),
154  't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1),
155 );
156 
157 if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) unset($arrayfields['t.lettering_code']);
158 
159 $listofformat = AccountancyExport::getType();
160 $formatexportset = $conf->global->ACCOUNTING_EXPORT_MODELCSV;
161 if (empty($listofformat[$formatexportset])) $formatexportset = 1;
162 
163 $error = 0;
164 
165 
166 /*
167  * Actions
168  */
169 
170 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
171 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
172 
173 $parameters = array('socid'=>$socid);
174 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
175 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
176 
177 if (empty($reshook))
178 {
179  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
180 
181  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
182  {
183  $search_mvt_num = '';
184  $search_doc_type = '';
185  $search_doc_ref = '';
186  $search_doc_date = '';
187  $search_accountancy_code = '';
188  $search_accountancy_code_start = '';
189  $search_accountancy_code_end = '';
190  $search_accountancy_aux_code = '';
191  $search_accountancy_aux_code_start = '';
192  $search_accountancy_aux_code_end = '';
193  $search_mvt_label = '';
194  $search_direction = '';
195  $search_ledger_code = '';
196  $search_date_start = '';
197  $search_date_end = '';
198  $search_date_creation_start = '';
199  $search_date_creation_end = '';
200  $search_date_modification_start = '';
201  $search_date_modification_end = '';
202  $search_date_export_start = '';
203  $search_date_export_end = '';
204  $search_debit = '';
205  $search_credit = '';
206  $search_lettering_code = '';
207  $search_not_reconciled = '';
208  }
209 
210  // Must be after the remove filter action, before the export.
211  $param = '';
212  $filter = array();
213  if (!empty($search_date_start)) {
214  $filter['t.doc_date>='] = $search_date_start;
215  $tmp = dol_getdate($search_date_start);
216  $param .= '&search_date_startmonth='.urlencode($tmp['mon']).'&search_date_startday='.urlencode($tmp['mday']).'&search_date_startyear='.urlencode($tmp['year']);
217  }
218  if (!empty($search_date_end)) {
219  $filter['t.doc_date<='] = $search_date_end;
220  $tmp = dol_getdate($search_date_end);
221  $param .= '&search_date_endmonth='.urlencode($tmp['mon']).'&search_date_endday='.urlencode($tmp['mday']).'&search_date_endyear='.urlencode($tmp['year']);
222  }
223  if (!empty($search_doc_date)) {
224  $filter['t.doc_date'] = $search_doc_date;
225  $tmp = dol_getdate($search_doc_date);
226  $param .= '&doc_datemonth='.urlencode($tmp['mon']).'&doc_dateday='.urlencode($tmp['mday']).'&doc_dateyear='.urlencode($tmp['year']);
227  }
228  if (!empty($search_doc_type)) {
229  $filter['t.doc_type'] = $search_doc_type;
230  $param .= '&search_doc_type='.urlencode($search_doc_type);
231  }
232  if (!empty($search_doc_ref)) {
233  $filter['t.doc_ref'] = $search_doc_ref;
234  $param .= '&search_doc_ref='.urlencode($search_doc_ref);
235  }
236  if (!empty($search_accountancy_code)) {
237  $filter['t.numero_compte'] = $search_accountancy_code;
238  $param .= '&search_accountancy_code='.urlencode($search_accountancy_code);
239  }
240  if (!empty($search_accountancy_code_start)) {
241  $filter['t.numero_compte>='] = $search_accountancy_code_start;
242  $param .= '&search_accountancy_code_start='.urlencode($search_accountancy_code_start);
243  }
244  if (!empty($search_accountancy_code_end)) {
245  $filter['t.numero_compte<='] = $search_accountancy_code_end;
246  $param .= '&search_accountancy_code_end='.urlencode($search_accountancy_code_end);
247  }
248  if (!empty($search_accountancy_aux_code)) {
249  $filter['t.subledger_account'] = $search_accountancy_aux_code;
250  $param .= '&search_accountancy_aux_code='.urlencode($search_accountancy_aux_code);
251  }
252  if (!empty($search_accountancy_aux_code_start)) {
253  $filter['t.subledger_account>='] = $search_accountancy_aux_code_start;
254  $param .= '&search_accountancy_aux_code_start='.urlencode($search_accountancy_aux_code_start);
255  }
256  if (!empty($search_accountancy_aux_code_end)) {
257  $filter['t.subledger_account<='] = $search_accountancy_aux_code_end;
258  $param .= '&search_accountancy_aux_code_end='.urlencode($search_accountancy_aux_code_end);
259  }
260  if (!empty($search_mvt_label)) {
261  $filter['t.label_operation'] = $search_mvt_label;
262  $param .= '&search_mvt_label='.urlencode($search_mvt_label);
263  }
264  if (!empty($search_direction)) {
265  $filter['t.sens'] = $search_direction;
266  $param .= '&search_direction='.urlencode($search_direction);
267  }
268  if (!empty($search_ledger_code)) {
269  $filter['t.code_journal'] = $search_ledger_code;
270  $param .= '&search_ledger_code='.urlencode($search_ledger_code);
271  }
272  if (!empty($search_mvt_num)) {
273  $filter['t.piece_num'] = $search_mvt_num;
274  $param .= '&search_mvt_num='.urlencode($search_mvt_num);
275  }
276  if (!empty($search_date_creation_start)) {
277  $filter['t.date_creation>='] = $search_date_creation_start;
278  $tmp = dol_getdate($search_date_creation_start);
279  $param .= '&date_creation_startmonth='.urlencode($tmp['mon']).'&date_creation_startday='.urlencode($tmp['mday']).'&date_creation_startyear='.urlencode($tmp['year']);
280  }
281  if (!empty($search_date_creation_end)) {
282  $filter['t.date_creation<='] = $search_date_creation_end;
283  $tmp = dol_getdate($search_date_creation_end);
284  $param .= '&date_creation_endmonth='.urlencode($tmp['mon']).'&date_creation_endday='.urlencode($tmp['mday']).'&date_creation_endyear='.urlencode($tmp['year']);
285  }
286  if (!empty($search_date_modification_start)) {
287  $filter['t.tms>='] = $search_date_modification_start;
288  $tmp = dol_getdate($search_date_modification_start);
289  $param .= '&date_modification_startmonth='.urlencode($tmp['mon']).'&date_modification_startday='.urlencode($tmp['mday']).'&date_modification_startyear='.urlencode($tmp['year']);
290  }
291  if (!empty($search_date_modification_end)) {
292  $filter['t.tms<='] = $search_date_modification_end;
293  $tmp = dol_getdate($search_date_modification_end);
294  $param .= '&date_modification_endmonth='.urlencode($tmp['mon']).'&date_modification_endday='.urlencode($tmp['mday']).'&date_modification_endyear='.urlencode($tmp['year']);
295  }
296  if (!empty($search_date_export_start)) {
297  $filter['t.date_export>='] = $search_date_export_start;
298  $tmp = dol_getdate($search_date_export_start);
299  $param .= '&date_export_startmonth='.urlencode($tmp['mon']).'&date_export_startday='.urlencode($tmp['mday']).'&date_export_startyear='.urlencode($tmp['year']);
300  }
301  if (!empty($search_date_export_end)) {
302  $filter['t.date_export<='] = $search_date_export_end;
303  $tmp = dol_getdate($search_date_export_end);
304  $param .= '&date_export_endmonth='.urlencode($tmp['mon']).'&date_export_endday='.urlencode($tmp['mday']).'&date_export_endyear='.urlencode($tmp['year']);
305  }
306  if (!empty($search_debit)) {
307  $filter['t.debit'] = $search_debit;
308  $param .= '&search_debit='.urlencode($search_debit);
309  }
310  if (!empty($search_credit)) {
311  $filter['t.credit'] = $search_credit;
312  $param .= '&search_credit='.urlencode($search_credit);
313  }
314  if (!empty($search_lettering_code)) {
315  $filter['t.lettering_code'] = $search_lettering_code;
316  $param .= '&search_lettering_code='.urlencode($search_lettering_code);
317  }
318  if (!empty($search_not_reconciled)) {
319  $filter['t.reconciled_option'] = $search_not_reconciled;
320  $param .= '&search_not_reconciled='.urlencode($search_not_reconciled);
321  }
322 }
323 
324 if ($action == 'delbookkeeping' && $user->rights->accounting->mouvements->supprimer) {
325  $import_key = GETPOST('importkey', 'alpha');
326 
327  if (!empty($import_key)) {
328  $result = $object->deleteByImportkey($import_key);
329  if ($result < 0) {
330  setEventMessages($object->error, $object->errors, 'errors');
331  }
332 
333  // Make a redirect to avoid to launch the delete later after a back button
334  header("Location: list.php".($param ? '?'.$param : ''));
335  exit;
336  }
337 }
338 if ($action == 'delbookkeepingyearconfirm' && $user->rights->accounting->mouvements->supprimer_tous) {
339  $delmonth = GETPOST('delmonth', 'int');
340  $delyear = GETPOST('delyear', 'int');
341  if ($delyear == -1) {
342  $delyear = 0;
343  }
344  $deljournal = GETPOST('deljournal', 'alpha');
345  if ($deljournal == -1) {
346  $deljournal = 0;
347  }
348 
349  if (!empty($delmonth) || !empty($delyear) || !empty($deljournal))
350  {
351  $result = $object->deleteByYearAndJournal($delyear, $deljournal, '', ($delmonth > 0 ? $delmonth : 0));
352  if ($result < 0) {
353  setEventMessages($object->error, $object->errors, 'errors');
354  } else {
355  setEventMessages("RecordDeleted", null, 'mesgs');
356  }
357 
358  // Make a redirect to avoid to launch the delete later after a back button
359  header("Location: list.php".($param ? '?'.$param : ''));
360  exit;
361  } else {
362  setEventMessages("NoRecordDeleted", null, 'warnings');
363  }
364 }
365 if ($action == 'delmouvconfirm' && $user->rights->accounting->mouvements->supprimer) {
366  $mvt_num = GETPOST('mvt_num', 'int');
367 
368  if (!empty($mvt_num)) {
369  $result = $object->deleteMvtNum($mvt_num);
370  if ($result < 0) {
371  setEventMessages($object->error, $object->errors, 'errors');
372  } else {
373  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
374  }
375 
376  header("Location: list.php?noreset=1".($param ? '&'.$param : ''));
377  exit;
378  }
379 }
380 if ($action == 'setreexport') {
381  $setreexport = GETPOST('value', 'int');
382  if (!dolibarr_set_const($db, "ACCOUNTING_REEXPORT", $setreexport, 'yesno', 0, '', $conf->entity)) $error++;
383 
384  if (!$error) {
385  if ($conf->global->ACCOUNTING_REEXPORT == 1) {
386  setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsEnable"), null, 'mesgs');
387  } else {
388  setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsDisable"), null, 'mesgs');
389  }
390  } else {
391  setEventMessages($langs->trans("Error"), null, 'errors');
392  }
393 }
394 
395 // Build and execute select (used by page and export action)
396 // must de set after the action that set $filter
397 // --------------------------------------------------------------------
398 
399 $sql = 'SELECT';
400 $sql .= ' t.rowid,';
401 $sql .= " t.doc_date,";
402 $sql .= " t.doc_type,";
403 $sql .= " t.doc_ref,";
404 $sql .= " t.fk_doc,";
405 $sql .= " t.fk_docdet,";
406 $sql .= " t.thirdparty_code,";
407 $sql .= " t.subledger_account,";
408 $sql .= " t.subledger_label,";
409 $sql .= " t.numero_compte,";
410 $sql .= " t.label_compte,";
411 $sql .= " t.label_operation,";
412 $sql .= " t.debit,";
413 $sql .= " t.credit,";
414 $sql .= " t.lettering_code,";
415 $sql .= " t.montant as amount,";
416 $sql .= " t.sens,";
417 $sql .= " t.fk_user_author,";
418 $sql .= " t.import_key,";
419 $sql .= " t.code_journal,";
420 $sql .= " t.journal_label,";
421 $sql .= " t.piece_num,";
422 $sql .= " t.date_creation,";
423 $sql .= " t.tms as date_modification,";
424 $sql .= " t.date_export";
425 $sql .= ' FROM '.MAIN_DB_PREFIX.$object->table_element.' as t';
426 // Manage filter
427 $sqlwhere = array();
428 if (count($filter) > 0) {
429  foreach ($filter as $key => $value) {
430  if ($key == 't.doc_date') {
431  $sqlwhere[] = $key.'=\''.$db->idate($value).'\'';
432  } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') {
433  $sqlwhere[] = $key.'\''.$db->idate($value).'\'';
434  } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
435  $sqlwhere[] = $key.'\''.$db->escape($value).'\'';
436  } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
437  $sqlwhere[] = $key.'='.$value;
438  } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
439  $sqlwhere[] = $key.' LIKE \''.$db->escape($value).'%\'';
440  } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') {
441  $sqlwhere[] = $key.'\''.$db->idate($value).'\'';
442  } elseif ($key == 't.tms>=' || $key == 't.tms<=') {
443  $sqlwhere[] = $key.'\''.$db->idate($value).'\'';
444  } elseif ($key == 't.date_export>=' || $key == 't.date_export<=') {
445  $sqlwhere[] = $key.'\''.$db->idate($value).'\'';
446  } elseif ($key == 't.credit' || $key == 't.debit') {
447  $sqlwhere[] = natural_search($key, $value, 1, 1);
448  } elseif ($key == 't.reconciled_option') {
449  $sqlwhere[] = 't.lettering_code IS NULL';
450  } else {
451  $sqlwhere[] = natural_search($key, $value, 0, 1);
452  }
453  }
454 }
455 $sql .= ' WHERE t.entity IN ('.getEntity('accountancy').')';
456 if ($conf->global->ACCOUNTING_REEXPORT == 0) {
457  $sql .= " AND t.date_export IS NULL";
458 }
459 if (count($sqlwhere) > 0) {
460  $sql .= ' AND '.implode(' AND ', $sqlwhere);
461 }
462 if (!empty($sortfield)) {
463  $sql .= $db->order($sortfield, $sortorder);
464 }
465 //print $sql;
466 
467 
468 // Export into a file with format defined into setup (FEC, CSV, ...)
469 // Must be after definition of $sql
470 if ($action == 'export_file' && $user->rights->accounting->mouvements->export) {
471  // TODO Replace the fetchAll + ->export later that consume too much memory on large export with the query($sql) and loop on each line to export them.
472  $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', $conf->global->ACCOUNTING_REEXPORT);
473 
474  if ($result < 0)
475  {
476  setEventMessages($object->error, $object->errors, 'errors');
477  } else {
478  // Export files
479  $accountancyexport = new AccountancyExport($db);
480  $accountancyexport->export($object->lines, $formatexportset);
481 
482  if (!empty($accountancyexport->errors))
483  {
484  setEventMessages('', $accountancyexport->errors, 'errors');
485  } else {
486  // Specify as export : update field date_export
487  $error = 0;
488  $db->begin();
489 
490  if (is_array($object->lines))
491  {
492  foreach ($object->lines as $movement)
493  {
494  $now = dol_now();
495 
496  $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping";
497  $sql .= " SET date_export = '".$db->idate($now)."'";
498  $sql .= " WHERE rowid = ".$movement->id;
499 
500  dol_syslog("/accountancy/bookeeping/list.php Function export_file Specify movements as exported sql=".$sql, LOG_DEBUG);
501  $result = $db->query($sql);
502  if (!$result)
503  {
504  $error++;
505  break;
506  }
507  }
508  }
509 
510  if (!$error)
511  {
512  $db->commit();
513  // setEventMessages($langs->trans("AllExportedMovementsWereRecordedAsExported"), null, 'mesgs');
514  } else {
515  $error++;
516  $db->rollback();
517  setEventMessages($langs->trans("NotAllExportedMovementsCouldBeRecordedAsExported"), null, 'errors');
518  }
519  }
520  exit;
521  }
522 }
523 
524 
525 /*
526  * View
527  */
528 
529 $formother = new FormOther($db);
530 $formfile = new FormFile($db);
531 
532 $title_page = $langs->trans("Operations").' - '.$langs->trans("Journals");
533 
534 // Count total nb of records
535 $nbtotalofrecords = '';
536 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
537 {
538  $resql = $db->query($sql);
539  $nbtotalofrecords = $db->num_rows($resql);
540  if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
541  {
542  $page = 0;
543  $offset = 0;
544  }
545 }
546 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
547 if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
548 {
549  $num = $nbtotalofrecords;
550 } else {
551  $sql .= $db->plimit($limit + 1, $offset);
552 
553  $resql = $db->query($sql);
554  if (!$resql)
555  {
556  dol_print_error($db);
557  exit;
558  }
559 
560  $num = $db->num_rows($resql);
561 }
562 
563 
564 // Output page
565 // --------------------------------------------------------------------
566 
567 llxHeader('', $title_page);
568 
569 
570 if ($action == 'delmouv') {
571  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?mvt_num='.GETPOST('mvt_num').$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvtPartial'), 'delmouvconfirm', '', 0, 1);
572  print $formconfirm;
573 }
574 if ($action == 'delbookkeepingyear') {
575  $form_question = array();
576  $delyear = GETPOST('delyear', 'int');
577  $deljournal = GETPOST('deljournal', 'alpha');
578 
579  if (empty($delyear)) {
580  $delyear = dol_print_date(dol_now(), '%Y');
581  }
582  $month_array = array();
583  for ($i = 1; $i <= 12; $i++) {
584  $month_array[$i] = $langs->trans("Month".sprintf("%02d", $i));
585  }
586  $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
587  $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1);
588 
589  $form_question['delmonth'] = array(
590  'name' => 'delmonth',
591  'type' => 'select',
592  'label' => $langs->trans('DelMonth'),
593  'values' => $month_array,
594  'default' => ''
595  );
596  $form_question['delyear'] = array(
597  'name' => 'delyear',
598  'type' => 'select',
599  'label' => $langs->trans('DelYear'),
600  'values' => $year_array,
601  'default' => $delyear
602  );
603  $form_question['deljournal'] = array(
604  'name' => 'deljournal',
605  'type' => 'other', // We don't use select here, the journal_array is already a select html component
606  'label' => $langs->trans('DelJournal'),
607  'value' => $journal_array,
608  'default' => $deljournal
609  );
610 
611  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'delbookkeepingyearconfirm', $form_question, '', 1, 300);
612  print $formconfirm;
613 }
614 
615 //$param=''; param started before
616 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
617 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
618 
619 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
620 print '<input type="hidden" name="token" value="'.newToken().'">';
621 print '<input type="hidden" name="action" value="list">';
622 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.urlencode($optioncss).'">';
623 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
624 print '<input type="hidden" name="sortfield" value="'.urlencode($sortfield).'">';
625 print '<input type="hidden" name="sortorder" value="'.urlencode($sortorder).'">';
626 
627 if (count($filter)) $buttonLabel = $langs->trans("ExportFilteredList");
628 else $buttonLabel = $langs->trans("ExportList");
629 
630 $parameters = array();
631 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
632 if (empty($reshook)) {
633  // Button re-export
634  if (!empty($conf->global->ACCOUNTING_REEXPORT)) {
635  $newcardbutton = '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=0'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("Activated"), 'switch_on').'</a> ';
636  } else {
637  $newcardbutton = '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=1'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a> ';
638  }
639  $newcardbutton .= '<span class="valignmiddle marginrightonly">'.$langs->trans("IncludeDocsAlreadyExported").'</span>';
640 
641  if (!empty($user->rights->accounting->mouvements->export)) $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file'.($param ? '&'.$param : ''), $user->rights->accounting->mouvements->export);
642 
643  $newcardbutton .= dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
644  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly'));
645  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbysubaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly'));
646 
647  $url = './card.php?action=create';
648  if (!empty($socid)) $url .= '&socid='.$socid;
649  $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', $url, '', $user->rights->accounting->mouvements->creer);
650 }
651 
652 print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
653 
654 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
655 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
656 if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
657 
658 $parameters = array();
659 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
660 if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
661 else $moreforfilter = $hookmanager->resPrint;
662 
663 print '<div class="div-table-responsive">';
664 print '<table class="tagtable liste centpercent">';
665 
666 // Filters lines
667 print '<tr class="liste_titre_filter">';
668 
669 // Movement number
670 if (!empty($arrayfields['t.piece_num']['checked']))
671 {
672  print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
673 }
674 // Code journal
675 if (!empty($arrayfields['t.code_journal']['checked']))
676 {
677  print '<td class="liste_titre center"><input type="text" name="search_ledger_code" size="3" value="'.(is_array($search_ledger_code) ? join('|', $search_ledger_code) : $search_ledger_code).'"></td>';
678 }
679 // Date document
680 if (!empty($arrayfields['t.doc_date']['checked']))
681 {
682  print '<td class="liste_titre center">';
683  print '<div class="nowrap">';
684  print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
685  print '</div>';
686  print '<div class="nowrap">';
687  print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
688  print '</div>';
689  print '</td>';
690 }
691 // Ref document
692 if (!empty($arrayfields['t.doc_ref']['checked']))
693 {
694  print '<td class="liste_titre"><input type="text" name="search_doc_ref" size="8" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
695 }
696 // Accountancy account
697 if (!empty($arrayfields['t.numero_compte']['checked']))
698 {
699  print '<td class="liste_titre">';
700  print '<div class="nowrap">';
701  print $langs->trans('From').' ';
702  print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, 'maxwidth200');
703  print '</div>';
704  print '<div class="nowrap">';
705  print $langs->trans('to').' ';
706  print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, 'maxwidth200');
707  print '</div>';
708  print '</td>';
709 }
710 // Subledger account
711 if (!empty($arrayfields['t.subledger_account']['checked']))
712 {
713  print '<td class="liste_titre">';
714  print '<div class="nowrap">';
715  // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
716  // use setup of keypress to select thirdparty and this hang browser on large database.
717  if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX))
718  {
719  print $langs->trans('From').' ';
720  print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1);
721  } else {
722  print '<input type="text" class="maxwidth100" name="search_accountancy_aux_code_start" value="'.$search_accountancy_aux_code_start.'" placeholder="'.$langs->trans("From").'">';
723  }
724  print '</div>';
725  print '<div class="nowrap">';
726  // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
727  // use setup of keypress to select thirdparty and this hang browser on large database.
728  if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX))
729  {
730  print $langs->trans('to').' ';
731  print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1);
732  } else {
733  print '<input type="text" class="maxwidth100" name="search_accountancy_aux_code_end" value="'.$search_accountancy_aux_code_end.'" placeholder="'.$langs->trans("to").'">';
734  }
735  print '</div>';
736  print '</td>';
737 }
738 // Label operation
739 if (!empty($arrayfields['t.label_operation']['checked']))
740 {
741  print '<td class="liste_titre">';
742  print '<input type="text" size="7" class="flat" name="search_mvt_label" value="'.$search_mvt_label.'"/>';
743  print '</td>';
744 }
745 // Debit
746 if (!empty($arrayfields['t.debit']['checked']))
747 {
748  print '<td class="liste_titre right">';
749  print '<input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'">';
750  print '</td>';
751 }
752 // Credit
753 if (!empty($arrayfields['t.credit']['checked']))
754 {
755  print '<td class="liste_titre right">';
756  print '<input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'">';
757  print '</td>';
758 }
759 // Lettering code
760 if (!empty($arrayfields['t.lettering_code']['checked']))
761 {
762  print '<td class="liste_titre center">';
763  print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
764  print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
765  print '</td>';
766 }
767 
768 
769 // Fields from hook
770 $parameters = array('arrayfields'=>$arrayfields);
771 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
772 print $hookmanager->resPrint;
773 
774 // Date creation
775 if (!empty($arrayfields['t.date_creation']['checked']))
776 {
777  print '<td class="liste_titre center">';
778  print '<div class="nowrap">';
779  print $form->selectDate($search_date_creation_start, 'date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
780  print '</div>';
781  print '<div class="nowrap">';
782  print $form->selectDate($search_date_creation_end, 'date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
783  print '</div>';
784  print '</td>';
785 }
786 // Date modification
787 if (!empty($arrayfields['t.tms']['checked']))
788 {
789  print '<td class="liste_titre center">';
790  print '<div class="nowrap">';
791  print $form->selectDate($search_date_modification_start, 'date_modification_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
792  print '</div>';
793  print '<div class="nowrap">';
794  print $form->selectDate($search_date_modification_end, 'date_modification_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
795  print '</div>';
796  print '</td>';
797 }
798 // Date export
799 if (!empty($arrayfields['t.date_export']['checked']))
800 {
801  print '<td class="liste_titre center">';
802  print '<div class="nowrap">';
803  print $form->selectDate($search_date_export_start, 'date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
804  print '</div>';
805  print '<div class="nowrap">';
806  print $form->selectDate($search_date_export_end, 'date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
807  print '</div>';
808  print '</td>';
809 }
810 // Action column
811 print '<td class="liste_titre center">';
812 $searchpicto = $form->showFilterButtons();
813 print $searchpicto;
814 print '</td>';
815 print "</tr>\n";
816 
817 print '<tr class="liste_titre">';
818 if (!empty($arrayfields['t.piece_num']['checked'])) print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, "", $sortfield, $sortorder);
819 if (!empty($arrayfields['t.code_journal']['checked'])) print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
820 if (!empty($arrayfields['t.doc_date']['checked'])) print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
821 if (!empty($arrayfields['t.doc_ref']['checked'])) print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
822 if (!empty($arrayfields['t.numero_compte']['checked'])) print_liste_field_titre($arrayfields['t.numero_compte']['label'], $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder);
823 if (!empty($arrayfields['t.subledger_account']['checked'])) print_liste_field_titre($arrayfields['t.subledger_account']['label'], $_SERVER['PHP_SELF'], "t.subledger_account", "", $param, "", $sortfield, $sortorder);
824 if (!empty($arrayfields['t.label_operation']['checked'])) print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
825 if (!empty($arrayfields['t.debit']['checked'])) print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
826 if (!empty($arrayfields['t.credit']['checked'])) print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
827 if (!empty($arrayfields['t.lettering_code']['checked'])) print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
828 // Hook fields
829 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
830 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
831 print $hookmanager->resPrint;
832 if (!empty($arrayfields['t.date_creation']['checked'])) print_liste_field_titre($arrayfields['t.date_creation']['label'], $_SERVER['PHP_SELF'], "t.date_creation", "", $param, '', $sortfield, $sortorder, 'center ');
833 if (!empty($arrayfields['t.tms']['checked'])) print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER['PHP_SELF'], "t.tms", "", $param, '', $sortfield, $sortorder, 'center ');
834 if (!empty($arrayfields['t.date_export']['checked'])) print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center ');
835 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
836 print "</tr>\n";
837 
838 
839 $line = new BookKeepingLine();
840 
841 // Loop on record
842 // --------------------------------------------------------------------
843 $i = 0;
844 $totalarray = array();
845 while ($i < min($num, $limit))
846 {
847  $obj = $db->fetch_object($resql);
848  if (empty($obj)) break; // Should not happen
849 
850  $line->id = $obj->rowid;
851  $line->doc_date = $db->jdate($obj->doc_date);
852  $line->doc_type = $obj->doc_type;
853  $line->doc_ref = $obj->doc_ref;
854  $line->fk_doc = $obj->fk_doc;
855  $line->fk_docdet = $obj->fk_docdet;
856  $line->thirdparty_code = $obj->thirdparty_code;
857  $line->subledger_account = $obj->subledger_account;
858  $line->subledger_label = $obj->subledger_label;
859  $line->numero_compte = $obj->numero_compte;
860  $line->label_compte = $obj->label_compte;
861  $line->label_operation = $obj->label_operation;
862  $line->debit = $obj->debit;
863  $line->credit = $obj->credit;
864  $line->montant = $obj->amount; // deprecated
865  $line->amount = $obj->amount;
866  $line->sens = $obj->sens;
867  $line->lettering_code = $obj->lettering_code;
868  $line->fk_user_author = $obj->fk_user_author;
869  $line->import_key = $obj->import_key;
870  $line->code_journal = $obj->code_journal;
871  $line->journal_label = $obj->journal_label;
872  $line->piece_num = $obj->piece_num;
873  $line->date_creation = $db->jdate($obj->date_creation);
874  $line->date_modification = $db->jdate($obj->date_modification);
875  $line->date_export = $db->jdate($obj->date_export);
876 
877  $total_debit += $line->debit;
878  $total_credit += $line->credit;
879 
880  print '<tr class="oddeven">';
881 
882  // Piece number
883  if (!empty($arrayfields['t.piece_num']['checked']))
884  {
885  print '<td>';
886  $object->id = $line->id;
887  $object->piece_num = $line->piece_num;
888  print $object->getNomUrl(1, '', 0, '', 1);
889  print '</td>';
890  if (!$i) $totalarray['nbfield']++;
891  }
892 
893  // Journal code
894  if (!empty($arrayfields['t.code_journal']['checked']))
895  {
896  $accountingjournal = new AccountingJournal($db);
897  $result = $accountingjournal->fetch('', $line->code_journal);
898  $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
899  print '<td class="center">'.$journaltoshow.'</td>';
900  if (!$i) $totalarray['nbfield']++;
901  }
902 
903  // Document date
904  if (!empty($arrayfields['t.doc_date']['checked']))
905  {
906  print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
907  if (!$i) $totalarray['nbfield']++;
908  }
909 
910  // Document ref
911  if (!empty($arrayfields['t.doc_ref']['checked']))
912  {
913  if ($line->doc_type == 'customer_invoice')
914  {
915  $langs->loadLangs(array('bills'));
916 
917  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
918  $objectstatic = new Facture($db);
919  $objectstatic->fetch($line->fk_doc);
920  //$modulepart = 'facture';
921 
922  $filename = dol_sanitizeFileName($line->doc_ref);
923  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
924  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
925  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
926  } elseif ($line->doc_type == 'supplier_invoice')
927  {
928  $langs->loadLangs(array('bills'));
929 
930  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
931  $objectstatic = new FactureFournisseur($db);
932  $objectstatic->fetch($line->fk_doc);
933  //$modulepart = 'invoice_supplier';
934 
935  $filename = dol_sanitizeFileName($line->doc_ref);
936  $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
937  $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
938  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
939  } elseif ($line->doc_type == 'expense_report')
940  {
941  $langs->loadLangs(array('trips'));
942 
943  require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
944  $objectstatic = new ExpenseReport($db);
945  $objectstatic->fetch($line->fk_doc);
946  //$modulepart = 'expensereport';
947 
948  $filename = dol_sanitizeFileName($line->doc_ref);
949  $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
950  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
951  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
952  } else {
953  // Other type
954  }
955 
956  print '<td class="nowrap">';
957 
958  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
959  // Picto + Ref
960  print '<td class="nobordernopadding nowrap">';
961 
962  if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report')
963  {
964  print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
965  print $documentlink;
966  } else {
967  print $line->doc_ref;
968  }
969  print '</td></tr></table>';
970 
971  print "</td>\n";
972  if (!$i) $totalarray['nbfield']++;
973  }
974 
975  // Account number
976  if (!empty($arrayfields['t.numero_compte']['checked']))
977  {
978  print '<td>'.length_accountg($line->numero_compte).'</td>';
979  if (!$i) $totalarray['nbfield']++;
980  }
981 
982  // Subledger account
983  if (!empty($arrayfields['t.subledger_account']['checked']))
984  {
985  print '<td>'.length_accounta($line->subledger_account).'</td>';
986  if (!$i) $totalarray['nbfield']++;
987  }
988 
989  // Label operation
990  if (!empty($arrayfields['t.label_operation']['checked']))
991  {
992  print '<td>'.$line->label_operation.'</td>';
993  if (!$i) $totalarray['nbfield']++;
994  }
995 
996  // Amount debit
997  if (!empty($arrayfields['t.debit']['checked']))
998  {
999  print '<td class="nowrap right">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
1000  if (!$i) $totalarray['nbfield']++;
1001  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
1002  $totalarray['val']['totaldebit'] += $line->debit;
1003  }
1004 
1005  // Amount credit
1006  if (!empty($arrayfields['t.credit']['checked']))
1007  {
1008  print '<td class="nowrap right">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
1009  if (!$i) $totalarray['nbfield']++;
1010  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
1011  $totalarray['val']['totalcredit'] += $line->credit;
1012  }
1013 
1014  // Lettering code
1015  if (!empty($arrayfields['t.lettering_code']['checked']))
1016  {
1017  print '<td class="center">'.$line->lettering_code.'</td>';
1018  if (!$i) $totalarray['nbfield']++;
1019  }
1020 
1021  // Fields from hook
1022  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1023  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1024  print $hookmanager->resPrint;
1025 
1026  // Creation operation date
1027  if (!empty($arrayfields['t.date_creation']['checked']))
1028  {
1029  print '<td class="center">'.dol_print_date($line->date_creation, 'dayhour').'</td>';
1030  if (!$i) $totalarray['nbfield']++;
1031  }
1032 
1033  // Modification operation date
1034  if (!empty($arrayfields['t.tms']['checked']))
1035  {
1036  print '<td class="center">'.dol_print_date($line->date_modification, 'dayhour').'</td>';
1037  if (!$i) $totalarray['nbfield']++;
1038  }
1039 
1040  // Exported operation date
1041  if (!empty($arrayfields['t.date_export']['checked']))
1042  {
1043  print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>';
1044  if (!$i) $totalarray['nbfield']++;
1045  }
1046 
1047  // Action column
1048  print '<td class="nowraponall center">';
1049  if (empty($line->date_export)) {
1050  if ($user->rights->accounting->mouvements->creer) {
1051  print '<a class="editfielda paddingleft marginrightonly" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?piece_num='.$line->piece_num.$param.'&page='.$page.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">'.img_edit().'</a>';
1052  }
1053  if ($user->rights->accounting->mouvements->supprimer) {
1054  print '<a class="reposition paddingleft marginrightonly" href="'.$_SERVER['PHP_SELF'].'?action=delmouv&mvt_num='.$line->piece_num.$param.'&page='.$page.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">'.img_delete().'</a>';
1055  }
1056  }
1057  print '</td>';
1058 
1059  if (!$i) $totalarray['nbfield']++;
1060 
1061  print "</tr>\n";
1062 
1063  $i++;
1064 }
1065 
1066 // Show total line
1067 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1068 
1069 
1070 print "</table>";
1071 print '</div>';
1072 
1073 // TODO Replace this with mass delete action
1074 if ($user->rights->accounting->mouvements->supprimer_tous) {
1075  print '<div class="tabsAction tabsActionNoBottom">'."\n";
1076  print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear'.($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>';
1077  print '</div>';
1078 }
1079 
1080 print '</form>';
1081 
1082 // End of page
1083 llxFooter();
1084 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_now($mode= 'auto')
Return date for now.
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:575
Class to manage suppliers invoices.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to manage Ledger (General Ledger and Subledger)
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
static getType()
Array with all export type available (key + label)
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
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...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to manage Trips and Expenses.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage generation of HTML components for accounting management.
Manage the different format accountancy export.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
Class to manage accounting accounts.
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
Class BookKeepingLine.