X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Ffiscalyears.php;h=e5e9c2f7f209be6fad1c8790a9c7abbc8e333be6;hb=34c15f2f88c2b4d8a18ca40f76df3b9748e463e1;hp=8dfe4a8f5197d6c084d6558e07f0c9ab45896337;hpb=f12dbe7523bb1abc6cd69b009ef8f0be838f5348;p=fa-stable.git diff --git a/admin/fiscalyears.php b/admin/fiscalyears.php index 8dfe4a8f..e5e9c2f7 100644 --- a/admin/fiscalyears.php +++ b/admin/fiscalyears.php @@ -1,5 +1,14 @@ . +***********************************************************************/ $page_security = 9; $path_to_root=".."; include_once($path_to_root . "/includes/session.inc"); @@ -47,13 +56,45 @@ 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; 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')); } @@ -141,7 +182,7 @@ function display_fiscalyears() label_cell($closed_text); edit_button_cell("Edit".$myrow['id'], _("Edit")); if ($myrow["id"] != $company_year) - edit_button_cell("Delete".$myrow['id'], _("Delete")); + delete_button_cell("Delete".$myrow['id'], _("Delete")); else label_cell(''); end_row(); @@ -187,7 +228,7 @@ function display_fiscalyear_edit($selected_id) end_table(1); - submit_add_or_update_center($selected_id == -1, '', true); + submit_add_or_update_center($selected_id == -1, '', 'both'); end_form(); }