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