Addition in test of duplicate fiscal year
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 7 Jul 2008 23:49:31 +0000 (23:49 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 7 Jul 2008 23:49:31 +0000 (23:49 +0000)
CHANGELOG.txt
admin/fiscalyears.php

index 8c38fdd40e03feb9c30d5f3e79c0757df4ca9d40..75662a8817fe9f3a54b2e82a85b3453ebc1c8685 100644 (file)
@@ -19,6 +19,10 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+08-Jul-2008 Joe Hunt
++ Addition in test of duplicate fiscal year
+$ /admin/fiscalyears.php
+
 07-Jul-2008 Joe Hunt
 # Corrected a subbug in 00000012 (blank page in sales_types.php).
 $ /sales/manage/sales_types.php
index da533d828c4c3521ac33f3b82093afc895e65ae8..269278889bdf84cbd83a6baa3f2f0887612c8b27 100644 (file)
@@ -15,15 +15,24 @@ page(_("Fiscal Years"), false, false, "", $js);
 simple_page_mode(true);
 //---------------------------------------------------------------------------------------------
 
+function is_date_in_fiscalyears($date)
+{
+       $date = date2sql($date);
+       $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE '$date' >= begin AND '$date' <= end";
+
+       $result = db_query($sql, "could not get all fiscal years");
+       return db_fetch($result) !== false;
+}
+
 function check_data()
 {
-       if (!is_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');
                return false;
        }
-       if (!is_date($_POST['to_date']))
+       if (!is_date($_POST['to_date']) || is_date_in_fiscalyears($_POST['to_date']))
        {
                display_error( _("Invalid END date in fiscal year."));
                set_focus('to_date');
@@ -37,7 +46,6 @@ function check_data()
        }
        return true;
 }
-
 //---------------------------------------------------------------------------------------------
 
 function handle_submit()
@@ -163,10 +171,10 @@ function display_fiscalyear_edit($selected_id)
                        $_POST['to_date']  = sql2date($myrow["end"]);
                        $_POST['closed']  = $myrow["closed"];
                }
-                       hidden('from_date');
-                       hidden('to_date');
-                       label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
-                       label_row(_("Fiscal Year End:"), $_POST['to_date']);
+               hidden('from_date');
+               hidden('to_date');
+               label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
+               label_row(_("Fiscal Year End:"), $_POST['to_date']);
        }
        else
        {
@@ -186,7 +194,7 @@ function display_fiscalyear_edit($selected_id)
 
 //---------------------------------------------------------------------------------------------
 
-if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
+if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
 {
        handle_submit();
 }