[000009] Delivery Note/Sales Invoice should not be editable after it has been voided.
[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         $totprevd = $totprevc = $totcurrd = $totcurrc = 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                 $rep->TextCol(0, 1, $account['account_code']);
118                 $rep->TextCol(1, 2,     $account['account_name']);
119
120                 if ($prev_balance >= 0.0)
121                 {
122                         $totprevd += $prev_balance;
123                         $rep->TextCol(2, 3,     number_format2(abs($prev_balance), $dec));
124                 }       
125                 else
126                 {
127                         $totprevc += $prev_balance;
128                         $rep->TextCol(3, 4,     number_format2(abs($prev_balance), $dec));
129                 }       
130                 if ($curr_balance >= 0.0)
131                 {
132                         $totcurrd += $curr_balance;
133                         $rep->TextCol(4, 5,     number_format2(abs($curr_balance), $dec));
134                 }       
135                 else
136                 {
137                         $totcurrc += $curr_balance;
138                         $rep->TextCol(5, 6,     number_format2(abs($curr_balance), $dec));
139                 }       
140                 if ($curr_balance + $prev_balance >= 0.0)
141                         $rep->TextCol(6, 7,     number_format2(abs($curr_balance + $prev_balance), $dec));
142                 else
143                         $rep->TextCol(7, 8,     number_format2(abs($curr_balance + $prev_balance), $dec));
144
145                 $rep->NewLine();
146
147                 if ($rep->row < $rep->bottomMargin + $rep->lineHeight)
148                 {
149                         $rep->Line($rep->row - 2);
150                         $rep->Header();
151                 }
152         }
153         $rep->Line($rep->row);
154         $rep->NewLine();
155         $rep->Font('bold');
156         $rep->TextCol(0, 2, _("Total"));
157
158         $rep->TextCol(2, 3,     number_format2(abs($totprevd), $dec));
159         $rep->TextCol(3, 4,     number_format2(abs($totprevc), $dec));
160         $rep->TextCol(4, 5,     number_format2(abs($totcurrd), $dec));
161         $rep->TextCol(5, 6,     number_format2(abs($totcurrc), $dec));
162         $rep->TextCol(6, 7,     number_format2(abs($totcurrd + $totprevd), $dec));
163         $rep->TextCol(7, 8,     number_format2(abs($totcurrc + $totprevc), $dec));
164         $rep->NewLine();
165         $totprev = $totprevd + $totprevc;
166         $totcurr = $totcurrd + $totcurrc;
167         $rep->TextCol(0, 2, _("Ending Balance"));
168
169         if ($totprev >= 0.0)
170                 $rep->TextCol(2, 3,     number_format2(abs($totprev), $dec));
171         else
172                 $rep->TextCol(3, 4,     number_format2(abs($totprev), $dec));
173         if ($totcurr >= 0.0)
174                 $rep->TextCol(4, 5,     number_format2(abs($totcurr), $dec));
175         else
176                 $rep->TextCol(5, 6,     number_format2(abs($totcurr), $dec));
177         if ($totcurr + $totprev >= 0.0)
178                 $rep->TextCol(6, 7,     number_format2(abs($totcurr + $totprev), $dec));
179         else
180                 $rep->TextCol(7, 8,     number_format2(abs($totcurr + $totprev), $dec));
181         
182         $rep->Line($rep->row - 6);
183         
184         $rep->End();
185 }
186
187 ?>