Merging changes up to 2.0.4
[fa-stable.git] / reporting / rep708.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       Trial Balance
9 // ----------------------------------------------------------------
10 $path_to_root="../";
11
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");
16
17 //----------------------------------------------------------------------------------------------------
18
19 // trial_inquiry_controls();
20 print_trial_balance();
21
22 //----------------------------------------------------------------------------------------------------
23
24 function print_trial_balance()
25 {
26         global $path_to_root;
27
28         include_once($path_to_root . "reporting/includes/pdf_report.inc");
29         $dim = get_company_pref('use_dimension');
30         $dimension = $dimension2 = 0;
31
32         $from = $_POST['PARAM_0'];
33         $to = $_POST['PARAM_1'];
34         $zero = $_POST['PARAM_2'];
35         if ($dim == 2)
36         {
37                 $dimension = $_POST['PARAM_3'];
38                 $dimension2 = $_POST['PARAM_4'];
39                 $comments = $_POST['PARAM_5'];
40         }
41         else if ($dim == 1)
42         {
43                 $dimension = $_POST['PARAM_3'];
44                 $comments = $_POST['PARAM_4'];
45         }
46         else
47         {
48                 $comments = $_POST['PARAM_3'];
49         }
50         $dec = user_price_dec();
51
52         $cols2 = array(0, 50, 230, 330, 430, 530);
53         //-------------0--1---2----3----4----5--
54
55         $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
56
57         $aligns2 = array('left', 'left', 'left', 'left', 'left');
58
59         $cols = array(0, 50, 200, 250, 300,     350, 400, 450, 500,     550);
60         //------------0--1---2----3----4----5----6----7----8----9--
61
62         $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'),
63                 _('Credit'), _('Debit'), _('Credit'));
64
65         $aligns = array('left', 'left', 'right', 'right', 'right', 'right',     'right', 'right');
66
67     if ($dim == 2)
68     {
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' => ''));
75     }
76     else if ($dim == 1)
77     {
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' => ''));
82     }
83     else
84     {
85         $params =   array(      0 => $comments,
86                                     1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
87     }
88
89         $rep = new FrontReport(_('Trial Balance'), "TrialBalance.pdf", user_pagesize());
90
91         $rep->Font();
92         $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
93         $rep->Header();
94         $totprev = $totcurr = 0.0;
95
96         $accounts = get_gl_accounts();
97
98         while ($account=db_fetch($accounts))
99         {
100
101                 if (is_account_balancesheet($account["account_code"]))
102                         $begin = "";
103                 else
104                 {
105                         $begin = begin_fiscalyear();
106                         if (date1_greater_date2($begin, $from))
107                                 $begin = $from;
108                         $begin = add_days($begin, -1);
109                 }
110
111                 $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
112
113                 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
114
115                 if ($zero == 0 && !$prev_balance && !$curr_balance)
116                         continue;
117                 $totprev += $prev_balance;
118                 $totcurr += $curr_balance;
119                 $rep->TextCol(0, 1, $account['account_code']);
120                 $rep->TextCol(1, 2,     $account['account_name']);
121
122                 if ($prev_balance >= 0.0)
123                         $rep->TextCol(2, 3,     number_format2(abs($prev_balance), $dec));
124                 else
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));
128                 else
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));
132                 else
133                         $rep->TextCol(7, 8,     number_format2(abs($curr_balance + $prev_balance), $dec));
134
135                 $rep->NewLine();
136
137                 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
138                 {
139                         $rep->Line($rep->row - 2);
140                         $rep->Header();
141                 }
142         }
143         $rep->Line($rep->row);
144         $rep->NewLine();
145         $rep->Font('bold');
146
147         $rep->TextCol(0, 2, _("Ending Balance"));
148
149         if ($totprev >= 0.0)
150                 $rep->TextCol(2, 3,     number_format2(abs($totprev), $dec));
151         else
152                 $rep->TextCol(3, 4,     number_format2(abs($totprev), $dec));
153         if ($totcurr >= 0.0)
154                 $rep->TextCol(4, 5,     number_format2(abs($totcurr), $dec));
155         else
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));
159         else
160                 $rep->TextCol(7, 8,     number_format2(abs($totcurr + $totprev), $dec));
161         
162         $rep->Line($rep->row - 6);
163         
164         $rep->End();
165 }
166
167 ?>