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;
\r
28 $cls_pdeb = $cls_pcre = $cls_cdeb = $cls_ccre = $cls_tdeb = $cls_tcre = $cls_pbal = $cls_cbal = $cls_tbal = 0;
\r
29 $grp_pdeb = $grp_pcre = $grp_cdeb = $grp_ccre = $grp_tdeb = $grp_tcre = $grp_pbal = $grp_cbal = $grp_tbal = 0;
\r
31 //----------------------------------------------------------------------------------------------------
\r
33 function display_type ($type, $typename, &$dec, &$rep, $from, $to, $zero, $balances, $dimension, $dimension2)
\r
35 global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
\r
37 $printtitle = 0; //Flag for printing type name
\r
39 //Get Accounts directly under this group/type
\r
40 $accounts = get_gl_accounts(null, null, $type);
\r
42 $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
\r
44 $begin = begin_fiscalyear();
\r
45 if (date1_greater_date2($begin, $from))
\r
47 $begin = add_days($begin, -1);
\r
48 while ($account=db_fetch($accounts))
\r
50 //Print Type Title if it has atleast one non-zero account
\r
54 $rep->TextCol(0, 8, _("Group")." - ".$type ." - ".$typename);
\r
57 $rep->Line($rep->row);
\r
61 $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
\r
62 $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
\r
63 $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
\r
65 if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
\r
67 $rep->TextCol(0, 1, $account['account_code']);
\r
68 $rep->TextCol(1, 2, $account['account_name']);
\r
71 if ($prev['balance'] >= 0.0)
\r
72 $rep->AmountCol(2, 3, $prev['balance'], $dec);
\r
74 $rep->AmountCol(3, 4, abs($prev['balance']), $dec);
\r
75 if ($curr['balance'] >= 0.0)
\r
76 $rep->AmountCol(4, 5, $curr['balance'], $dec);
\r
78 $rep->AmountCol(5, 6, abs($curr['balance']), $dec);
\r
79 if ($tot['balance'] >= 0.0)
\r
80 $rep->AmountCol(6, 7, $tot['balance'], $dec);
\r
82 $rep->AmountCol(7, 8, abs($tot['balance']), $dec);
\r
86 $rep->AmountCol(2, 3, $prev['debit'], $dec);
\r
87 $rep->AmountCol(3, 4, $prev['credit'], $dec);
\r
88 $rep->AmountCol(4, 5, $curr['debit'], $dec);
\r
89 $rep->AmountCol(5, 6, $curr['credit'], $dec);
\r
90 $rep->AmountCol(6, 7, $tot['debit'], $dec);
\r
91 $rep->AmountCol(7, 8, $tot['credit'], $dec);
\r
92 $pdeb += $prev['debit'];
\r
93 $pcre += $prev['credit'];
\r
94 $cdeb += $curr['debit'];
\r
95 $ccre += $curr['credit'];
\r
96 $tdeb += $tot['debit'];
\r
97 $tcre += $tot['credit'];
\r
99 $pbal += $prev['balance'];
\r
100 $cbal += $curr['balance'];
\r
101 $tbal += $tot['balance'];
\r
104 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
\r
106 $rep->Line($rep->row - 2);
\r
111 //Get Account groups/types under this group/type
\r
112 $result = get_account_types(false, false, $type);
\r
113 while ($accounttype=db_fetch($result))
\r
115 //Print Type Title if has sub types and not previously printed
\r
119 $rep->TextCol(0, 8, _("Group")." - ".$type ." - ".$typename);
\r
122 $rep->Line($rep->row);
\r
125 display_type($accounttype["id"], $accounttype["name"].' ('.$typename.')', $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2);
\r
129 //----------------------------------------------------------------------------------------------------
131 print_trial_balance();
133 //----------------------------------------------------------------------------------------------------
135 function print_trial_balance()
137 global $path_to_root;
138 global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
\r
140 $dim = get_company_pref('use_dimension');
141 $dimension = $dimension2 = 0;
143 $from = $_POST['PARAM_0'];
144 $to = $_POST['PARAM_1'];
145 $zero = $_POST['PARAM_2'];
146 $balances = $_POST['PARAM_3'];
149 $dimension = $_POST['PARAM_4'];
150 $dimension2 = $_POST['PARAM_5'];
151 $comments = $_POST['PARAM_6'];
152 $destination = $_POST['PARAM_7'];
156 $dimension = $_POST['PARAM_4'];
157 $comments = $_POST['PARAM_5'];
158 $destination = $_POST['PARAM_6'];
162 $comments = $_POST['PARAM_4'];
163 $destination = $_POST['PARAM_5'];
166 include_once($path_to_root . "/reporting/includes/excel_report.inc");
168 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
169 $dec = user_price_dec();
171 //$cols2 = array(0, 50, 230, 330, 430, 530);
172 $cols2 = array(0, 50, 190, 310, 430, 530);
173 //-------------0--1---2----3----4----5--
175 $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
177 $aligns2 = array('left', 'left', 'left', 'left', 'left');
179 //$cols = array(0, 50, 200, 250, 300, 350, 400, 450, 500, 550);
180 $cols = array(0, 50, 150, 210, 270, 330, 390, 450, 510, 570);
\r
181 //$cols = array(0, 50, 190, 250, 310, 370, 430, 490, 550);
\r
182 //------------0--1---2----3----4----5----6----7----8--
\r
184 $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
185 _('Credit'), _('Debit'), _('Credit'));
187 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right');
191 $params = array( 0 => $comments,
192 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
193 2 => array('text' => _('Dimension')." 1",
194 'from' => get_dimension_string($dimension), 'to' => ''),
195 3 => array('text' => _('Dimension')." 2",
196 'from' => get_dimension_string($dimension2), 'to' => ''));
200 $params = array( 0 => $comments,
201 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
202 2 => array('text' => _('Dimension'),
203 'from' => get_dimension_string($dimension), 'to' => ''));
207 $params = array( 0 => $comments,
208 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
211 $rep = new FrontReport(_('Trial Balance'), "TrialBalance", user_pagesize());
214 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
217 $classresult = get_account_classes(false);
\r
218 while ($class = db_fetch($classresult))
\r
220 $rep->Font('bold');
\r
221 $rep->TextCol(0, 1, $class['cid']);
\r
222 $rep->TextCol(1, 4, $class['class_name']);
\r
226 //Get Account groups/types under this group/type with no parents
\r
227 $typeresult = get_account_types(false, $class['cid'], -1);
\r
228 while ($accounttype=db_fetch($typeresult))
\r
230 display_type($accounttype["id"], $accounttype["name"], $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2);
\r
234 $rep->Line($rep->row);
238 //$prev = get_balance(null, $dimension, $dimension2, $begin, $from, false, false);
239 //$curr = get_balance(null, $dimension, $dimension2, $from, $to, true, true);
240 //$tot = get_balance(null, $dimension, $dimension2, $begin, $to, false, true);
244 $rep->TextCol(0, 2, _("Total"));
245 $rep->AmountCol(2, 3, $pdeb, $dec);
246 $rep->AmountCol(3, 4, $pcre, $dec);
247 $rep->AmountCol(4, 5, $cdeb, $dec);
248 $rep->AmountCol(5, 6, $ccre, $dec);
249 $rep->AmountCol(6, 7, $tdeb, $dec);
250 $rep->AmountCol(7, 8, $tcre, $dec);
253 $rep->TextCol(0, 2, _("Ending Balance"));
256 $rep->AmountCol(2, 3, $pbal, $dec);
258 $rep->AmountCol(3, 4, abs($pbal), $dec);
260 $rep->AmountCol(4, 5, $cbal, $dec);
262 $rep->AmountCol(5, 6, abs($cbal), $dec);
264 $rep->AmountCol(6, 7, $tbal, $dec);
266 $rep->AmountCol(7, 8, abs($tbal), $dec);
269 $rep->Line($rep->row + 10);
270 if (($pbal = round2($pbal, $dec)) != 0.0)
274 $rep->TextCol(0, 8, _("The Opening Balance is not in balance, probably due to a non closed Previous Fiscalyear."));