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