cb11746c132f49eb791ceaf6b0412f59a7a694d7
[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
95         $accounts = get_gl_accounts();
96
97         while ($account=db_fetch($accounts))
98         {
99
100                 if (is_account_balancesheet($account["account_code"]))
101                         $begin = "";
102                 else
103                 {
104                         if ($from < $begin)
105                                 $begin = add_days($from, -1);
106                         else
107                                 $begin = add_days(begin_fiscalyear(), -1);
108                 }
109
110                 $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
111
112                 $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
113
114                 if ($zero == 0 && !$prev_balance && !$curr_balance)
115                         continue;
116
117                 $rep->TextCol(0, 1, $account['account_code']);
118                 $rep->TextCol(1, 2,     $account['account_name']);
119
120                 if ($prev_balance > 0.0)
121                         $rep->TextCol(2, 3,     number_format2(abs($prev_balance), $dec));
122                 else
123                         $rep->TextCol(3, 4,     number_format2(abs($prev_balance), $dec));
124                 if ($curr_balance > 0.0)
125                         $rep->TextCol(4, 5,     number_format2(abs($curr_balance), $dec));
126                 else
127                         $rep->TextCol(5, 6,     number_format2(abs($curr_balance), $dec));
128                 if ($curr_balance + $prev_balance > 0.0)
129                         $rep->TextCol(6, 7,     number_format2(abs($curr_balance + $prev_balance), $dec));
130                 else
131                         $rep->TextCol(7, 8,     number_format2(abs($curr_balance + $prev_balance), $dec));
132
133                 $rep->NewLine();
134
135                 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
136                 {
137                         $rep->Line($rep->row - 2);
138                         $rep->Header();
139                 }
140         }
141         $rep->Line($rep->row);
142         $rep->End();
143 }
144
145 ?>