[0000277] Changed so FA suggest the next begin day in new Fiscal Year (read only).
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 9 Nov 2010 16:47:40 +0000 (16:47 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 9 Nov 2010 16:47:40 +0000 (16:47 +0000)
But only if there are any fiscal years before. Otherwise is is normal.

CHANGELOG.txt
admin/db/fiscalyears_db.inc
admin/fiscalyears.php

index 4fe99378459d259ac350b21d682db5a323435f7a..3d89f86f819d04bd14e2fd920b6da5bebbad9e4a 100644 (file)
@@ -19,6 +19,12 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+09-Nov-2010 Joe Hunt
+! [0000277] Changed so FA suggest the next begin day in new Fiscal Year (read only).
+  But only if there are any fiscal years before. Otherwise is is normal.
+$ /admin/db/fiscalyears_db.inc
+  /admin/fiscalyears.php
+  
 09-Nov-2010 Janusz Dobrowolski
 # Session destroy added on install finish, fixed pasword/admin login update.
 $ /install/index.php
index ebf6d4773e6680f076282cd9b7e8e679848fdea7..b2f62413045d903703db9f67ecc5d7b1b0bb6a6d 100644 (file)
@@ -81,17 +81,23 @@ function is_date_in_fiscalyears($date, $closed=true)
        return db_fetch($result) !== false;
 }
 
-function is_bad_begin_date($date)
+function check_begin_date($date="", $check=true)
 {
-       $bdate = date2sql($date);
-       $sql = "SELECT MAX(end) FROM ".TB_PREF."fiscal_year WHERE begin < '$bdate'";
-
+       $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);
-       return ($max !== $date);
+       if ($check)
+               return ($max === $date);
+       else 
+               return $max;
 }
 
 function check_years_before($date, $closed=false)
index b2d2913b9102c8abf3eda152fc1c15ebba3bea3c..1926d48e1719c6c0a6bec73b5ac605f4f8f2b5e8 100644 (file)
@@ -29,7 +29,7 @@ simple_page_mode(true);
 
 function check_data()
 {
-       if (!is_date($_POST['from_date']) || is_date_in_fiscalyears($_POST['from_date']) || is_bad_begin_date($_POST['from_date']))
+       if (!is_date($_POST['from_date']) || is_date_in_fiscalyears($_POST['from_date']) || !check_begin_date($_POST['from_date']))
        {
                display_error( _("Invalid BEGIN date in fiscal year."));
                set_focus('from_date');
@@ -196,7 +196,16 @@ function display_fiscalyear_edit($selected_id)
        }
        else
        {
-               date_row(_("Fiscal Year Begin:"), 'from_date', '', null, 0, 0, 1001);
+               $begin = check_begin_date("", false);
+               if ($begin)
+               {
+                       $_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 End:"), 'to_date', '', null, 0, 0, 1001);
        }
        hidden('selected_id', $selected_id);