From: Joe Hunt Date: Sun, 10 May 2009 22:55:34 +0000 (+0000) Subject: Changed creating of fiscal year so gap is not allowed. Cannot close year if open... X-Git-Tag: v2.4.2~19^2~1391 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=648e692322b803116b6657f9a796e11e153d43bb;p=fa-stable.git Changed creating of fiscal year so gap is not allowed. Cannot close year if open years before. --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6fb068e6..18b4ed10 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,10 @@ Legend: ! -> Note $ -> Affected files +11-May-2009 Joe Hunt +! Changed creating of fiscal year so gap is not allowed. Cannot close year if open years before. +$ /admin/fiscalyers.php + 10-May-2009 Janusz Dobrowolski ! Support for periodic journal trans closing/indexing $ /includes/db/audit_trail_db.inc diff --git a/admin/fiscalyears.php b/admin/fiscalyears.php index e5cc244b..48deeb97 100644 --- a/admin/fiscalyears.php +++ b/admin/fiscalyears.php @@ -33,9 +33,32 @@ function is_date_in_fiscalyears($date) return db_fetch($result) !== false; } +function is_bad_begin_date($date) +{ + $bdate = date2sql($date); + $sql = "SELECT MAX(end) FROM ".TB_PREF."fiscal_year 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); + return ($max !== $date); +} + +function check_open_before($date) +{ + $date = date2sql($date); + $sql = "SELECT COUNT(*) FROM ".TB_PREF."fiscal_year WHERE begin < '$date' AND closed=0"; + + $result = db_query($sql, "could not check open fiscal years"); + $row = db_fetch_row($result); + return ($row[0] > 0); +} + function check_data() { - if (!is_date($_POST['from_date']) || is_date_in_fiscalyears($_POST['from_date'])) + if (!is_date($_POST['from_date']) || is_date_in_fiscalyears($_POST['from_date']) || is_bad_begin_date($_POST['from_date'])) { display_error( _("Invalid BEGIN date in fiscal year.")); set_focus('from_date'); @@ -106,7 +129,15 @@ function handle_submit() if ($selected_id != -1) { if ($_POST['closed'] == 1) + { + if (check_open_before($_POST['from_date'])) + { + display_error( _("Cannot CLOSE this year because there are open fiscal years before")); + set_focus('closed'); + return false; + } close_year($selected_id); + } else open_year($selected_id); update_fiscalyear($selected_id, $_POST['closed']);