X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Ffiscalyears.php;h=e5cc244b56f227c1ff21a16183f9e2294608c2c3;hb=30c04f9f87e74bd4201f56ce25f02d4c5d01f99b;hp=8aa558b0d908b8ef92c31d029d2218fb0977da2c;hpb=b17df731b4bb055c2fdd568bc4be9e5caa0ee07b;p=fa-stable.git diff --git a/admin/fiscalyears.php b/admin/fiscalyears.php index 8aa558b0..e5cc244b 100644 --- a/admin/fiscalyears.php +++ b/admin/fiscalyears.php @@ -1,13 +1,13 @@ . + See the License here . ***********************************************************************/ $page_security = 9; $path_to_root=".."; @@ -56,6 +56,48 @@ 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()); + + begin_transaction(); + $to = sql2date($to); + + if ($balance != 0.0) + { + $co = get_company_prefs(); + + $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); + + } + close_transactions($to); + commit_transaction(); +} + +function open_year($year) +{ + $myrow = get_fiscalyear($year); + $from = sql2date($myrow['begin']); + + begin_transaction(); + open_transactions($from); + commit_transaction(); +} function handle_submit() { @@ -63,6 +105,10 @@ function handle_submit() if ($selected_id != -1) { + if ($_POST['closed'] == 1) + close_year($selected_id); + else + open_year($selected_id); update_fiscalyear($selected_id, $_POST['closed']); display_notification(_('Selected fiscal year has been updated')); } @@ -196,7 +242,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(); }