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 $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
29 //----------------------------------------------------------------------------------------------------
31 function display_type ($type, $typename, &$dec, &$rep, $from, $to, $zero, $balances, $dimension, $dimension2)
33 global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
35 $printtitle = 0; //Flag for printing type name
37 //Get Accounts directly under this group/type
38 $accounts = get_gl_accounts(null, null, $type);
40 $begin = begin_fiscalyear();
41 if (date1_greater_date2($begin, $from))
43 $begin = add_days($begin, -1);
44 while ($account=db_fetch($accounts))
46 //Print Type Title if it has atleast one non-zero account
50 $rep->TextCol(0, 8, _("Group")." - ".$type ." - ".$typename);
53 $rep->Line($rep->row);
57 $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
58 $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
59 $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
61 if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
63 $rep->TextCol(0, 1, $account['account_code']);
64 $rep->TextCol(1, 2, $account['account_name']);
67 if ($prev['balance'] >= 0.0)
68 $rep->AmountCol(2, 3, $prev['balance'], $dec);
70 $rep->AmountCol(3, 4, abs($prev['balance']), $dec);
71 if ($curr['balance'] >= 0.0)
72 $rep->AmountCol(4, 5, $curr['balance'], $dec);
74 $rep->AmountCol(5, 6, abs($curr['balance']), $dec);
75 if ($tot['balance'] >= 0.0)
76 $rep->AmountCol(6, 7, $tot['balance'], $dec);
78 $rep->AmountCol(7, 8, abs($tot['balance']), $dec);
82 $rep->AmountCol(2, 3, $prev['debit'], $dec);
83 $rep->AmountCol(3, 4, $prev['credit'], $dec);
84 $rep->AmountCol(4, 5, $curr['debit'], $dec);
85 $rep->AmountCol(5, 6, $curr['credit'], $dec);
86 $rep->AmountCol(6, 7, $tot['debit'], $dec);
87 $rep->AmountCol(7, 8, $tot['credit'], $dec);
88 $pdeb += $prev['debit'];
89 $pcre += $prev['credit'];
90 $cdeb += $curr['debit'];
91 $ccre += $curr['credit'];
92 $tdeb += $tot['debit'];
93 $tcre += $tot['credit'];
96 $pbal += $prev['balance'];
97 $cbal += $curr['balance'];
98 $tbal += $tot['balance'];
101 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
103 $rep->Line($rep->row - 2);
108 //Get Account groups/types under this group/type
109 $result = get_account_types(false, false, $type);
110 while ($accounttype=db_fetch($result))
112 //Print Type Title if has sub types and not previously printed
116 $rep->TextCol(0, 8, _("Group")." - ".$type ." - ".$typename);
119 $rep->Line($rep->row);
122 display_type($accounttype["id"], $accounttype["name"].' ('.$typename.')', $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2);
126 //----------------------------------------------------------------------------------------------------
128 print_trial_balance();
130 //----------------------------------------------------------------------------------------------------
132 function print_trial_balance()
134 global $path_to_root;
135 global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
137 $dim = get_company_pref('use_dimension');
138 $dimension = $dimension2 = 0;
140 $from = $_POST['PARAM_0'];
141 $to = $_POST['PARAM_1'];
142 $zero = $_POST['PARAM_2'];
143 $balances = $_POST['PARAM_3'];
146 $dimension = $_POST['PARAM_4'];
147 $dimension2 = $_POST['PARAM_5'];
148 $comments = $_POST['PARAM_6'];
149 $destination = $_POST['PARAM_7'];
153 $dimension = $_POST['PARAM_4'];
154 $comments = $_POST['PARAM_5'];
155 $destination = $_POST['PARAM_6'];
159 $comments = $_POST['PARAM_4'];
160 $destination = $_POST['PARAM_5'];
163 include_once($path_to_root . "/reporting/includes/excel_report.inc");
165 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
166 $dec = user_price_dec();
168 $cols2 = array(0, 50, 190, 310, 430, 530);
169 //-------------0--1---2----3----4----5--
171 $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
173 $aligns2 = array('left', 'left', 'left', 'left', 'left');
175 $cols = array(0, 50, 150, 210, 270, 330, 390, 450, 510, 570);
176 //------------0--1---2----3----4----5----6----7----8--
178 $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
179 _('Credit'), _('Debit'), _('Credit'));
181 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right');
185 $params = array( 0 => $comments,
186 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
187 2 => array('text' => _('Dimension')." 1",
188 'from' => get_dimension_string($dimension), 'to' => ''),
189 3 => array('text' => _('Dimension')." 2",
190 'from' => get_dimension_string($dimension2), 'to' => ''));
194 $params = array( 0 => $comments,
195 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
196 2 => array('text' => _('Dimension'),
197 'from' => get_dimension_string($dimension), 'to' => ''));
201 $params = array( 0 => $comments,
202 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
205 $rep = new FrontReport(_('Trial Balance'), "TrialBalance", user_pagesize());
208 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
211 $classresult = get_account_classes(false);
212 while ($class = db_fetch($classresult))
215 $rep->TextCol(0, 1, $class['cid']);
216 $rep->TextCol(1, 4, $class['class_name']);
220 //Get Account groups/types under this group/type with no parents
221 $typeresult = get_account_types(false, $class['cid'], -1);
222 while ($accounttype=db_fetch($typeresult))
224 display_type($accounttype["id"], $accounttype["name"], $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2);
228 $rep->Line($rep->row);
234 $rep->TextCol(0, 2, _("Total"));
235 $rep->AmountCol(2, 3, $pdeb, $dec);
236 $rep->AmountCol(3, 4, $pcre, $dec);
237 $rep->AmountCol(4, 5, $cdeb, $dec);
238 $rep->AmountCol(5, 6, $ccre, $dec);
239 $rep->AmountCol(6, 7, $tdeb, $dec);
240 $rep->AmountCol(7, 8, $tcre, $dec);
243 $rep->TextCol(0, 2, _("Ending Balance"));
246 $rep->AmountCol(2, 3, $pbal, $dec);
248 $rep->AmountCol(3, 4, abs($pbal), $dec);
250 $rep->AmountCol(4, 5, $cbal, $dec);
252 $rep->AmountCol(5, 6, abs($cbal), $dec);
254 $rep->AmountCol(6, 7, $tbal, $dec);
256 $rep->AmountCol(7, 8, abs($tbal), $dec);
259 $rep->Line($rep->row + 10);
260 if (($pbal = round2($pbal, $dec)) != 0.0 && $dimension == 0 && $dimension2 == 0)
264 $rep->TextCol(0, 8, _("The Opening Balance is not in balance, probably due to a non closed Previous Fiscalyear."));