1<?php 2/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com> 3 * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro> 4 * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr> 5 * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net> 6 * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22/** 23 * \file htdocs/accountancy/bookkeeping/list.php 24 * \ingroup Accountancy (Double entries) 25 * \brief List operation of book keeping 26 */ 27require '../../main.inc.php'; 28require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php'; 29require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; 30require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; 31require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; 32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; 33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; 34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; 35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; 36require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 37 38// Load translation files required by the page 39$langs->loadLangs(array("accountancy", "compta")); 40 41$socid = GETPOST('socid', 'int'); 42 43$action = GETPOST('action', 'aZ09'); 44$search_mvt_num = GETPOST('search_mvt_num', 'int'); 45$search_doc_type = GETPOST("search_doc_type", 'alpha'); 46$search_doc_ref = GETPOST("search_doc_ref", 'alpha'); 47$search_date_startyear = GETPOST('search_date_startyear', 'int'); 48$search_date_startmonth = GETPOST('search_date_startmonth', 'int'); 49$search_date_startday = GETPOST('search_date_startday', 'int'); 50$search_date_endyear = GETPOST('search_date_endyear', 'int'); 51$search_date_endmonth = GETPOST('search_date_endmonth', 'int'); 52$search_date_endday = GETPOST('search_date_endday', 'int'); 53$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); 54$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); 55$search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); 56$search_date_creation_startyear = GETPOST('search_date_creation_startyear', 'int'); 57$search_date_creation_startmonth = GETPOST('search_date_creation_startmonth', 'int'); 58$search_date_creation_startday = GETPOST('search_date_creation_startday', 'int'); 59$search_date_creation_endyear = GETPOST('search_date_creation_endyear', 'int'); 60$search_date_creation_endmonth = GETPOST('search_date_creation_endmonth', 'int'); 61$search_date_creation_endday = GETPOST('search_date_creation_endday', 'int'); 62$search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear); 63$search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear); 64$search_date_modification_startyear = GETPOST('search_date_modification_startyear', 'int'); 65$search_date_modification_startmonth = GETPOST('search_date_modification_startmonth', 'int'); 66$search_date_modification_startday = GETPOST('search_date_modification_startday', 'int'); 67$search_date_modification_endyear = GETPOST('search_date_modification_endyear', 'int'); 68$search_date_modification_endmonth = GETPOST('search_date_modification_endmonth', 'int'); 69$search_date_modification_endday = GETPOST('search_date_modification_endday', 'int'); 70$search_date_modification_start = dol_mktime(0, 0, 0, $search_date_modification_startmonth, $search_date_modification_startday, $search_date_modification_startyear); 71$search_date_modification_end = dol_mktime(23, 59, 59, $search_date_modification_endmonth, $search_date_modification_endday, $search_date_modification_endyear); 72$search_date_export_startyear = GETPOST('search_date_export_startyear', 'int'); 73$search_date_export_startmonth = GETPOST('search_date_export_startmonth', 'int'); 74$search_date_export_startday = GETPOST('search_date_export_startday', 'int'); 75$search_date_export_endyear = GETPOST('search_date_export_endyear', 'int'); 76$search_date_export_endmonth = GETPOST('search_date_export_endmonth', 'int'); 77$search_date_export_endday = GETPOST('search_date_export_endday', 'int'); 78$search_date_export_start = dol_mktime(0, 0, 0, $search_date_export_startmonth, $search_date_export_startday, $search_date_export_startyear); 79$search_date_export_end = dol_mktime(23, 59, 59, $search_date_export_endmonth, $search_date_export_endday, $search_date_export_endyear); 80$search_date_validation_startyear = GETPOST('search_date_validation_startyear', 'int'); 81$search_date_validation_startmonth = GETPOST('search_date_validation_startmonth', 'int'); 82$search_date_validation_startday = GETPOST('search_date_validation_startday', 'int'); 83$search_date_validation_endyear = GETPOST('search_date_validation_endyear', 'int'); 84$search_date_validation_endmonth = GETPOST('search_date_validation_endmonth', 'int'); 85$search_date_validation_endday = GETPOST('search_date_validation_endday', 'int'); 86$search_date_validation_start = dol_mktime(0, 0, 0, $search_date_validation_startmonth, $search_date_validation_startday, $search_date_validation_startyear); 87$search_date_validation_end = dol_mktime(23, 59, 59, $search_date_validation_endmonth, $search_date_validation_endday, $search_date_validation_endyear); 88 89//var_dump($search_date_start);exit; 90if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) { 91 $action = 'delbookkeepingyear'; 92} 93if (GETPOST("button_export_file_x") || GETPOST("button_export_file.x") || GETPOST("button_export_file")) { 94 $action = 'export_file'; 95} 96 97$search_accountancy_code = GETPOST("search_accountancy_code"); 98$search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); 99if ($search_accountancy_code_start == - 1) { 100 $search_accountancy_code_start = ''; 101} 102$search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha'); 103if ($search_accountancy_code_end == - 1) { 104 $search_accountancy_code_end = ''; 105} 106 107$search_accountancy_aux_code = GETPOST("search_accountancy_aux_code", 'alpha'); 108$search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha'); 109if ($search_accountancy_aux_code_start == - 1) { 110 $search_accountancy_aux_code_start = ''; 111} 112$search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha'); 113if ($search_accountancy_aux_code_end == - 1) { 114 $search_accountancy_aux_code_end = ''; 115} 116$search_mvt_label = GETPOST('search_mvt_label', 'alpha'); 117$search_direction = GETPOST('search_direction', 'alpha'); 118$search_debit = GETPOST('search_debit', 'alpha'); 119$search_credit = GETPOST('search_credit', 'alpha'); 120$search_ledger_code = GETPOST('search_ledger_code', 'array'); 121$search_lettering_code = GETPOST('search_lettering_code', 'alpha'); 122$search_not_reconciled = GETPOST('search_not_reconciled', 'alpha'); 123 124// Load variable for pagination 125$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); 126$sortfield = GETPOST('sortfield', 'aZ09comma'); 127$sortorder = GETPOST('sortorder', 'aZ09comma'); 128$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 129if (empty($page) || $page < 0) { 130 $page = 0; 131} 132$offset = $limit * $page; 133$pageprev = $page - 1; 134$pagenext = $page + 1; 135if ($sortorder == "") { 136 $sortorder = "ASC"; 137} 138if ($sortfield == "") { 139 $sortfield = "t.piece_num,t.rowid"; 140} 141 142// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context 143$object = new BookKeeping($db); 144$hookmanager->initHooks(array('bookkeepinglist')); 145 146$formaccounting = new FormAccounting($db); 147$form = new Form($db); 148 149if (!in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && !GETPOSTISSET('begin') && !GETPOSTISSET('formfilteraction') && GETPOST('page', 'int') == '' && !GETPOST('noreset', 'int') && $user->rights->accounting->mouvements->export) { 150 if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('restore_lastsearch_values') && !GETPOST('search_accountancy_code_start')) { 151 $query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; 152 $query .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1"; 153 $res = $db->query($query); 154 155 if ($res->num_rows > 0) { 156 $fiscalYear = $db->fetch_object($res); 157 $search_date_start = strtotime($fiscalYear->date_start); 158 $search_date_end = strtotime($fiscalYear->date_end); 159 } else { 160 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); 161 $year_start = dol_print_date(dol_now(), '%Y'); 162 if (dol_print_date(dol_now(), '%m') < $month_start) { 163 $year_start--; // If current month is lower that starting fiscal month, we start last year 164 } 165 $year_end = $year_start + 1; 166 $month_end = $month_start - 1; 167 if ($month_end < 1) { 168 $month_end = 12; 169 $year_end--; 170 } 171 $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); 172 $search_date_end = dol_get_last_day($year_end, $month_end); 173 } 174 } 175} 176 177 178$arrayfields = array( 179 't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1), 180 't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1), 181 't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1), 182 't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1), 183 't.numero_compte'=>array('label'=>$langs->trans("AccountAccountingShort"), 'checked'=>1), 184 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1), 185 't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1), 186 't.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1), 187 't.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1), 188 't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1), 189 't.date_creation'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0), 190 't.tms'=>array('label'=>$langs->trans("DateModification"), 'checked'=>0), 191 't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1), 192 't.date_validated'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1), 193); 194 195if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) { 196 unset($arrayfields['t.lettering_code']); 197} 198 199$listofformat = AccountancyExport::getType(); 200$formatexportset = $conf->global->ACCOUNTING_EXPORT_MODELCSV; 201if (empty($listofformat[$formatexportset])) { 202 $formatexportset = 1; 203} 204 205$error = 0; 206 207if (empty($conf->accounting->enabled)) { 208 accessforbidden(); 209} 210if ($user->socid > 0) { 211 accessforbidden(); 212} 213if (empty($user->rights->accounting->mouvements->lire)) { 214 accessforbidden(); 215} 216 217 218/* 219 * Actions 220 */ 221 222if (GETPOST('cancel', 'alpha')) { 223 $action = 'list'; $massaction = ''; 224} 225if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { 226 $massaction = ''; 227} 228 229$parameters = array('socid'=>$socid); 230$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks 231if ($reshook < 0) { 232 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 233} 234 235if (empty($reshook)) { 236 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; 237 238 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 239 $search_mvt_num = ''; 240 $search_doc_type = ''; 241 $search_doc_ref = ''; 242 $search_doc_date = ''; 243 $search_accountancy_code = ''; 244 $search_accountancy_code_start = ''; 245 $search_accountancy_code_end = ''; 246 $search_accountancy_aux_code = ''; 247 $search_accountancy_aux_code_start = ''; 248 $search_accountancy_aux_code_end = ''; 249 $search_mvt_label = ''; 250 $search_direction = ''; 251 $search_ledger_code = array(); 252 $search_date_startyear = ''; 253 $search_date_startmonth = ''; 254 $search_date_startday = ''; 255 $search_date_endyear = ''; 256 $search_date_endmonth = ''; 257 $search_date_endday = ''; 258 $search_date_start = ''; 259 $search_date_end = ''; 260 $search_date_creation_startyear = ''; 261 $search_date_creation_startmonth = ''; 262 $search_date_creation_startday = ''; 263 $search_date_creation_endyear = ''; 264 $search_date_creation_endmonth = ''; 265 $search_date_creation_endday = ''; 266 $search_date_creation_start = ''; 267 $search_date_creation_end = ''; 268 $search_date_modification_startyear = ''; 269 $search_date_modification_startmonth = ''; 270 $search_date_modification_startday = ''; 271 $search_date_modification_endyear = ''; 272 $search_date_modification_endmonth = ''; 273 $search_date_modification_endday = ''; 274 $search_date_modification_start = ''; 275 $search_date_modification_end = ''; 276 $search_date_export_startyear = ''; 277 $search_date_export_startmonth = ''; 278 $search_date_export_startday = ''; 279 $search_date_export_endyear = ''; 280 $search_date_export_endmonth = ''; 281 $search_date_export_endday = ''; 282 $search_date_export_start = ''; 283 $search_date_export_end = ''; 284 $search_date_validation_startyear = ''; 285 $search_date_validation_startmonth = ''; 286 $search_date_validation_startday = ''; 287 $search_date_validation_endyear = ''; 288 $search_date_validation_endmonth = ''; 289 $search_date_validation_endday = ''; 290 $search_date_validation_start = ''; 291 $search_date_validation_end = ''; 292 $search_debit = ''; 293 $search_credit = ''; 294 $search_lettering_code = ''; 295 $search_not_reconciled = ''; 296 } 297 298 // Must be after the remove filter action, before the export. 299 $param = ''; 300 $filter = array(); 301 if (!empty($search_date_start)) { 302 $filter['t.doc_date>='] = $search_date_start; 303 $tmp = dol_getdate($search_date_start); 304 $param .= '&search_date_startmonth='.urlencode($tmp['mon']).'&search_date_startday='.urlencode($tmp['mday']).'&search_date_startyear='.urlencode($tmp['year']); 305 } 306 if (!empty($search_date_end)) { 307 $filter['t.doc_date<='] = $search_date_end; 308 $tmp = dol_getdate($search_date_end); 309 $param .= '&search_date_endmonth='.urlencode($tmp['mon']).'&search_date_endday='.urlencode($tmp['mday']).'&search_date_endyear='.urlencode($tmp['year']); 310 } 311 if (!empty($search_doc_date)) { 312 $filter['t.doc_date'] = $search_doc_date; 313 $tmp = dol_getdate($search_doc_date); 314 $param .= '&doc_datemonth='.urlencode($tmp['mon']).'&doc_dateday='.urlencode($tmp['mday']).'&doc_dateyear='.urlencode($tmp['year']); 315 } 316 if (!empty($search_doc_type)) { 317 $filter['t.doc_type'] = $search_doc_type; 318 $param .= '&search_doc_type='.urlencode($search_doc_type); 319 } 320 if (!empty($search_doc_ref)) { 321 $filter['t.doc_ref'] = $search_doc_ref; 322 $param .= '&search_doc_ref='.urlencode($search_doc_ref); 323 } 324 if (!empty($search_accountancy_code)) { 325 $filter['t.numero_compte'] = $search_accountancy_code; 326 $param .= '&search_accountancy_code='.urlencode($search_accountancy_code); 327 } 328 if (!empty($search_accountancy_code_start)) { 329 $filter['t.numero_compte>='] = $search_accountancy_code_start; 330 $param .= '&search_accountancy_code_start='.urlencode($search_accountancy_code_start); 331 } 332 if (!empty($search_accountancy_code_end)) { 333 $filter['t.numero_compte<='] = $search_accountancy_code_end; 334 $param .= '&search_accountancy_code_end='.urlencode($search_accountancy_code_end); 335 } 336 if (!empty($search_accountancy_aux_code)) { 337 $filter['t.subledger_account'] = $search_accountancy_aux_code; 338 $param .= '&search_accountancy_aux_code='.urlencode($search_accountancy_aux_code); 339 } 340 if (!empty($search_accountancy_aux_code_start)) { 341 $filter['t.subledger_account>='] = $search_accountancy_aux_code_start; 342 $param .= '&search_accountancy_aux_code_start='.urlencode($search_accountancy_aux_code_start); 343 } 344 if (!empty($search_accountancy_aux_code_end)) { 345 $filter['t.subledger_account<='] = $search_accountancy_aux_code_end; 346 $param .= '&search_accountancy_aux_code_end='.urlencode($search_accountancy_aux_code_end); 347 } 348 if (!empty($search_mvt_label)) { 349 $filter['t.label_operation'] = $search_mvt_label; 350 $param .= '&search_mvt_label='.urlencode($search_mvt_label); 351 } 352 if (!empty($search_direction)) { 353 $filter['t.sens'] = $search_direction; 354 $param .= '&search_direction='.urlencode($search_direction); 355 } 356 if (!empty($search_ledger_code)) { 357 $filter['t.code_journal'] = $search_ledger_code; 358 foreach ($search_ledger_code as $code) { 359 $param .= '&search_ledger_code[]='.urlencode($code); 360 } 361 } 362 if (!empty($search_mvt_num)) { 363 $filter['t.piece_num'] = $search_mvt_num; 364 $param .= '&search_mvt_num='.urlencode($search_mvt_num); 365 } 366 if (!empty($search_date_creation_start)) { 367 $filter['t.date_creation>='] = $search_date_creation_start; 368 $tmp = dol_getdate($search_date_creation_start); 369 $param .= '&search_date_creation_startmonth='.urlencode($tmp['mon']).'&search_date_creation_startday='.urlencode($tmp['mday']).'&search_date_creation_startyear='.urlencode($tmp['year']); 370 } 371 if (!empty($search_date_creation_end)) { 372 $filter['t.date_creation<='] = $search_date_creation_end; 373 $tmp = dol_getdate($search_date_creation_end); 374 $param .= '&search_date_creation_endmonth='.urlencode($tmp['mon']).'&search_date_creation_endday='.urlencode($tmp['mday']).'&search_date_creation_endyear='.urlencode($tmp['year']); 375 } 376 if (!empty($search_date_modification_start)) { 377 $filter['t.tms>='] = $search_date_modification_start; 378 $tmp = dol_getdate($search_date_modification_start); 379 $param .= '&search_date_modification_startmonth='.urlencode($tmp['mon']).'&search_date_modification_startday='.urlencode($tmp['mday']).'&search_date_modification_startyear='.urlencode($tmp['year']); 380 } 381 if (!empty($search_date_modification_end)) { 382 $filter['t.tms<='] = $search_date_modification_end; 383 $tmp = dol_getdate($search_date_modification_end); 384 $param .= '&search_date_modification_endmonth='.urlencode($tmp['mon']).'&search_date_modification_endday='.urlencode($tmp['mday']).'&search_date_modification_endyear='.urlencode($tmp['year']); 385 } 386 if (!empty($search_date_export_start)) { 387 $filter['t.date_export>='] = $search_date_export_start; 388 $tmp = dol_getdate($search_date_export_start); 389 $param .= '&search_date_export_startmonth='.urlencode($tmp['mon']).'&search_date_export_startday='.urlencode($tmp['mday']).'&search_date_export_startyear='.urlencode($tmp['year']); 390 } 391 if (!empty($search_date_export_end)) { 392 $filter['t.date_export<='] = $search_date_export_end; 393 $tmp = dol_getdate($search_date_export_end); 394 $param .= '&search_date_export_endmonth='.urlencode($tmp['mon']).'&search_date_export_endday='.urlencode($tmp['mday']).'&search_date_export_endyear='.urlencode($tmp['year']); 395 } 396 if (!empty($search_date_validation_start)) { 397 $filter['t.date_validated>='] = $search_date_validation_start; 398 $tmp = dol_getdate($search_date_validation_start); 399 $param .= '&search_date_validation_startmonth='.urlencode($tmp['mon']).'&search_date_validation_startday='.urlencode($tmp['mday']).'&search_date_validation_startyear='.urlencode($tmp['year']); 400 } 401 if (!empty($search_date_validation_end)) { 402 $filter['t.date_validated<='] = $search_date_validation_end; 403 $tmp = dol_getdate($search_date_validation_end); 404 $param .= '&search_date_validation_endmonth='.urlencode($tmp['mon']).'&search_date_validation_endday='.urlencode($tmp['mday']).'&search_date_validation_endyear='.urlencode($tmp['year']); 405 } 406 if (!empty($search_debit)) { 407 $filter['t.debit'] = $search_debit; 408 $param .= '&search_debit='.urlencode($search_debit); 409 } 410 if (!empty($search_credit)) { 411 $filter['t.credit'] = $search_credit; 412 $param .= '&search_credit='.urlencode($search_credit); 413 } 414 if (!empty($search_lettering_code)) { 415 $filter['t.lettering_code'] = $search_lettering_code; 416 $param .= '&search_lettering_code='.urlencode($search_lettering_code); 417 } 418 if (!empty($search_not_reconciled)) { 419 $filter['t.reconciled_option'] = $search_not_reconciled; 420 $param .= '&search_not_reconciled='.urlencode($search_not_reconciled); 421 } 422} 423 424if ($action == 'delbookkeeping' && $user->rights->accounting->mouvements->supprimer) { 425 $import_key = GETPOST('importkey', 'alpha'); 426 427 if (!empty($import_key)) { 428 $result = $object->deleteByImportkey($import_key); 429 if ($result < 0) { 430 setEventMessages($object->error, $object->errors, 'errors'); 431 } 432 433 // Make a redirect to avoid to launch the delete later after a back button 434 header("Location: list.php".($param ? '?'.$param : '')); 435 exit; 436 } 437} 438if ($action == 'delbookkeepingyearconfirm' && $user->rights->accounting->mouvements->supprimer_tous) { 439 $delmonth = GETPOST('delmonth', 'int'); 440 $delyear = GETPOST('delyear', 'int'); 441 if ($delyear == -1) { 442 $delyear = 0; 443 } 444 $deljournal = GETPOST('deljournal', 'alpha'); 445 if ($deljournal == -1) { 446 $deljournal = 0; 447 } 448 449 if (!empty($delmonth) || !empty($delyear) || !empty($deljournal)) { 450 $result = $object->deleteByYearAndJournal($delyear, $deljournal, '', ($delmonth > 0 ? $delmonth : 0)); 451 if ($result < 0) { 452 setEventMessages($object->error, $object->errors, 'errors'); 453 } else { 454 setEventMessages("RecordDeleted", null, 'mesgs'); 455 } 456 457 // Make a redirect to avoid to launch the delete later after a back button 458 header("Location: list.php".($param ? '?'.$param : '')); 459 exit; 460 } else { 461 setEventMessages("NoRecordDeleted", null, 'warnings'); 462 } 463} 464if ($action == 'delmouvconfirm' && $user->rights->accounting->mouvements->supprimer) { 465 $mvt_num = GETPOST('mvt_num', 'int'); 466 467 if (!empty($mvt_num)) { 468 $result = $object->deleteMvtNum($mvt_num); 469 if ($result < 0) { 470 setEventMessages($object->error, $object->errors, 'errors'); 471 } else { 472 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); 473 } 474 475 header("Location: list.php?noreset=1".($param ? '&'.$param : '')); 476 exit; 477 } 478} 479if ($action == 'setreexport') { 480 $setreexport = GETPOST('value', 'int'); 481 if (!dolibarr_set_const($db, "ACCOUNTING_REEXPORT", $setreexport, 'yesno', 0, '', $conf->entity)) { 482 $error++; 483 } 484 485 if (!$error) { 486 if ($conf->global->ACCOUNTING_REEXPORT == 1) { 487 setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsEnable"), null, 'mesgs'); 488 } else { 489 setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsDisable"), null, 'mesgs'); 490 } 491 } else { 492 setEventMessages($langs->trans("Error"), null, 'errors'); 493 } 494} 495 496// Build and execute select (used by page and export action) 497// must de set after the action that set $filter 498// -------------------------------------------------------------------- 499 500$sql = 'SELECT'; 501$sql .= ' t.rowid,'; 502$sql .= " t.doc_date,"; 503$sql .= " t.doc_type,"; 504$sql .= " t.doc_ref,"; 505$sql .= " t.fk_doc,"; 506$sql .= " t.fk_docdet,"; 507$sql .= " t.thirdparty_code,"; 508$sql .= " t.subledger_account,"; 509$sql .= " t.subledger_label,"; 510$sql .= " t.numero_compte,"; 511$sql .= " t.label_compte,"; 512$sql .= " t.label_operation,"; 513$sql .= " t.debit,"; 514$sql .= " t.credit,"; 515$sql .= " t.lettering_code,"; 516$sql .= " t.montant as amount,"; 517$sql .= " t.sens,"; 518$sql .= " t.fk_user_author,"; 519$sql .= " t.import_key,"; 520$sql .= " t.code_journal,"; 521$sql .= " t.journal_label,"; 522$sql .= " t.piece_num,"; 523$sql .= " t.date_creation,"; 524$sql .= " t.tms as date_modification,"; 525$sql .= " t.date_export,"; 526$sql .= " t.date_validated as date_validation"; 527$sql .= ' FROM '.MAIN_DB_PREFIX.$object->table_element.' as t'; 528// Manage filter 529$sqlwhere = array(); 530if (count($filter) > 0) { 531 foreach ($filter as $key => $value) { 532 if ($key == 't.doc_date') { 533 $sqlwhere[] = $key.'=\''.$db->idate($value).'\''; 534 } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') { 535 $sqlwhere[] = $key.'\''.$db->idate($value).'\''; 536 } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=') { 537 $sqlwhere[] = $key.'\''.$db->escape($value).'\''; 538 } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { 539 $sqlwhere[] = $key.'='.$value; 540 } elseif ($key == 't.numero_compte') { 541 $sqlwhere[] = $key.' LIKE \''.$db->escape($value).'%\''; 542 } elseif ($key == 't.subledger_account') { 543 $sqlwhere[] = natural_search($key, $value, 0, 1); 544 } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') { 545 $sqlwhere[] = $key.'\''.$db->idate($value).'\''; 546 } elseif ($key == 't.tms>=' || $key == 't.tms<=') { 547 $sqlwhere[] = $key.'\''.$db->idate($value).'\''; 548 } elseif ($key == 't.date_export>=' || $key == 't.date_export<=') { 549 $sqlwhere[] = $key.'\''.$db->idate($value).'\''; 550 } elseif ($key == 't.date_validated>=' || $key == 't.date_validated<=') { 551 $sqlwhere[] = $key.'\''.$db->idate($value).'\''; 552 } elseif ($key == 't.credit' || $key == 't.debit') { 553 $sqlwhere[] = natural_search($key, $value, 1, 1); 554 } elseif ($key == 't.reconciled_option') { 555 $sqlwhere[] = 't.lettering_code IS NULL'; 556 } elseif ($key == 't.code_journal' && !empty($value)) { 557 $sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1); 558 } else { 559 $sqlwhere[] = natural_search($key, $value, 0, 1); 560 } 561 } 562} 563$sql .= ' WHERE t.entity IN ('.getEntity('accountancy').')'; 564if (empty($conf->global->ACCOUNTING_REEXPORT)) { 565 $sql .= " AND t.date_export IS NULL"; 566} 567if (count($sqlwhere) > 0) { 568 $sql .= ' AND '.implode(' AND ', $sqlwhere); 569} 570if (!empty($sortfield)) { 571 $sql .= $db->order($sortfield, $sortorder); 572} 573//print $sql; 574 575 576// Export into a file with format defined into setup (FEC, CSV, ...) 577// Must be after definition of $sql 578if ($action == 'export_fileconfirm' && $user->rights->accounting->mouvements->export) { 579 // TODO Replace the fetchAll to get all ->line followed by call to ->export(). It consumew too much memory on large export. Replace this with the query($sql) and loop on each line to export them. 580 $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', (empty($conf->global->ACCOUNTING_REEXPORT) ? 0 : 1)); 581 582 if ($result < 0) { 583 setEventMessages($object->error, $object->errors, 'errors'); 584 } else { 585 // Export files 586 $accountancyexport = new AccountancyExport($db); 587 $accountancyexport->export($object->lines, $formatexportset); 588 589 $notifiedexportdate = GETPOST('notifiedexportdate', 'alpha'); 590 $notifiedvalidationdate = GETPOST('notifiedvalidationdate', 'alpha'); 591 592 if (!empty($accountancyexport->errors)) { 593 setEventMessages('', $accountancyexport->errors, 'errors'); 594 } elseif (!empty($notifiedexportdate) || !empty($notifiedvalidationdate)) { 595 // Specify as export : update field date_export or date_validated 596 $error = 0; 597 $db->begin(); 598 599 if (is_array($object->lines)) { 600 foreach ($object->lines as $movement) { 601 $now = dol_now(); 602 603 $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping"; 604 $sql .= " SET"; 605 if (!empty($notifiedexportdate) && !empty($notifiedvalidationdate)) { 606 $sql .= " date_export = '".$db->idate($now)."'"; 607 $sql .= ", date_validated = '".$db->idate($now)."'"; 608 } elseif (!empty($notifiedexportdate)) { 609 $sql .= " date_export = '".$db->idate($now)."'"; 610 } elseif (!empty($notifiedvalidationdate)) { 611 $sql .= " date_validated = '".$db->idate($now)."'"; 612 } 613 $sql .= " WHERE rowid = ".((int) $movement->id); 614 615 dol_syslog("/accountancy/bookkeeping/list.php Function export_file Specify movements as exported sql=".$sql, LOG_DEBUG); 616 $result = $db->query($sql); 617 if (!$result) { 618 $error++; 619 break; 620 } 621 } 622 } 623 624 if (!$error) { 625 $db->commit(); 626 // setEventMessages($langs->trans("AllExportedMovementsWereRecordedAsExportedOrValidated"), null, 'mesgs'); 627 } else { 628 $error++; 629 $db->rollback(); 630 setEventMessages($langs->trans("NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated"), null, 'errors'); 631 } 632 } 633 exit; 634 } 635} 636 637 638/* 639 * View 640 */ 641 642$formother = new FormOther($db); 643$formfile = new FormFile($db); 644 645$title_page = $langs->trans("Operations").' - '.$langs->trans("Journals"); 646 647// Count total nb of records 648$nbtotalofrecords = ''; 649if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { 650 $resql = $db->query($sql); 651 $nbtotalofrecords = $db->num_rows($resql); 652 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 653 $page = 0; 654 $offset = 0; 655 } 656} 657// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. 658if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) { 659 $num = $nbtotalofrecords; 660} else { 661 $sql .= $db->plimit($limit + 1, $offset); 662 663 $resql = $db->query($sql); 664 if (!$resql) { 665 dol_print_error($db); 666 exit; 667 } 668 669 $num = $db->num_rows($resql); 670} 671 672 673// Output page 674// -------------------------------------------------------------------- 675 676llxHeader('', $title_page); 677 678$formconfirm = ''; 679 680if ($action == 'export_file') { 681 $form_question = array(); 682 683 $form_question['notifiedexportdate'] = array( 684 'name' => 'notifiedexportdate', 685 'type' => 'checkbox', 686 'label' => $langs->trans('NotifiedExportDate'), 687 'value' => (!empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE) ? 'false' : 'true'), 688 ); 689 $form_question['notifiedvalidationdate'] = array( 690 'name' => 'notifiedvalidationdate', 691 'type' => 'checkbox', 692 'label' => $langs->trans('NotifiedValidationDate'), 693 'value' => (!empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE) ? 'false' : 'true'), 694 ); 695 696 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', $langs->trans('ConfirmExportFile'), 'export_fileconfirm', $form_question, '', 1, 300, 600); 697} 698if ($action == 'delmouv') { 699 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?mvt_num='.GETPOST('mvt_num').$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvtPartial'), 'delmouvconfirm', '', 0, 1); 700} 701if ($action == 'delbookkeepingyear') { 702 $form_question = array(); 703 $delyear = GETPOST('delyear', 'int'); 704 $deljournal = GETPOST('deljournal', 'alpha'); 705 706 if (empty($delyear)) { 707 $delyear = dol_print_date(dol_now(), '%Y'); 708 } 709 $month_array = array(); 710 for ($i = 1; $i <= 12; $i++) { 711 $month_array[$i] = $langs->trans("Month".sprintf("%02d", $i)); 712 } 713 $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array'); 714 $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1); 715 716 $form_question['delmonth'] = array( 717 'name' => 'delmonth', 718 'type' => 'select', 719 'label' => $langs->trans('DelMonth'), 720 'values' => $month_array, 721 'default' => '' 722 ); 723 $form_question['delyear'] = array( 724 'name' => 'delyear', 725 'type' => 'select', 726 'label' => $langs->trans('DelYear'), 727 'values' => $year_array, 728 'default' => $delyear 729 ); 730 $form_question['deljournal'] = array( 731 'name' => 'deljournal', 732 'type' => 'other', // We don't use select here, the journal_array is already a select html component 733 'label' => $langs->trans('DelJournal'), 734 'value' => $journal_array, 735 'default' => $deljournal 736 ); 737 738 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'delbookkeepingyearconfirm', $form_question, '', 1, 300); 739} 740 741// Print form confirm 742print $formconfirm; 743 744//$param=''; param started before 745if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { 746 $param .= '&contextpage='.urlencode($contextpage); 747} 748if ($limit > 0 && $limit != $conf->liste_limit) { 749 $param .= '&limit='.urlencode($limit); 750} 751 752print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'; 753print '<input type="hidden" name="token" value="'.newToken().'">'; 754print '<input type="hidden" name="action" value="list">'; 755if ($optioncss != '') { 756 print '<input type="hidden" name="optioncss" value="'.urlencode($optioncss).'">'; 757} 758print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; 759print '<input type="hidden" name="sortfield" value="'.urlencode($sortfield).'">'; 760print '<input type="hidden" name="sortorder" value="'.urlencode($sortorder).'">'; 761 762$massactionbutton = ''; 763 764if (count($filter)) { 765 $buttonLabel = $langs->trans("ExportFilteredList"); 766} else { 767 $buttonLabel = $langs->trans("ExportList"); 768} 769 770$parameters = array(); 771$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook 772if (empty($reshook)) { 773 // Button re-export 774 if (!empty($conf->global->ACCOUNTING_REEXPORT)) { 775 $newcardbutton = '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=0'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("Activated"), 'switch_on').'</a> '; 776 } else { 777 $newcardbutton = '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=1'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a> '; 778 } 779 $newcardbutton .= '<span class="valignmiddle marginrightonly">'.$langs->trans("IncludeDocsAlreadyExported").'</span>'; 780 781 if (!empty($user->rights->accounting->mouvements->export)) { 782 $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file'.($param ? '&'.$param : ''), $user->rights->accounting->mouvements->export); 783 } 784 785 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected')); 786 $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly')); 787 $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbysubaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly')); 788 789 $url = './card.php?action=create'; 790 if (!empty($socid)) { 791 $url .= '&socid='.$socid; 792 } 793 $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', $url, '', $user->rights->accounting->mouvements->creer); 794} 795 796print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); 797 798$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; 799$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields 800if ($massactionbutton) { 801 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); 802} 803 804$parameters = array(); 805$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook 806if (empty($reshook)) { 807 $moreforfilter .= $hookmanager->resPrint; 808} else { 809 $moreforfilter = $hookmanager->resPrint; 810} 811 812print '<div class="div-table-responsive">'; 813print '<table class="tagtable liste centpercent">'; 814 815// Filters lines 816print '<tr class="liste_titre_filter">'; 817 818// Movement number 819if (!empty($arrayfields['t.piece_num']['checked'])) { 820 print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="'.dol_escape_htmltag($search_mvt_num).'"></td>'; 821} 822// Code journal 823if (!empty($arrayfields['t.code_journal']['checked'])) { 824 print '<td class="liste_titre center">'; 825 print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1, 'maxwidth150'); 826 print '</td>'; 827} 828// Date document 829if (!empty($arrayfields['t.doc_date']['checked'])) { 830 print '<td class="liste_titre center">'; 831 print '<div class="nowrap">'; 832 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); 833 print '</div>'; 834 print '<div class="nowrap">'; 835 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); 836 print '</div>'; 837 print '</td>'; 838} 839// Ref document 840if (!empty($arrayfields['t.doc_ref']['checked'])) { 841 print '<td class="liste_titre"><input type="text" name="search_doc_ref" size="8" value="'.dol_escape_htmltag($search_doc_ref).'"></td>'; 842} 843// Accountancy account 844if (!empty($arrayfields['t.numero_compte']['checked'])) { 845 print '<td class="liste_titre">'; 846 print '<div class="nowrap">'; 847 print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200', 'account'); 848 print '</div>'; 849 print '<div class="nowrap">'; 850 print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200', 'account'); 851 print '</div>'; 852 print '</td>'; 853} 854// Subledger account 855if (!empty($arrayfields['t.subledger_account']['checked'])) { 856 print '<td class="liste_titre">'; 857 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not 858 // use setup of keypress to select thirdparty and this hang browser on large database. 859 if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { 860 print '<div class="nowrap">'; 861 //print $langs->trans('From').' '; 862 print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', $langs->trans('From'), 'maxwidth250', 'subledgeraccount'); 863 print '</div>'; 864 print '<div class="nowrap">'; 865 print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', $langs->trans('to'), 'maxwidth250', 'subledgeraccount'); 866 print '</div>'; 867 } else { 868 print '<input type="text" class="maxwidth75" name="search_accountancy_aux_code" value="'.$search_accountancy_aux_code.'">'; 869 } 870 print '</td>'; 871} 872// Label operation 873if (!empty($arrayfields['t.label_operation']['checked'])) { 874 print '<td class="liste_titre">'; 875 print '<input type="text" size="7" class="flat" name="search_mvt_label" value="'.$search_mvt_label.'"/>'; 876 print '</td>'; 877} 878// Debit 879if (!empty($arrayfields['t.debit']['checked'])) { 880 print '<td class="liste_titre right">'; 881 print '<input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'">'; 882 print '</td>'; 883} 884// Credit 885if (!empty($arrayfields['t.credit']['checked'])) { 886 print '<td class="liste_titre right">'; 887 print '<input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'">'; 888 print '</td>'; 889} 890// Lettering code 891if (!empty($arrayfields['t.lettering_code']['checked'])) { 892 print '<td class="liste_titre center">'; 893 print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>'; 894 print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>'; 895 print '</td>'; 896} 897 898// Fields from hook 899$parameters = array('arrayfields'=>$arrayfields); 900$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook 901print $hookmanager->resPrint; 902 903// Date creation 904if (!empty($arrayfields['t.date_creation']['checked'])) { 905 print '<td class="liste_titre center">'; 906 print '<div class="nowrap">'; 907 print $form->selectDate($search_date_creation_start, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); 908 print '</div>'; 909 print '<div class="nowrap">'; 910 print $form->selectDate($search_date_creation_end, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); 911 print '</div>'; 912 print '</td>'; 913} 914// Date modification 915if (!empty($arrayfields['t.tms']['checked'])) { 916 print '<td class="liste_titre center">'; 917 print '<div class="nowrap">'; 918 print $form->selectDate($search_date_modification_start, 'search_date_modification_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); 919 print '</div>'; 920 print '<div class="nowrap">'; 921 print $form->selectDate($search_date_modification_end, 'search_date_modification_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); 922 print '</div>'; 923 print '</td>'; 924} 925// Date export 926if (!empty($arrayfields['t.date_export']['checked'])) { 927 print '<td class="liste_titre center">'; 928 print '<div class="nowrap">'; 929 print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); 930 print '</div>'; 931 print '<div class="nowrap">'; 932 print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); 933 print '</div>'; 934 print '</td>'; 935} 936// Date validation 937if (!empty($arrayfields['t.date_validated']['checked'])) { 938 print '<td class="liste_titre center">'; 939 print '<div class="nowrap">'; 940 print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); 941 print '</div>'; 942 print '<div class="nowrap">'; 943 print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); 944 print '</div>'; 945 print '</td>'; 946} 947// Action column 948print '<td class="liste_titre center">'; 949$searchpicto = $form->showFilterButtons(); 950print $searchpicto; 951print '</td>'; 952print "</tr>\n"; 953 954print '<tr class="liste_titre">'; 955if (!empty($arrayfields['t.piece_num']['checked'])) { 956 print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, "", $sortfield, $sortorder); 957} 958if (!empty($arrayfields['t.code_journal']['checked'])) { 959 print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center '); 960} 961if (!empty($arrayfields['t.doc_date']['checked'])) { 962 print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center '); 963} 964if (!empty($arrayfields['t.doc_ref']['checked'])) { 965 print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder); 966} 967if (!empty($arrayfields['t.numero_compte']['checked'])) { 968 print_liste_field_titre($arrayfields['t.numero_compte']['label'], $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); 969} 970if (!empty($arrayfields['t.subledger_account']['checked'])) { 971 print_liste_field_titre($arrayfields['t.subledger_account']['label'], $_SERVER['PHP_SELF'], "t.subledger_account", "", $param, "", $sortfield, $sortorder); 972} 973if (!empty($arrayfields['t.label_operation']['checked'])) { 974 print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); 975} 976if (!empty($arrayfields['t.debit']['checked'])) { 977 print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right '); 978} 979if (!empty($arrayfields['t.credit']['checked'])) { 980 print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right '); 981} 982if (!empty($arrayfields['t.lettering_code']['checked'])) { 983 print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center '); 984} 985// Hook fields 986$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); 987$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook 988print $hookmanager->resPrint; 989if (!empty($arrayfields['t.date_creation']['checked'])) { 990 print_liste_field_titre($arrayfields['t.date_creation']['label'], $_SERVER['PHP_SELF'], "t.date_creation", "", $param, '', $sortfield, $sortorder, 'center '); 991} 992if (!empty($arrayfields['t.tms']['checked'])) { 993 print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER['PHP_SELF'], "t.tms", "", $param, '', $sortfield, $sortorder, 'center '); 994} 995if (!empty($arrayfields['t.date_export']['checked'])) { 996 print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center '); 997} 998if (!empty($arrayfields['t.date_validated']['checked'])) { 999 print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated", "", $param, '', $sortfield, $sortorder, 'center '); 1000} 1001print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); 1002print "</tr>\n"; 1003 1004 1005$line = new BookKeepingLine(); 1006 1007// Loop on record 1008// -------------------------------------------------------------------- 1009$i = 0; 1010$totalarray = array(); 1011while ($i < min($num, $limit)) { 1012 $obj = $db->fetch_object($resql); 1013 if (empty($obj)) { 1014 break; // Should not happen 1015 } 1016 1017 $line->id = $obj->rowid; 1018 $line->doc_date = $db->jdate($obj->doc_date); 1019 $line->doc_type = $obj->doc_type; 1020 $line->doc_ref = $obj->doc_ref; 1021 $line->fk_doc = $obj->fk_doc; 1022 $line->fk_docdet = $obj->fk_docdet; 1023 $line->thirdparty_code = $obj->thirdparty_code; 1024 $line->subledger_account = $obj->subledger_account; 1025 $line->subledger_label = $obj->subledger_label; 1026 $line->numero_compte = $obj->numero_compte; 1027 $line->label_compte = $obj->label_compte; 1028 $line->label_operation = $obj->label_operation; 1029 $line->debit = $obj->debit; 1030 $line->credit = $obj->credit; 1031 $line->montant = $obj->amount; // deprecated 1032 $line->amount = $obj->amount; 1033 $line->sens = $obj->sens; 1034 $line->lettering_code = $obj->lettering_code; 1035 $line->fk_user_author = $obj->fk_user_author; 1036 $line->import_key = $obj->import_key; 1037 $line->code_journal = $obj->code_journal; 1038 $line->journal_label = $obj->journal_label; 1039 $line->piece_num = $obj->piece_num; 1040 $line->date_creation = $db->jdate($obj->date_creation); 1041 $line->date_modification = $db->jdate($obj->date_modification); 1042 $line->date_export = $db->jdate($obj->date_export); 1043 $line->date_validation = $db->jdate($obj->date_validation); 1044 1045 $total_debit += $line->debit; 1046 $total_credit += $line->credit; 1047 1048 print '<tr class="oddeven">'; 1049 1050 // Piece number 1051 if (!empty($arrayfields['t.piece_num']['checked'])) { 1052 print '<td>'; 1053 $object->id = $line->id; 1054 $object->piece_num = $line->piece_num; 1055 print $object->getNomUrl(1, '', 0, '', 1); 1056 print '</td>'; 1057 if (!$i) { 1058 $totalarray['nbfield']++; 1059 } 1060 } 1061 1062 // Journal code 1063 if (!empty($arrayfields['t.code_journal']['checked'])) { 1064 $accountingjournal = new AccountingJournal($db); 1065 $result = $accountingjournal->fetch('', $line->code_journal); 1066 $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal); 1067 print '<td class="center">'.$journaltoshow.'</td>'; 1068 if (!$i) { 1069 $totalarray['nbfield']++; 1070 } 1071 } 1072 1073 // Document date 1074 if (!empty($arrayfields['t.doc_date']['checked'])) { 1075 print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>'; 1076 if (!$i) { 1077 $totalarray['nbfield']++; 1078 } 1079 } 1080 1081 // Document ref 1082 if (!empty($arrayfields['t.doc_ref']['checked'])) { 1083 if ($line->doc_type == 'customer_invoice') { 1084 $langs->loadLangs(array('bills')); 1085 1086 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; 1087 $objectstatic = new Facture($db); 1088 $objectstatic->fetch($line->fk_doc); 1089 //$modulepart = 'facture'; 1090 1091 $filename = dol_sanitizeFileName($line->doc_ref); 1092 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref); 1093 $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id; 1094 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); 1095 } elseif ($line->doc_type == 'supplier_invoice') { 1096 $langs->loadLangs(array('bills')); 1097 1098 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; 1099 $objectstatic = new FactureFournisseur($db); 1100 $objectstatic->fetch($line->fk_doc); 1101 //$modulepart = 'invoice_supplier'; 1102 1103 $filename = dol_sanitizeFileName($line->doc_ref); 1104 $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref); 1105 $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref); 1106 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir); 1107 } elseif ($line->doc_type == 'expense_report') { 1108 $langs->loadLangs(array('trips')); 1109 1110 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; 1111 $objectstatic = new ExpenseReport($db); 1112 $objectstatic->fetch($line->fk_doc); 1113 //$modulepart = 'expensereport'; 1114 1115 $filename = dol_sanitizeFileName($line->doc_ref); 1116 $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref); 1117 $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id; 1118 $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); 1119 } elseif ($line->doc_type == 'bank') { 1120 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; 1121 $objectstatic = new AccountLine($db); 1122 $objectstatic->fetch($line->fk_doc); 1123 } else { 1124 // Other type 1125 } 1126 1127 print '<td class="nowrap">'; 1128 1129 print '<table class="nobordernopadding"><tr class="nocellnopadd">'; 1130 // Picto + Ref 1131 print '<td class="nobordernopadding nowrap">'; 1132 1133 if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') { 1134 print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1); 1135 print $documentlink; 1136 } elseif ($line->doc_type == 'bank') { 1137 print $objectstatic->getNomUrl(1); 1138 $bank_ref = strstr($line->doc_ref, '-'); 1139 print " " . $bank_ref; 1140 } else { 1141 print $line->doc_ref; 1142 } 1143 print '</td></tr></table>'; 1144 1145 print "</td>\n"; 1146 if (!$i) { 1147 $totalarray['nbfield']++; 1148 } 1149 } 1150 1151 // Account number 1152 if (!empty($arrayfields['t.numero_compte']['checked'])) { 1153 print '<td>'.length_accountg($line->numero_compte).'</td>'; 1154 if (!$i) { 1155 $totalarray['nbfield']++; 1156 } 1157 } 1158 1159 // Subledger account 1160 if (!empty($arrayfields['t.subledger_account']['checked'])) { 1161 print '<td>'.length_accounta($line->subledger_account).'</td>'; 1162 if (!$i) { 1163 $totalarray['nbfield']++; 1164 } 1165 } 1166 1167 // Label operation 1168 if (!empty($arrayfields['t.label_operation']['checked'])) { 1169 print '<td>'.$line->label_operation.'</td>'; 1170 if (!$i) { 1171 $totalarray['nbfield']++; 1172 } 1173 } 1174 1175 // Amount debit 1176 if (!empty($arrayfields['t.debit']['checked'])) { 1177 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>'; 1178 if (!$i) { 1179 $totalarray['nbfield']++; 1180 } 1181 if (!$i) { 1182 $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit'; 1183 } 1184 $totalarray['val']['totaldebit'] += $line->debit; 1185 } 1186 1187 // Amount credit 1188 if (!empty($arrayfields['t.credit']['checked'])) { 1189 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>'; 1190 if (!$i) { 1191 $totalarray['nbfield']++; 1192 } 1193 if (!$i) { 1194 $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit'; 1195 } 1196 $totalarray['val']['totalcredit'] += $line->credit; 1197 } 1198 1199 // Lettering code 1200 if (!empty($arrayfields['t.lettering_code']['checked'])) { 1201 print '<td class="center">'.$line->lettering_code.'</td>'; 1202 if (!$i) { 1203 $totalarray['nbfield']++; 1204 } 1205 } 1206 1207 // Fields from hook 1208 $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); 1209 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook 1210 print $hookmanager->resPrint; 1211 1212 // Creation operation date 1213 if (!empty($arrayfields['t.date_creation']['checked'])) { 1214 print '<td class="center">'.dol_print_date($line->date_creation, 'dayhour').'</td>'; 1215 if (!$i) { 1216 $totalarray['nbfield']++; 1217 } 1218 } 1219 1220 // Modification operation date 1221 if (!empty($arrayfields['t.tms']['checked'])) { 1222 print '<td class="center">'.dol_print_date($line->date_modification, 'dayhour').'</td>'; 1223 if (!$i) { 1224 $totalarray['nbfield']++; 1225 } 1226 } 1227 1228 // Exported operation date 1229 if (!empty($arrayfields['t.date_export']['checked'])) { 1230 print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>'; 1231 if (!$i) { 1232 $totalarray['nbfield']++; 1233 } 1234 } 1235 1236 // Validated operation date 1237 if (!empty($arrayfields['t.date_validated']['checked'])) { 1238 print '<td class="center">'.dol_print_date($line->date_validation, 'dayhour').'</td>'; 1239 if (!$i) { 1240 $totalarray['nbfield']++; 1241 } 1242 } 1243 1244 // Action column 1245 print '<td class="nowraponall center">'; 1246 if (empty($line->date_export) && empty($line->date_validation)) { 1247 if ($user->rights->accounting->mouvements->creer) { 1248 print '<a class="editfielda paddingleft marginrightonly" href="' . DOL_URL_ROOT . '/accountancy/bookkeeping/card.php?piece_num=' . $line->piece_num . $param . '&page=' . $page . ($sortfield ? '&sortfield=' . $sortfield : '') . ($sortorder ? '&sortorder=' . $sortorder : '') . '">' . img_edit() . '</a>'; 1249 } 1250 } 1251 if (empty($line->date_validation)) { 1252 if ($user->rights->accounting->mouvements->supprimer) { 1253 print '<a class="reposition paddingleft marginrightonly" href="'.$_SERVER['PHP_SELF'].'?action=delmouv&mvt_num='.$line->piece_num.$param.'&page='.$page.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">'.img_delete().'</a>'; 1254 } 1255 } 1256 print '</td>'; 1257 1258 if (!$i) { 1259 $totalarray['nbfield']++; 1260 } 1261 1262 print "</tr>\n"; 1263 1264 $i++; 1265} 1266 1267// Show total line 1268include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; 1269 1270 1271print "</table>"; 1272print '</div>'; 1273 1274// TODO Replace this with mass delete action 1275if ($user->rights->accounting->mouvements->supprimer_tous) { 1276 print '<div class="tabsAction tabsActionNoBottom">'."\n"; 1277 print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear'.($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>'; 1278 print '</div>'; 1279} 1280 1281print '</form>'; 1282 1283// End of page 1284llxFooter(); 1285$db->close(); 1286