From 5ee2c3abc170f8e4cf00c000b6312eb27f618713 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Thu, 18 Nov 2010 22:08:06 +0000 Subject: [PATCH] Could not enter a year before other years (removed readonly begin) and better check for first end year. --- CHANGELOG.txt | 5 +++++ admin/db/fiscalyears_db.inc | 25 ++++++++++++++----------- admin/fiscalyears.php | 17 ++++++++++------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7dc096c3..a16ba2f6 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -28,6 +28,11 @@ $ /install/isession.inc /install/lang/es_MX/LC_MESSAGES/es_MX.mo (new) 18-Nov-2010 Joe Hunt +# Could not enter a year before other years (removed readonly begin) + and better check for first end year. +$ /adminfiscalyears.php + /admin/db/fiscalyears_db.inc + ! Scrambled graphic images to avoid unwanted downloads. $ /reporting/rep102.php /reporting/rep202.php diff --git a/admin/db/fiscalyears_db.inc b/admin/db/fiscalyears_db.inc index b2f62413..669e8c3c 100644 --- a/admin/db/fiscalyears_db.inc +++ b/admin/db/fiscalyears_db.inc @@ -81,23 +81,26 @@ function is_date_in_fiscalyears($date, $closed=true) return db_fetch($result) !== false; } -function check_begin_date($date="", $check=true) +function check_begin_end_date($date1, $date2) +{ + $sql = "SELECT MAX(end), MIN(begin) FROM ".TB_PREF."fiscal_year"; + $result = db_query($sql, "could not retrieve last fiscal years"); + $row = db_fetch_row($result); + if ($row[0] === null) + return true; + $max = add_days(sql2date($row[0]), 1); + $min = add_days(sql2date($row[1]), -1); + return ($max === $date1 || $min === $date2); +} + +function next_begin_date() { $sql = "SELECT MAX(end) FROM ".TB_PREF."fiscal_year"; - if ($date !== "") - { - $bdate = date2sql($date); - $sql .= " WHERE begin < '$bdate'"; - } $result = db_query($sql, "could not retrieve last fiscal years"); $row = db_fetch_row($result); if ($row[0] === null) return false; - $max = add_days(sql2date($row[0]), 1); - if ($check) - return ($max === $date); - else - return $max; + return add_days(sql2date($row[0]), 1); } function check_years_before($date, $closed=false) diff --git a/admin/fiscalyears.php b/admin/fiscalyears.php index 1926d48e..d886608f 100644 --- a/admin/fiscalyears.php +++ b/admin/fiscalyears.php @@ -29,7 +29,7 @@ simple_page_mode(true); function check_data() { - if (!is_date($_POST['from_date']) || is_date_in_fiscalyears($_POST['from_date']) || !check_begin_date($_POST['from_date'])) + if (!is_date($_POST['from_date']) || is_date_in_fiscalyears($_POST['from_date'])) { display_error( _("Invalid BEGIN date in fiscal year.")); set_focus('from_date'); @@ -41,6 +41,12 @@ function check_data() set_focus('to_date'); return false; } + if (!check_begin_end_date($_POST['from_date'], $_POST['to_date'])) + { + display_error( _("Invalid BEGIN or END date in fiscal year.")); + set_focus('from_date'); + return false; + } if (date1_greater_date2($_POST['from_date'], $_POST['to_date'])) { display_error( _("BEGIN date bigger than END date.")); @@ -196,16 +202,13 @@ function display_fiscalyear_edit($selected_id) } else { - $begin = check_begin_date("", false); - if ($begin) + $begin = next_begin_date(); + if ($begin && $Mode != 'ADD_ITEM') { $_POST['from_date'] = $begin; - hidden('from_date', $begin); $_POST['to_date'] = end_month(add_months($begin, 11)); - label_row(_("Fiscal Year Begin:"), $_POST['from_date']); } - else - date_row(_("Fiscal Year Begin:"), 'from_date', '', null, 0, 0, 1001); + date_row(_("Fiscal Year Begin:"), 'from_date', '', null, 0, 0, 1001); date_row(_("Fiscal Year End:"), 'to_date', '', null, 0, 0, 1001); } hidden('selected_id', $selected_id); -- 2.30.2