2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_GLANALYTIC';
13 // ----------------------------------------------------------------
17 // Title: Trial Balance
18 // ----------------------------------------------------------------
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/ui.inc");
23 include_once($path_to_root . "/includes/date_functions.inc");
24 include_once($path_to_root . "/includes/data_checks.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
27 //----------------------------------------------------------------------------------------------------
29 print_trial_balance();
31 //----------------------------------------------------------------------------------------------------
33 function print_trial_balance()
37 $dim = get_company_pref('use_dimension');
38 $dimension = $dimension2 = 0;
40 $from = $_POST['PARAM_0'];
41 $to = $_POST['PARAM_1'];
42 $zero = $_POST['PARAM_2'];
43 $balances = $_POST['PARAM_3'];
46 $dimension = $_POST['PARAM_4'];
47 $dimension2 = $_POST['PARAM_5'];
48 $comments = $_POST['PARAM_6'];
49 $destination = $_POST['PARAM_7'];
53 $dimension = $_POST['PARAM_4'];
54 $comments = $_POST['PARAM_5'];
55 $destination = $_POST['PARAM_6'];
59 $comments = $_POST['PARAM_4'];
60 $destination = $_POST['PARAM_5'];
63 include_once($path_to_root . "/reporting/includes/excel_report.inc");
65 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
66 $dec = user_price_dec();
68 //$cols2 = array(0, 50, 230, 330, 430, 530);
69 $cols2 = array(0, 50, 190, 310, 430, 530);
70 //-------------0--1---2----3----4----5--
72 $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
74 $aligns2 = array('left', 'left', 'left', 'left', 'left');
76 //$cols = array(0, 50, 200, 250, 300, 350, 400, 450, 500, 550);
77 $cols = array(0, 50, 150, 210, 270, 330, 390, 450, 510, 570);
78 //------------0--1---2----3----4----5----6----7----8----9--
80 $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
81 _('Credit'), _('Debit'), _('Credit'));
83 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right');
87 $params = array( 0 => $comments,
88 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
89 2 => array('text' => _('Dimension')." 1",
90 'from' => get_dimension_string($dimension), 'to' => ''),
91 3 => array('text' => _('Dimension')." 2",
92 'from' => get_dimension_string($dimension2), 'to' => ''));
96 $params = array( 0 => $comments,
97 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
98 2 => array('text' => _('Dimension'),
99 'from' => get_dimension_string($dimension), 'to' => ''));
103 $params = array( 0 => $comments,
104 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
107 $rep = new FrontReport(_('Trial Balance'), "TrialBalance", user_pagesize());
110 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
113 $accounts = get_gl_accounts();
115 $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
116 $begin = begin_fiscalyear();
117 if (date1_greater_date2($begin, $from))
119 $begin = add_days($begin, -1);
120 while ($account=db_fetch($accounts))
122 $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
123 $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
124 $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
126 if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
128 $rep->TextCol(0, 1, $account['account_code']);
129 $rep->TextCol(1, 2, $account['account_name']);
132 if ($prev['balance'] >= 0.0)
133 $rep->AmountCol(2, 3, $prev['balance'], $dec);
135 $rep->AmountCol(3, 4, abs($prev['balance']), $dec);
136 if ($curr['balance'] >= 0.0)
137 $rep->AmountCol(4, 5, $curr['balance'], $dec);
139 $rep->AmountCol(5, 6, abs($curr['balance']), $dec);
140 if ($tot['balance'] >= 0.0)
141 $rep->AmountCol(6, 7, $tot['balance'], $dec);
143 $rep->AmountCol(7, 8, abs($tot['balance']), $dec);
147 $rep->AmountCol(2, 3, $prev['debit'], $dec);
148 $rep->AmountCol(3, 4, $prev['credit'], $dec);
149 $rep->AmountCol(4, 5, $curr['debit'], $dec);
150 $rep->AmountCol(5, 6, $curr['credit'], $dec);
151 $rep->AmountCol(6, 7, $tot['debit'], $dec);
152 $rep->AmountCol(7, 8, $tot['credit'], $dec);
153 $pdeb += $prev['debit'];
154 $pcre += $prev['credit'];
155 $cdeb += $curr['debit'];
156 $ccre += $curr['credit'];
157 $tdeb += $tot['debit'];
158 $tcre += $tot['credit'];
161 $pbal += $prev['balance'];
162 $cbal += $curr['balance'];
163 $tbal += $tot['balance'];
166 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
168 $rep->Line($rep->row - 2);
172 $rep->Line($rep->row);
176 //$prev = get_balance(null, $dimension, $dimension2, $begin, $from, false, false);
177 //$curr = get_balance(null, $dimension, $dimension2, $from, $to, true, true);
178 //$tot = get_balance(null, $dimension, $dimension2, $begin, $to, false, true);
182 $rep->TextCol(0, 2, _("Total"));
183 $rep->AmountCol(2, 3, $pdeb, $dec);
184 $rep->AmountCol(3, 4, $pcre, $dec);
185 $rep->AmountCol(4, 5, $cdeb, $dec);
186 $rep->AmountCol(5, 6, $ccre, $dec);
187 $rep->AmountCol(6, 7, $tdeb, $dec);
188 $rep->AmountCol(7, 8, $tcre, $dec);
191 $rep->TextCol(0, 2, _("Ending Balance"));
194 $rep->AmountCol(2, 3, $pbal, $dec);
196 $rep->AmountCol(3, 4, abs($pbal), $dec);
198 $rep->AmountCol(4, 5, $cbal, $dec);
200 $rep->AmountCol(5, 6, abs($cbal), $dec);
202 $rep->AmountCol(6, 7, $tbal, $dec);
204 $rep->AmountCol(7, 8, abs($tbal), $dec);
207 $rep->Line($rep->row);
208 if (($pbal = round2($pbal, $dec)) != 0.0)
212 $rep->TextCol(0, 8, _("The Opening Balance is not in balance, probably due to a non closed Previous Fiscalyear."));