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