diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 1cdef9af6a9..15e7acd7deb 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -57,6 +57,7 @@ if (GETPOST("exportcsv")) $action = 'export_csv'; $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):$conf->liste_limit; +if (empty($page) || $page < 0) { $page = 0; } $offset = $limit * $page; @@ -68,17 +69,27 @@ $form = new Form($db); if (empty($search_date_start) && ! GETPOSTISSET('formfilteraction')) { - $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); - $year_start = dol_print_date(dol_now(), '%Y'); - $year_end = $year_start + 1; - $month_end = $month_start - 1; - if ($month_end < 1) - { - $month_end = 12; - $year_end--; + $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; + $sql.= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'"; + $sql.= $db->plimit(1); + $res = $db->query($sql); + if ($res->num_rows > 0) { + $fiscalYear = $db->fetch_object($res); + $search_date_start = strtotime($fiscalYear->date_start); + $search_date_end = strtotime($fiscalYear->date_end); + } else { + $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); + $year_start = dol_print_date(dol_now(), '%Y'); + $year_end = $year_start + 1; + $month_end = $month_start - 1; + if ($month_end < 1) + { + $month_end = 12; + $year_end--; + } + $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); + $search_date_end = dol_get_last_day($year_end, $month_end); } - $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); - $search_date_end = dol_get_last_day($year_end, $month_end); } if ($sortorder == "") $sortorder = "ASC"; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 0310906ab6b..29dfbeeec59 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -101,17 +101,26 @@ $form = new Form($db); if (! in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && ! isset($_POST['begin']) && ! isset($_GET['begin']) && ! isset($_POST['formfilteraction']) && empty($page) && ! GETPOST('noreset','int')) { - $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); - $year_start = dol_print_date(dol_now(), '%Y'); - $year_end = $year_start + 1; - $month_end = $month_start - 1; - if ($month_end < 1) - { - $month_end = 12; - $year_end--; + $query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; + $query .= " where date_start < now() and date_end > now() limit 1"; + $res = $db->query($query); + if ($res->num_rows > 0) { + $fiscalYear = $db->fetch_object($res); + $search_date_start = strtotime($fiscalYear->date_start); + $search_date_end = strtotime($fiscalYear->date_end); + } else { + $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); + $year_start = dol_print_date(dol_now(), '%Y'); + $year_end = $year_start + 1; + $month_end = $month_start - 1; + if ($month_end < 1) + { + $month_end = 12; + $year_end--; + } + $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); + $search_date_end = dol_get_last_day($year_end, $month_end); } - $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); - $search_date_end = dol_get_last_day($year_end, $month_end); } diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index f73b57b42f3..08aa1aac19d 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -40,34 +40,18 @@ $page = GETPOST("page"); $sortorder = GETPOST("sortorder"); $sortfield = GETPOST("sortfield"); $action = GETPOST('action', 'alpha'); - -if (empty($search_date_start)) -{ - $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); - $year_start = dol_print_date(dol_now(), '%Y'); - $year_end = $year_start + 1; - $month_end = $month_start - 1; - if ($month_end < 1) - { - $month_end = 12; - $year_end--; - } - $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); - $search_date_end = dol_get_last_day($year_end, $month_end); -} - +$search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); +$search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); $search_accountancy_code = GETPOST("search_accountancy_code"); - $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); if ($search_accountancy_code_start == - 1) { $search_accountancy_code_start = ''; } $search_label_account = GETPOST('search_label_account', 'alpha'); - $search_mvt_label = GETPOST('search_mvt_label', 'alpha'); $search_direction = GETPOST('search_direction', 'alpha'); $search_ledger_code = GETPOST('search_ledger_code', 'alpha'); @@ -77,15 +61,37 @@ $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->AC $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page','int'); -if ($page < 0) { $page = 0; } +if (empty($page) || $page < 0) { $page = 0; } $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if ($sortorder == "") $sortorder = "ASC"; if ($sortfield == "") $sortfield = "t.rowid"; -if (empty($search_date_start)) $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y')); -if (empty($search_date_end)) $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y')); +if (empty($search_date_start)) { + $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; + $sql.= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'"; + $sql.= $db->plimit(1); + $res = $db->query($sql); + + if ($res->num_rows > 0) { + $fiscalYear = $db->fetch_object($res); + $search_date_start = strtotime($fiscalYear->date_start); + $search_date_end = strtotime($fiscalYear->date_end); + } else { + $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); + $year_start = dol_print_date(dol_now(), '%Y'); + $year_end = $year_start + 1; + $month_end = $month_start - 1; + if ($month_end < 1) + { + $month_end = 12; + $year_end--; + } + $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); + $search_date_end = dol_get_last_day($year_end, $month_end); + } +} $object = new BookKeeping($db); @@ -95,39 +101,38 @@ $filter = array (); if (! empty($search_date_start)) { $filter['t.doc_date>='] = $search_date_start; - $options .= '&date_startmonth=' . GETPOST('date_startmonth', 'int') . '&date_startday=' . GETPOST('date_startday', 'int') . '&date_startyear=' . GETPOST('date_startyear', 'int'); + $options .= '&date_startmonth=' . GETPOST('date_startmonth', 'int') . '&date_startday=' . GETPOST('date_startday', 'int') . '&date_startyear=' . GETPOST('date_startyear', 'int'); } if (! empty($search_date_end)) { $filter['t.doc_date<='] = $search_date_end; - $options .= '&date_endmonth=' . GETPOST('date_endmonth', 'int') . '&date_endday=' . GETPOST('date_endday', 'int') . '&date_endyear=' . GETPOST('date_endyear', 'int'); + $options .= '&date_endmonth=' . GETPOST('date_endmonth', 'int') . '&date_endday=' . GETPOST('date_endday', 'int') . '&date_endyear=' . GETPOST('date_endyear', 'int'); } if (! empty($search_doc_date)) { $filter['t.doc_date'] = $search_doc_date; - $options .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int'); + $options .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int'); } - 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 { if (! empty($search_accountancy_code_start)) { $filter['t.numero_compte'] = $search_accountancy_code_start; - $options .= '&search_accountancy_code_start=' . $search_accountancy_code_start; + $options .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start); } if (! empty($search_label_account)) { $filter['t.label_operation'] = $search_label_account; - $options .= '&search_label_account=' . $search_label_account; + $options .= '&search_label_account=' . urlencode($search_label_account); } if (! empty($search_mvt_label)) { $filter['t.label_operation'] = $search_mvt_label; - $options .= '&search_mvt_label=' . $search_mvt_label; + $options .= '&search_mvt_label=' . urlencode($search_mvt_label); } if (! empty($search_direction)) { $filter['t.sens'] = $search_direction; - $options .= '&search_direction=' . $search_direction; + $options .= '&search_direction=' . urlencode($search_direction); } if (! empty($search_ledger_code)) { $filter['t.code_journal'] = $search_ledger_code; - $options .= '&search_ledger_code=' . $search_ledger_code; + $options .= '&search_ledger_code=' . urlencode($search_ledger_code); } } @@ -174,6 +179,7 @@ $title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By" llxHeader('', $title_page); + // List $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { @@ -184,6 +190,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { } $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter); + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } @@ -225,7 +232,11 @@ print '
' . $langs->trans("ViewFlatList") . ''; $addbutton = '' . $langs->trans("NewAccountingMvt") . ''; -print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords,'title_accountancy',0,$viewflat.$addbutton,'', $limit); +$param=$options; +if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); +if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + +print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $result, $nbtotalofrecords, 'title_accountancy', 0, $viewflat.$addbutton, '', $limit); // Reverse sort order if ( preg_match('/^asc/i', $sortorder) ) diff --git a/htdocs/accountancy/bookkeeping/listbyyear.php b/htdocs/accountancy/bookkeeping/listbyyear.php deleted file mode 100644 index bf7578bb752..00000000000 --- a/htdocs/accountancy/bookkeeping/listbyyear.php +++ /dev/null @@ -1,295 +0,0 @@ - - * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2013-2016 Florian Henry - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * \file htdocs/accountancy/bookkeeping/listbyyear.php - * \ingroup Advanced accountancy - * \brief Book keeping by year - */ -require '../../main.inc.php'; - -// Class -require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; -require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; -require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; -require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; - -// Langs -$langs->load("accountancy"); - -$page = GETPOST("page"); -$sortorder = GETPOST("sortorder"); -$sortfield = GETPOST("sortfield"); -$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):$conf->liste_limit; -$search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); -$search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); -$search_doc_type = GETPOST('search_doc_type', 'alpha'); -$search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); -$search_doc_ref = GETPOST('search_doc_ref', 'alpha'); -$search_numero_compte = GETPOST('search_numero_compte', 'alpha'); -$search_numero_compte_start = GETPOST('search_numero_compte_start', 'alpha'); -if ($search_numero_compte_start == - 1) { - $search_numero_compte_start = ''; -} -$search_numero_compte_end = GETPOST('search_numero_compte_end', 'alpha'); -if ($search_numero_compte_end == - 1) { - $search_numero_compte_end = ''; -} -$search_subledger_account = GETPOST('search_subledger_account', 'alpha'); -$search_subledger_account_start = GETPOST('search_subledger_account_start', 'alpha'); -if ($search_subledger_account_start == - 1) { - $search_subledger_account_start = ''; -} -$search_subledger_account_end = GETPOST('search_subledger_account_end', 'alpha'); -if ($search_subledger_account_end == - 1) { - $search_subledger_account_end = ''; -} -$search_label_operation = GETPOST('search_label_operation', 'alpha'); -$search_sens = GETPOST('search_sens', 'alpha'); -$search_code_journal = GETPOST('search_code_journal', 'alpha'); - -$object = new BookKeeping($db); -$form = new Form($db); -$formaccounting = new FormAccounting($db); - -// Filter -if (empty($search_date_start)) { - $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y')); - $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y')); -} -if ($sortorder == "") - $sortorder = "ASC"; -if ($sortfield == "") - $sortfield = "t.rowid"; - -$offset = $limit * $page; - - -/* - * Actions - */ - -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 -{ - $search_doc_type = ""; - $search_doc_date = ""; - $search_doc_ref = ""; - $search_numero_compte = ""; - $search_subledger_account = ""; - $search_label_operation = ""; - $search_sens = ""; - $search_code_journal = ""; -} - -$options = ''; -$filter = array (); -if (! empty($search_date_start)) { - $filter['t.doc_date>='] = $search_date_start; - $options .= '&date_startmonth=' . GETPOST('date_startmonth', 'int') . '&date_startday=' . GETPOST('date_startday', 'int') . '&date_startyear=' . GETPOST('date_startyear', 'int'); -} -if (! empty($search_date_end)) { - $filter['t.doc_date<='] = $search_date_end; - $options .= '&date_endmonth=' . GETPOST('date_endmonth', 'int') . '&date_endday=' . GETPOST('date_endday', 'int') . '&date_endyear=' . GETPOST('date_endyear', 'int'); -} -if (! empty($search_doc_type)) { - $filter['t.doc_type'] = $search_doc_type; - $options .= '&search_doc_type=' . $search_doc_type; -} -if (! empty($search_doc_date)) { - $filter['t.doc_date'] = $search_doc_date; - $options .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int'); -} -if (! empty($search_doc_ref)) { - $filter['t.doc_ref'] = $search_doc_ref; - $options .= '&search_doc_ref=' . $search_doc_ref; -} -if (! empty($search_numero_compte)) { - $filter['t.numero_compte'] = $search_numero_compte; - $options .= '&search_numero_compte=' . $search_numero_compte; -} -if (! empty($search_numero_compte_start)) { - $filter['t.numero_compte>='] = $search_numero_compte_start; - $options .= '&search_numero_compte_start=' . $search_numero_compte_start; -} -if (! empty($search_numero_compte_end)) { - $filter['t.numero_compte<='] = $search_numero_compte_end; - $options .= '&search_numero_compte_end=' . $search_numero_compte_end; -} -if (! empty($search_subledger_account)) { - $filter['t.subledger_account'] = $search_subledger_account; - $options .= '&search_subledger_account=' . $search_subledger_account; -} -if (! empty($search_subledger_account_start)) { - $filter['t.subledger_account>='] = $search_subledger_account_start; - $options .= '&search_subledger_account_start=' . $search_subledger_account_start; -} -if (! empty($search_subledger_account_end)) { - $filter['t.subledger_account<='] = $search_subledger_account_end; - $options .= '&search_subledger_account_end=' . $search_subledger_account_end; -} -if (! empty($search_label_operation)) { - $filter['t.label_operation'] = $search_label_operation; - $options .= '&search_label_operation=' . $search_label_operation; -} -if (! empty($search_sens)) { - $filter['t.sens'] = $search_sens; - $options .= '&search_sens=' . $search_sens; -} -if (! empty($search_code_journal)) { - $filter['t.code_journal'] = $search_code_journal; - $options .= '&search_code_journal=' . $search_code_journal; -} - - -/* - * Actions - */ - -llxHeader('', $langs->trans("Bookkeeping")); - -$nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $nbtotalofrecords = $object->fetchAll($sortorder, $sortfield, 0, 0); - if ($nbtotalofrecords < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -$result = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter); -if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); -} - -print_barre_liste($langs->trans("Bookkeeping") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end), $page, $_SERVER['PHP_SELF'], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords, 'title_accountancy'); - -print ''; -print '
'; -print $langs->trans('DateStart') . ': '; -print $form->select_date($search_date_start, 'date_start'); -print $langs->trans('DateEnd') . ': '; -print $form->select_date($search_date_end, 'date_end'); -print '
'; -print '
'; -print $langs->trans('From') . ' ' . $langs->trans('AccountAccounting') . ': '; -print $formaccounting->select_account($search_numero_compte_start, 'search_numero_compte_start', 1, array (), 1, 1, ''); -print $langs->trans('To') . ' ' . $langs->trans('AccountAccounting') . ': '; -print $formaccounting->select_account($search_numero_compte_end, 'search_numero_compte_end', 1, array (), 1, 1, ''); -print '
'; -print '
'; -print $langs->trans('From') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; -print $formaccounting->select_auxaccount($search_subledger_account_start, 'search_subledger_account_start', 1); -print $langs->trans('To') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; -print $formaccounting->select_auxaccount($search_subledger_account_end, 'search_subledger_account_end', 1); -print '
'; -print ""; - -print ''; -print_liste_field_titre("NumPiece", $_SERVER['PHP_SELF'], "t.piece_num", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre("Doctype", $_SERVER['PHP_SELF'], "t.doc_type", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre("Date", $_SERVER['PHP_SELF'], "t.doc_date", "", $options, 'align="center"', $sortfield, $sortorder); -print_liste_field_titre("Docref", $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre("ThirdPartyAccount", $_SERVER['PHP_SELF'], "t.subledger_account", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre("Label", $_SERVER['PHP_SELF'], "t.label_operation", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="center"', $sortfield, $sortorder); -print_liste_field_titre("Amount", $_SERVER['PHP_SELF'], "t.montant", "", $options, 'align="center"', $sortfield, $sortorder); -print_liste_field_titre("Sens", $_SERVER['PHP_SELF'], "t.sens", "", $options, 'align="center"', $sortfield, $sortorder); -print_liste_field_titre("Codejournal", $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="center"', $sortfield, $sortorder); -print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); -print "\n"; - -print ''; -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print ''; - -print "\n"; - -foreach ( $object->lines as $line ) { - - print ''; - print '' . "\n"; - print '' . "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; -} -print "
'; -print ''; -print ''; -print ''; -print ''; -print $form->select_date($search_doc_date, 'doc_date', 0, 0, 1); -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ' '; -print ''; -print '
' . $line->piece_num . '' . $line->doc_type . '' . dol_print_date($line->doc_date) . '' . $line->doc_ref . '' . length_accountg($line->numero_compte) . '' . length_accounta($line->subledger_account) . '' . $line->label_operation . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->montant) . '' . $line->sens . '' . $line->code_journal . '' . img_edit() . '
"; -print ''; - -llxFooter(); -$db->close(); diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index e426b8a21a1..4aba5bb0591 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -628,13 +628,15 @@ class BookKeeping extends CommonObject * @param array $filter filter array * @param string $filtermode filter mode (AND or OR) * - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, >=0 if OK */ public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; dol_syslog(__METHOD__, LOG_DEBUG); + $this->lines = array(); + $sql = 'SELECT'; $sql .= ' t.rowid,'; $sql .= " t.doc_date,"; @@ -695,7 +697,6 @@ class BookKeeping extends CommonObject if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } - $this->lines = array (); $resql = $this->db->query($sql); if ($resql) { @@ -737,7 +738,7 @@ class BookKeeping extends CommonObject $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - return - 1; + return -1; } } diff --git a/htdocs/accountancy/expensereport/list.php b/htdocs/accountancy/expensereport/list.php index 0e4b9b05ac9..eed1479ab0a 100644 --- a/htdocs/accountancy/expensereport/list.php +++ b/htdocs/accountancy/expensereport/list.php @@ -71,7 +71,7 @@ $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->AC $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page','int'); -if ($page < 0) { $page = 0; } +if (empty($page) || $page < 0) { $page = 0; } $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 5d9871eecfb..49d81d5d11d 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -73,7 +73,7 @@ $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->AC $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page','int'); -if ($page < 0) { $page = 0; } +if (empty($page) || $page < 0) { $page = 0; } $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 1c6a0c00145..b2b7efc3a1c 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -262,17 +262,17 @@ if ($action == 'removelogo') require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $logofile=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; - dol_delete_file($logofile); + if ($mysoc->logo != '') dol_delete_file($logofile); dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO",$conf->entity); $mysoc->logo=''; $logosmallfile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; - dol_delete_file($logosmallfile); + if ($mysoc->logo_small != '') dol_delete_file($logosmallfile); dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$conf->entity); $mysoc->logo_small=''; $logominifile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini; - dol_delete_file($logominifile); + if ($mysoc->logo_mini != '') dol_delete_file($logominifile); dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$conf->entity); $mysoc->logo_mini=''; } @@ -370,7 +370,6 @@ if ($action == 'edit' || $action == 'updateedit') print ''."\n"; // Web - print ''; print ''; print ''."\n"; @@ -384,8 +383,7 @@ if ($action == 'edit' || $action == 'updateedit') } // Logo - - print ''; + print ''; print ''; // Note - print ''; print ''; diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index cd63037c668..d5b30d67d11 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -388,14 +388,14 @@ class Documents extends DolibarrApi * Upload a file. * * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. - * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "image/mywebsite", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. + * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "image/mywebsite", "filecontent": "Y29udGVudCB0ZXh0Cg==", "fileencoding": "base64", "overwriteifexists": "0" }. * * @param string $filename Name of file to create ('FA1705-0123.txt') * @param string $modulepart Name of module or area concerned by file upload ('facture', 'project', 'project_task', ...) * @param string $ref Reference of object (This will define subdir automatically and store submited file into it) * @param string $subdir Subdirectory (Only if ref not provided) * @param string $filecontent File content (string with file content. An empty file will be created if this parameter is not provided) - * @param string $fileencoding File encoding (''=no encoding, 'base64'=Base 64) + * @param string $fileencoding File encoding (''=no encoding, 'base64'=Base 64) {@example '' or 'base64'} * @param int $overwriteifexists Overwrite file if exists (1 by default) * * @throws 200 diff --git a/htdocs/api/index.php b/htdocs/api/index.php index d588fbdad1d..99334880d3a 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -79,6 +79,9 @@ if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($ } +// This 2 lines are usefull only if we want to exclude some Urls from the explorer +//use Luracast\Restler\Explorer; +//Explorer::$excludedPaths = array('/categories'); // Analyze URLs diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php index a4dab57305c..639d9df909d 100644 --- a/htdocs/blockedlog/class/blockedlog.class.php +++ b/htdocs/blockedlog/class/blockedlog.class.php @@ -349,8 +349,11 @@ class BlockedLog } // Add user info - $this->fk_user = $user->id; - $this->user_fullname = $user->getFullName($langs); + if (! empty($user)) + { + $this->fk_user = $user->id; + $this->user_fullname = $user->getFullName($langs); + } // Field specific to object diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index f164a1249a5..13225c2c5d3 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -384,29 +384,29 @@ if ($resql) $arrayofselected=is_array($toselect)?$toselect:array(); $param=''; - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - if ($sall) $param.='&sall='.$sall; - if ($socid > 0) $param.='&socid='.$socid; - if ($viewstatut != '') $param.='&viewstatut='.$viewstatut; - if ($search_orderday) $param.='&search_orderday='.$search_orderday; - if ($search_ordermonth) $param.='&search_ordermonth='.$search_ordermonth; - if ($search_orderyear) $param.='&search_orderyear='.$search_orderyear; - if ($search_deliveryday) $param.='&search_deliveryday='.$search_deliveryday; - if ($search_deliverymonth) $param.='&search_deliverymonth='.$search_deliverymonth; - if ($search_deliveryyear) $param.='&search_deliveryyear='.$search_deliveryyear; - if ($search_ref) $param.='&search_ref='.$search_ref; - if ($search_company) $param.='&search_company='.$search_company; - if ($search_ref_customer) $param.='&search_ref_customer='.$search_ref_customer; - if ($search_user > 0) $param.='&search_user='.$search_user; - if ($search_sale > 0) $param.='&search_sale='.$search_sale; - if ($search_total_ht != '') $param.='&search_total_ht='.$search_total_ht; - if ($search_total_vat != '') $param.='&search_total_vat='.$search_total_vat; - if ($search_total_ttc != '') $param.='&search_total_ttc='.$search_total_ttc; - if ($search_project_ref >= 0) $param.="&search_project_ref=".$search_project_ref; - if ($show_files) $param.='&show_files=' .$show_files; - if ($optioncss != '') $param.='&optioncss='.$optioncss; - if ($billed != '') $param.='&billed='.$billed; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + if ($sall) $param.='&sall='.urlencode($sall); + if ($socid > 0) $param.='&socid='.urlencode($socid); + if ($viewstatut != '') $param.='&viewstatut='.urlencode($viewstatut); + if ($search_orderday) $param.='&search_orderday='.urlencode($search_orderday); + if ($search_ordermonth) $param.='&search_ordermonth='.urlencode($search_ordermonth); + if ($search_orderyear) $param.='&search_orderyear='.urlencode($search_orderyear); + if ($search_deliveryday) $param.='&search_deliveryday='.urlencode($search_deliveryday); + if ($search_deliverymonth) $param.='&search_deliverymonth='.urlencode($search_deliverymonth); + if ($search_deliveryyear) $param.='&search_deliveryyear='.urlencode($search_deliveryyear); + if ($search_ref) $param.='&search_ref='.urlencode($search_ref); + if ($search_company) $param.='&search_company='.urlencode($search_company); + if ($search_ref_customer) $param.='&search_ref_customer='.urlencode($search_ref_customer); + if ($search_user > 0) $param.='&search_user='.urlencode($search_user); + if ($search_sale > 0) $param.='&search_sale='.urlencode($search_sale); + if ($search_total_ht != '') $param.='&search_total_ht='.urlencode($search_total_ht); + if ($search_total_vat != '') $param.='&search_total_vat='.urlencode($search_total_vat); + if ($search_total_ttc != '') $param.='&search_total_ttc='.urlencode($search_total_ttc); + if ($search_project_ref >= 0) $param.="&search_project_ref=".urlencode($search_project_ref); + if ($show_files) $param.='&show_files=' .urlencode($show_files); + if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); + if ($billed != '') $param.='&billed='.urlencode($billed); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 6e7c963a11c..1f307b00c69 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -177,7 +177,7 @@ class Contact extends CommonObject if (empty($this->priv)) $this->priv = 0; if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request - $entity = isset($this->entity)?$this->entity:$conf->entity; + $entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity); $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople ("; $sql.= " datec"; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 55abcee5699..d71277a77ee 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6221,7 +6221,7 @@ abstract class CommonObject if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); - if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) + if ($this->fields[$key]['notnull'] == 1 && ! isset($values[$key])) { $error++; $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); @@ -6299,23 +6299,15 @@ abstract class CommonObject $res = $this->db->query($sql); if ($res) { - if ($obj = $this->db->fetch_object($res)) + $obj = $this->db->fetch_object($res); + if ($obj) { - if ($obj) - { - $this->setVarsFromFetchObj($obj); - return $this->id; - } - else - { - return 0; - } + $this->setVarsFromFetchObj($obj); + return $this->id; } else { - $this->error = $this->db->lasterror(); - $this->errors[] = $this->error; - return -1; + return 0; } } else diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a3e1f73d74f..8230786c449 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1931,11 +1931,11 @@ class Form if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { $sql.= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; - if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level; + if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql.= " AND price_level=".$price_level; $sql.= " ORDER BY date_price"; $sql.= " DESC LIMIT 1) as price_rowid"; - $sql.= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; - if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level; + $sql.= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable + if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql.= " AND price_level=".$price_level; $sql.= " ORDER BY date_price"; $sql.= " DESC LIMIT 1) as price_by_qty"; $selectFields.= ", price_rowid, price_by_qty"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 0776a649fc8..96222974a13 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5395,7 +5395,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob $substitutionarray['__[AnyConstantKey]__']=$outputlangs->trans('ValueOfConstant'); $substitutionarray['__DOL_MAIN_URL_ROOT__']=DOL_MAIN_URL_ROOT; } - if (empty($exclude) || ! in_array('mycompany', $exclude)) + if ((empty($exclude) || ! in_array('mycompany', $exclude)) && is_object($mysoc)) { $substitutionarray=array_merge($substitutionarray, array( '__MYCOMPANY_NAME__' => $mysoc->name, diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index c437d47ce69..d14a60ab94f 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -254,7 +254,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $type = $val['type']; $type = preg_replace('/:.*$/', '', $type); // For case type = 'integer:Societe:societe/class/societe.class.php' - + if ($type == 'html') $type = 'text'; // html modulebuilder type is a text type in database $texttoinsert.= "\t".$key." ".$type; if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index a7b71157080..a61d103c16f 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -80,7 +80,8 @@ function checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmod $newdir=dol_osencode($dir); // Check if file found (do not use dol_is_file to avoid loading files.lib.php) - if (is_file($newdir.'/'.$authfile)) $fullauthfile=$newdir.'/'.$authfile; + $tmpnewauthfile = $newdir.(preg_match('/\/$/',$newdir)?'':'/').$authfile; + if (is_file($tmpnewauthfile)) $fullauthfile=$tmpnewauthfile; } $result=false; @@ -89,7 +90,7 @@ function checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmod { // Call function to check user/password $function='check_user_password_'.$mode; - $login=call_user_func($function,$usertotest,$passwordtotest,$entitytotest); + $login=call_user_func($function, $usertotest, $passwordtotest, $entitytotest); if ($login) // Login is successfull { $test=false; // To stop once at first login success diff --git a/htdocs/core/login/functions_empty.php b/htdocs/core/login/functions_empty.php index e4379ee2c3a..b2ce4a3c533 100644 --- a/htdocs/core/login/functions_empty.php +++ b/htdocs/core/login/functions_empty.php @@ -33,9 +33,12 @@ */ function check_user_password_empty($usertotest,$passwordtotest,$entitytotest) { + global $langs; + dol_syslog("functions_empty::check_user_password_empty usertotest=".$usertotest); $login=''; + $_SESSION["dol_loginmesg"]=$langs->trans("FailedToLogin"); return $login; } diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 013271336cb..49a65d01c5c 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -244,9 +244,9 @@ if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file - - -
'; print ''; print ''; @@ -402,7 +400,6 @@ if ($action == 'edit' || $action == 'updateedit') print '
'; print '