[0004216] Print Work Orders: database error fixed when voided WO is in selected range.
[fa-stable.git] / admin / fiscalyears.php
index 1c674ff4ee7f57a9386d66b9400956c03ac1ea68..d6d05c5a14153a643c25e7fc4c924adcd66c32cc 100644 (file)
@@ -20,7 +20,7 @@ include_once($path_to_root . "/includes/ui.inc");
 include_once($path_to_root . "/sales/includes/db/cust_trans_db.inc");
 include_once($path_to_root . "/admin/db/maintenance_db.inc");
 $js = "";
-if ($use_date_picker)
+if (user_use_date_picker())
        $js .= get_js_date_picker();
 page(_($help_context = "Fiscal Years"), false, false, "", $js);
 
@@ -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']))
        {
                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."));
@@ -93,7 +99,7 @@ function check_can_delete($selected_id)
        // PREVENT DELETES IF DEPENDENT RECORDS IN gl_trans
        if (check_years_before(sql2date($myrow['begin']), true))
        {
-               display_error(_("Cannot delete this fiscal year because thera are fiscal years before."));
+               display_error(_("Cannot delete this fiscal year because there are fiscal years before."));
                return false;
        }
        if ($myrow['closed'] == 0)
@@ -120,16 +126,14 @@ function handle_delete()
 
 function display_fiscalyears()
 {
-       global $table_style;
-
        $company_year = get_company_pref('f_year');
 
        $result = get_all_fiscalyears();
        start_form();
-       display_note(_("Warning: During fiscal year removal all transactions 
+       display_note(_("Warning: Deleting a fiscal year all transactions 
                are removed and converted into relevant balances. This process is irreversible!"), 
-               0, 0, "class='currentfg'");
-       start_table($table_style);
+               0, 1, "class='currentfg'");
+       start_table(TABLESTYLE);
 
        $th = array(_("Fiscal Year Begin"), _("Fiscal Year End"), _("Closed"), "", "");
        table_header($th);
@@ -161,7 +165,7 @@ function display_fiscalyears()
                if ($myrow["id"] != $company_year) {
                        delete_button_cell("Delete".$myrow['id'], _("Delete"));
                        submit_js_confirm("Delete".$myrow['id'],
-                               sprintf(_("Are you sure you want to remove fiscal year %s - %s? All transactions are removed and converted into relevant balances. Do you want to continue ?"), $from, $to));
+                               sprintf(_("Are you sure you want to delete fiscal year %s - %s? All transactions are deleted and converted into relevant balances. Do you want to continue ?"), $from, $to));
                } else
                        label_cell('');
                end_row();
@@ -176,10 +180,10 @@ function display_fiscalyears()
 
 function display_fiscalyear_edit($selected_id)
 {
-       global $table_style2, $Mode;
+       global $Mode;
 
        start_form();
-       start_table($table_style2);
+       start_table(TABLESTYLE2);
 
        if ($selected_id != -1)
        {
@@ -198,6 +202,12 @@ function display_fiscalyear_edit($selected_id)
        }
        else
        {
+               $begin = next_begin_date();
+               if ($begin && $Mode != 'ADD_ITEM')
+               {
+                       $_POST['from_date'] = $begin;
+                       $_POST['to_date'] = end_month(add_months($begin, 11));
+               }
                date_row(_("Fiscal Year Begin:"), 'from_date', '', null, 0, 0, 1001);
                date_row(_("Fiscal Year End:"), 'to_date', '', null, 0, 0, 1001);
        }
@@ -243,4 +253,3 @@ display_fiscalyear_edit($selected_id);
 
 end_page();
 
-?>