Changed creating of fiscal year so gap is not allowed. Cannot close year if open...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 10 May 2009 22:55:34 +0000 (22:55 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 10 May 2009 22:55:34 +0000 (22:55 +0000)
CHANGELOG.txt
admin/fiscalyears.php

index 6fb068e67898e688a9170e3eb354a9659102149a..18b4ed10864329409ce165d46ba00676d8517dc0 100644 (file)
@@ -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
index e5cc244b56f227c1ff21a16183f9e2294608c2c3..48deeb972da8b019164266b2422b52b7161280ed 100644 (file)
@@ -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']);