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