4 // ----------------------------------------------------------------
8 // Title: Trial Balance
9 // ----------------------------------------------------------------
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "gl/includes/gl_db.inc");
17 //----------------------------------------------------------------------------------------------------
19 // trial_inquiry_controls();
20 print_trial_balance();
22 //----------------------------------------------------------------------------------------------------
24 function print_trial_balance()
28 include_once($path_to_root . "reporting/includes/pdf_report.inc");
29 $dim = get_company_pref('use_dimension');
30 $dimension = $dimension2 = 0;
32 $from = $_POST['PARAM_0'];
33 $to = $_POST['PARAM_1'];
34 $zero = $_POST['PARAM_2'];
37 $dimension = $_POST['PARAM_3'];
38 $dimension2 = $_POST['PARAM_4'];
39 $comments = $_POST['PARAM_5'];
43 $dimension = $_POST['PARAM_3'];
44 $comments = $_POST['PARAM_4'];
48 $comments = $_POST['PARAM_3'];
50 $dec = user_price_dec();
52 $cols2 = array(0, 50, 230, 330, 430, 530);
53 //-------------0--1---2----3----4----5--
55 $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
57 $aligns2 = array('left', 'left', 'left', 'left', 'left');
59 $cols = array(0, 50, 200, 250, 300, 350, 400, 450, 500, 550);
60 //------------0--1---2----3----4----5----6----7----8----9--
62 $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
63 _('Credit'), _('Debit'), _('Credit'));
65 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right');
69 $params = array( 0 => $comments,
70 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
71 2 => array('text' => _('Dimension')." 1",
72 'from' => get_dimension_string($dimension), 'to' => ''),
73 3 => array('text' => _('Dimension')." 2",
74 'from' => get_dimension_string($dimension2), 'to' => ''));
78 $params = array( 0 => $comments,
79 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
80 2 => array('text' => _('Dimension'),
81 'from' => get_dimension_string($dimension), 'to' => ''));
85 $params = array( 0 => $comments,
86 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
89 $rep = new FrontReport(_('Trial Balance'), "TrialBalance.pdf", user_pagesize());
92 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
94 $totprev = $totcurr = 0.0;
96 $accounts = get_gl_accounts();
98 while ($account=db_fetch($accounts))
101 if (is_account_balancesheet($account["account_code"]))
105 $begin = begin_fiscalyear();
106 if (date1_greater_date2($begin, $from))
108 $begin = add_days($begin, -1);
111 $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
113 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
115 if ($zero == 0 && !$prev_balance && !$curr_balance)
117 $totprev += $prev_balance;
118 $totcurr += $curr_balance;
119 $rep->TextCol(0, 1, $account['account_code']);
120 $rep->TextCol(1, 2, $account['account_name']);
122 if ($prev_balance >= 0.0)
123 $rep->TextCol(2, 3, number_format2(abs($prev_balance), $dec));
125 $rep->TextCol(3, 4, number_format2(abs($prev_balance), $dec));
126 if ($curr_balance >= 0.0)
127 $rep->TextCol(4, 5, number_format2(abs($curr_balance), $dec));
129 $rep->TextCol(5, 6, number_format2(abs($curr_balance), $dec));
130 if ($curr_balance + $prev_balance >= 0.0)
131 $rep->TextCol(6, 7, number_format2(abs($curr_balance + $prev_balance), $dec));
133 $rep->TextCol(7, 8, number_format2(abs($curr_balance + $prev_balance), $dec));
137 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
139 $rep->Line($rep->row - 2);
143 $rep->Line($rep->row);
147 $rep->TextCol(0, 2, _("Ending Balance"));
150 $rep->TextCol(2, 3, number_format2(abs($totprev), $dec));
152 $rep->TextCol(3, 4, number_format2(abs($totprev), $dec));
154 $rep->TextCol(4, 5, number_format2(abs($totcurr), $dec));
156 $rep->TextCol(5, 6, number_format2(abs($totcurr), $dec));
157 if ($totcurr + $totprev >= 0.0)
158 $rep->TextCol(6, 7, number_format2(abs($totcurr + $totprev), $dec));
160 $rep->TextCol(7, 8, number_format2(abs($totcurr + $totprev), $dec));
162 $rep->Line($rep->row - 6);