X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=gl%2Finquiry%2Fgl_trial_balance.php;h=27fc37df0e70b185ccf17a2f85d094e64c31fa70;hb=b814319d8fa32f95ee65de79df28083d9d38f68e;hp=d6587c3143365be774e3575a0f921f6a5e54dfcc;hpb=431531eebf3ba494002cfbf7ea36f9e82d4975c0;p=fa-stable.git diff --git a/gl/inquiry/gl_trial_balance.php b/gl/inquiry/gl_trial_balance.php index d6587c31..27fc37df 100644 --- a/gl/inquiry/gl_trial_balance.php +++ b/gl/inquiry/gl_trial_balance.php @@ -1,5 +1,14 @@ . +***********************************************************************/ $page_security = 8; $path_to_root="../.."; @@ -18,6 +27,12 @@ if ($use_date_picker) page(_("Trial Balance"), false, false, "", $js); //---------------------------------------------------------------------------------------------------- +// Ajax updates +// +if (get_post('Show')) +{ + $Ajax->activate('balance_tbl'); +} function gl_inquiry_controls() @@ -26,44 +41,41 @@ function gl_inquiry_controls() start_table("class='tablestyle_noborder'"); - date_cells(_("From:"), 'TransFromDate', null, -30); + date_cells(_("From:"), 'TransFromDate', '', null, -30); date_cells(_("To:"), 'TransToDate'); check_cells(_("No zero values"), 'NoZero', null); + check_cells(_("Only balances"), 'Balance', null); - submit_cells('Show',_("Show")); + submit_cells('Show',_("Show"),'','', true); end_table(); end_form(); } //---------------------------------------------------------------------------------------------------- -function get_balance($account, $from, $to, $from_incl=true, $to_incl=true) { - - $sql = "SELECT SUM(amount) As TransactionSum FROM ".TB_PREF."gl_trans - WHERE account=$account"; - - if ($from) - { - $from_date = date2sql($from); - if ($from_incl) - $sql .= " AND tran_date >= '$from_date'"; - else - $sql .= " AND tran_date > '$from_date'"; - } - - if ($to) - { - $to_date = date2sql($to); - if ($to_incl) - $sql .= " AND tran_date <= '$to_date' "; - else - $sql .= " AND tran_date < '$to_date' "; - } +function get_balance($account, $from, $to, $from_incl=true, $to_incl=true) +{ + $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) AS debit, SUM(IF(amount < 0, -amount, 0)) AS credit, SUM(amount) AS balance + FROM ".TB_PREF."gl_trans,".TB_PREF."chart_master,".TB_PREF."chart_types, ".TB_PREF."chart_class + WHERE ".TB_PREF."gl_trans.account=".TB_PREF."chart_master.account_code AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id + AND ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid AND"; + + if ($account != null) + $sql .= " account='$account' AND"; + $from_date = date2sql($from); + if ($from_incl) + $sql .= " tran_date >= '$from_date' AND"; + else + $sql .= " tran_date > IF(".TB_PREF."chart_class.balance_sheet=1, '0000-00-00', '$from_date') AND"; + $to_date = date2sql($to); + if ($to_incl) + $sql .= " tran_date <= '$to_date' "; + else + $sql .= " tran_date < '$to_date' "; $result = db_query($sql,"No general ledger accounts were returned"); - $row = db_fetch_row($result); - return $row[0]; + return db_fetch($result); } //---------------------------------------------------------------------------------------------------- @@ -72,6 +84,7 @@ function display_trial_balance() { global $table_style, $path_to_root; + div_start('balance_tbl'); start_table($table_style); $tableheader = "