diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index cf2fea62567..3d8d469b63f 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -60,8 +60,8 @@ if ($type == 'sub') { $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : $context_default; $show_subgroup = GETPOST('show_subgroup', 'alpha'); -$search_date_start = GETPOSTDATE('date_start', 'getpost'); -$search_date_end = GETPOSTDATE('date_end', 'getpostend'); +$search_date_start = GETPOSTDATE('date_start', 'getpost', 'auto', 'search_date_start_accountancy'); +$search_date_end = GETPOSTDATE('date_end', 'getpostend', 'auto', 'search_date_end_accountancy'); $search_ledger_code = GETPOST('search_ledger_code', 'array'); $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 6045a4bcb32..7dff65c8697 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -68,8 +68,8 @@ $search_doc_ref = GETPOST("search_doc_ref", 'alpha'); $search_doc_date = GETPOSTDATE('doc_date', 'getpost'); // deprecated. Can use 'search_date_start/end' -$search_date_start = GETPOSTDATE('search_date_start', 'getpost'); -$search_date_end = GETPOSTDATE('search_date_end', 'getpostend'); +$search_date_start = GETPOSTDATE('search_date_start', 'getpost', 'auto', 'search_date_start_accountancy'); +$search_date_end = GETPOSTDATE('search_date_end', 'getpostend', 'auto', 'search_date_end_accountancy'); $search_date_creation_start = GETPOSTDATE('search_date_creation_start', 'getpost'); $search_date_creation_end = GETPOSTDATE('search_date_creation_end', 'getpostend'); diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index d99973f7a69..5abd6f84719 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -69,12 +69,12 @@ $search_doc_date = GETPOSTDATE('doc_date', 'getpost'); // deprecated. Can use 's $search_date_startyear = GETPOSTINT('search_date_startyear'); $search_date_startmonth = GETPOSTINT('search_date_startmonth'); $search_date_startday = GETPOSTINT('search_date_startday'); -$search_date_start = GETPOSTDATE('search_date_start', 'getpost'); +$search_date_start = GETPOSTDATE('search_date_start', 'getpost', 'auto', 'search_date_start_accountancy'); $search_date_endyear = GETPOSTINT('search_date_endyear'); $search_date_endmonth = GETPOSTINT('search_date_endmonth'); $search_date_endday = GETPOSTINT('search_date_endday'); -$search_date_end = GETPOSTDATE('search_date_end', 'getpostend'); +$search_date_end = GETPOSTDATE('search_date_end', 'getpostend', 'auto', 'search_date_end_accountancy'); $search_date_export_startyear = GETPOSTINT('search_date_export_startyear'); $search_date_export_startmonth = GETPOSTINT('search_date_export_startmonth'); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4da74eb109c..60715181d98 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1157,17 +1157,18 @@ function GETPOSTFLOAT($paramname, $rounding = '') * Helper function that combines values of a dolibarr DatePicker (such as Form::selectDate) for year, month, day (and * optionally hour, minute, second) fields to return a timestamp. * - * @param string $prefix Prefix used to build the date selector (for instance using Form::selectDate). Example: 'select_datec' - * @param string $hourTime 'getpost' or 'getpostend' to include hour, minute, second values from the HTTP request, - * or 'XX:YY:ZZ' to set hour, minute, second respectively, for example '23:59:59' - * or 'end' means '23:59:59' - * or '' means '00:00:00' (default) - * @param int|string $gm Passed to dol_mktime. If most cases, when used with 'getpost' or 'getpostend', it should be 'tzuserrel'. - * @return int|string Date as a timestamp, '' or false if error + * @param string $prefix Prefix used to build the date selector (for instance using Form::selectDate). Example: 'select_datec' + * @param string $hourTime 'getpost' or 'getpostend' to include hour, minute, second values from the HTTP request, + * or 'XX:YY:ZZ' to set hour, minute, second respectively, for example '23:59:59' + * or 'end' means '23:59:59' + * or '' means '00:00:00' (default) + * @param int|string $gm Passed to dol_mktime. In most cases, when used with 'getpost' or 'getpostend', it should be 'tzuserrel'. Use 'auto' if you need dates related to 'tzserver' (like in accountancy). + * @param string $saverestore Use a string context to save retrieved date so it will be used on next retrieve using same context if not defined. + * @return int|string Date as a timestamp, '' or false if error * * @see dol_mktime() */ -function GETPOSTDATE($prefix, $hourTime = '', $gm = 'auto') +function GETPOSTDATE($prefix, $hourTime = '', $gm = 'auto', $saverestore = '') { $m = array(); if ($hourTime === 'getpost' || $hourTime === 'getpostend') { @@ -1183,13 +1184,30 @@ function GETPOSTDATE($prefix, $hourTime = '', $gm = 'auto') } else { $hour = $minute = $second = 0; } + + if ($saverestore && !GETPOSTISSET($prefix.'day') && !GETPOSTISSET($prefix.'month') && !GETPOSTISSET($prefix.'year')) { + $day = $_SESSION['DOLDATE_'.$saverestore.'_day']; + $month = $_SESSION['DOLDATE_'.$saverestore.'_month']; + $year = $_SESSION['DOLDATE_'.$saverestore.'_year']; + } else { + $month = GETPOSTINT($prefix . 'month'); + $day = GETPOSTINT($prefix . 'day'); + $year = GETPOSTINT($prefix . 'year'); + } + // normalize out of range values $hour = (int) min($hour, 23); $minute = (int) min($minute, 59); $second = (int) min($second, 59); - //print "$hour, $minute, $second, GETPOSTINT($prefix . 'month'), GETPOSTINT($prefix . 'day'), GETPOSTINT($prefix . 'year'), $gm
"; - return dol_mktime($hour, $minute, $second, GETPOSTINT($prefix . 'month'), GETPOSTINT($prefix . 'day'), GETPOSTINT($prefix . 'year'), $gm); + if ($saverestore) { + $_SESSION['DOLDATE_'.$saverestore.'_day'] = $day; + $_SESSION['DOLDATE_'.$saverestore.'_month'] = $month; + $_SESSION['DOLDATE_'.$saverestore.'_year'] = $year; + } + + //print "$hour, $minute, $second, $month, $day, $year, $gm
"; + return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm); }