dolibarr 23.0.4
listbyaccount.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2016 Neil Orley <neil.orley@oeris.fr>
3 * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
4 * Copyright (C) 2013-2020 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2013-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
6 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2025 Nicolas Barrouillet <nicolas@pragma-tech.fr>
9 * Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../../main.inc.php';
33
34require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
37require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
38require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43
52// Load translation files required by the page
53$langs->loadLangs(array("accountancy", "categories", "compta", "other"));
54
55$journal_code = GETPOST('code_journal', 'alpha');
56$account = GETPOST("account", 'int');
57$massdate = dol_mktime(0, 0, 0, GETPOSTINT('massdatemonth'), GETPOSTINT('massdateday'), GETPOSTINT('massdateyear'));
58
59$action = GETPOST('action', 'aZ09');
60$socid = GETPOSTINT('socid');
61$mode = (GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : 'customer'); // Only for tab view
62$massaction = GETPOST('massaction', 'alpha');
63$confirm = GETPOST('confirm', 'alpha');
64$toselect = GETPOST('toselect', 'array:int');
65$type = GETPOST('type', 'alpha');
66if ($type == 'sub') {
67 $context_default = 'bookkeepingbysubaccountlist';
68} else {
69 $context_default = 'bookkeepingbyaccountlist';
70}
71$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : $context_default;
72
73$search_doc_date = GETPOSTDATE('doc_date', 'getpost'); // deprecated. Can use 'search_date_start/end'
74
75$search_date_startyear = GETPOSTINT('search_date_startyear');
76$search_date_startmonth = GETPOSTINT('search_date_startmonth');
77$search_date_startday = GETPOSTINT('search_date_startday');
78$search_date_start = GETPOSTDATE('search_date_start', 'getpost', 'auto', 'search_date_start_accountancy');
79
80$search_date_endyear = GETPOSTINT('search_date_endyear');
81$search_date_endmonth = GETPOSTINT('search_date_endmonth');
82$search_date_endday = GETPOSTINT('search_date_endday');
83$search_date_end = GETPOSTDATE('search_date_end', 'getpostend', 'auto', 'search_date_end_accountancy');
84
85$search_date_export_startyear = GETPOSTINT('search_date_export_startyear');
86$search_date_export_startmonth = GETPOSTINT('search_date_export_startmonth');
87$search_date_export_startday = GETPOSTINT('search_date_export_startday');
88$search_date_export_start = GETPOSTDATE('search_date_export_start', 'getpost');
89
90$search_date_export_endyear = GETPOSTINT('search_date_export_endyear');
91$search_date_export_endmonth = GETPOSTINT('search_date_export_endmonth');
92$search_date_export_endday = GETPOSTINT('search_date_export_endday');
93$search_date_export_end = GETPOSTDATE('search_date_export_start', 'getpostend');
94
95$search_date_validation_startyear = GETPOSTINT('search_date_validation_startyear');
96$search_date_validation_startmonth = GETPOSTINT('search_date_validation_startmonth');
97$search_date_validation_startday = GETPOSTINT('search_date_validation_startday');
98$search_date_validation_start = GETPOSTDATE('search_date_validation_start', 'getpost');
99
100$search_date_validation_endyear = GETPOSTINT('search_date_validation_endyear');
101$search_date_validation_endmonth = GETPOSTINT('search_date_validation_endmonth');
102$search_date_validation_endday = GETPOSTINT('search_date_validation_endday');
103$search_date_validation_end = GETPOSTDATE('search_date_validation_end', 'getpostend');
104
105// Due date start
106$search_date_due_start_day = GETPOSTINT('search_date_due_start_day');
107$search_date_due_start_month = GETPOSTINT('search_date_due_start_month');
108$search_date_due_start_year = GETPOSTINT('search_date_due_start_year');
109$search_date_due_start = GETPOSTDATE('search_date_due_start_', 'getpost');
110
111// Due date end
112$search_date_due_end_day = GETPOSTINT('search_date_due_end_day');
113$search_date_due_end_month = GETPOSTINT('search_date_due_end_month');
114$search_date_due_end_year = GETPOSTINT('search_date_due_end_year');
115$search_date_due_end = GETPOSTDATE('search_date_due_end_', 'getpostend');
116
117$search_import_key = GETPOST("search_import_key", 'alpha');
118
119$search_account_category = GETPOSTINT('search_account_category');
120
121$search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
122if ($search_accountancy_code_start == - 1) {
123 $search_accountancy_code_start = '';
124}
125$search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
126if ($search_accountancy_code_end == - 1) {
127 $search_accountancy_code_end = '';
128}
129$search_doc_ref = GETPOST('search_doc_ref', 'alpha');
130$search_label_operation = GETPOST('search_label_operation', 'alpha');
131$search_mvt_num = GETPOST('search_mvt_num', 'alpha');
132$search_direction = GETPOST('search_direction', 'alpha');
133$search_ledger_code = GETPOST('search_ledger_code', 'array');
134$search_debit = GETPOST('search_debit', 'alpha');
135$search_credit = GETPOST('search_credit', 'alpha');
136$search_lettering_code = GETPOST('search_lettering_code', 'alpha');
137$search_not_reconciled = GETPOST('search_not_reconciled', 'alpha');
138
139if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
140 $action = 'delbookkeepingyear';
141}
142
143// Load variable for pagination
144$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION', $conf->liste_limit);
145$sortfield = GETPOST('sortfield', 'aZ09comma');
146$sortorder = GETPOST('sortorder', 'aZ09comma');
147$optioncss = GETPOST('optioncss', 'alpha');
148$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
149if (empty($page) || $page < 0) {
150 $page = 0;
151}
152$offset = $limit * $page;
153$pageprev = $page - 1;
154$pagenext = $page + 1;
155if ($sortorder == "") {
156 $sortorder = "ASC";
157}
158if ($sortfield == "") {
159 $sortfield = "t.doc_date,t.rowid";
160}
161
162// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
163$object = new BookKeeping($db);
164$formfile = new FormFile($db);
165$hookmanager->initHooks(array($context_default));
166
167$formaccounting = new FormAccounting($db);
168$form = new Form($db);
169
170if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('search_date_startday') && !GETPOSTISSET('search_date_startmonth') && !GETPOSTISSET('search_date_starthour')) {
171 $sql = "SELECT date_start, date_end";
172 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear ";
173 if (getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT')) {
174 $sql .= " WHERE rowid = " . getDolGlobalInt('ACCOUNTANCY_FISCALYEAR_DEFAULT');
175 } else {
176 $sql .= " WHERE date_start < '" . $db->idate(dol_now()) . "' and date_end > '" . $db->idate(dol_now()) . "'";
177 }
178 $sql .= $db->plimit(1);
179 $res = $db->query($sql);
180
181 if ($res !== false && $db->num_rows($res) > 0) {
182 $fiscalYear = $db->fetch_object($res);
183 $search_date_start = strtotime($fiscalYear->date_start);
184 $search_date_end = strtotime($fiscalYear->date_end);
185 } else {
186 $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
187 $year_start = (int) dol_print_date(dol_now(), '%Y');
188 if (dol_print_date(dol_now(), '%m') < $month_start) {
189 $year_start--; // If current month is lower that starting fiscal month, we start last year
190 }
191 $year_end = $year_start + 1;
192 $month_end = $month_start - 1;
193 if ($month_end < 1) {
194 $month_end = 12;
195 $year_end--;
196 }
197 $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
198 $search_date_end = dol_get_last_day($year_end, $month_end);
199 }
200}
201
202$arrayfields = array(
203 // 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
204 't.piece_num' => array('label' => "TransactionNumShort", 'checked' => '1'),
205 't.code_journal' => array('label' => "Codejournal", 'checked' => '1'),
206 't.doc_date' => array('label' => "Docdate", 'checked' => '1'),
207 't.doc_ref' => array('label' => "Piece", 'checked' => '1'),
208 't.label_operation' => array('label' => "Label", 'checked' => '1'),
209 't.lettering_code' => array('label' => "Lettering", 'checked' => '1'),
210 't.debit' => array('label' => "AccountingDebit", 'checked' => '1'),
211 't.credit' => array('label' => "AccountingCredit", 'checked' => '1'),
212 't.balance' => array('label' => "Balance", 'checked' => '1'),
213 't.date_export' => array('label' => "DateExport", 'checked' => '-1'),
214 't.date_validated' => array('label' => "DateValidation", 'checked' => '-1', 'enabled' => (string) (int) !getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")),
215 't.date_lim_reglement' => array('label' => "DateDue", 'checked' => '0'),
216 't.import_key' => array('label' => "ImportId", 'checked' => '-1', 'position' => 1100),
217);
218
219if (!getDolGlobalString('ACCOUNTING_ENABLE_LETTERING')) {
220 unset($arrayfields['t.lettering_code']);
221}
222
223if ($search_date_start && empty($search_date_startyear)) {
224 $tmparray = dol_getdate($search_date_start);
225 $search_date_startyear = $tmparray['year'];
226 $search_date_startmonth = $tmparray['mon'];
227 $search_date_startday = $tmparray['mday'];
228}
229if ($search_date_end && empty($search_date_endyear)) {
230 $tmparray = dol_getdate($search_date_end);
231 $search_date_endyear = $tmparray['year'];
232 $search_date_endmonth = $tmparray['mon'];
233 $search_date_endday = $tmparray['mday'];
234}
235
236if (!isModEnabled('accounting')) {
238}
239if ($user->socid > 0) {
241}
242if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
244}
245
246$error = 0;
247$result = -1; // For static analysis
248$documentlink = ''; // For static analysis
249
250// Permissions
251$permissiontoread = $user->hasRight('accounting', 'mouvements', 'lire');
252$permissiontoadd = $user->hasRight('accounting', 'mouvements', 'creer');
253$permissiontodelete = $user->hasRight('accounting', 'mouvements', 'supprimer');
254$permissiontoexport = $user->hasRight('accounting', 'mouvements', 'export');
255
256
257/*
258 * Action
259 */
260
261$filter = array();
262$param = '';
263$url_param = '';
264
265if (GETPOST('cancel', 'alpha')) {
266 $action = 'list';
267 $massaction = '';
268}
269if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunletteringauto' && $massaction != 'preunletteringmanual' && $massaction != 'predeletebookkeepingwriting') {
270 $massaction = '';
271}
272
273$parameters = array('socid' => $socid);
274$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
275if ($reshook < 0) {
276 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
277}
278
279if (empty($reshook)) {
280 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
281
282 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
283 $search_doc_date = '';
284 $search_account_category = '';
285 $search_accountancy_code_start = '';
286 $search_accountancy_code_end = '';
287 $search_label_account = '';
288 $search_doc_ref = '';
289 $search_label_operation = '';
290 $search_mvt_num = '';
291 $search_direction = '';
292 $search_ledger_code = array();
293 $search_date_start = '';
294 $search_date_end = '';
295 $search_date_startyear = '';
296 $search_date_startmonth = '';
297 $search_date_startday = '';
298 $search_date_endyear = '';
299 $search_date_endmonth = '';
300 $search_date_endday = '';
301 $search_date_export_start = '';
302 $search_date_export_end = '';
303 $search_date_export_startyear = '';
304 $search_date_export_startmonth = '';
305 $search_date_export_startday = '';
306 $search_date_export_endyear = '';
307 $search_date_export_endmonth = '';
308 $search_date_export_endday = '';
309 $search_date_validation_start = '';
310 $search_date_validation_end = '';
311 $search_date_validation_startyear = '';
312 $search_date_validation_startmonth = '';
313 $search_date_validation_startday = '';
314 $search_date_validation_endyear = '';
315 $search_date_validation_endmonth = '';
316 $search_date_validation_endday = '';
317 // Due date start
318 $search_date_due_start_day = '';
319 $search_date_due_start_month = '';
320 $search_date_due_start_year = '';
321 $search_date_due_start = '';
322 // Due date end
323 $search_date_due_end_day = '';
324 $search_date_due_end_month = '';
325 $search_date_due_end_year = '';
326 $search_date_due_end = '';
327 $search_lettering_code = '';
328 $search_debit = '';
329 $search_credit = '';
330 $search_not_reconciled = '';
331 $search_import_key = '';
332 $toselect = array();
333 unset($_SESSION['DOLDATE_search_date_start_accountancy_day']);
334 unset($_SESSION['DOLDATE_search_date_start_accountancy_month']);
335 unset($_SESSION['DOLDATE_search_date_start_accountancy_year']);
336 unset($_SESSION['DOLDATE_search_date_end_accountancy_day']);
337 unset($_SESSION['DOLDATE_search_date_end_accountancy_month']);
338 unset($_SESSION['DOLDATE_search_date_end_accountancy_year']);
339 }
340
341 if (!empty($socid)) {
342 $param = '&socid='.$socid;
343 }
344 if (!empty($search_date_start)) {
345 $filter['t.doc_date>='] = $search_date_start;
346 $param .= '&search_date_startmonth='.$search_date_startmonth.'&search_date_startday='.$search_date_startday.'&search_date_startyear='.$search_date_startyear;
347 }
348 if (!empty($search_date_end)) {
349 $filter['t.doc_date<='] = $search_date_end;
350 $param .= '&search_date_endmonth='.$search_date_endmonth.'&search_date_endday='.$search_date_endday.'&search_date_endyear='.$search_date_endyear;
351 }
352 if (!empty($search_doc_date)) {
353 $filter['t.doc_date'] = $search_doc_date;
354 $param .= '&doc_datemonth='.GETPOSTINT('doc_datemonth').'&doc_dateday='.GETPOSTINT('doc_dateday').'&doc_dateyear='.GETPOSTINT('doc_dateyear');
355 }
356 if ($search_account_category != '-1' && !empty($search_account_category)) {
357 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
358 $accountingcategory = new AccountancyCategory($db);
359
360 $listofaccountsforgroup = $accountingcategory->getCptsCat(0, 'fk_accounting_category = '.((int) $search_account_category));
361 $listofaccountsforgroup2 = array();
362 if (is_array($listofaccountsforgroup)) {
363 foreach ($listofaccountsforgroup as $tmpval) {
364 $listofaccountsforgroup2[] = "'".$db->escape((string) $tmpval['account_number'])."'";
365 }
366 }
367 if (!empty($listofaccountsforgroup2)) {
368 $filter['t.search_accounting_code_in'] = implode(',', $listofaccountsforgroup2);
369 } else {
370 $filter['t.search_accounting_code_in'] = "''";
371 setEventMessages($langs->trans("ThisCategoryHasNoItems"), null, 'warnings');
372 }
373 $param .= '&search_account_category='.urlencode((string) ($search_account_category));
374 }
375 if (!empty($search_accountancy_code_start)) {
376 if ($type == 'sub') {
377 $filter['t.subledger_account>='] = $search_accountancy_code_start;
378 } else {
379 $filter['t.numero_compte>='] = $search_accountancy_code_start;
380 }
381 $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start);
382 }
383 if (!empty($search_accountancy_code_end)) {
384 if ($type == 'sub') {
385 $filter['t.subledger_account<='] = $search_accountancy_code_end;
386 } else {
387 $filter['t.numero_compte<='] = $search_accountancy_code_end;
388 }
389 $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end);
390 }
391 if (!empty($search_label_account)) {
392 $filter['t.label_compte'] = $search_label_account;
393 $param .= '&search_label_compte='.urlencode($search_label_account);
394 }
395 if (!empty($search_mvt_num)) {
396 $filter['t.piece_num'] = $search_mvt_num;
397 $param .= '&search_mvt_num='.urlencode((string) ($search_mvt_num));
398 }
399 if (!empty($search_doc_ref)) {
400 $filter['t.doc_ref'] = $search_doc_ref;
401 $param .= '&search_doc_ref='.urlencode($search_doc_ref);
402 }
403 if (!empty($search_label_operation)) {
404 $filter['t.label_operation'] = $search_label_operation;
405 $param .= '&search_label_operation='.urlencode($search_label_operation);
406 }
407 if (!empty($search_direction)) {
408 $filter['t.sens'] = $search_direction;
409 $param .= '&search_direction='.urlencode($search_direction);
410 }
411 if (!empty($search_ledger_code)) {
412 $filter['t.code_journal'] = $search_ledger_code;
413 foreach ($search_ledger_code as $code) {
414 $param .= '&search_ledger_code[]='.urlencode($code);
415 }
416 }
417 if (!empty($search_lettering_code)) {
418 $filter['t.lettering_code'] = $search_lettering_code;
419 $param .= '&search_lettering_code='.urlencode($search_lettering_code);
420 }
421 if (!empty($search_debit)) {
422 $filter['t.debit'] = $search_debit;
423 $param .= '&search_debit='.urlencode($search_debit);
424 }
425 if (!empty($search_credit)) {
426 $filter['t.credit'] = $search_credit;
427 $param .= '&search_credit='.urlencode($search_credit);
428 }
429 if (!empty($search_not_reconciled)) {
430 $filter['t.reconciled_option'] = $search_not_reconciled;
431 $param .= '&search_not_reconciled='.urlencode($search_not_reconciled);
432 }
433 if (!empty($search_date_export_start)) {
434 $filter['t.date_export>='] = $search_date_export_start;
435 $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;
436 }
437 if (!empty($search_date_export_end)) {
438 $filter['t.date_export<='] = $search_date_export_end;
439 $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;
440 }
441 if (!empty($search_date_validation_start)) {
442 $filter['t.date_validated>='] = $search_date_validation_start;
443 $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;
444 }
445 if (!empty($search_date_validation_end)) {
446 $filter['t.date_validated<='] = $search_date_validation_end;
447 $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;
448 }
449 // Due date start
450 if (!empty($search_date_due_start)) {
451 $filter['t.date_lim_reglement>='] = $search_date_due_start;
452 $param .= '&search_date_due_start_day='.$search_date_due_start_day.'&search_date_due_start_month='.$search_date_due_start_month.'&search_date_due_start_year='.$search_date_due_start_year;
453 }
454 // Due date end
455 if (!empty($search_date_due_end)) {
456 $filter['t.date_lim_reglement<='] = $search_date_due_end;
457 $param .= '&search_date_due_end_day='.$search_date_due_end_day.'&search_date_due_end_month='.$search_date_due_end_month.'&search_date_due_end_year='.$search_date_due_end_year;
458 }
459 if (!empty($search_import_key)) {
460 $filter['t.import_key'] = $search_import_key;
461 $param .= '&search_import_key='.urlencode($search_import_key);
462 }
463 // param with type of list
464 $url_param = substr($param, 1); // remove first "&"
465 if (!empty($type)) {
466 $param = '&type='.$type.$param;
467 }
468
469 // Actions
470 if ($action === 'exporttopdf' && $permissiontoadd) {
471 if ($type == "sub") {
472 $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter, 'AND', 1);
473 } else {
474 $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter);
475 }
476 require_once DOL_DOCUMENT_ROOT . '/core/modules/accountancy/doc/pdf_ledger.modules.php';
477 $pdf = new pdf_ledger($db);
478 $pdf->fromDate = $search_date_start;
479 $pdf->toDate = $search_date_end;
480 $pdf->ledgerType = $type;
481
482 $result = $pdf->write_file($object, $langs);
483
484 if ($result < 0) {
485 setEventMessage($pdf->error, "errors");
486 } else {
487 // Generated PDF is directly sent to the browser
488 exit;
489 }
490 }
491
492 // Mass actions
493 $objectclass = 'Bookkeeping';
494 $objectlabel = 'Bookkeeping';
495 $uploaddir = $conf->societe->dir_output;
496
497 global $error;
498 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
499
500 if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'supprimer')) {
501 $db->begin();
502
503 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
504 $lettering = new Lettering($db);
505 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
506 if ($nb_lettering < 0) {
507 setEventMessages('', $lettering->errors, 'errors');
508 $error++;
509 }
510 }
511
512 $nbok = 0;
513 if (!$error) {
514 foreach ($toselect as $toselectid) {
515 $result = $object->fetch($toselectid);
516 if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
517 $result = $object->deleteMvtNum($object->piece_num);
518 if ($result > 0) {
519 $nbok++;
520 } elseif ($result == 0) {
521 setEventMessages($langs->trans("ErrorBookkeepingDocDateNotOnActiveFiscalPeriod"), null, 'errors');
522 $error += 1;
523 break;
524 } else {
525 setEventMessages($object->error, $object->errors, 'errors');
526 $error++;
527 break;
528 }
529 } elseif ($result < 0) {
530 setEventMessages($object->error, $object->errors, 'errors');
531 $error++;
532 break;
533 } elseif (isset($object->date_validation) && $object->date_validation != '') {
534 setEventMessages($langs->trans("ValidatedRecordWhereFound"), null, 'errors');
535 $error++;
536 break;
537 }
538 }
539 }
540
541 if (!$error) {
542 $db->commit();
543
544 // Message for elements well deleted
545 if ($nbok > 1) {
546 setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
547 } elseif ($nbok > 0) {
548 setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
549 } elseif (!$error) {
550 setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
551 }
552
553 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
554 exit;
555 } else {
556 $db->rollback();
557 }
558 }
559
560 // massaction cloning
561 if (!$error && $action == 'clonebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'creer')) {
562 $result = $object->newCloneMass($toselect, $journal_code, $massdate);
563 if ($result == -1) {
564 $error++;
565 }
566 if ($error) {
567 $db->commit();
568 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
569 exit;
570 } else {
571 $db->rollback();
572 }
573 }
574
575 // massaction assign new account
576 if (!$error && $action == 'assignaccountbookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'creer')) {
577 $result = $object->assignAccountMass($toselect, (int) $account);
578 if ($result == -1) {
579 $error++;
580 }
581 if (!$error) {
582 $db->commit();
583 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
584 exit();
585 } else {
586 $db->rollback();
587 }
588 }
589
590 // mass action return account
591 if (!$error && $action == 'returnaccountbookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'creer')) {
592 $result = $object->newReturnAccount($toselect, $journal_code, $massdate);
593 if ($result == -1) {
594 $error++;
595 }
596 if (!$error) {
597 $db->commit();
598 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
599 exit();
600 } else {
601 $db->rollback();
602 }
603 }
604
605 // others mass actions
606 if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
607 if ($massaction == 'letteringauto' && $permissiontoadd) {
608 $lettering = new Lettering($db);
609 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect);
610 if ($nb_lettering < 0) {
611 setEventMessages('', $lettering->errors, 'errors');
612 $error++;
613 $nb_lettering = max(0, abs($nb_lettering) - 2);
614 } elseif ($nb_lettering == 0) {
615 $nb_lettering = 0;
616 setEventMessages($langs->trans('AccountancyNoLetteringModified'), array(), 'mesgs');
617 }
618 if ($nb_lettering == 1) {
619 setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
620 } elseif ($nb_lettering > 1) {
621 setEventMessages($langs->trans('AccountancyLetteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
622 }
623
624 if (!$error) {
625 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
626 exit();
627 }
628 } elseif ($massaction == 'letteringmanual' && $permissiontoadd) {
629 $lettering = new Lettering($db);
630 $result = $lettering->updateLettering($toselect);
631 if ($result < 0) {
632 setEventMessages('', $lettering->errors, 'errors');
633 } else {
634 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoLetteringModified' : 'AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
635 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
636 exit();
637 }
638 } elseif ($type == 'sub' && $massaction == 'letteringpartial') {
639 $lettering = new Lettering($db);
640 $result = $lettering->updateLettering($toselect, 0, true);
641 if ($result < 0) {
642 setEventMessages('', $lettering->errors, 'errors');
643 } else {
644 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoLetteringModified' : 'AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
645 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
646 exit();
647 }
648 } elseif ($action == 'unletteringauto' && $confirm == "yes" && $permissiontoadd) {
649 $lettering = new Lettering($db);
650 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
651 if ($nb_lettering < 0) {
652 setEventMessages('', $lettering->errors, 'errors');
653 $error++;
654 $nb_lettering = max(0, abs($nb_lettering) - 2);
655 } elseif ($nb_lettering == 0) {
656 $nb_lettering = 0;
657 setEventMessages($langs->trans('AccountancyNoUnletteringModified'), array(), 'mesgs');
658 }
659 if ($nb_lettering == 1) {
660 setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
661 } elseif ($nb_lettering > 1) {
662 setEventMessages($langs->trans('AccountancyUnletteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
663 }
664
665 if (!$error) {
666 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
667 exit();
668 }
669 } elseif ($action == 'unletteringmanual' && $confirm == "yes" && $permissiontoadd) {
670 $lettering = new Lettering($db);
671 $nb_lettering = $lettering->deleteLettering($toselect);
672 if ($result < 0) {
673 setEventMessages('', $lettering->errors, 'errors');
674 } else {
675 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoUnletteringModified' : 'AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
676 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
677 exit();
678 }
679 }
680 }
681}
682
683
684/*
685 * View
686 */
687
688$formaccounting = new FormAccounting($db);
689$formfile = new FormFile($db);
690$formother = new FormOther($db);
691$form = new Form($db);
692
693$title_page = $langs->trans("Operations").' - '.$langs->trans("VueByAccountAccounting").' (';
694if ($type == 'sub') {
695 $title_page .= $langs->trans("BookkeepingSubAccount");
696} else {
697 $title_page .= $langs->trans("Bookkeeping");
698}
699$title_page .= ')';
700$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double';
701llxHeader('', $title_page, $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-consultation page-'.(($type == 'sub') ? 'sub' : '').'ledger');
702
703if (!empty($socid)) {
704 $companystatic = new Societe($db);
705 $res = $companystatic->fetch($socid);
706 if ($res > 0) {
707 $tmpobject = $object;
708 $object = $companystatic; // $object must be of type Societe when calling societe_prepare_head
709 $head = societe_prepare_head($companystatic);
710 $object = $tmpobject;
711
712 print dol_get_fiche_head($head, 'accounting', $langs->trans("ThirdParty"), -1, 'company');
713
714 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
715
716 dol_banner_tab($companystatic, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
717
718 print '<div class="fichecenter">';
719
720 print '<div class="underbanner clearboth"></div>';
721 print '<table class="border centpercent tableforfield">';
722
723 // Type Prospect/Customer/Supplier
724 print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
725 print $companystatic->getTypeUrl(1);
726 print '</td></tr>';
727
728 // Customer code
729 if ($companystatic->client && !empty($companystatic->code_client)) {
730 print '<tr><td class="titlefield">';
731 print $langs->trans('CustomerCode').'</td><td>';
732 print showValueWithClipboardCPButton(dol_escape_htmltag($companystatic->code_client));
733 $tmpcheck = $companystatic->check_codeclient();
734 if ($tmpcheck != 0 && $tmpcheck != -5) {
735 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
736 }
737 print '</td>';
738 print '</tr>';
739 }
740 // Supplier code
741 if ($companystatic->fournisseur && !empty($companystatic->code_fournisseur)) {
742 print '<tr><td class="titlefield">';
743 print $langs->trans('SupplierCode').'</td><td>';
744 print showValueWithClipboardCPButton(dol_escape_htmltag($companystatic->code_fournisseur));
745 $tmpcheck = $companystatic->check_codefournisseur();
746 if ($tmpcheck != 0 && $tmpcheck != -5) {
747 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
748 }
749 print '</td>';
750 print '</tr>';
751 }
752
753 print '</table>';
754 print '</div>';
755 print dol_get_fiche_end();
756
757 print info_admin($langs->trans("WarningThisPageContainsOnlyEntriesTransferredInAccounting"));
758 print '<br>';
759
760 // Choice of mode (customer / supplier)
761 if (!empty($conf->dol_use_jmobile)) {
762 print "\n".'<div class="fichecenter"><div class="nowrap">'."\n";
763 }
764
765 if ($companystatic->client && !empty($companystatic->code_compta_client)) {
766 if ($mode != 'customer') {
767 if (!empty($companystatic->code_compta_client)) {
768 $subledger_start_account = $subledger_end_account = $companystatic->code_compta_client;
769 } else {
770 $subledger_start_account = $subledger_end_account = '';
771 }
772 print '<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="' . $_SERVER["PHP_SELF"] . '?mode=customer&socid='.$socid.'&type=sub&search_accountancy_code_start='.$subledger_start_account.'&search_accountancy_code_end='.$subledger_end_account.'">';
773 } else {
774 print '<span class="a-mesure marginleftonly marginrightonly">';
775 }
776
777 print $langs->trans("CustomerAccountancyCodeShort");
778 if ($mode != 'customer') {
779 print '</a>';
780 } else {
781 print '</span>';
782 }
783 }
784
785 if ($companystatic->fournisseur && !empty($companystatic->code_compta_fournisseur)) {
786 if ($mode != 'supplier') {
787 if (!empty($companystatic->code_compta_fournisseur)) {
788 $subledger_start_account = $subledger_end_account = $companystatic->code_compta_fournisseur;
789 } else {
790 $subledger_start_account = $subledger_end_account = '';
791 }
792 print '<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="' . $_SERVER["PHP_SELF"] . '?mode=supplier&socid='.$socid.'&type=sub&search_accountancy_code_start='.$subledger_start_account.'&search_accountancy_code_end='.$subledger_end_account.'">';
793 } else {
794 print '<span class="a-mesure marginleftonly marginrightonly">';
795 }
796 print $langs->trans("SupplierAccountancyCodeShort");
797 if ($mode != 'supplier') {
798 print '</a>';
799 } else {
800 print '</span>';
801 }
802 }
803
804 if (!empty($conf->dol_use_jmobile)) {
805 print '</div></div>';
806 } else {
807 print '<br>';
808 }
809 print '<br>';
810 }
811}
812
813// List
814$nbtotalofrecords = '';
815if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
816 // TODO Perf Replace this by a count
817 if ($type == 'sub') {
818 $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter, 'AND', 1, 1);
819 } else {
820 $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter, 'AND', 0, 1);
821 }
822
823 if ($nbtotalofrecords < 0) {
824 setEventMessages($object->error, $object->errors, 'errors');
825 $error++;
826 }
827}
828
829$num = 0;
830if (!$error) {
831 if ($type == 'sub') {
832 $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter, 'AND', 1);
833 } else {
834 $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter, 'AND', 0);
835 }
836 //$num = count($object->lines);
837 $num = $result; // $result is total nb of lines, or limit + 1, but $object->lines is always limited to $limit
838
839 if ($result < 0) {
840 setEventMessages($object->error, $object->errors, 'errors');
841 }
842}
843
844$arrayofselected = is_array($toselect) ? $toselect : array();
845
846// Print form confirm
847$formconfirm = '';
848print $formconfirm;
849
850// List of mass actions available
851$arrayofmassactions = array();
852if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) {
853 $arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringAuto');
854 $arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringAuto');
855 $arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringManual');
856 if ($type == 'sub') {
857 $arrayofmassactions['letteringpartial'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringPartial');
858 }
859 $arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringManual');
860}
861if ($user->hasRight('accounting', 'mouvements', 'creer')) {
862 $arrayofmassactions['preclonebookkeepingwriting'] = img_picto('', 'clone', 'class="pictofixedwidth"').$langs->trans("Clone");
863}
864if ($user->hasRight('accounting', 'mouvements', 'creer')) {
865 $arrayofmassactions['preassignaccountbookkeepingwriting'] = img_picto('', 'fa-exchange-alt', 'class="pictofixedwidth"').$langs->trans("AssignAccount");
866}
867if ($user->hasRight('accounting', 'mouvements', 'creer')) {
868 $arrayofmassactions['prereturnaccountbookkeepingwriting'] = img_picto('', 'undo', 'class="pictofixedwidth"').$langs->trans("ReturnAccount");
869}
870if ($user->hasRight('accounting', 'mouvements', 'supprimer')) {
871 $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
872}
873
874if (GETPOSTINT('nomassaction') || in_array($massaction, array('preunletteringauto', 'preunletteringmanual', 'predeletebookkeepingwriting', 'preclonebookkeepingwriting', 'preassignaccountbookkeepingwriting', 'prereturnaccountbookkeepingwriting'))) {
875 $arrayofmassactions = array();
876}
877$massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions);
878
879print '<form method="POST" id="searchFormList" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
880print '<input type="hidden" name="token" value="'.newToken().'">';
881print '<input type="hidden" name="action" value="list">';
882if ($optioncss != '') {
883 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
884}
885print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
886print '<input type="hidden" name="type" value="'.$type.'">';
887if (!empty($socid)) {
888 print '<input type="hidden" name="socid" value="' . $socid . '">';
889}
890print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
891print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
892print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
893
894$parameters = array('param' => $param);
895$reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
896if ($reshook < 0) {
897 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
898}
899
900$newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint;
901
902if (empty($reshook)) {
903 // Remove navigation buttons if in thirdparty tab mode, except for PDF printing
904 if (empty($socid)) {
905 $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/list.php?' . $param);
906 if ($type == 'sub') {
907 $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly'));
908 $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'));
909 } else {
910 $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
911 $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'));
912 }
913 }
914 $newcardbutton .= dolGetButtonTitle($langs->trans('ExportToPdf'), '', 'fa fa-file-pdf paddingleft', $_SERVER['PHP_SELF'] . '?action=exporttopdf'.(!empty($type) ? '&type=sub' : '').'&' . $url_param, '', $permissiontoexport, array('morecss' => 'marginleftonly'));
915
916 $newcardbutton .= dolGetButtonTitleSeparator();
917
918 $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=create'.(!empty($type) ? '&type=sub' : '').'&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
919}
920
921if ($contextpage != $_SERVER["PHP_SELF"]) {
922 $param .= '&contextpage='.urlencode($contextpage);
923}
924if ($limit > 0 && $limit != $conf->liste_limit) {
925 $param .= '&limit='.((int) $limit);
926}
927
928print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
929
930if ($massaction == 'preunletteringauto') {
931 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringAuto"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringauto", null, '', 0, 200, 500, 1);
932} elseif ($massaction == 'preunletteringmanual') {
933 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringManual"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringmanual", null, '', 0, 200, 500, 1);
934} elseif ($massaction == 'predeletebookkeepingwriting') {
935 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
936} elseif ($massaction == 'preassignaccountbookkeepingwriting') {
937 $input = $formaccounting->select_account('', 'account', 1);
938 $formquestion = array(array('type' => 'other', 'name' => 'account', 'label' => '<span class="fieldrequired">' . $langs->trans("AccountAccountingShort") . '</span>', 'value' => $input),);
939 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("confirmMassAssignAccountBookkeepingWritingConfirm"), $langs->trans("ConfirmMassAssignAccountBookkeepingWritingQuestion", count($toselect)), "assignaccountbookkeepingwriting", $formquestion, '', 0, 200, 500, 1);
940} elseif ($massaction == 'preclonebookkeepingwriting') {
941 $input1 = $form->selectDate('', 'massdate', 0, 0, 0, "create_mvt", 1, 1);
942 $input2 = $formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
943 $formquestion = array(
944 array(
945 'type' => 'other',
946 'name' => 'massdate',
947 'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>',
948 'value' => $input1
949 )
950 );
951
952 if (getDolGlobalString('ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL')) {
953 $formquestion[] = array(
954 'type' => 'text',
955 'name' => 'code_journal',
956 'label' => '<span class="fieldrequired">' . $langs->trans("Codejournal") . '</span>',
957 'value' => $input2
958 );
959 }
960
961 print $form->formconfirm(
962 $_SERVER["PHP_SELF"],
963 $langs->trans("ConfirmMassCloneBookkeepingWriting"),
964 $langs->trans("ConfirmMassCloneBookkeepingWritingQuestion", count($toselect)),
965 "clonebookkeepingwriting",
966 $formquestion,
967 '', 0, 200, 500, 1
968 );
969} elseif ($massaction == 'prereturnaccountbookkeepingwriting') {
970 $input1 = $form->selectDate('', 'massdate', 0, 0, 0, "create_mvt", 1, 1);
971 $formquestion = array(array('type' => 'other', 'name' => 'massdate', 'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>', 'value' => $input1));
972 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassReturnAccountBookkeepingWriting"), $langs->trans("ConfirmMassReturnAccountBookkeepingWritingQuestion", count($toselect)), "returnaccountbookkeepingwriting", $formquestion, '', 0, 200, 500, 1);
973}
974
975include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
976
977$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
978$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
979if ($massactionbutton && $contextpage != 'poslist') {
980 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
981}
982
983// Reverse sort order
984if (preg_match('/^asc/i', $sortorder)) {
985 $sortorder = "asc";
986} else {
987 $sortorder = "desc";
988}
989
990// Warning to explain why the list of record is not consistent with the other list view (missing a lot of lines)
991if ($type == 'sub' && !$socid) {
992 print info_admin($langs->trans("WarningRecordWithoutSubledgerAreExcluded"));
993 print '<br>';
994}
995
996$moreforfilter = '';
997
998// Search on accountancy custom groups or account
999$moreforfilter .= '<div class="divsearchfield">';
1000$moreforfilter .= $langs->trans('AccountAccounting').': ';
1001$moreforfilter .= '<div class="nowrap inline-block">';
1002if ($type == 'sub') {
1003 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
1004 $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), 'maxwidth200');
1005 } else {
1006 $moreforfilter .= '<input type="text" class="maxwidth150" name="search_accountancy_code_start" value="'.dol_escape_htmltag($search_accountancy_code_start).'" placeholder="'.$langs->trans('From').'">';
1007 }
1008} else {
1009 $moreforfilter .= $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200');
1010}
1011$moreforfilter .= ' ';
1012if ($type == 'sub') {
1013 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
1014 $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), 'maxwidth200');
1015 } else {
1016 $moreforfilter .= '<input type="text" class="maxwidth150" name="search_accountancy_code_end" value="'.dol_escape_htmltag($search_accountancy_code_end).'" placeholder="'.$langs->trans('to').'">';
1017 }
1018} else {
1019 $moreforfilter .= $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200');
1020}
1021
1022if (empty($socid)) {
1023 $moreforfilter .= '&nbsp;&nbsp;&nbsp;<a id="previous_account" accesskey="p" title="' . $conf->browser->stringforfirstkey . ' p" class="classfortooltip" href="#"><i class="fa fa-chevron-left"></i></a>';
1024 $moreforfilter .= '&nbsp;&nbsp;&nbsp;<a id="next_account" accesskey="n" title="' . $conf->browser->stringforfirstkey . ' n" class="classfortooltip" href="#"><i class="fa fa-chevron-right"></i></a>';
1025 $moreforfilter .= <<<SCRIPT
1026<script type="text/javascript">
1027 jQuery(document).ready(function() {
1028 var searchFormList = $('#searchFormList');
1029 var searchAccountancyCodeStart = $('#search_accountancy_code_start');
1030 var searchAccountancyCodeEnd = $('#search_accountancy_code_end');
1031 jQuery('#previous_account').on('click', function() {
1032 var previousOption = searchAccountancyCodeStart.find('option:selected').prev('option');
1033 if (previousOption.length == 1) searchAccountancyCodeStart.val(previousOption.attr('value'));
1034 searchAccountancyCodeEnd.val(searchAccountancyCodeStart.val());
1035 searchFormList.submit();
1036 });
1037 jQuery('#next_account').on('click', function() {
1038 var nextOption = searchAccountancyCodeStart.find('option:selected').next('option');
1039 if (nextOption.length == 1) searchAccountancyCodeStart.val(nextOption.attr('value'));
1040 searchAccountancyCodeEnd.val(searchAccountancyCodeStart.val());
1041 searchFormList.submit();
1042 });
1043 jQuery('input[name="search_mvt_num"]').on("keypress", function(event) {
1044 console.log(event);
1045 });
1046 });
1047</script>
1048SCRIPT;
1049}
1050$moreforfilter .= '</div>';
1051$moreforfilter .= '</div>';
1052
1053if (empty($socid)) {
1054 $moreforfilter .= '<div class="divsearchfield">';
1055 $moreforfilter .= $langs->trans('AccountingCategory') . ': ';
1056 $moreforfilter .= '<div class="nowrap inline-block">';
1057 $moreforfilter .= $formaccounting->select_accounting_category($search_account_category, 'search_account_category', 1, 0, 0, 0);
1058 $moreforfilter .= '</div>';
1059 $moreforfilter .= '</div>';
1060}
1061
1062$parameters = array();
1063$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1064if (empty($reshook)) {
1065 $moreforfilter .= $hookmanager->resPrint;
1066} else {
1067 $moreforfilter = $hookmanager->resPrint;
1068}
1069
1070print '<div class="liste_titre liste_titre_bydiv centpercent">';
1071print $moreforfilter;
1072print '</div>';
1073
1074print '<div class="div-table-responsive">';
1075print '<table class="tagtable liste centpercent listwithfilterbefore">';
1076
1077// Filters lines
1078print '<tr class="liste_titre_filter">';
1079// Action column
1080if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1081 print '<td class="liste_titre center">';
1082 $searchpicto = $form->showFilterButtons('left');
1083 print $searchpicto;
1084 print '</td>';
1085}
1086// Movement number
1087if (!empty($arrayfields['t.piece_num']['checked'])) {
1088 print '<td class="liste_titre"><input type="text" name="search_mvt_num" class="width50" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
1089}
1090// Code journal
1091if (!empty($arrayfields['t.code_journal']['checked'])) {
1092 print '<td class="liste_titre center">';
1093 print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1, 'maxwidth75');
1094 print '</td>';
1095}
1096// Date document
1097if (!empty($arrayfields['t.doc_date']['checked'])) {
1098 print '<td class="liste_titre center">';
1099 print '<div class="nowrapfordate">';
1100 print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1101 print '</div>';
1102 print '<div class="nowrapfordate">';
1103 print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1104 print '</div>';
1105 print '</td>';
1106}
1107// Ref document
1108if (!empty($arrayfields['t.doc_ref']['checked'])) {
1109 print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"/></td>';
1110}
1111// Label operation
1112if (!empty($arrayfields['t.label_operation']['checked'])) {
1113 print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_operation" value="'.dol_escape_htmltag($search_label_operation).'"/></td>';
1114}
1115// Matching code
1116if (!empty($arrayfields['t.lettering_code']['checked'])) {
1117 print '<td class="liste_titre center">';
1118 print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
1119 print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
1120 print '</td>';
1121}
1122// Debit
1123if (!empty($arrayfields['t.debit']['checked'])) {
1124 print '<td class="liste_titre right"><input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'"></td>';
1125}
1126// Credit
1127if (!empty($arrayfields['t.credit']['checked'])) {
1128 print '<td class="liste_titre right"><input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'"></td>';
1129}
1130// Balance
1131if (!empty($arrayfields['t.balance']['checked'])) {
1132 print '<td></td>';
1133}
1134// Date export
1135if (!empty($arrayfields['t.date_export']['checked'])) {
1136 print '<td class="liste_titre center">';
1137 print '<div class="nowrapfordate">';
1138 print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1139 print '</div>';
1140 print '<div class="nowrapfordate">';
1141 print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1142 print '</div>';
1143 print '</td>';
1144}
1145// Date validation
1146if (!empty($arrayfields['t.date_validated']['checked'])) {
1147 print '<td class="liste_titre center">';
1148 print '<div class="nowrapfordate">';
1149 print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1150 print '</div>';
1151 print '<div class="nowrapfordate">';
1152 print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1153 print '</div>';
1154 print '</td>';
1155}
1156// Due date start and end
1157if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1158 print '<td class="liste_titre center">';
1159 print '<div class="nowrapfordate">';
1160 print $form->selectDate($search_date_due_start, 'search_date_due_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1161 print '</div>';
1162 print '<div class="nowrapfordate">';
1163 print $form->selectDate($search_date_due_end, 'search_date_due_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1164 print '</div>';
1165 print '</td>';
1166}
1167if (!empty($arrayfields['t.import_key']['checked'])) {
1168 print '<td class="liste_titre center">';
1169 print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
1170 print '</td>';
1171}
1172
1173// Fields from hook
1174$parameters = array('arrayfields' => $arrayfields);
1175$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1176print $hookmanager->resPrint;
1177
1178// Action column
1179if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1180 print '<td class="liste_titre center">';
1181 $searchpicto = $form->showFilterButtons();
1182 print $searchpicto;
1183 print '</td>';
1184}
1185print "</tr>\n";
1186
1187print '<tr class="liste_titre">';
1188if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1189 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1190}
1191if (!empty($arrayfields['t.piece_num']['checked'])) {
1192 print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax80imp ');
1193}
1194if (!empty($arrayfields['t.code_journal']['checked'])) {
1195 print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
1196}
1197if (!empty($arrayfields['t.doc_date']['checked'])) {
1198 print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
1199}
1200if (!empty($arrayfields['t.doc_ref']['checked'])) {
1201 print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
1202}
1203if (!empty($arrayfields['t.label_operation']['checked'])) {
1204 print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
1205}
1206if (!empty($arrayfields['t.lettering_code']['checked'])) {
1207 print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
1208}
1209if (!empty($arrayfields['t.debit']['checked'])) {
1210 print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
1211}
1212if (!empty($arrayfields['t.credit']['checked'])) {
1213 print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
1214}
1215if (!empty($arrayfields['t.balance']['checked'])) {
1216 print_liste_field_titre($arrayfields['t.balance']['label'], "", "", "", $param, '', $sortfield, $sortorder, 'right ');
1217}
1218if (!empty($arrayfields['t.date_export']['checked'])) {
1219 print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center ');
1220}
1221if (!empty($arrayfields['t.date_validated']['checked'])) {
1222 print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated", "", $param, '', $sortfield, $sortorder, 'center ');
1223}
1224// Due date
1225if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1226 print_liste_field_titre($arrayfields['t.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], 't.date_lim_reglement', '', $param, '', $sortfield, $sortorder, 'center ');
1227}
1228if (!empty($arrayfields['t.import_key']['checked'])) {
1229 print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER["PHP_SELF"], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1230}
1231// Hook fields
1232$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1233$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1234print $hookmanager->resPrint;
1235if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1236 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1237}
1238print "</tr>\n";
1239
1240$displayed_account_number = null; // Start with undefined to be able to distinguish with empty
1241
1242$objectstatic = null; // Init for static analysis
1243$objectlink = ''; // Init for static analysis
1244$result = -1; // Init for static analysis
1245
1246// Loop on record
1247// --------------------------------------------------------------------
1248$i = 0;
1249
1250$totalarray = array();
1251$totalarray['nbfield'] = 0;
1252$sous_total_debit = 0;
1253$sous_total_credit = 0;
1254$totalarray['val'] = array();
1255$totalarray['val']['totaldebit'] = 0;
1256$totalarray['val']['totalcredit'] = 0;
1257$totalarray['val']['totalbalance'] = 0;
1258
1259// Init for static analysis
1260$colspan = 0; // colspan before field 'label of operation'
1261$colspanend = 0; // colspan after debit/credit
1262$accountg = '-';
1263
1264$colspan = 0; // colspan before field 'label of operation'
1265$colspanend = 3; // colspan after debit/credit
1266if (!empty($arrayfields['t.piece_num']['checked'])) { $colspan++; }
1267if (!empty($arrayfields['t.code_journal']['checked'])) { $colspan++; }
1268if (!empty($arrayfields['t.doc_date']['checked'])) { $colspan++; }
1269if (!empty($arrayfields['t.doc_ref']['checked'])) { $colspan++; }
1270if (!empty($arrayfields['t.label_operation']['checked'])) { $colspan++; }
1271if (!empty($arrayfields['t.date_export']['checked'])) { $colspanend++; }
1272if (!empty($arrayfields['t.date_validated']['checked'])) { $colspanend++; }
1273if (!empty($arrayfields['t.lettering_code']['checked'])) { $colspanend++; }
1274if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1275 $colspan++;
1276 $colspanend--;
1277}
1278
1279while ($i < min($num, $limit)) {
1280 $line = $object->lines[$i];
1281
1282 if ($type == 'sub') {
1283 $accountg = length_accounta($line->subledger_account);
1284 } else {
1285 $accountg = length_accountg($line->numero_compte);
1286 }
1287 //if (empty($accountg)) $accountg = '-';
1288
1289 $colspan = 0; // colspan before field 'label of operation'
1290 $colspanend = 0; // colspan after debit/credit
1291 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1292 $colspan++;
1293 }
1294 if (!empty($arrayfields['t.piece_num']['checked'])) {
1295 $colspan++;
1296 }
1297 if (!empty($arrayfields['t.code_journal']['checked'])) {
1298 $colspan++;
1299 }
1300 if (!empty($arrayfields['t.doc_date']['checked'])) {
1301 $colspan++;
1302 }
1303 if (!empty($arrayfields['t.doc_ref']['checked'])) {
1304 $colspan++;
1305 }
1306 if (!empty($arrayfields['t.label_operation']['checked'])) {
1307 $colspan++;
1308 }
1309 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1310 $colspan++;
1311 }
1312
1313 if (!empty($arrayfields['t.balance']['checked'])) {
1314 $colspanend++;
1315 }
1316 if (!empty($arrayfields['t.date_export']['checked'])) {
1317 $colspanend++;
1318 }
1319 if (!empty($arrayfields['t.date_validated']['checked'])) {
1320 $colspanend++;
1321 }
1322 // Due date
1323 if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1324 $colspanend++;
1325 }
1326 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1327 $colspanend++;
1328 }
1329 if (!empty($arrayfields['t.import_key']['checked'])) {
1330 $colspanend++;
1331 }
1332 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1333 $colspan++;
1334 $colspanend--;
1335 }
1336
1337 // Is it a break ?
1338 if ($accountg != $displayed_account_number || !isset($displayed_account_number)) {
1339 // Show a subtotal by accounting account
1340 if (isset($displayed_account_number)) {
1341 print '<tr class="liste_total">';
1342 if ($type == 'sub') {
1343 print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accounta($displayed_account_number) . ':</td>';
1344 } else {
1345 print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accountg($displayed_account_number) . ':</td>';
1346 }
1347 print '<td class="nowrap right">'.price(price2num($sous_total_debit, 'MT')).'</td>';
1348 print '<td class="nowrap right">'.price(price2num($sous_total_credit, 'MT')).'</td>';
1349 if ($colspanend > 0) {
1350 print '<td colspan="'.$colspanend.'"></td>';
1351 }
1352 print '</tr>';
1353 // Show balance of last shown account
1354 $balance = $sous_total_debit - $sous_total_credit;
1355 print '<tr class="liste_total">';
1356 print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
1357 if ($balance > 0) {
1358 print '<td class="nowraponall right">';
1359 print price(price2num($sous_total_debit - $sous_total_credit, 'MT'));
1360 print '</td>';
1361 print '<td></td>';
1362 } else {
1363 print '<td></td>';
1364 print '<td class="nowraponall right">';
1365 print price(price2num($sous_total_credit - $sous_total_debit, 'MT'));
1366 print '</td>';
1367 }
1368 if ($colspanend > 0) {
1369 print '<td colspan="'.$colspanend.'"></td>';
1370 }
1371 print '</tr>';
1372 }
1373
1374 // Show the break account
1375 print '<tr class="trforbreaknobg">';
1376 print '<td colspan="'.($totalarray['nbfield'] ? $totalarray['nbfield'] : count($arrayfields) + 1).'" class="tdforbreak">';
1377 if ($type == 'sub') {
1378 if ($line->subledger_account != "" && $line->subledger_account != '-1') {
1379 print empty($line->subledger_label) ? '<span class="error">'.$langs->trans("Unknown").'</span>' : $line->subledger_label;
1380 print ' : ';
1381 print length_accounta($line->subledger_account);
1382 } else {
1383 // Should not happen: subledger account must be null or a non empty value
1384 print '<span class="error">' . $langs->trans("Unknown");
1385 if ($line->subledger_label) {
1386 print ' (' . $line->subledger_label . ')';
1387 $htmltext = 'EmptyStringForSubledgerAccountButSubledgerLabelDefined';
1388 } else {
1389 $htmltext = 'EmptyStringForSubledgerAccountAndSubledgerLabel';
1390 }
1391 print $form->textwithpicto('', $htmltext);
1392 print '</span>';
1393 }
1394 } else {
1395 if ($line->numero_compte != "" && $line->numero_compte != '-1') {
1396 print length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte);
1397 } else {
1398 print '<span class="error">' . $langs->trans("Unknown") . '</span>';
1399 }
1400 }
1401 print '</td>';
1402 print '</tr>';
1403
1404 $displayed_account_number = $accountg;
1405 //if (empty($displayed_account_number)) $displayed_account_number='-';
1406 $sous_total_debit = 0;
1407 $sous_total_credit = 0;
1408 }
1409
1410 print '<tr class="oddeven">';
1411 // Action column
1412 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1413 print '<td class="nowraponall center">';
1414 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
1415 $selected = 0;
1416 if (in_array($line->id, $arrayofselected)) {
1417 $selected = 1;
1418 }
1419 print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
1420 }
1421 print '</td>';
1422 if (!$i) {
1423 $totalarray['nbfield']++;
1424 }
1425 }
1426 // Piece number
1427 if (!empty($arrayfields['t.piece_num']['checked'])) {
1428 print '<td class="nowraponall">';
1429 $object->id = $line->id;
1430 $object->piece_num = $line->piece_num;
1431 $object->ref = $line->ref;
1432 print $object->getNomUrl(1, '', 0, '', 1);
1433 print '<span class="hideonsmartphone">';
1434 if (!empty($line->date_export)) {
1435 print img_picto($langs->trans("DateExport").": ".dol_print_date($line->date_export, 'dayhour')." (".$langs->trans("TransactionExportDesc").")", 'fa-file-export', 'class="paddingleft pictofixedwidth opacitymedium"');
1436 }
1437 if (!empty($line->date_validation)) {
1438 print img_picto($langs->trans("DateValidation").": ".dol_print_date($line->date_validation, 'dayhour')." (".$langs->trans("TransactionBlockedLockedDesc").")", 'fa-lock', 'class="paddingleft pictofixedwidth opacitymedium"');
1439 }
1440 print '</span>';
1441 print '</td>';
1442 if (!$i) {
1443 $totalarray['nbfield']++;
1444 }
1445 }
1446
1447 // Journal code
1448 if (!empty($arrayfields['t.code_journal']['checked'])) {
1449 $accountingjournal = new AccountingJournal($db);
1450 $result = $accountingjournal->fetch(0, $line->code_journal);
1451 $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
1452 print '<td class="center tdoverflowmax80">'.$journaltoshow.'</td>';
1453 if (!$i) {
1454 $totalarray['nbfield']++;
1455 }
1456 }
1457
1458 // Document date
1459 if (!empty($arrayfields['t.doc_date']['checked'])) {
1460 print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
1461 if (!$i) {
1462 $totalarray['nbfield']++;
1463 }
1464 }
1465
1466 // Document ref
1467 $modulepart = '';
1468 if (!empty($arrayfields['t.doc_ref']['checked'])) {
1469 if ($line->doc_type == 'customer_invoice') {
1470 $langs->loadLangs(array('bills'));
1471
1472 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1473 $objectstatic = new Facture($db);
1474 $objectstatic->fetch($line->fk_doc);
1475 //$modulepart = 'facture';
1476
1477 $filename = dol_sanitizeFileName($line->doc_ref);
1478 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1479 $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1480 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1481 } elseif ($line->doc_type == 'supplier_invoice') {
1482 $langs->loadLangs(array('bills'));
1483
1484 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1485 $objectstatic = new FactureFournisseur($db);
1486 $objectstatic->fetch($line->fk_doc);
1487
1488 $modulepart = 'invoice_supplier';
1489 $filename = dol_sanitizeFileName($line->doc_ref);
1490 $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1491 $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1492 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
1493 } elseif ($line->doc_type == 'expense_report') {
1494 $langs->loadLangs(array('trips'));
1495
1496 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1497 $objectstatic = new ExpenseReport($db);
1498 $objectstatic->fetch($line->fk_doc);
1499 //$modulepart = 'expensereport';
1500
1501 $filename = dol_sanitizeFileName($line->doc_ref);
1502 $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1503 $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1504 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1505 } elseif ($line->doc_type == 'bank') {
1506 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1507 $objectstatic = new AccountLine($db);
1508 $objectstatic->fetch($line->fk_doc);
1509 } else {
1510 // Other type
1511 }
1512
1513 print '<td class="tdoverflowmax250">';
1514
1515 // Picto + Ref
1516 if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
1517 print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1518 print $documentlink;
1519 } elseif ($line->doc_type == 'bank') {
1520 print $objectstatic->getNomUrl(1);
1521 $bank_ref = strstr($line->doc_ref, '-');
1522 print ' <span class="classfortooltip" title="'.dol_escape_htmltag($line->doc_ref).'">'.dol_escape_htmltag($bank_ref).'</span>';
1523 } else {
1524 print $line->doc_ref;
1525 }
1526
1527 print "</td>\n";
1528 if (!$i) {
1529 $totalarray['nbfield']++;
1530 }
1531 }
1532
1533 // Label operation
1534 if (!empty($arrayfields['t.label_operation']['checked'])) {
1535 // Show a link to the customer/supplier invoice
1536 $doc_ref = preg_replace('/\‍(.*\‍)/', '', $line->doc_ref);
1537 if (strlen(length_accounta($line->subledger_account)) == 0) {
1538 print '<td class="small tdoverflowmax350 classfortooltip" title="'.dol_escape_htmltag($line->label_operation).'">'.dol_escape_htmltag($line->label_operation).'</td>';
1539 } else {
1540 print '<td class="small tdoverflowmax350 classfortooltip" title="'.dol_escape_htmltag($line->label_operation.($line->label_operation ? '<br>' : '').'<span style="font-size:0.8em">('.length_accounta($line->subledger_account).')').'">'.dol_escape_htmltag($line->label_operation).($line->label_operation ? '<br>' : '').'<span style="font-size:0.8em">('.dol_escape_htmltag(length_accounta($line->subledger_account)).')</span></td>';
1541 }
1542 if (!$i) {
1543 $totalarray['nbfield']++;
1544 }
1545 }
1546
1547 // Matching code
1548 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1549 print '<td class="center">'.dol_escape_htmltag((string) $line->lettering_code).'</td>';
1550 if (!$i) {
1551 $totalarray['nbfield']++;
1552 }
1553 }
1554
1555 // Amount debit
1556 if (!empty($arrayfields['t.debit']['checked'])) {
1557 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
1558 if (!$i) {
1559 $totalarray['nbfield']++;
1560 }
1561 if (!$i) {
1562 $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
1563 }
1564 $totalarray['val']['totaldebit'] += (float) $line->debit;
1565 }
1566
1567 // Amount credit
1568 if (!empty($arrayfields['t.credit']['checked'])) {
1569 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
1570 if (!$i) {
1571 $totalarray['nbfield']++;
1572 }
1573 if (!$i) {
1574 $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
1575 }
1576 $totalarray['val']['totalcredit'] += (float) $line->credit;
1577 }
1578
1579 // Amount balance
1580 if (!empty($arrayfields['t.balance']['checked'])) {
1581 print '<td class="right nowraponall amount">'.price(price2num($sous_total_debit + $line->debit - $sous_total_credit - $line->credit, 'MT')).'</td>';
1582 if (!$i) {
1583 $totalarray['nbfield']++;
1584 }
1585 if (!$i) {
1586 $totalarray['pos'][$totalarray['nbfield']] = 'totalbalance';
1587 };
1588 $totalarray['val']['totalbalance'] += $line->debit - $line->credit;
1589 }
1590
1591 // Exported operation date
1592 if (!empty($arrayfields['t.date_export']['checked'])) {
1593 print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>';
1594 if (!$i) {
1595 $totalarray['nbfield']++;
1596 }
1597 }
1598
1599 // Validated operation date
1600 if (!empty($arrayfields['t.date_validated']['checked'])) {
1601 print '<td class="center">'.dol_print_date($line->date_validation, 'dayhour').'</td>';
1602 if (!$i) {
1603 $totalarray['nbfield']++;
1604 }
1605 }
1606
1607 // Due date
1608 if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1609 print '<td class="center">'.dol_print_date($line->date_lim_reglement, 'day').'</td>';
1610 if (!$i) {
1611 $totalarray['nbfield']++;
1612 }
1613 }
1614
1615 if (!empty($arrayfields['t.import_key']['checked'])) {
1616 print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($line->import_key).'">'.dol_escape_htmltag($line->import_key)."</td>\n";
1617 if (!$i) {
1618 $totalarray['nbfield']++;
1619 }
1620 }
1621
1622 // Fields from hook
1623 $parameters = array('arrayfields' => $arrayfields, 'obj' => $line);
1624 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1625 print $hookmanager->resPrint;
1626
1627 // Action column
1628 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1629 print '<td class="nowraponall center">';
1630 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
1631 $selected = 0;
1632 if (in_array($line->id, $arrayofselected)) {
1633 $selected = 1;
1634 }
1635 print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
1636 }
1637 print '</td>';
1638 if (!$i) {
1639 $totalarray['nbfield']++;
1640 }
1641 }
1642
1643 // Comptabilise le sous-total
1644 $sous_total_debit += $line->debit;
1645 $sous_total_credit += $line->credit;
1646
1647 print "</tr>\n";
1648
1649 $i++;
1650}
1651
1652if ($num > 0 && $colspan > 0) {
1653 print '<tr class="liste_total">';
1654 print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("TotalForAccount").' '.$accountg.':</td>';
1655 print '<td class="nowrap right">'.price(price2num($sous_total_debit, 'MT')).'</td>';
1656 print '<td class="nowrap right">'.price(price2num($sous_total_credit, 'MT')).'</td>';
1657 if ($colspanend > 0) {
1658 print '<td colspan="'.$colspanend.'"></td>';
1659 }
1660 print '</tr>';
1661
1662 // Show balance of last shown account
1663 $balance = $sous_total_debit - $sous_total_credit;
1664 print '<tr class="liste_total">';
1665 print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
1666 if ($balance > 0) {
1667 print '<td class="nowraponall right">';
1668 print price(price2num($sous_total_debit - $sous_total_credit, 'MT'));
1669 print '</td>';
1670 print '<td></td>';
1671 } else {
1672 print '<td></td>';
1673 print '<td class="nowraponall right">';
1674 print price(price2num($sous_total_credit - $sous_total_debit, 'MT'));
1675 print '</td>';
1676 }
1677 if ($colspanend > 0) {
1678 print '<td colspan="'.$colspanend.'"></td>';
1679 }
1680 print '</tr>';
1681}
1682
1683
1684// Clean total values to round them
1685if (!empty($totalarray['val']['totaldebit'])) {
1686 $totalarray['val']['totaldebit'] = (float) price2num($totalarray['val']['totaldebit'], 'MT');
1687}
1688if (!empty($totalarray['val']['totalcredit'])) {
1689 $totalarray['val']['totalcredit'] = (float) price2num($totalarray['val']['totalcredit'], 'MT');
1690}
1691if (!empty($totalarray['val']['totalbalance'])) {
1692 $totalarray['val']['totalbalance'] = (float) price2num($totalarray['val']['totaldebit'] - $totalarray['val']['totalcredit'], 'MT');
1693}
1694
1695// Show total line
1696$trforbreaknobg = 1; // used in list_print_total.tpl.php
1697include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1698
1699// If no record found
1700if ($num == 0) {
1701 $colspan = 1;
1702 foreach ($arrayfields as $key => $val) {
1703 if (!empty($val['checked'])) {
1704 $colspan++;
1705 }
1706 }
1707 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1708}
1709
1710$parameters = array('arrayfields' => $arrayfields);
1711$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1712print $hookmanager->resPrint;
1713
1714print "</table>";
1715print '</div>';
1716
1717print '</form>';
1718
1719// End of page
1720llxFooter();
1721$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition export.php:1216
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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank transaction lines.
Class to manage categories of an accounting account.
Class to manage accounting journals.
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.
Class permettant la generation de composants html autre Only common components are here.
Class Lettering.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to build sending documents with model Espadon.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:637
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:132
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.