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 ***********************************************************************/
13 // ----------------------------------------------------------------
17 // Title: Trial Balance
18 // ----------------------------------------------------------------
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 //----------------------------------------------------------------------------------------------------
28 print_trial_balance();
30 //----------------------------------------------------------------------------------------------------
32 function print_trial_balance()
36 $dim = get_company_pref('use_dimension');
37 $dimension = $dimension2 = 0;
39 $from = $_POST['PARAM_0'];
40 $to = $_POST['PARAM_1'];
41 $zero = $_POST['PARAM_2'];
42 $balances = $_POST['PARAM_3'];
45 $dimension = $_POST['PARAM_4'];
46 $dimension2 = $_POST['PARAM_5'];
47 $comments = $_POST['PARAM_6'];
48 $destination = $_POST['PARAM_7'];
52 $dimension = $_POST['PARAM_4'];
53 $comments = $_POST['PARAM_5'];
54 $destination = $_POST['PARAM_6'];
58 $comments = $_POST['PARAM_4'];
59 $destination = $_POST['PARAM_5'];
62 include_once($path_to_root . "/reporting/includes/excel_report.inc");
64 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
65 $dec = user_price_dec();
67 //$cols2 = array(0, 50, 230, 330, 430, 530);
68 $cols2 = array(0, 50, 190, 310, 430, 530);
69 //-------------0--1---2----3----4----5--
71 $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
73 $aligns2 = array('left', 'left', 'left', 'left', 'left');
75 //$cols = array(0, 50, 200, 250, 300, 350, 400, 450, 500, 550);
76 $cols = array(0, 50, 150, 210, 270, 330, 390, 450, 510, 570);
77 //------------0--1---2----3----4----5----6----7----8----9--
79 $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
80 _('Credit'), _('Debit'), _('Credit'));
82 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right');
86 $params = array( 0 => $comments,
87 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
88 2 => array('text' => _('Dimension')." 1",
89 'from' => get_dimension_string($dimension), 'to' => ''),
90 3 => array('text' => _('Dimension')." 2",
91 'from' => get_dimension_string($dimension2), 'to' => ''));
95 $params = array( 0 => $comments,
96 1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
97 2 => array('text' => _('Dimension'),
98 'from' => get_dimension_string($dimension), 'to' => ''));
102 $params = array( 0 => $comments,
103 1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
106 $rep = new FrontReport(_('Trial Balance'), "TrialBalance", user_pagesize());
109 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
112 $accounts = get_gl_accounts();
114 $pdeb = $pcre = $cdeb = $ccre = $tdeb = $tcre = $pbal = $cbal = $tbal = 0;
115 $begin = begin_fiscalyear();
116 if (date1_greater_date2($begin, $from))
118 $begin = add_days($begin, -1);
119 while ($account=db_fetch($accounts))
121 $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
122 $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
123 $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
125 if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance'])
127 $rep->TextCol(0, 1, $account['account_code']);
128 $rep->TextCol(1, 2, $account['account_name']);
131 if ($prev['balance'] >= 0.0)
132 $rep->AmountCol(2, 3, $prev['balance'], $dec);
134 $rep->AmountCol(3, 4, abs($prev['balance']), $dec);
135 if ($curr['balance'] >= 0.0)
136 $rep->AmountCol(4, 5, $curr['balance'], $dec);
138 $rep->AmountCol(5, 6, abs($curr['balance']), $dec);
139 if ($tot['balance'] >= 0.0)
140 $rep->AmountCol(6, 7, $tot['balance'], $dec);
142 $rep->AmountCol(7, 8, abs($tot['balance']), $dec);
146 $rep->AmountCol(2, 3, $prev['debit'], $dec);
147 $rep->AmountCol(3, 4, $prev['credit'], $dec);
148 $rep->AmountCol(4, 5, $curr['debit'], $dec);
149 $rep->AmountCol(5, 6, $curr['credit'], $dec);
150 $rep->AmountCol(6, 7, $tot['debit'], $dec);
151 $rep->AmountCol(7, 8, $tot['credit'], $dec);
152 $pdeb += $prev['debit'];
153 $pcre += $prev['credit'];
154 $cdeb += $curr['debit'];
155 $ccre += $curr['credit'];
156 $tdeb += $tot['debit'];
157 $tcre += $tot['credit'];
160 $pbal += $prev['balance'];
161 $cbal += $curr['balance'];
162 $tbal += $tot['balance'];
165 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
167 $rep->Line($rep->row - 2);
171 $rep->Line($rep->row);
175 //$prev = get_balance(null, $dimension, $dimension2, $begin, $from, false, false);
176 //$curr = get_balance(null, $dimension, $dimension2, $from, $to, true, true);
177 //$tot = get_balance(null, $dimension, $dimension2, $begin, $to, false, true);
181 $rep->TextCol(0, 2, _("Total"));
182 $rep->AmountCol(2, 3, $pdeb, $dec);
183 $rep->AmountCol(3, 4, $pcre, $dec);
184 $rep->AmountCol(4, 5, $cdeb, $dec);
185 $rep->AmountCol(5, 6, $ccre, $dec);
186 $rep->AmountCol(6, 7, $tdeb, $dec);
187 $rep->AmountCol(7, 8, $tcre, $dec);
190 $rep->TextCol(0, 2, _("Ending Balance"));
193 $rep->AmountCol(2, 3, $pbal, $dec);
195 $rep->AmountCol(3, 4, abs($pbal), $dec);
197 $rep->AmountCol(4, 5, $cbal, $dec);
199 $rep->AmountCol(5, 6, abs($cbal), $dec);
201 $rep->AmountCol(6, 7, $tbal, $dec);
203 $rep->AmountCol(7, 8, abs($tbal), $dec);
206 $rep->Line($rep->row);