dolibarr  13.0.2
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-2016 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2013-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../../main.inc.php';
29 
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array("accountancy", "compta"));
40 
41 $action = GETPOST('action', 'aZ09');
42 $search_date_startyear = GETPOST('search_date_startyear', 'int');
43 $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
44 $search_date_startday = GETPOST('search_date_startday', 'int');
45 $search_date_endyear = GETPOST('search_date_endyear', 'int');
46 $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
47 $search_date_endday = GETPOST('search_date_endday', 'int');
48 $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
49 $search_date_end = dol_mktime(0, 0, 0, $search_date_endmonth, $search_date_endday, $search_date_endyear);
50 $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
51 $search_date_export_startyear = GETPOST('search_date_export_startyear', 'int');
52 $search_date_export_startmonth = GETPOST('search_date_export_startmonth', 'int');
53 $search_date_export_startday = GETPOST('search_date_export_startday', 'int');
54 $search_date_export_endyear = GETPOST('search_date_export_endyear', 'int');
55 $search_date_export_endmonth = GETPOST('search_date_export_endmonth', 'int');
56 $search_date_export_endday = GETPOST('search_date_export_endday', 'int');
57 $search_date_export_start = dol_mktime(0, 0, 0, $search_date_export_startmonth, $search_date_export_startday, $search_date_export_startyear);
58 $search_date_export_end = dol_mktime(0, 0, 0, $search_date_export_endmonth, $search_date_export_endday, $search_date_export_endyear);
59 
60 $search_accountancy_code = GETPOST("search_accountancy_code");
61 $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
62 if ($search_accountancy_code_start == - 1) {
63  $search_accountancy_code_start = '';
64 }
65 $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
66 if ($search_accountancy_code_end == - 1) {
67  $search_accountancy_code_end = '';
68 }
69 $search_doc_ref = GETPOST('search_doc_ref', 'alpha');
70 $search_label_operation = GETPOST('search_label_operation', 'alpha');
71 $search_mvt_num = GETPOST('search_mvt_num', 'int');
72 $search_direction = GETPOST('search_direction', 'alpha');
73 $search_ledger_code = GETPOST('search_ledger_code', 'alpha');
74 $search_debit = GETPOST('search_debit', 'alpha');
75 $search_credit = GETPOST('search_credit', 'alpha');
76 $search_lettering_code = GETPOST('search_lettering_code', 'alpha');
77 $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha');
78 
79 if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
80  $action = 'delbookkeepingyear';
81 }
82 
83 // Load variable for pagination
84 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
85 $sortfield = GETPOST('sortfield', 'aZ09comma');
86 $sortorder = GETPOST('sortorder', 'aZ09comma');
87 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
88 if (empty($page) || $page < 0) { $page = 0; }
89 $offset = $limit * $page;
90 $pageprev = $page - 1;
91 $pagenext = $page + 1;
92 if ($sortorder == "") $sortorder = "ASC";
93 if ($sortfield == "") $sortfield = "t.doc_date,t.rowid";
94 
95 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
96 $object = new BookKeeping($db);
97 $formfile = new FormFile($db);
98 $hookmanager->initHooks(array('bookkeepingbyaccountlist'));
99 
100 $formaccounting = new FormAccounting($db);
101 $form = new Form($db);
102 
103 if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('search_date_startday') && !GETPOSTISSET('search_date_startmonth') && !GETPOSTISSET('search_date_starthour')) {
104  $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
105  $sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'";
106  $sql .= $db->plimit(1);
107  $res = $db->query($sql);
108 
109  if ($res->num_rows > 0) {
110  $fiscalYear = $db->fetch_object($res);
111  $search_date_start = strtotime($fiscalYear->date_start);
112  $search_date_end = strtotime($fiscalYear->date_end);
113  } else {
114  $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
115  $year_start = dol_print_date(dol_now(), '%Y');
116  if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year
117  $year_end = $year_start + 1;
118  $month_end = $month_start - 1;
119  if ($month_end < 1)
120  {
121  $month_end = 12;
122  $year_end--;
123  }
124  $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
125  $search_date_end = dol_get_last_day($year_end, $month_end);
126  }
127 }
128 
129 $arrayfields = array(
130  // 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
131  't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1),
132  't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
133  't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1),
134  't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1),
135  't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
136  't.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1),
137  't.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1),
138  't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1),
139  't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1),
140 );
141 
142 if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) unset($arrayfields['t.lettering_code']);
143 
144 if ($search_date_start && empty($search_date_startyear)) {
145  $tmparray = dol_getdate($search_date_start);
146  $search_date_startyear = $tmparray['year'];
147  $search_date_startmonth = $tmparray['mon'];
148  $search_date_startday = $tmparray['mday'];
149 }
150 if ($search_date_end && empty($search_date_endyear)) {
151  $tmparray = dol_getdate($search_date_end);
152  $search_date_endyear = $tmparray['year'];
153  $search_date_endmonth = $tmparray['mon'];
154  $search_date_endday = $tmparray['mday'];
155 }
156 
157 
158 /*
159  * Action
160  */
161 
162 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
163 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
164 
165 $parameters = array('socid'=>$socid);
166 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
167 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
168 
169 if (empty($reshook))
170 {
171  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
172 
173  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
174  {
175  $search_doc_date = '';
176  $search_accountancy_code = '';
177  $search_accountancy_code_start = '';
178  $search_accountancy_code_end = '';
179  $search_label_account = '';
180  $search_doc_ref = '';
181  $search_label_operation = '';
182  $search_mvt_num = '';
183  $search_direction = '';
184  $search_ledger_code = '';
185  $search_date_start = '';
186  $search_date_end = '';
187  $search_date_startyear = '';
188  $search_date_startmonth = '';
189  $search_date_startday = '';
190  $search_date_endyear = '';
191  $search_date_endmonth = '';
192  $search_date_endday = '';
193  $search_date_export_start = '';
194  $search_date_export_end = '';
195  $search_date_export_startyear = '';
196  $search_date_export_startmonth = '';
197  $search_date_export_startday = '';
198  $search_date_export_endyear = '';
199  $search_date_export_endmonth = '';
200  $search_date_export_endday = '';
201  $search_debit = '';
202  $search_credit = '';
203  $search_lettering_code = '';
204  $search_not_reconciled = '';
205  }
206 
207  // Must be after the remove filter action, before the export.
208  $param = '';
209  $filter = array();
210 
211  if (!empty($search_date_start)) {
212  $filter['t.doc_date>='] = $search_date_start;
213  $param .= '&search_date_startmonth='.$search_date_startmonth.'&search_date_startday='.$search_date_startday.'&search_date_startyear='.$search_date_startyear;
214  }
215  if (!empty($search_date_end)) {
216  $filter['t.doc_date<='] = $search_date_end;
217  $param .= '&search_date_endmonth='.$search_date_endmonth.'&search_date_endday='.$search_date_endday.'&search_date_endyear='.$search_date_endyear;
218  }
219  if (!empty($search_doc_date)) {
220  $filter['t.doc_date'] = $search_doc_date;
221  $param .= '&doc_datemonth='.GETPOST('doc_datemonth', 'int').'&doc_dateday='.GETPOST('doc_dateday', 'int').'&doc_dateyear='.GETPOST('doc_dateyear', 'int');
222  }
223  if (!empty($search_accountancy_code_start)) {
224  $filter['t.numero_compte>='] = $search_accountancy_code_start;
225  $param .= '&search_accountancy_code_start='.urlencode($search_accountancy_code_start);
226  }
227  if (!empty($search_accountancy_code_end)) {
228  $filter['t.numero_compte<='] = $search_accountancy_code_end;
229  $param .= '&search_accountancy_code_end='.urlencode($search_accountancy_code_end);
230  }
231  if (!empty($search_label_account)) {
232  $filter['t.label_compte'] = $search_label_account;
233  $param .= '&search_label_compte='.urlencode($search_label_account);
234  }
235  if (!empty($search_mvt_num)) {
236  $filter['t.piece_num'] = $search_mvt_num;
237  $param .= '&search_mvt_num='.urlencode($search_mvt_num);
238  }
239  if (!empty($search_doc_ref)) {
240  $filter['t.doc_ref'] = $search_doc_ref;
241  $param .= '&search_doc_ref='.urlencode($search_doc_ref);
242  }
243  if (!empty($search_label_operation)) {
244  $filter['t.label_operation'] = $search_label_operation;
245  $param .= '&search_label_operation='.urlencode($search_label_operation);
246  }
247  if (!empty($search_direction)) {
248  $filter['t.sens'] = $search_direction;
249  $param .= '&search_direction='.urlencode($search_direction);
250  }
251  if (!empty($search_ledger_code)) {
252  $filter['t.code_journal'] = $search_ledger_code;
253  $param .= '&search_ledger_code='.urlencode($search_ledger_code);
254  }
255  if (!empty($search_debit)) {
256  $filter['t.debit'] = $search_debit;
257  $param .= '&search_debit='.urlencode($search_debit);
258  }
259  if (!empty($search_credit)) {
260  $filter['t.credit'] = $search_credit;
261  $param .= '&search_credit='.urlencode($search_credit);
262  }
263  if (!empty($search_lettering_code)) {
264  $filter['t.lettering_code'] = $search_lettering_code;
265  $param .= '&search_lettering_code='.urlencode($search_lettering_code);
266  }
267  if (!empty($search_not_reconciled)) {
268  $filter['t.reconciled_option'] = $search_not_reconciled;
269  $param .= '&search_not_reconciled='.urlencode($search_not_reconciled);
270  }
271  if (!empty($search_date_export_start)) {
272  $filter['t.date_export>='] = $search_date_export_start;
273  $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;
274  }
275  if (!empty($search_date_export_end)) {
276  $filter['t.date_export<='] = $search_date_export_end;
277  $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;
278  }
279 }
280 
281 if ($action == 'delbookkeeping' && $user->rights->accounting->mouvements->supprimer) {
282  $import_key = GETPOST('importkey', 'alpha');
283 
284  if (!empty($import_key)) {
285  $result = $object->deleteByImportkey($import_key);
286  if ($result < 0) {
287  setEventMessages($object->error, $object->errors, 'errors');
288  }
289 
290  // Make a redirect to avoid to launch the delete later after a back button
291  header("Location: ".$_SERVER["PHP_SELF"].($param ? '?'.$param : ''));
292  exit;
293  }
294 }
295 if ($action == 'delbookkeepingyearconfirm' && $user->rights->accounting->mouvements->supprimer_tous) {
296  $delmonth = GETPOST('delmonth', 'int');
297  $delyear = GETPOST('delyear', 'int');
298  if ($delyear == -1) {
299  $delyear = 0;
300  }
301  $deljournal = GETPOST('deljournal', 'alpha');
302  if ($deljournal == -1) {
303  $deljournal = 0;
304  }
305 
306  if (!empty($delmonth) || !empty($delyear) || !empty($deljournal))
307  {
308  $result = $object->deleteByYearAndJournal($delyear, $deljournal, '', ($delmonth > 0 ? $delmonth : 0));
309  if ($result < 0) {
310  setEventMessages($object->error, $object->errors, 'errors');
311  } else {
312  setEventMessages("RecordDeleted", null, 'mesgs');
313  }
314 
315  // Make a redirect to avoid to launch the delete later after a back button
316  header("Location: ".$_SERVER["PHP_SELF"].($param ? '?'.$param : ''));
317  exit;
318  } else {
319  setEventMessages("NoRecordDeleted", null, 'warnings');
320  }
321 }
322 if ($action == 'delmouvconfirm' && $user->rights->accounting->mouvements->supprimer) {
323  $mvt_num = GETPOST('mvt_num', 'int');
324 
325  if (!empty($mvt_num)) {
326  $result = $object->deleteMvtNum($mvt_num);
327  if ($result < 0) {
328  setEventMessages($object->error, $object->errors, 'errors');
329  } else {
330  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
331  }
332 
333  header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
334  exit;
335  }
336 }
337 
338 
339 /*
340  * View
341  */
342 
343 $formaccounting = new FormAccounting($db);
344 $formfile = new FormFile($db);
345 $formother = new FormOther($db);
346 $form = new Form($db);
347 
348 $title_page = $langs->trans("Operations").' - '.$langs->trans("VueByAccountAccounting").' ('.$langs->trans("Bookkeeping").')';
349 
350 llxHeader('', $title_page);
351 
352 // List
353 $nbtotalofrecords = '';
354 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
355  $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter);
356  if ($nbtotalofrecords < 0) {
357  setEventMessages($object->error, $object->errors, 'errors');
358  }
359 }
360 
361 $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter);
362 
363 if ($result < 0) {
364  setEventMessages($object->error, $object->errors, 'errors');
365 }
366 
367 $num = count($object->lines);
368 
369 
370 if ($action == 'delmouv') {
371  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?mvt_num='.GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvtPartial'), 'delmouvconfirm', '', 0, 1);
372  print $formconfirm;
373 }
374 if ($action == 'delbookkeepingyear') {
375  $form_question = array();
376  $delyear = GETPOST('delyear', 'int');
377  $deljournal = GETPOST('deljournal', 'alpha');
378 
379  if (empty($delyear)) {
380  $delyear = dol_print_date(dol_now(), '%Y');
381  }
382  $month_array = array();
383  for ($i = 1; $i <= 12; $i++) {
384  $month_array[$i] = $langs->trans("Month".sprintf("%02d", $i));
385  }
386  $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
387  $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1);
388 
389  $form_question['delmonth'] = array(
390  'name' => 'delmonth',
391  'type' => 'select',
392  'label' => $langs->trans('DelMonth'),
393  'values' => $month_array,
394  'default' => ''
395  );
396  $form_question['delyear'] = array(
397  'name' => 'delyear',
398  'type' => 'select',
399  'label' => $langs->trans('DelYear'),
400  'values' => $year_array,
401  'default' => $delyear
402  );
403  $form_question['deljournal'] = array(
404  'name' => 'deljournal',
405  'type' => 'other', // We don't use select here, the journal_array is already a select html component
406  'label' => $langs->trans('DelJournal'),
407  'value' => $journal_array,
408  'default' => $deljournal
409  );
410 
411  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'delbookkeepingyearconfirm', $form_question, '', 1, 300);
412  print $formconfirm;
413 }
414 
415 
416 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
417 print '<input type="hidden" name="token" value="'.newToken().'">';
418 print '<input type="hidden" name="action" value="list">';
419 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
420 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
421 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
422 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
423 
424 $parameters = array();
425 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
426 if (empty($reshook)) {
427  $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param);
428  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
429  $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbysubaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly'));
430  $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=create');
431 }
432 
433 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
434 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
435 
436 print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $result, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
437 
438 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
439 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
440 if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
441 
442 // Reverse sort order
443 if (preg_match('/^asc/i', $sortorder)) $sortorder = "asc";
444 else $sortorder = "desc";
445 
446 $moreforfilter = '';
447 
448 // Accountancy account
449 $moreforfilter .= '<div class="divsearchfield">';
450 $moreforfilter .= $langs->trans('AccountAccounting').': ';
451 $moreforfilter .= '<div class="nowrap inline-block">';
452 $moreforfilter .= $langs->trans('From').' ';
453 $moreforfilter .= $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, 'maxwidth200');
454 $moreforfilter .= ' '.$langs->trans('to').' ';
455 $moreforfilter .= $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, 'maxwidth200');
456 $moreforfilter .= '</div>';
457 $moreforfilter .= '</div>';
458 
459 $parameters = array();
460 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
461 if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
462 else $moreforfilter = $hookmanager->resPrint;
463 
464 print '<div class="liste_titre liste_titre_bydiv centpercent">';
465 print $moreforfilter;
466 print '</div>';
467 
468 print '<div class="div-table-responsive">';
469 print '<table class="tagtable liste centpercent">';
470 
471 // Filters lines
472 print '<tr class="liste_titre_filter">';
473 
474 // Movement number
475 if (!empty($arrayfields['t.piece_num']['checked']))
476 {
477  print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
478 }
479 // Code journal
480 if (!empty($arrayfields['t.code_journal']['checked'])) {
481  print '<td class="liste_titre center"><input type="text" name="search_ledger_code" size="3" value="'.dol_escape_htmltag($search_ledger_code).'"></td>';
482 }
483 // Date document
484 if (!empty($arrayfields['t.doc_date']['checked'])) {
485  print '<td class="liste_titre center">';
486  print '<div class="nowrap">';
487  print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
488  print '</div>';
489  print '<div class="nowrap">';
490  print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
491  print '</div>';
492  print '</td>';
493 }
494 // Ref document
495 if (!empty($arrayfields['t.doc_ref']['checked'])) {
496  print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"/></td>';
497 }
498 // Label operation
499 if (!empty($arrayfields['t.label_operation']['checked'])) {
500  print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_operation" value="'.dol_escape_htmltag($search_label_operation).'"/></td>';
501 }
502 // Debit
503 if (!empty($arrayfields['t.debit']['checked'])) {
504  print '<td class="liste_titre right"><input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'"></td>';
505 }
506 // Credit
507 if (!empty($arrayfields['t.credit']['checked'])) {
508  print '<td class="liste_titre right"><input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'"></td>';
509 }
510 // Lettering code
511 if (!empty($arrayfields['t.lettering_code']['checked']))
512 {
513  print '<td class="liste_titre center">';
514  print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
515  print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
516  print '</td>';
517 }
518 // Date export
519 if (!empty($arrayfields['t.date_export']['checked'])) {
520  print '<td class="liste_titre center">';
521  print '<div class="nowrap">';
522  print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
523  print '</div>';
524  print '<div class="nowrap">';
525  print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
526  print '</div>';
527  print '</td>';
528 }
529 
530 // Fields from hook
531 $parameters = array('arrayfields'=>$arrayfields);
532 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
533 print $hookmanager->resPrint;
534 
535 // Action column
536 print '<td class="liste_titre center">';
537 $searchpicto = $form->showFilterButtons();
538 print $searchpicto;
539 print '</td>';
540 print "</tr>\n";
541 
542 print '<tr class="liste_titre">';
543 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);
544 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 ');
545 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 ');
546 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);
547 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);
548 if (!empty($arrayfields['t.debit']['checked'])) print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
549 if (!empty($arrayfields['t.credit']['checked'])) print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
550 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 ');
551 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 ');
552 // Hook fields
553 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
554 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
555 print $hookmanager->resPrint;
556 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
557 print "</tr>\n";
558 
559 
560 $total_debit = 0;
561 $total_credit = 0;
562 $sous_total_debit = 0;
563 $sous_total_credit = 0;
564 $displayed_account_number = null; // Start with undefined to be able to distinguish with empty
565 
566 // Loop on record
567 // --------------------------------------------------------------------
568 $i = 0;
569 $totalarray = array();
570 while ($i < min($num, $limit))
571 {
572  $line = $object->lines[$i];
573 
574  $total_debit += $line->debit;
575  $total_credit += $line->credit;
576 
577  $accountg = length_accountg($line->numero_compte);
578  //if (empty($accountg)) $accountg = '-';
579 
580  // Is it a break ?
581  if ($accountg != $displayed_account_number || !isset($displayed_account_number)) {
582  $colnumber = 5;
583  $colnumberend = 7;
584 
585  if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING) || empty($arrayfields['t.lettering_code']['checked'])) $colnumber--;
586  if (empty($arrayfields['t.date_export']['checked'])) $colnumber--;
587 
588  $colspan = $totalarray['nbfield'] - $colnumber;
589  $colspanend = $totalarray['nbfield'] - $colnumberend;
590  // Show a subtotal by accounting account
591  if (isset($displayed_account_number)) {
592  print '<tr class="liste_total">';
593  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("TotalForAccount").' '.length_accountg($displayed_account_number).':</td>';
594  print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
595  print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
596  print '<td colspan="'.$colspanend.'"></td>';
597  print '</tr>';
598  // Show balance of last shown account
599  $balance = $sous_total_debit - $sous_total_credit;
600  print '<tr class="liste_total">';
601  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
602  if ($balance > 0)
603  {
604  print '<td class="nowraponall right">';
605  print price($sous_total_debit - $sous_total_credit);
606  print '</td>';
607  print '<td></td>';
608  } else {
609  print '<td></td>';
610  print '<td class="nowraponall right">';
611  print price($sous_total_credit - $sous_total_debit);
612  print '</td>';
613  }
614  print '<td colspan="'.$colspanend.'"></td>';
615  print '</tr>';
616  }
617 
618  // Show the break account
619  print "<tr>";
620  print '<td colspan="'.($totalarray['nbfield'] ? $totalarray['nbfield'] : 10).'" style="font-weight:bold; border-bottom: 1pt solid black;">';
621  if ($line->numero_compte != "" && $line->numero_compte != '-1') print length_accountg($line->numero_compte).' : '.$object->get_compte_desc($line->numero_compte);
622  else print '<span class="error">'.$langs->trans("Unknown").'</span>';
623  print '</td>';
624  print '</tr>';
625 
626  $displayed_account_number = $accountg;
627  //if (empty($displayed_account_number)) $displayed_account_number='-';
628  $sous_total_debit = 0;
629  $sous_total_credit = 0;
630 
631  $colspan = 0;
632  }
633 
634  print '<tr class="oddeven">';
635 
636  // Piece number
637  if (!empty($arrayfields['t.piece_num']['checked']))
638  {
639  print '<td>';
640  $object->id = $line->id;
641  $object->piece_num = $line->piece_num;
642  print $object->getNomUrl(1, '', 0, '', 1);
643  print '</td>';
644  if (!$i) $totalarray['nbfield']++;
645  }
646 
647  // Journal code
648  if (!empty($arrayfields['t.code_journal']['checked']))
649  {
650  $accountingjournal = new AccountingJournal($db);
651  $result = $accountingjournal->fetch('', $line->code_journal);
652  $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
653  print '<td class="center">'.$journaltoshow.'</td>';
654  if (!$i) $totalarray['nbfield']++;
655  }
656 
657  // Document date
658  if (!empty($arrayfields['t.doc_date']['checked']))
659  {
660  print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
661  if (!$i) $totalarray['nbfield']++;
662  }
663 
664  // Document ref
665  if (!empty($arrayfields['t.doc_ref']['checked']))
666  {
667  if ($line->doc_type == 'customer_invoice')
668  {
669  $langs->loadLangs(array('bills'));
670 
671  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
672  $objectstatic = new Facture($db);
673  $objectstatic->fetch($line->fk_doc);
674  //$modulepart = 'facture';
675 
676  $filename = dol_sanitizeFileName($line->doc_ref);
677  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
678  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
679  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
680  } elseif ($line->doc_type == 'supplier_invoice')
681  {
682  $langs->loadLangs(array('bills'));
683 
684  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
685  $objectstatic = new FactureFournisseur($db);
686  $objectstatic->fetch($line->fk_doc);
687  //$modulepart = 'invoice_supplier';
688 
689  $filename = dol_sanitizeFileName($line->doc_ref);
690  $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
691  $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
692  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
693  } elseif ($line->doc_type == 'expense_report')
694  {
695  $langs->loadLangs(array('trips'));
696 
697  require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
698  $objectstatic = new ExpenseReport($db);
699  $objectstatic->fetch($line->fk_doc);
700  //$modulepart = 'expensereport';
701 
702  $filename = dol_sanitizeFileName($line->doc_ref);
703  $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
704  $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
705  $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
706  } else {
707  // Other type
708  }
709 
710  print '<td class="maxwidth400">';
711 
712  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
713  // Picto + Ref
714  print '<td class="nobordernopadding">';
715 
716  if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report')
717  {
718  print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
719  print $documentlink;
720  } else {
721  print $line->doc_ref;
722  }
723  print '</td></tr></table>';
724 
725  print "</td>\n";
726  if (!$i) $totalarray['nbfield']++;
727  }
728 
729  // Label operation
730  if (!empty($arrayfields['t.label_operation']['checked'])) {
731  // Affiche un lien vers la facture client/fournisseur
732  $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref);
733  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>';
734  if (!$i) $totalarray['nbfield']++;
735  }
736 
737  // Amount debit
738  if (!empty($arrayfields['t.debit']['checked']))
739  {
740  print '<td class="nowrap right">'.($line->debit ? price($line->debit) : '').'</td>';
741  if (!$i) $totalarray['nbfield']++;
742  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
743  $totalarray['val']['totaldebit'] += $line->debit;
744  }
745 
746  // Amount credit
747  if (!empty($arrayfields['t.credit']['checked'])) {
748  print '<td class="nowrap right">'.($line->credit ? price($line->credit) : '').'</td>';
749  if (!$i) $totalarray['nbfield']++;
750  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
751  $totalarray['val']['totalcredit'] += $line->credit;
752  }
753 
754  // Lettering code
755  if (!empty($arrayfields['t.lettering_code']['checked']))
756  {
757  print '<td class="center">'.$line->lettering_code.'</td>';
758  if (!$i) $totalarray['nbfield']++;
759  }
760 
761  // Exported operation date
762  if (!empty($arrayfields['t.date_export']['checked']))
763  {
764  print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>';
765  if (!$i) $totalarray['nbfield']++;
766  }
767 
768  // Fields from hook
769  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj);
770  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
771  print $hookmanager->resPrint;
772 
773  // Action column
774  print '<td class="nowraponall center">';
775  if (empty($line->date_export)) {
776  if ($user->rights->accounting->mouvements->creer) {
777  print '<a class="editfielda" 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>';
778  }
779  if ($user->rights->accounting->mouvements->supprimer) {
780  print ' &nbsp; <a class="paddingleft" href="'.$_SERVER['PHP_SELF'].'?action=delmouv&mvt_num='.$line->piece_num.$param.'&page='.$page.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">'.img_delete().'</a>';
781  }
782  }
783  print '</td>';
784  if (!$i) $totalarray['nbfield']++;
785 
786  // Comptabilise le sous-total
787  $sous_total_debit += $line->debit;
788  $sous_total_credit += $line->credit;
789 
790  print "</tr>\n";
791 
792  $i++;
793 }
794 
795 if ($num > 0) {
796  $colspan = $totalarray['nbfield'] - $colnumber;
797  $colspanend = $totalarray['nbfield'] - $colnumberend;
798  print '<tr class="liste_total">';
799  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("TotalForAccount").' '.$accountg.':</td>';
800  print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
801  print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
802  print '<td colspan="'.$colspanend.'"></td>';
803  print '</tr>';
804  // Show balance of last shown account
805  $balance = $sous_total_debit - $sous_total_credit;
806  print '<tr class="liste_total">';
807  print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
808  if ($balance > 0)
809  {
810  print '<td class="nowraponall right">';
811  print price($sous_total_debit - $sous_total_credit);
812  print '</td>';
813  print '<td></td>';
814  } else {
815  print '<td></td>';
816  print '<td class="nowraponall right">';
817  print price($sous_total_credit - $sous_total_debit);
818  print '</td>';
819  }
820  print '<td colspan="'.$colspanend.'"></td>';
821  print '</tr>';
822 }
823 
824 // Show total line
825 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
826 
827 
828 print "</table>";
829 print '</div>';
830 
831 // TODO Replace this with mass delete action
832 if ($user->rights->accounting->mouvements->supprimer_tous) {
833  print '<div class="tabsAction tabsActionNoBottom">'."\n";
834  print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear'.($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>';
835  print '</div>';
836 }
837 
838 print '</form>';
839 
840 // End of page
841 llxFooter();
842 $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.
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.
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.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
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.
Class to manage accounting accounts.
Class to manage invoices.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.