dolibarr 24.0.2
listbyaccount.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2016 Neil Orley <neil.orley@oeris.fr>
3 * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
4 * Copyright (C) 2013-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;
499 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
500
501 if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'supprimer')) {
502 $db->begin();
503
504 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
505 $lettering = new Lettering($db);
506 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
507 if ($nb_lettering < 0) {
508 setEventMessages('', $lettering->errors, 'errors');
509 $error += 1;
510 }
511 }
512
513 $nbok = 0;
514 if (!$error) {
515 foreach ($toselect as $toselectid) {
516 $result = $object->fetch($toselectid);
517 if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
518 $result = $object->deleteMvtNum($object->piece_num);
519 if ($result > 0) {
520 $nbok++;
521 } elseif ($result == 0) {
522 setEventMessages($langs->trans("ErrorBookkeepingDocDateNotOnActiveFiscalPeriod"), null, 'errors');
523 $error += 1;
524 break;
525 } else {
526 setEventMessages($object->error, $object->errors, 'errors');
527 $error += 1;
528 break;
529 }
530 } elseif ($result < 0) {
531 setEventMessages($object->error, $object->errors, 'errors');
532 $error += 1;
533 break;
534 } elseif (isset($object->date_validation) && $object->date_validation != '') {
535 setEventMessages($langs->trans("ValidatedRecordWhereFound"), null, 'errors');
536 $error += 1;
537 break;
538 }
539 }
540 }
541
542 if (!$error) {
543 $db->commit();
544
545 // Message for elements well deleted
546 if ($nbok > 1) {
547 setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
548 } elseif ($nbok > 0) {
549 setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
550 } elseif (!$error) {
551 setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
552 }
553
554 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
555 exit;
556 } else {
557 $db->rollback();
558 }
559 }
560
561 // massaction cloning
562 if (!$error && $action == 'clonebookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'creer')) {
563 $result = $object->newCloneMass($toselect, $journal_code, $massdate);
564 if ($result == -1) {
565 $error += 1;
566 }
567 if (!$error) {
568 $db->commit();
569 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
570 exit;
571 } else {
572 $db->rollback();
573 }
574 }
575
576 // massaction assign new account
577 if (!$error && $action == 'assignaccountbookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'creer')) {
578 $result = $object->assignAccountMass($toselect, (int) $account);
579 if ($result == -1) {
580 $error += 1;
581 }
582 if (!$error) {
583 $db->commit();
584 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
585 exit();
586 } else {
587 $db->rollback();
588 }
589 }
590
591 // mass action return account
592 if (!$error && $action == 'returnaccountbookkeepingwriting' && $confirm == "yes" && $user->hasRight('accounting', 'mouvements', 'creer')) {
593 $result = $object->newReturnAccount($toselect, $journal_code, $massdate);
594 if ($result == -1) {
595 $error += 1;
596 }
597 if (!$error) {
598 $db->commit();
599 header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
600 exit();
601 } else {
602 $db->rollback();
603 }
604 }
605
606 // others mass actions
607 if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
608 if ($massaction == 'generalmatchingmanual' && $permissiontoadd) {
609 $lettering = new Lettering($db);
610 $result = $lettering->updateGeneralMatching($toselect);
611 if ($result < 0) {
612 setEventMessages('', $lettering->errors, 'errors');
613 } else {
614 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoMachingModified' : 'AccountancyOneMatchingModifiedSuccessfully'), array(), 'mesgs');
615 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
616 exit;
617 }
618 } elseif ($massaction == 'generalmatchingpartial' && $permissiontoadd) {
619 $lettering = new Lettering($db);
620 $result = $lettering->updateGeneralMatching($toselect, true);
621 if ($result < 0) {
622 setEventMessages('', $lettering->errors, 'errors');
623 } else {
624 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoMachingModified' : 'AccountancyOneMatchingModifiedSuccessfully'), array(), 'mesgs');
625 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
626 exit;
627 }
628 } elseif ($action == 'generalunmatchingmanual' && $confirm == 'yes' && $permissiontodelete) {
629 $lettering = new Lettering($db);
630 $result = $lettering->deleteGeneralMatching($toselect);
631 if ($result < 0) {
632 setEventMessages('', $lettering->errors, 'errors');
633 } else {
634 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoUnmatchingModified' : 'AccountancyOneUnmatchingModifiedSuccessfully'), array(), 'mesgs');
635 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
636 exit;
637 }
638 } elseif ($type == 'sub' && $massaction == 'letteringauto' && $permissiontoadd) {
639 $lettering = new Lettering($db);
640 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect);
641 if ($nb_lettering < 0) {
642 setEventMessages('', $lettering->errors, 'errors');
643 $error += 1;
644 $nb_lettering = max(0, abs($nb_lettering) - 2);
645 } elseif ($nb_lettering == 0) {
646 $nb_lettering = 0;
647 setEventMessages($langs->trans('AccountancyNoMatchingModified'), array(), 'mesgs');
648 }
649 if ($nb_lettering == 1) {
650 setEventMessages($langs->trans('AccountancyOneMatchingModifiedSuccessfully'), array(), 'mesgs');
651 } elseif ($nb_lettering > 1) {
652 setEventMessages($langs->trans('AccountancyMatchingModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
653 }
654
655 if (!$error) {
656 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
657 exit();
658 }
659 } elseif ($type == 'sub' && $massaction == 'letteringmanual' && $permissiontoadd) {
660 $lettering = new Lettering($db);
661 $result = $lettering->updateLettering($toselect);
662 if ($result < 0) {
663 setEventMessages('', $lettering->errors, 'errors');
664 } else {
665 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoMatchingModified' : 'AccountancyOneMatchingModifiedSuccessfully'), array(), 'mesgs');
666 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
667 exit();
668 }
669 } elseif ($type == 'sub' && $massaction == 'letteringpartial' && $permissiontoadd) {
670 $lettering = new Lettering($db);
671 $result = $lettering->updateLettering($toselect, 0, true);
672 if ($result < 0) {
673 setEventMessages('', $lettering->errors, 'errors');
674 } else {
675 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoMatchingModified' : 'AccountancyOneMatchingModifiedSuccessfully'), array(), 'mesgs');
676 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
677 exit();
678 }
679 } elseif ($type == 'sub' && $action == 'unletteringauto' && $confirm == "yes" && $permissiontoadd) {
680 $lettering = new Lettering($db);
681 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
682 if ($nb_lettering < 0) {
683 setEventMessages('', $lettering->errors, 'errors');
684 $error += 1;
685 $nb_lettering = max(0, abs($nb_lettering) - 2);
686 } elseif ($nb_lettering == 0) {
687 $nb_lettering = 0;
688 setEventMessages($langs->trans('AccountancyNoUnmatchingModified'), array(), 'mesgs');
689 }
690 if ($nb_lettering == 1) {
691 setEventMessages($langs->trans('AccountancyOneUnmatchingModifiedSuccessfully'), array(), 'mesgs');
692 } elseif ($nb_lettering > 1) {
693 setEventMessages($langs->trans('AccountancyUnmatchingModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
694 }
695
696 if (!$error) {
697 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
698 exit();
699 }
700 } elseif ($type == 'sub' && $action == 'unletteringmanual' && $confirm == "yes" && $permissiontoadd) {
701 $lettering = new Lettering($db);
702 $nb_lettering = $lettering->deleteLettering($toselect);
703 if ($result < 0) {
704 setEventMessages('', $lettering->errors, 'errors');
705 } else {
706 setEventMessages($langs->trans($result == 0 ? 'AccountancyNoUnmatchingModified' : 'AccountancyOneUnmatchingModifiedSuccessfully'), array(), 'mesgs');
707 header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
708 exit();
709 }
710 }
711 }
712}
713
714
715/*
716 * View
717 */
718
719$formaccounting = new FormAccounting($db);
720$formfile = new FormFile($db);
721$formother = new FormOther($db);
722$form = new Form($db);
723
724$title_page = $langs->trans("Operations").' - '.$langs->trans("VueByAccountAccounting").' (';
725if ($type == 'sub') {
726 $title_page .= $langs->trans("BookkeepingSubAccount");
727} else {
728 $title_page .= $langs->trans("Bookkeeping");
729}
730$title_page .= ')';
731$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double';
732llxHeader('', $title_page, $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-consultation page-'.(($type == 'sub') ? 'sub' : '').'ledger');
733
734if (!empty($socid)) {
735 $companystatic = new Societe($db);
736 $res = $companystatic->fetch($socid);
737 if ($res > 0) {
738 $tmpobject = $object;
739 $object = $companystatic; // $object must be of type Societe when calling societe_prepare_head
740 $head = societe_prepare_head($companystatic);
741 $object = $tmpobject;
742
743 print dol_get_fiche_head($head, 'accounting', $langs->trans("ThirdParty"), -1, 'company');
744
745 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
746
747 dol_banner_tab($companystatic, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
748
749 print '<div class="fichecenter">';
750
751 print '<div class="underbanner clearboth"></div>';
752 print '<table class="border centpercent tableforfield">';
753
754 // Type Prospect/Customer/Supplier
755 print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
756 print $companystatic->getTypeUrl(1);
757 print '</td></tr>';
758
759 // Customer code
760 if ($companystatic->client && !empty($companystatic->code_client)) {
761 print '<tr><td class="titlefield">';
762 print $langs->trans('CustomerCode').'</td><td>';
763 print showValueWithClipboardCPButton(dol_escape_htmltag($companystatic->code_client));
764 $tmpcheck = $companystatic->check_codeclient();
765 if ($tmpcheck != 0 && $tmpcheck != -5) {
766 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
767 }
768 print '</td>';
769 print '</tr>';
770 }
771 // Supplier code
772 if ($companystatic->fournisseur && !empty($companystatic->code_fournisseur)) {
773 print '<tr><td class="titlefield">';
774 print $langs->trans('SupplierCode').'</td><td>';
775 print showValueWithClipboardCPButton(dol_escape_htmltag($companystatic->code_fournisseur));
776 $tmpcheck = $companystatic->check_codefournisseur();
777 if ($tmpcheck != 0 && $tmpcheck != -5) {
778 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
779 }
780 print '</td>';
781 print '</tr>';
782 }
783
784 print '</table>';
785 print '</div>';
786 print dol_get_fiche_end();
787
788 print info_admin($langs->trans("WarningThisPageContainsOnlyEntriesTransferredInAccounting"));
789 print '<br>';
790
791 // Choice of mode (customer / supplier)
792 if (!empty($conf->dol_use_jmobile)) {
793 print "\n".'<div class="fichecenter"><div class="nowrap">'."\n";
794 }
795
796 if ($companystatic->client && !empty($companystatic->code_compta_client)) {
797 if ($mode != 'customer') {
798 if (!empty($companystatic->code_compta_client)) {
799 $subledger_start_account = $subledger_end_account = $companystatic->code_compta_client;
800 } else {
801 $subledger_start_account = $subledger_end_account = '';
802 }
803 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.'">';
804 } else {
805 print '<span class="a-mesure marginleftonly marginrightonly">';
806 }
807
808 print $langs->trans("CustomerAccountancyCodeShort");
809 if ($mode != 'customer') {
810 print '</a>';
811 } else {
812 print '</span>';
813 }
814 }
815
816 if ($companystatic->fournisseur && !empty($companystatic->code_compta_fournisseur)) {
817 if ($mode != 'supplier') {
818 if (!empty($companystatic->code_compta_fournisseur)) {
819 $subledger_start_account = $subledger_end_account = $companystatic->code_compta_fournisseur;
820 } else {
821 $subledger_start_account = $subledger_end_account = '';
822 }
823 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.'">';
824 } else {
825 print '<span class="a-mesure marginleftonly marginrightonly">';
826 }
827 print $langs->trans("SupplierAccountancyCodeShort");
828 if ($mode != 'supplier') {
829 print '</a>';
830 } else {
831 print '</span>';
832 }
833 }
834
835 if (!empty($conf->dol_use_jmobile)) {
836 print '</div></div>';
837 } else {
838 print '<br>';
839 }
840 print '<br>';
841 }
842}
843
844// List
845$nbtotalofrecords = '';
846if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
847 // TODO Perf Replace this by a count
848 if ($type == 'sub') {
849 $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter, 'AND', 1, 1);
850 } else {
851 $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter, 'AND', 0, 1);
852 }
853
854 if ($nbtotalofrecords < 0) {
855 setEventMessages($object->error, $object->errors, 'errors');
856 $error += 1;
857 }
858}
859
860$num = 0;
861if (!$error) {
862 if ($type == 'sub') {
863 $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter, 'AND', 1);
864 } else {
865 $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter, 'AND', 0);
866 }
867 //$num = count($object->lines);
868 $num = $result; // $result is total nb of lines, or limit + 1, but $object->lines is always limited to $limit
869
870 if ($result < 0) {
871 setEventMessages($object->error, $object->errors, 'errors');
872 }
873}
874
875$arrayofselected = is_array($toselect) ? $toselect : array();
876
877// Print form confirm
878$formconfirm = '';
879print $formconfirm;
880
881// List of mass actions available
882$arrayofmassactions = array();
883if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) {
884 if ($type == 'sub') {
885 // Auxiliary ledger matching only
886 $arrayofmassactions['letteringauto'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringAuto');
887 $arrayofmassactions['preunletteringauto'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringAuto');
888 $arrayofmassactions['letteringmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringManual');
889 $arrayofmassactions['letteringpartial'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('LetteringPartial');
890 $arrayofmassactions['preunletteringmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('UnletteringManual');
891 } else {
892 // General ledger matching only
893 $arrayofmassactions['generalmatchingmanual'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('GeneralMatchingManual');
894 $arrayofmassactions['generalmatchingpartial'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('GeneralMatchingPartial');
895 $arrayofmassactions['pregeneralunmatchingmanual'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('GeneralUnmatchingManual');
896 }
897}
898if ($user->hasRight('accounting', 'mouvements', 'creer')) {
899 $arrayofmassactions['preclonebookkeepingwriting'] = img_picto('', 'clone', 'class="pictofixedwidth"').$langs->trans("Clone");
900}
901if ($user->hasRight('accounting', 'mouvements', 'creer')) {
902 $arrayofmassactions['preassignaccountbookkeepingwriting'] = img_picto('', 'fa-exchange-alt', 'class="pictofixedwidth"').$langs->trans("AssignAccount");
903}
904if ($user->hasRight('accounting', 'mouvements', 'creer')) {
905 $arrayofmassactions['prereturnaccountbookkeepingwriting'] = img_picto('', 'undo', 'class="pictofixedwidth"').$langs->trans("ReturnAccount");
906}
907if ($user->hasRight('accounting', 'mouvements', 'supprimer')) {
908 $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
909}
910
911if (GETPOSTINT('nomassaction') || in_array($massaction, array('preunletteringauto', 'preunletteringmanual', 'pregeneralunmatchingmanual', 'predeletebookkeepingwriting', 'preclonebookkeepingwriting', 'preassignaccountbookkeepingwriting', 'prereturnaccountbookkeepingwriting'))) {
912 $arrayofmassactions = array();
913}
914$massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions);
915
916print '<form method="POST" id="searchFormList" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
917print '<input type="hidden" name="token" value="'.newToken().'">';
918print '<input type="hidden" name="action" value="list">';
919if ($optioncss != '') {
920 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
921}
922print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
923print '<input type="hidden" name="type" value="'.$type.'">';
924if (!empty($socid)) {
925 print '<input type="hidden" name="socid" value="' . $socid . '">';
926}
927print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
928print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
929print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
930
931$parameters = array('param' => $param);
932$reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
933if ($reshook < 0) {
934 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
935}
936
937$newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint;
938
939if (empty($reshook)) {
940 // Remove navigation buttons if in thirdparty tab mode, except for PDF printing
941 if (empty($socid)) {
942 $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/list.php?' . $param);
943 if ($type == 'sub') {
944 $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly'));
945 $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'));
946 } else {
947 $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
948 $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'));
949 }
950 }
951 $newcardbutton .= dolGetButtonTitle($langs->trans('ExportToPdf'), '', 'fa fa-file-pdf paddingleft', $_SERVER['PHP_SELF'] . '?token=' . newToken() .'&action=exporttopdf'.(!empty($type) ? '&type=sub' : '').'&' . $url_param, '', $permissiontoexport, array('morecss' => 'marginleftonly'));
952
953 $newcardbutton .= dolGetButtonTitleSeparator();
954
955 $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);
956}
957
958if ($contextpage != $_SERVER["PHP_SELF"]) {
959 $param .= '&contextpage='.urlencode($contextpage);
960}
961if ($limit > 0 && $limit != $conf->liste_limit) {
962 $param .= '&limit='.((int) $limit);
963}
964
965print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
966
967if ($massaction == 'preunletteringauto') {
968 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringAuto"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringauto", null, '', 0, 200, 500, 1);
969} elseif ($massaction == 'preunletteringmanual') {
970 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnletteringManual"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unletteringmanual", null, '', 0, 200, 500, 1);
971} elseif ($massaction == 'pregeneralunmatchingmanual') {
972 print $form->formconfirm($_SERVER['PHP_SELF'], $langs->trans('ConfirmMassGeneralUnmatchingManual'), $langs->trans('ConfirmMassGeneralUnmatchingQuestion', count($toselect)), 'generalunmatchingmanual', null, '', 0, 200, 500, 1);
973} elseif ($massaction == 'predeletebookkeepingwriting') {
974 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
975} elseif ($massaction == 'preassignaccountbookkeepingwriting') {
976 $input = $formaccounting->select_account('', 'account', 1);
977 $formquestion = array(array('type' => 'other', 'name' => 'account', 'label' => '<span class="fieldrequired">' . $langs->trans("AccountAccountingShort") . '</span>', 'value' => $input),);
978 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("confirmMassAssignAccountBookkeepingWritingConfirm"), $langs->trans("ConfirmMassAssignAccountBookkeepingWritingQuestion", count($toselect)), "assignaccountbookkeepingwriting", $formquestion, '', 0, 200, 500, 1);
979} elseif ($massaction == 'preclonebookkeepingwriting') {
980 $input1 = $form->selectDate('', 'massdate', 0, 0, 0, "create_mvt", 1, 1);
981 $input2 = $formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
982 $formquestion = array(
983 array(
984 'type' => 'other',
985 'name' => 'massdate',
986 'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>',
987 'value' => $input1
988 )
989 );
990
991 if (getDolGlobalString('ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL')) {
992 $formquestion[] = array(
993 'type' => 'text',
994 'name' => 'code_journal',
995 'label' => '<span class="fieldrequired">' . $langs->trans("Codejournal") . '</span>',
996 'value' => $input2
997 );
998 }
999
1000 print $form->formconfirm(
1001 $_SERVER["PHP_SELF"],
1002 $langs->trans("ConfirmMassCloneBookkeepingWriting"),
1003 $langs->trans("ConfirmMassCloneBookkeepingWritingQuestion", count($toselect)),
1004 "clonebookkeepingwriting",
1005 $formquestion,
1006 '', 0, 200, 500, 1
1007 );
1008} elseif ($massaction == 'prereturnaccountbookkeepingwriting') {
1009 $input1 = $form->selectDate('', 'massdate', 0, 0, 0, "create_mvt", 1, 1);
1010 $formquestion = array(array('type' => 'other', 'name' => 'massdate', 'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>', 'value' => $input1));
1011 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassReturnAccountBookkeepingWriting"), $langs->trans("ConfirmMassReturnAccountBookkeepingWritingQuestion", count($toselect)), "returnaccountbookkeepingwriting", $formquestion, '', 0, 200, 500, 1);
1012}
1013
1014include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1015
1016$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1017$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields
1018if ($massactionbutton && $contextpage != 'poslist') {
1019 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
1020}
1021
1022// Reverse sort order
1023if (preg_match('/^asc/i', $sortorder)) {
1024 $sortorder = "asc";
1025} else {
1026 $sortorder = "desc";
1027}
1028
1029// Warning to explain why the list of record is not consistent with the other list view (missing a lot of lines)
1030if ($type == 'sub' && !$socid) {
1031 print info_admin($langs->trans("WarningRecordWithoutSubledgerAreExcluded"));
1032 print '<br>';
1033}
1034
1035$moreforfilter = '';
1036
1037// Search on accountancy custom groups or account
1038$moreforfilter .= '<div class="divsearchfield">';
1039$moreforfilter .= $langs->trans('AccountAccounting').': ';
1040$moreforfilter .= '<div class="nowrap inline-block">';
1041if ($type == 'sub') {
1042 $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), 'maxwidth200');
1043} else {
1044 $moreforfilter .= $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200');
1045}
1046$moreforfilter .= ' ';
1047if ($type == 'sub') {
1048 $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), 'maxwidth200');
1049} else {
1050 $moreforfilter .= $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200');
1051}
1052
1053if (empty($socid)) {
1054 $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>';
1055 $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>';
1056 $moreforfilter .= <<<SCRIPT
1057<script type="text/javascript">
1058 jQuery(document).ready(function() {
1059 var searchFormList = $('#searchFormList');
1060 var searchAccountancyCodeStart = $('#search_accountancy_code_start');
1061 var searchAccountancyCodeEnd = $('#search_accountancy_code_end');
1062 jQuery('#previous_account').on('click', function() {
1063 var previousOption = searchAccountancyCodeStart.find('option:selected').prev('option');
1064 if (previousOption.length == 1) searchAccountancyCodeStart.val(previousOption.attr('value'));
1065 searchAccountancyCodeEnd.val(searchAccountancyCodeStart.val());
1066 searchFormList.submit();
1067 });
1068 jQuery('#next_account').on('click', function() {
1069 var nextOption = searchAccountancyCodeStart.find('option:selected').next('option');
1070 if (nextOption.length == 1) searchAccountancyCodeStart.val(nextOption.attr('value'));
1071 searchAccountancyCodeEnd.val(searchAccountancyCodeStart.val());
1072 searchFormList.submit();
1073 });
1074 jQuery('input[name="search_mvt_num"]').on("keypress", function(event) {
1075 console.log(event);
1076 });
1077 });
1078</script>
1079SCRIPT;
1080}
1081$moreforfilter .= '</div>';
1082$moreforfilter .= '</div>';
1083
1084if (empty($socid)) {
1085 $moreforfilter .= '<div class="divsearchfield">';
1086 $moreforfilter .= $langs->trans('AccountingCategory') . ': ';
1087 $moreforfilter .= '<div class="nowrap inline-block">';
1088 $moreforfilter .= $formaccounting->select_accounting_category($search_account_category, 'search_account_category', 1, 0, 0, 0);
1089 $moreforfilter .= '</div>';
1090 $moreforfilter .= '</div>';
1091}
1092
1093$parameters = array();
1094$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1095if (empty($reshook)) {
1096 $moreforfilter .= $hookmanager->resPrint;
1097} else {
1098 $moreforfilter = $hookmanager->resPrint;
1099}
1100
1101print '<div class="liste_titre liste_titre_bydiv centpercent">';
1102print $moreforfilter;
1103print '</div>';
1104
1105print '<div class="div-table-responsive">';
1106print '<table class="tagtable liste centpercent listwithfilterbefore">';
1107
1108// Filters lines
1109print '<tr class="liste_titre_filter">';
1110// Action column
1111if ($conf->main_checkbox_left_column) {
1112 print '<td class="liste_titre center">';
1113 $searchpicto = $form->showFilterButtons('left');
1114 print $searchpicto;
1115 print '</td>';
1116}
1117// Movement number
1118if (!empty($arrayfields['t.piece_num']['checked'])) {
1119 print '<td class="liste_titre"><input type="text" name="search_mvt_num" class="width50" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
1120}
1121// Code journal
1122if (!empty($arrayfields['t.code_journal']['checked'])) {
1123 print '<td class="liste_titre center">';
1124 print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1, 'maxwidth75');
1125 print '</td>';
1126}
1127// Date document
1128if (!empty($arrayfields['t.doc_date']['checked'])) {
1129 print '<td class="liste_titre center">';
1130 print '<div class="nowrapfordate">';
1131 print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1132 print '</div>';
1133 print '<div class="nowrapfordate">';
1134 print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1135 print '</div>';
1136 print '</td>';
1137}
1138// Ref document
1139if (!empty($arrayfields['t.doc_ref']['checked'])) {
1140 print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"/></td>';
1141}
1142// Label operation
1143if (!empty($arrayfields['t.label_operation']['checked'])) {
1144 print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_operation" value="'.dol_escape_htmltag($search_label_operation).'"/></td>';
1145}
1146// Matching code
1147if (!empty($arrayfields['t.lettering_code']['checked'])) {
1148 print '<td class="liste_titre center">';
1149 print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
1150 print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
1151 print '</td>';
1152}
1153// Debit
1154if (!empty($arrayfields['t.debit']['checked'])) {
1155 print '<td class="liste_titre right"><input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'"></td>';
1156}
1157// Credit
1158if (!empty($arrayfields['t.credit']['checked'])) {
1159 print '<td class="liste_titre right"><input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'"></td>';
1160}
1161// Balance
1162if (!empty($arrayfields['t.balance']['checked'])) {
1163 print '<td></td>';
1164}
1165// Date export
1166if (!empty($arrayfields['t.date_export']['checked'])) {
1167 print '<td class="liste_titre center">';
1168 print '<div class="nowrapfordate">';
1169 print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1170 print '</div>';
1171 print '<div class="nowrapfordate">';
1172 print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1173 print '</div>';
1174 print '</td>';
1175}
1176// Date validation
1177if (!empty($arrayfields['t.date_validated']['checked'])) {
1178 print '<td class="liste_titre center">';
1179 print '<div class="nowrapfordate">';
1180 print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1181 print '</div>';
1182 print '<div class="nowrapfordate">';
1183 print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1184 print '</div>';
1185 print '</td>';
1186}
1187// Due date start and end
1188if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1189 print '<td class="liste_titre center">';
1190 print '<div class="nowrapfordate">';
1191 print $form->selectDate($search_date_due_start, 'search_date_due_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
1192 print '</div>';
1193 print '<div class="nowrapfordate">';
1194 print $form->selectDate($search_date_due_end, 'search_date_due_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1195 print '</div>';
1196 print '</td>';
1197}
1198if (!empty($arrayfields['t.import_key']['checked'])) {
1199 print '<td class="liste_titre center">';
1200 print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
1201 print '</td>';
1202}
1203
1204// Fields from hook
1205$parameters = array('arrayfields' => $arrayfields);
1206$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1207print $hookmanager->resPrint;
1208
1209// Action column
1210if (!$conf->main_checkbox_left_column) {
1211 print '<td class="liste_titre center">';
1212 $searchpicto = $form->showFilterButtons();
1213 print $searchpicto;
1214 print '</td>';
1215}
1216print "</tr>\n";
1217
1218print '<tr class="liste_titre">';
1219if ($conf->main_checkbox_left_column) {
1220 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1221}
1222if (!empty($arrayfields['t.piece_num']['checked'])) {
1223 print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax80imp ');
1224}
1225if (!empty($arrayfields['t.code_journal']['checked'])) {
1226 print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
1227}
1228if (!empty($arrayfields['t.doc_date']['checked'])) {
1229 print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
1230}
1231if (!empty($arrayfields['t.doc_ref']['checked'])) {
1232 print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
1233}
1234if (!empty($arrayfields['t.label_operation']['checked'])) {
1235 print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
1236}
1237if (!empty($arrayfields['t.lettering_code']['checked'])) {
1238 print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
1239}
1240if (!empty($arrayfields['t.debit']['checked'])) {
1241 print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
1242}
1243if (!empty($arrayfields['t.credit']['checked'])) {
1244 print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
1245}
1246if (!empty($arrayfields['t.balance']['checked'])) {
1247 print_liste_field_titre($arrayfields['t.balance']['label'], "", "", "", $param, '', $sortfield, $sortorder, 'right ');
1248}
1249if (!empty($arrayfields['t.date_export']['checked'])) {
1250 print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center ');
1251}
1252if (!empty($arrayfields['t.date_validated']['checked'])) {
1253 print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated", "", $param, '', $sortfield, $sortorder, 'center ');
1254}
1255// Due date
1256if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1257 print_liste_field_titre($arrayfields['t.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], 't.date_lim_reglement', '', $param, '', $sortfield, $sortorder, 'center ');
1258}
1259if (!empty($arrayfields['t.import_key']['checked'])) {
1260 print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER["PHP_SELF"], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1261}
1262// Hook fields
1263$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1264$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1265print $hookmanager->resPrint;
1266if (!$conf->main_checkbox_left_column) {
1267 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1268}
1269print "</tr>\n";
1270
1271$displayed_account_number = null; // Start with undefined to be able to distinguish with empty
1272
1273$objectstatic = null; // Init for static analysis
1274$objectlink = ''; // Init for static analysis
1275$result = -1; // Init for static analysis
1276
1277// Loop on record
1278// --------------------------------------------------------------------
1279$i = 0;
1280
1281$totalarray = array();
1282$totalarray['nbfield'] = 0;
1283$sous_total_debit = 0;
1284$sous_total_credit = 0;
1285$totalarray['val'] = array();
1286$totalarray['val']['totaldebit'] = 0;
1287$totalarray['val']['totalcredit'] = 0;
1288$totalarray['val']['totalbalance'] = 0;
1289
1290// Init for static analysis
1291$colspan = 0; // colspan before field 'label of operation'
1292$colspanend = 0; // colspan after debit/credit
1293$accountg = '-';
1294
1295$colspan = 0; // colspan before field 'label of operation'
1296$colspanend = 3; // colspan after debit/credit
1297if (!empty($arrayfields['t.piece_num']['checked'])) { $colspan++; }
1298if (!empty($arrayfields['t.code_journal']['checked'])) { $colspan++; }
1299if (!empty($arrayfields['t.doc_date']['checked'])) { $colspan++; }
1300if (!empty($arrayfields['t.doc_ref']['checked'])) { $colspan++; }
1301if (!empty($arrayfields['t.label_operation']['checked'])) { $colspan++; }
1302if (!empty($arrayfields['t.date_export']['checked'])) { $colspanend++; }
1303if (!empty($arrayfields['t.date_validated']['checked'])) { $colspanend++; }
1304if (!empty($arrayfields['t.lettering_code']['checked'])) { $colspanend++; }
1305if ($conf->main_checkbox_left_column) {
1306 $colspan++;
1307 $colspanend--;
1308}
1309
1310while ($i < min($num, $limit)) {
1311 $line = $object->lines[$i];
1312
1313 if ($type == 'sub') {
1314 $accountg = length_accounta($line->subledger_account);
1315 } else {
1316 $accountg = length_accountg($line->numero_compte);
1317 }
1318 //if (empty($accountg)) $accountg = '-';
1319
1320 $colspan = 0; // colspan before field 'label of operation'
1321 $colspanend = 0; // colspan after debit/credit
1322 if ($conf->main_checkbox_left_column) {
1323 $colspan++;
1324 }
1325 if (!empty($arrayfields['t.piece_num']['checked'])) {
1326 $colspan++;
1327 }
1328 if (!empty($arrayfields['t.code_journal']['checked'])) {
1329 $colspan++;
1330 }
1331 if (!empty($arrayfields['t.doc_date']['checked'])) {
1332 $colspan++;
1333 }
1334 if (!empty($arrayfields['t.doc_ref']['checked'])) {
1335 $colspan++;
1336 }
1337 if (!empty($arrayfields['t.label_operation']['checked'])) {
1338 $colspan++;
1339 }
1340 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1341 $colspan++;
1342 }
1343
1344 if (!empty($arrayfields['t.balance']['checked'])) {
1345 $colspanend++;
1346 }
1347 if (!empty($arrayfields['t.date_export']['checked'])) {
1348 $colspanend++;
1349 }
1350 if (!empty($arrayfields['t.date_validated']['checked'])) {
1351 $colspanend++;
1352 }
1353 // Due date
1354 if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1355 $colspanend++;
1356 }
1357 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1358 $colspanend++;
1359 }
1360 if (!empty($arrayfields['t.import_key']['checked'])) {
1361 $colspanend++;
1362 }
1363 if (!$conf->main_checkbox_left_column) {
1364 $colspan++;
1365 $colspanend--;
1366 }
1367
1368 // Is it a break ?
1369 if ($accountg != $displayed_account_number || !isset($displayed_account_number)) {
1370 // Show a subtotal by accounting account
1371 if (isset($displayed_account_number)) {
1372 print '<tr class="liste_total">';
1373 if ($type == 'sub') {
1374 print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accounta($displayed_account_number) . ':</td>';
1375 } else {
1376 print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accountg($displayed_account_number) . ':</td>';
1377 }
1378 print '<td class="nowrap right">'.price(price2num($sous_total_debit, 'MT')).'</td>';
1379 print '<td class="nowrap right">'.price(price2num($sous_total_credit, 'MT')).'</td>';
1380 if ($colspanend > 0) {
1381 print '<td colspan="'.$colspanend.'"></td>';
1382 }
1383 print '</tr>';
1384 // Show balance of last shown account
1385 $balance = $sous_total_debit - $sous_total_credit;
1386 print '<tr class="liste_total">';
1387 print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
1388 if ($balance > 0) {
1389 print '<td class="nowraponall right">';
1390 print price(price2num($sous_total_debit - $sous_total_credit, 'MT'));
1391 print '</td>';
1392 print '<td></td>';
1393 } else {
1394 print '<td></td>';
1395 print '<td class="nowraponall right">';
1396 print price(price2num($sous_total_credit - $sous_total_debit, 'MT'));
1397 print '</td>';
1398 }
1399 if ($colspanend > 0) {
1400 print '<td colspan="'.$colspanend.'"></td>';
1401 }
1402 print '</tr>';
1403 }
1404
1405 // Show the break account
1406 print '<tr class="trforbreaknobg">';
1407 print '<td colspan="'.($totalarray['nbfield'] ? $totalarray['nbfield'] : count($arrayfields) + 1).'" class="tdforbreak">';
1408 if ($type == 'sub') {
1409 if ($line->subledger_account != "" && $line->subledger_account != '-1') {
1410 print empty($line->subledger_label) ? '<span class="error">'.$langs->trans("Unknown").'</span>' : $line->subledger_label;
1411 print ' : ';
1412 print length_accounta($line->subledger_account);
1413 } else {
1414 // Should not happen: subledger account must be null or a non empty value
1415 print '<span class="error">' . $langs->trans("Unknown");
1416 if ($line->subledger_label) {
1417 print ' (' . $line->subledger_label . ')';
1418 $htmltext = 'EmptyStringForSubledgerAccountButSubledgerLabelDefined';
1419 } else {
1420 $htmltext = 'EmptyStringForSubledgerAccountAndSubledgerLabel';
1421 }
1422 print $form->textwithpicto('', $htmltext);
1423 print '</span>';
1424 }
1425 } else {
1426 if ($line->numero_compte != "" && $line->numero_compte != '-1') {
1427 print length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte);
1428 } else {
1429 print '<span class="error">' . $langs->trans("Unknown") . '</span>';
1430 }
1431 }
1432 print '</td>';
1433 print '</tr>';
1434
1435 $displayed_account_number = $accountg;
1436 //if (empty($displayed_account_number)) $displayed_account_number='-';
1437 $sous_total_debit = 0;
1438 $sous_total_credit = 0;
1439 }
1440
1441 print '<tr class="oddeven">';
1442 // Action column
1443 if ($conf->main_checkbox_left_column) {
1444 print '<td class="nowraponall center">';
1445 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
1446 $selected = 0;
1447 if (in_array($line->id, $arrayofselected)) {
1448 $selected = 1;
1449 }
1450 print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
1451 }
1452 print '</td>';
1453 if (!$i) {
1454 $totalarray['nbfield']++;
1455 }
1456 }
1457 // Piece number
1458 if (!empty($arrayfields['t.piece_num']['checked'])) {
1459 print '<td class="nowraponall">';
1460 $object->id = $line->id;
1461 $object->piece_num = $line->piece_num;
1462 $object->ref = $line->ref;
1463 print $object->getNomUrl(1, '', 0, '', 1);
1464 print '<span class="hideonsmartphone">';
1465 if (!empty($line->date_export)) {
1466 print img_picto($langs->trans("DateExport").": ".dol_print_date($line->date_export, 'dayhour')." (".$langs->trans("TransactionExportDesc").")", 'fa-file-export', 'class="paddingleft pictofixedwidth opacitymedium"');
1467 }
1468 if (!empty($line->date_validation)) {
1469 print img_picto($langs->trans("DateValidation").": ".dol_print_date($line->date_validation, 'dayhour')." (".$langs->trans("TransactionBlockedLockedDesc").")", 'fa-lock', 'class="paddingleft pictofixedwidth opacitymedium"');
1470 }
1471 print '</span>';
1472 print '</td>';
1473 if (!$i) {
1474 $totalarray['nbfield']++;
1475 }
1476 }
1477
1478 // Journal code
1479 if (!empty($arrayfields['t.code_journal']['checked'])) {
1480 $accountingjournal = new AccountingJournal($db);
1481 $result = $accountingjournal->fetch(0, $line->code_journal);
1482 $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
1483 print '<td class="center tdoverflowmax80">'.$journaltoshow.'</td>';
1484 if (!$i) {
1485 $totalarray['nbfield']++;
1486 }
1487 }
1488
1489 // Document date
1490 if (!empty($arrayfields['t.doc_date']['checked'])) {
1491 print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
1492 if (!$i) {
1493 $totalarray['nbfield']++;
1494 }
1495 }
1496
1497 // Document ref
1498 $modulepart = '';
1499 if (!empty($arrayfields['t.doc_ref']['checked'])) {
1500 if ($line->doc_type == 'customer_invoice') {
1501 $langs->loadLangs(array('bills'));
1502
1503 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1504 $objectstatic = new Facture($db);
1505 $objectstatic->fetch($line->fk_doc);
1506 //$modulepart = 'facture';
1507
1508 $filename = dol_sanitizeFileName($line->doc_ref);
1509 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1510 $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1511 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1512 } elseif ($line->doc_type == 'supplier_invoice') {
1513 $langs->loadLangs(array('bills'));
1514
1515 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1516 $objectstatic = new FactureFournisseur($db);
1517 $objectstatic->fetch($line->fk_doc);
1518
1519 $modulepart = 'invoice_supplier';
1520 $filename = dol_sanitizeFileName($line->doc_ref);
1521 $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1522 $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
1523 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
1524 } elseif ($line->doc_type == 'expense_report') {
1525 $langs->loadLangs(array('trips'));
1526
1527 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
1528 $objectstatic = new ExpenseReport($db);
1529 $objectstatic->fetch($line->fk_doc);
1530 //$modulepart = 'expensereport';
1531
1532 $filename = dol_sanitizeFileName($line->doc_ref);
1533 $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
1534 $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
1535 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1536 } elseif ($line->doc_type == 'bank') {
1537 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1538 $objectstatic = new AccountLine($db);
1539 $objectstatic->fetch($line->fk_doc);
1540 } else {
1541 // Other type
1542 }
1543
1544 print '<td class="tdoverflowmax250">';
1545
1546 // Picto + Ref
1547 if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
1548 print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
1549 print $documentlink;
1550 } elseif ($line->doc_type == 'bank') {
1551 print $objectstatic->getNomUrl(1);
1552 $bank_ref = strstr($line->doc_ref, '-');
1553 print ' <span class="classfortooltip" title="'.dol_escape_htmltag($line->doc_ref).'">'.dol_escape_htmltag($bank_ref).'</span>';
1554 } else {
1555 print $line->doc_ref;
1556 }
1557
1558 print "</td>\n";
1559 if (!$i) {
1560 $totalarray['nbfield']++;
1561 }
1562 }
1563
1564 // Label operation
1565 if (!empty($arrayfields['t.label_operation']['checked'])) {
1566 // Show a link to the customer/supplier invoice
1567 $doc_ref = preg_replace('/\‍(.*\‍)/', '', $line->doc_ref);
1568 if (strlen(length_accounta($line->subledger_account)) == 0) {
1569 print '<td class="small tdoverflowmax350 classfortooltip" title="'.dol_escape_htmltag($line->label_operation).'">'.dol_escape_htmltag($line->label_operation).'</td>';
1570 } else {
1571 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>';
1572 }
1573 if (!$i) {
1574 $totalarray['nbfield']++;
1575 }
1576 }
1577
1578 // Matching code
1579 if (!empty($arrayfields['t.lettering_code']['checked'])) {
1580 $tooltipText = "";
1581 if (!empty($line->matching_general)) {
1582 $tooltipText .= $langs->trans('GeneralMatching');
1583 } elseif (empty($line->matching_general) && !empty($line->lettering_code)) {
1584 $tooltipText .= $langs->trans('AuxiliaryMatching');
1585 }
1586 print '<td class="center classfortooltip" title="'.$tooltipText.'">';
1587 if ($type == 'sub') {
1588 // Auxiliary account matching
1589 if (!empty($line->lettering_code)) {
1590 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable
1591 print '<span class="badge badge-status1"><i class="fas fa-user fa-xs"></i> ' . dol_escape_htmltag((string) $line->lettering_code) . '</span>';
1592 }
1593 } elseif (!empty($line->matching_general) && !empty($line->lettering_code)) {
1594 print '<span class="badge badge-status4"><i class="fas fa-book fa-xs"></i> ' . dol_escape_htmltag((string) $line->lettering_code) . '</span>';
1595 }
1596 print '</td>';
1597 if (!$i) $totalarray['nbfield']++;
1598 }
1599
1600 // Amount debit
1601 if (!empty($arrayfields['t.debit']['checked'])) {
1602 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
1603 if (!$i) {
1604 $totalarray['nbfield']++;
1605 }
1606 if (!$i) {
1607 $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
1608 }
1609 $totalarray['val']['totaldebit'] += (float) $line->debit;
1610 }
1611
1612 // Amount credit
1613 if (!empty($arrayfields['t.credit']['checked'])) {
1614 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
1615 if (!$i) {
1616 $totalarray['nbfield']++;
1617 }
1618 if (!$i) {
1619 $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
1620 }
1621 $totalarray['val']['totalcredit'] += (float) $line->credit;
1622 }
1623
1624 // Amount balance
1625 if (!empty($arrayfields['t.balance']['checked'])) {
1626 print '<td class="right nowraponall amount">'.price(price2num($sous_total_debit + $line->debit - $sous_total_credit - $line->credit, 'MT')).'</td>';
1627 if (!$i) {
1628 $totalarray['nbfield']++;
1629 }
1630 if (!$i) {
1631 $totalarray['pos'][$totalarray['nbfield']] = 'totalbalance';
1632 };
1633 $totalarray['val']['totalbalance'] += $line->debit - $line->credit;
1634 }
1635
1636 // Exported operation date
1637 if (!empty($arrayfields['t.date_export']['checked'])) {
1638 print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>';
1639 if (!$i) {
1640 $totalarray['nbfield']++;
1641 }
1642 }
1643
1644 // Validated operation date
1645 if (!empty($arrayfields['t.date_validated']['checked'])) {
1646 print '<td class="center">'.dol_print_date($line->date_validation, 'dayhour').'</td>';
1647 if (!$i) {
1648 $totalarray['nbfield']++;
1649 }
1650 }
1651
1652 // Due date
1653 if (!empty($arrayfields['t.date_lim_reglement']['checked'])) {
1654 print '<td class="center">'.dol_print_date($line->date_lim_reglement, 'day').'</td>';
1655 if (!$i) {
1656 $totalarray['nbfield']++;
1657 }
1658 }
1659
1660 if (!empty($arrayfields['t.import_key']['checked'])) {
1661 print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($line->import_key).'">'.dol_escape_htmltag($line->import_key)."</td>\n";
1662 if (!$i) {
1663 $totalarray['nbfield']++;
1664 }
1665 }
1666
1667 // Fields from hook
1668 $parameters = array('arrayfields' => $arrayfields, 'obj' => $line);
1669 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1670 print $hookmanager->resPrint;
1671
1672 // Action column
1673 if (!$conf->main_checkbox_left_column) {
1674 print '<td class="nowraponall center">';
1675 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
1676 $selected = 0;
1677 if (in_array($line->id, $arrayofselected)) {
1678 $selected = 1;
1679 }
1680 print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
1681 }
1682 print '</td>';
1683 if (!$i) {
1684 $totalarray['nbfield']++;
1685 }
1686 }
1687
1688 // Comptabilise le sous-total
1689 $sous_total_debit += $line->debit;
1690 $sous_total_credit += $line->credit;
1691
1692 print "</tr>\n";
1693
1694 $i++;
1695}
1696
1697if ($num > 0 && $colspan > 0) {
1698 print '<tr class="liste_total">';
1699 print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("TotalForAccount").' '.$accountg.':</td>';
1700 print '<td class="nowrap right">'.price(price2num($sous_total_debit, 'MT')).'</td>';
1701 print '<td class="nowrap right">'.price(price2num($sous_total_credit, 'MT')).'</td>';
1702 if ($colspanend > 0) {
1703 print '<td colspan="'.$colspanend.'"></td>';
1704 }
1705 print '</tr>';
1706
1707 // Show balance of last shown account
1708 $balance = $sous_total_debit - $sous_total_credit;
1709 print '<tr class="liste_total">';
1710 print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
1711 if ($balance > 0) {
1712 print '<td class="nowraponall right">';
1713 print price(price2num($sous_total_debit - $sous_total_credit, 'MT'));
1714 print '</td>';
1715 print '<td></td>';
1716 } else {
1717 print '<td></td>';
1718 print '<td class="nowraponall right">';
1719 print price(price2num($sous_total_credit - $sous_total_debit, 'MT'));
1720 print '</td>';
1721 }
1722 if ($colspanend > 0) {
1723 print '<td colspan="'.$colspanend.'"></td>';
1724 }
1725 print '</tr>';
1726}
1727
1728
1729// Clean total values to round them
1730if (!empty($totalarray['val']['totaldebit'])) {
1731 $totalarray['val']['totaldebit'] = (float) price2num($totalarray['val']['totaldebit'], 'MT');
1732}
1733if (!empty($totalarray['val']['totalcredit'])) {
1734 $totalarray['val']['totalcredit'] = (float) price2num($totalarray['val']['totalcredit'], 'MT');
1735}
1736if (!empty($totalarray['val']['totalbalance'])) {
1737 $totalarray['val']['totalbalance'] = (float) price2num($totalarray['val']['totaldebit'] - $totalarray['val']['totalcredit'], 'MT');
1738}
1739
1740// Show total line
1741$trforbreaknobg = 1; // used in list_print_total.tpl.php
1742include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1743
1744// If no record found
1745if ($num == 0) {
1746 $colspan = 1;
1747 foreach ($arrayfields as $key => $val) {
1748 if (!empty($val['checked'])) {
1749 $colspan++;
1750 }
1751 }
1752 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1753}
1754
1755$parameters = array('arrayfields' => $arrayfields);
1756$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1757print $hookmanager->resPrint;
1758
1759print "</table>";
1760print '</div>';
1761
1762print '</form>';
1763
1764// End of page
1765llxFooter();
1766$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition list.php:501
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 to help generate other html components 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, $subtabs='')
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:639
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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)
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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='', $textonpictotooltip='', $cssfordropdown='info_admin')
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:137
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.