X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Ffiscalyears.php;h=d6d05c5a14153a643c25e7fc4c924adcd66c32cc;hb=7e6e0807990447d2977b970c3a0fd28dc9250194;hp=e5e9c2f7f209be6fad1c8790a9c7abbc8e333be6;hpb=ac67fd3d7312c358ddec72393538cf4590c66f49;p=fa-stable.git diff --git a/admin/fiscalyears.php b/admin/fiscalyears.php index e5e9c2f7..d6d05c5a 100644 --- a/admin/fiscalyears.php +++ b/admin/fiscalyears.php @@ -9,30 +9,24 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -$page_security = 9; -$path_to_root=".."; +$page_security = 'SA_FISCALYEARS'; +$path_to_root = ".."; include_once($path_to_root . "/includes/session.inc"); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/admin/db/company_db.inc"); +include_once($path_to_root . "/admin/db/fiscalyears_db.inc"); 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(_("Fiscal Years"), false, false, "", $js); +page(_($help_context = "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']) || is_date_in_fiscalyears($_POST['from_date'])) @@ -47,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.")); @@ -55,48 +55,31 @@ function check_data() } return true; } -//--------------------------------------------------------------------------------------------- -function close_year($year) -{ - $myrow = get_fiscalyear($year); - $to = $myrow['end']; - // retrieve total balances from balance sheet accounts - $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans INNER JOIN ".TB_PREF."chart_master ON account=account_code - INNER JOIN ".TB_PREF."chart_types ON account_type=id INNER JOIN ".TB_PREF."chart_class ON class_id=cid - WHERE balance_sheet=1 AND tran_date <= '$to'"; - $result = db_query($sql, "The total balance could not be calculated"); - - $row = db_fetch_row($result); - $balance = round2($row[0], user_price_dec()); - if ($balance != 0.0) - { - $co = get_company_prefs(); - $to = sql2date($to); - - begin_transaction(); - - $trans_type = systypes::journal_entry(); - $trans_id = get_next_trans_no($trans_type); - - add_gl_trans($trans_type, $trans_id, $to, $co['retained_earnings_act'], - 0, 0, _("Closing Year"), -$balance); - add_gl_trans($trans_type, $trans_id, $to, $co['profit_loss_year_act'], - 0, 0, _("Closing Year"), $balance); - commit_transaction(); - } -} - function handle_submit() { global $selected_id, $Mode; + $ok = true; if ($selected_id != -1) { if ($_POST['closed'] == 1) - close_year($selected_id); - update_fiscalyear($selected_id, $_POST['closed']); - display_notification(_('Selected fiscal year has been updated')); + { + if (check_years_before($_POST['from_date'], false)) + { + display_error( _("Cannot CLOSE this year because there are open fiscal years before")); + set_focus('closed'); + return false; + } + $ok = close_year($selected_id); + } + else + open_year($selected_id); + if ($ok) + { + update_fiscalyear($selected_id, $_POST['closed']); + display_notification(_('Selected fiscal year has been updated')); + } } else { @@ -114,29 +97,26 @@ function check_can_delete($selected_id) { $myrow = get_fiscalyear($selected_id); // PREVENT DELETES IF DEPENDENT RECORDS IN gl_trans - $from = $myrow['begin']; - $to = $myrow['end']; - $sql= "SELECT COUNT(*) FROM ".TB_PREF."gl_trans WHERE tran_date >= '$from' AND tran_date <= '$to'"; - $result = db_query($sql, "could not query gl_trans master"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (check_years_before(sql2date($myrow['begin']), true)) { - display_error(_("Cannot delete this fiscal year because items have been created referring to it.")); + display_error(_("Cannot delete this fiscal year because there are fiscal years before.")); + return false; + } + if ($myrow['closed'] == 0) + { + display_error(_("Cannot delete this fiscal year because the fiscal year is not closed.")); return false; } - return true; } -//--------------------------------------------------------------------------------------------- - function handle_delete() { global $selected_id, $Mode; if (check_can_delete($selected_id)) { //only delete if used in neither customer or supplier, comp prefs, bank trans accounts - delete_fiscalyear($selected_id); + delete_this_fiscalyear($selected_id); display_notification(_('Selected fiscal year has been deleted')); } $Mode = 'RESET'; @@ -146,13 +126,14 @@ function handle_delete() function display_fiscalyears() { - global $table_style; - $company_year = get_company_pref('f_year'); $result = get_all_fiscalyears(); start_form(); - start_table($table_style); + display_note(_("Warning: Deleting a fiscal year all transactions + are removed and converted into relevant balances. This process is irreversible!"), + 0, 1, "class='currentfg'"); + start_table(TABLESTYLE); $th = array(_("Fiscal Year Begin"), _("Fiscal Year End"), _("Closed"), "", ""); table_header($th); @@ -181,9 +162,11 @@ function display_fiscalyears() label_cell($to); label_cell($closed_text); edit_button_cell("Edit".$myrow['id'], _("Edit")); - if ($myrow["id"] != $company_year) + if ($myrow["id"] != $company_year) { delete_button_cell("Delete".$myrow['id'], _("Delete")); - else + submit_js_confirm("Delete".$myrow['id'], + 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(); } @@ -197,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) { @@ -219,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); } @@ -264,4 +253,3 @@ display_fiscalyear_edit($selected_id); end_page(); -?>