*** empty log message ***
[fa-stable.git] / reporting / rep704.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       GL Accounts Transactions
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_GL_transactions();
21
22 //----------------------------------------------------------------------------------------------------
23
24 function print_GL_transactions()
25 {
26         global $path_to_root;
27
28         include_once($path_to_root . "reporting/includes/pdf_report.inc");
29
30         $rep = new FrontReport(_('GL Account Transactions'), "GLAccountTransactions.pdf", user_pagesize());
31         $dim = get_company_pref('use_dimension');
32         $dimension = $dimension2 = 0;
33
34         $from = $_POST['PARAM_0'];
35         $to = $_POST['PARAM_1'];
36         $fromacc = $_POST['PARAM_2'];
37         $toacc = $_POST['PARAM_3'];
38         if ($dim == 2)
39         {
40                 $dimension = $_POST['PARAM_4'];
41                 $dimension2 = $_POST['PARAM_5'];
42                 $comments = $_POST['PARAM_6'];
43         }
44         else if ($dim == 1)
45         {
46                 $dimension = $_POST['PARAM_4'];
47                 $comments = $_POST['PARAM_5'];
48         }
49         else
50         {
51                 $comments = $_POST['PARAM_4'];
52         }
53         $dec = user_price_dec();
54
55         $cols = array(0, 70, 90, 140, 210, 280, 340, 400, 450, 510, 570);
56         //------------0--1---2---3----4----5----6----7----8----9----10-------
57         //-----------------------dim1-dim2-----------------------------------
58         //-----------------------dim1----------------------------------------
59         //-------------------------------------------------------------------
60         $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
61
62         if ($dim == 2)
63                 $headers = array(_('Type'),     _('#'), _('Date'), _('Dimension')." 1", _('Dimension')." 2", 
64                         _('Person/Item'), _('Debit'),   _('Credit'), _('Balance'));
65         else if ($dim == 1)             
66                 $headers = array(_('Type'),     _('#'), _('Date'), _('Dimension'), "", _('Person/Item'),
67                         _('Debit'),     _('Credit'), _('Balance'));
68         else    
69                 $headers = array(_('Type'),     _('#'), _('Date'), "", "", _('Person/Item'),
70                         _('Debit'),     _('Credit'), _('Balance'));
71
72         if ($dim == 2)
73         {
74         $params =   array(      0 => $comments,
75                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
76                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc),
77                         3 => array('text' => _('Dimension')." 1", 'from' => get_dimension_string($dimension),
78                             'to' => ''),
79                         4 => array('text' => _('Dimension')." 2", 'from' => get_dimension_string($dimension2),
80                             'to' => ''));
81     }
82     else if ($dim == 1)
83     {
84         $params =   array(      0 => $comments,
85                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
86                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc),
87                         3 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension),
88                             'to' => ''));
89     }
90     else
91     {
92         $params =   array(      0 => $comments,
93                                     1 => array('text' => _('Period'), 'from' => $from, 'to' => $to),
94                                     2 => array('text' => _('Accounts'),'from' => $fromacc,'to' => $toacc));
95     }
96         
97         $rep->Font();
98         $rep->Info($params, $cols, $headers, $aligns);
99         $rep->Header();
100
101         $accounts = get_gl_accounts($fromacc, $toacc);
102
103         while ($account=db_fetch($accounts)) 
104         {
105                 $begin = begin_fiscalyear();
106                 if (is_account_balancesheet($account["account_code"]))
107                         $begin = "";
108                 elseif ($from < $begin)
109                         $begin = $from;
110                 $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
111
112                 $trans = get_gl_transactions($from, $to, -1, $account['account_code'], $dimension, $dimension2);
113                 $rows = db_num_rows($trans);
114                 if ($prev_balance == 0.0 && $rows == 0)
115                         continue;
116                 $rep->Font('bold');     
117                 $rep->TextCol(0, 3,     $account['account_code'] . " " . $account['account_name']);
118                 $rep->TextCol(3, 5, _('Opening Balance'));
119                 if ($prev_balance > 0.0)
120                         $rep->TextCol(6, 7,     number_format2(abs($prev_balance), $dec));
121                 else
122                         $rep->TextCol(7, 8,     number_format2(abs($prev_balance), $dec));
123                 $rep->Font();   
124                 $total = $prev_balance;
125                 $rep->NewLine(2);
126                 if ($rows > 0) 
127                 {
128                         while ($myrow=db_fetch($trans))
129                         {
130                                 $total += $myrow['amount'];
131
132                                 $rep->TextCol(0, 1,     systypes::name($myrow["type"]));
133                                 $rep->TextCol(1, 2,     $myrow['type_no']);
134                                 $rep->TextCol(2, 3,     sql2date($myrow["tran_date"]));
135                                 if ($dim >= 1)
136                                         $rep->TextCol(3, 4,     get_dimension_string($myrow['dimension_id']));
137                                 if ($dim > 1)
138                                         $rep->TextCol(4, 5,     get_dimension_string($myrow['dimension2_id']));
139                                 $rep->TextCol(5, 6,     payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"], false));
140                                 if ($myrow['amount'] > 0.0)
141                                         $rep->TextCol(6, 7,     number_format2(abs($myrow['amount']), $dec));
142                                 else    
143                                         $rep->TextCol(7, 8,     number_format2(abs($myrow['amount']), $dec));
144                                 $rep->TextCol(8, 9,     number_format2($total, $dec));
145                                 $rep->NewLine();
146                                 if ($rep->row < $rep->bottomMargin + $rep->lineHeight) 
147                                 {
148                                         $rep->Line($rep->row - 2);
149                                         $rep->Header();
150                                 }
151                         }
152                         $rep->NewLine();
153                 }
154                 $rep->Font('bold');     
155                 $rep->TextCol(3, 5,     _("Ending Balance"));
156                 if ($total > 0.0)
157                         $rep->TextCol(6, 7,     number_format2(abs($total), $dec));
158                 else
159                         $rep->TextCol(7, 8,     number_format2(abs($total), $dec));
160                 $rep->Font();   
161                 $rep->Line($rep->row - $rep->lineHeight + 4);
162                 $rep->NewLine(2, 1);
163         }
164         $rep->End();
165 }
166
167 ?>