01d3606a420f84a9c46d9ce57525daf6785b2ebc
[fa-stable.git] / reporting / rep702.php
1 <?php
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 ***********************************************************************/
12 $page_security = 'SA_GLANALYTIC';
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       List of Journal Entries
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
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");
25 include_once($path_to_root . "/includes/ui/ui_view.inc");
26
27 //----------------------------------------------------------------------------------------------------
28
29 print_list_of_journal_entries();
30
31 //----------------------------------------------------------------------------------------------------
32
33 function print_list_of_journal_entries()
34 {
35     global $path_to_root, $systypes_array;
36
37     $from = $_POST['PARAM_0'];
38     $to = $_POST['PARAM_1'];
39     $systype = $_POST['PARAM_2'];
40     $comments = $_POST['PARAM_3'];
41         $destination = $_POST['PARAM_4'];
42         if ($destination)
43                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
44         else
45                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
46
47     $dec = user_price_dec();
48
49     $cols = array(0, 100, 240, 300, 400, 460, 520, 580);
50
51     $headers = array(_('Type/Account'), _('Reference').'/'._('Account Name'), _('Date/Dim.'),
52         _('Person/Item/Memo'), _('Debit'), _('Credit'));
53
54     $aligns = array('left', 'left', 'left', 'left', 'right', 'right');
55
56     $params =   array(  0 => $comments,
57                                     1 => array('text' => _('Period'), 'from' => $from,'to' => $to),
58                         2 => array('text' => _('Type'), 'from' => 
59                                                 $systype == -1 ? _('All') : $systypes_array[$systype],
60                             'to' => ''));
61
62     $rep = new FrontReport(_('List of Journal Entries'), "JournalEntries", user_pagesize());
63
64     $rep->Font();
65     $rep->Info($params, $cols, $headers, $aligns);
66     $rep->NewPage();
67
68     if ($systype == -1)
69         $systype = null;
70
71     $trans = get_gl_transactions($from, $to, -1, null, 0, 0, $systype);
72
73     $typeno = $type = 0;
74     $debit = $credit = 0.0;
75     $totdeb = $totcre = 0.0;
76     while ($myrow=db_fetch($trans))
77     {
78         if ($type != $myrow['type'] || $typeno != $myrow['type_no'])
79         {
80             if ($typeno != 0)
81             {
82                 $rep->Line($rep->row += 6);
83                 $rep->NewLine();
84                 $rep->AmountCol(4, 5, $debit, $dec);
85                 $rep->AmountCol(5, 6, abs($credit), $dec);
86                 $totdeb += $debit;
87                 $totcre += $credit;
88                 $debit = $credit = 0.0;
89                                 $rep->Line($rep->row -= 4);
90                 $rep->NewLine();
91             }
92             $typeno = $myrow['type_no'];
93             $type = $myrow['type'];
94             $TransName = $systypes_array[$myrow['type']];
95             $rep->TextCol(0, 1, $TransName . " # " . $myrow['type_no']);
96             $rep->TextCol(1, 2, get_reference($myrow['type'], $myrow['type_no']));
97             $rep->DateCol(2, 3, $myrow['tran_date'], true);
98             $coms =  payment_person_name($myrow["person_type_id"],$myrow["person_id"]);
99             $memo = get_comments_string($myrow['type'], $myrow['type_no']);
100             if ($memo != '')
101             {
102                 if ($coms == "")
103                         $coms = $memo;
104                 else
105                         $coms .= " / ".$memo;
106             }           
107             $rep->TextCol(3, 6, $coms);
108             $rep->NewLine(2);
109         }
110         $rep->TextCol(0, 1, $myrow['account']);
111         $rep->TextCol(1, 2, $myrow['account_name']);
112         $dim_str = get_dimension_string($myrow['dimension_id']);
113         $dim_str2 = get_dimension_string($myrow['dimension2_id']);
114         if ($dim_str2 != "")
115                 $dim_str .= "/".$dim_str2;
116         $rep->TextCol(2, 3, $dim_str);
117         $rep->TextCol(3, 4, $myrow['memo_']);
118         if ($myrow['amount'] > 0.0) {
119                 $debit += $myrow['amount'];
120             $rep->AmountCol(4, 5, abs($myrow['amount']), $dec);
121         }    
122         else {
123                 $credit += $myrow['amount'];
124             $rep->AmountCol(5, 6, abs($myrow['amount']), $dec);
125         }    
126         $rep->NewLine(1, 2);
127     }
128         if ($typeno != 0)
129         {
130                 $rep->Line($rep->row += 6);
131                 $rep->NewLine();
132                 $rep->AmountCol(4, 5, $debit, $dec);
133                 $rep->AmountCol(5, 6, abs($credit), $dec);
134                 $totdeb += $debit;
135                 $totcre += $credit;
136                 $rep->Line($rep->row -= 4);
137                 $rep->NewLine();
138         $rep->TextCol(0, 4, _("Total"));
139                 $rep->AmountCol(4, 5, $totdeb, $dec);
140                 $rep->AmountCol(5, 6, abs($totcre), $dec);
141                 $rep->Line($rep->row -= 4);
142         }
143     $rep->End();
144 }
145
146 ?>