Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[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         $orientation = $_POST['PARAM_4'];
42         $destination = $_POST['PARAM_5'];
43         if ($destination)
44                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
45         else
46                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
47
48         $orientation = ($orientation ? 'L' : 'P');
49     $dec = user_price_dec();
50
51     $cols = array(0, 100, 240, 300, 400, 460, 520, 580);
52
53     $headers = array(_('Type/Account'), _('Reference').'/'._('Account Name'), _('Date/Dim.'),
54         _('Person/Item/Memo'), _('Debit'), _('Credit'));
55
56     $aligns = array('left', 'left', 'left', 'left', 'right', 'right');
57
58     $params =   array(  0 => $comments,
59                                     1 => array('text' => _('Period'), 'from' => $from,'to' => $to),
60                         2 => array('text' => _('Type'), 'from' => 
61                                                 $systype == -1 ? _('All') : $systypes_array[$systype],
62                             'to' => ''));
63
64     $rep = new FrontReport(_('List of Journal Entries'), "JournalEntries", user_pagesize(), 9, $orientation);
65     if ($orientation == 'L')
66         recalculate_cols($cols);
67
68     $rep->Font();
69     $rep->Info($params, $cols, $headers, $aligns);
70     $rep->NewPage();
71
72     if ($systype == -1)
73         $systype = null;
74
75     $trans = get_gl_transactions($from, $to, -1, null, 0, 0, $systype);
76
77     $typeno = $type = 0;
78     $debit = $credit = 0.0;
79     $totdeb = $totcre = 0.0;
80     while ($myrow=db_fetch($trans))
81     {
82         if ($type != $myrow['type'] || $typeno != $myrow['type_no'])
83         {
84             if ($typeno != 0)
85             {
86                 $rep->Line($rep->row += 6);
87                 $rep->NewLine();
88                 $rep->AmountCol(4, 5, $debit, $dec);
89                 $rep->AmountCol(5, 6, abs($credit), $dec);
90                 $totdeb += $debit;
91                 $totcre += $credit;
92                 $debit = $credit = 0.0;
93                                 $rep->Line($rep->row -= 4);
94                 $rep->NewLine();
95             }
96             $typeno = $myrow['type_no'];
97             $type = $myrow['type'];
98             $TransName = $systypes_array[$myrow['type']];
99             $rep->TextCol(0, 1, $TransName . " # " . $myrow['type_no']);
100             $rep->TextCol(1, 2, get_reference($myrow['type'], $myrow['type_no']));
101             $rep->DateCol(2, 3, $myrow['tran_date'], true);
102             $memo = get_comments_string($myrow['type'], $myrow['type_no']);
103                         $rep->TextCol(3, 6, $memo);
104             $rep->NewLine();
105         }
106         $rep->TextCol(0, 1, $myrow['account']);
107         $rep->TextCol(1, 2, $myrow['account_name']);
108         $coms =  get_subaccount_name($myrow["account"], $myrow["person_id"]);
109         $rep->TextCol(3, 6, $coms);
110         $dim_str = get_dimension_string($myrow['dimension_id']);
111         $dim_str2 = get_dimension_string($myrow['dimension2_id']);
112         if ($dim_str2 != "")
113                 $dim_str .= "/".$dim_str2;
114         $rep->TextCol(2, 3, $dim_str);
115         $rep->TextCol(3, 4, $myrow['memo_']);
116         if ($myrow['amount'] > 0.0) {
117                 $debit += $myrow['amount'];
118             $rep->AmountCol(4, 5, abs($myrow['amount']), $dec);
119         }    
120         else {
121                 $credit += $myrow['amount'];
122             $rep->AmountCol(5, 6, abs($myrow['amount']), $dec);
123         }    
124         $rep->NewLine(1, 2);
125     }
126         if ($typeno != 0)
127         {
128                 $rep->Line($rep->row += 6);
129                 $rep->NewLine();
130                 $rep->AmountCol(4, 5, $debit, $dec);
131                 $rep->AmountCol(5, 6, abs($credit), $dec);
132                 $totdeb += $debit;
133                 $totcre += $credit;
134                 $rep->Line($rep->row -= 4);
135                 $rep->NewLine();
136         $rep->TextCol(0, 4, _("Total"));
137                 $rep->AmountCol(4, 5, $totdeb, $dec);
138                 $rep->AmountCol(5, 6, abs($totcre), $dec);
139                 $rep->Line($rep->row -= 4);
140         }
141     $rep->End();
142 }
143