New journal inquiry.
[fa-stable.git] / gl / inquiry / journal_inquiry.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
13 $page_security = 8;
14 $path_to_root="../..";
15
16 include($path_to_root . "/includes/db_pager.inc");
17 include_once($path_to_root . "/includes/session.inc");
18
19 include_once($path_to_root . "/includes/date_functions.inc");
20 include_once($path_to_root . "/includes/ui.inc");
21 $js = "";
22 if ($use_popup_windows)
23         $js .= get_js_open_window(800, 500);
24 if ($use_date_picker)
25         $js .= get_js_date_picker();
26
27 page(_("Journal Inquiry"), false, false, "", $js);
28
29 //-----------------------------------------------------------------------------------
30 // Ajax updates
31 //
32 if (get_post('Search'))
33 {
34         $Ajax->activate('journal_tbl');
35 }
36 //--------------------------------------------------------------------------------------
37 if (!isset($_POST['filterType']))
38         $_POST['filterType'] = -1;
39
40 start_form();
41
42 start_table("class='tablestyle_noborder'");
43 start_row();
44
45 ref_cells(_("Reference:"), 'Ref', '',null, _('Enter reference fragment or leave empty'));
46
47 journal_types_list_cells(_("Transaction Type:"), "filterType");
48 date_cells(_("From:"), 'FromDate', '', null, 0, 0, -1);
49 date_cells(_("To:"), 'ToDate');
50
51 submit_cells('Search', _("Search"), '', '', 'default');
52
53 end_row();
54 end_table();
55
56 end_form();
57
58 function systype_name($dummy, $type)
59 {
60         return systypes::name($type);
61 }
62
63 function view_link($row) 
64 {
65         return get_trans_view_str($row["type"], $row["type_no"]);
66 }
67
68 function gl_link($row) 
69 {
70         return get_gl_view_str($row["type"], $row["type_no"]);
71 }
72
73 function is_closed($row)
74 {
75         return $row['gl_seq'] ? _('Yes') : _('No');
76 }
77
78 $editors = array(
79         0 => "/gl/gl_journal.php?ModifyGL=Yes&trans_no=%d&trans_type=%d",
80 //      1=> Bank Payment,
81 //      2=> Bank Deposit,
82 //      4=> Funds Transfer,
83    10=> "/sales/customer_invoice.php?ModifyInvoice=%d",
84 //   11=>
85 // free hand (debtors_trans.order_==0)
86 //      "/sales/credit_note_entry.php?ModifyCredit=%d"
87 // credit invoice
88 //      "/sales/customer_credit_invoice.php?ModifyCredit=%d"
89 //       12=> Customer Payment,
90    13=> "/sales/customer_delivery.php?ModifyDelivery=%d",
91 //   16=> Location Transfer,
92 //   17=> Inventory Adjustment,
93 //   20=> Supplier Invoice,
94 //   21=> Supplier Credit Note,
95 //   22=> Supplier Payment,
96 //   25=> Purchase Order Delivery,
97 //   28=> Work Order Issue,
98 //   29=> Work Order Production",
99 //   35=> Cost Update,
100 );
101
102 function edit_link($row)
103 {
104         global $editors;
105
106         return isset($editors[$row["type"]]) ? 
107                 pager_link(_("Edit"), 
108                         sprintf($editors[$row["type"]], $row["type_no"], $row["type"]),
109                         ICON_EDIT) : '';
110 }
111
112 $sql = "SELECT  gl.tran_date,
113                                 gl.type,
114                                 gl.type_no,
115                                 refs.reference,
116                                 SUM(IF(gl.amount>0, gl.amount,0)) as amount,"
117                                 ."com.memo_"
118                 ." FROM ". TB_PREF."gl_trans as gl"
119                 ." LEFT JOIN ". TB_PREF."comments as com ON 
120                         (gl.type=com.type AND gl.type_no=com.id)"
121                 ." LEFT JOIN ". TB_PREF."refs as refs ON 
122                         (gl.type=refs.type AND gl.type_no=refs.id)
123                 WHERE gl.tran_date >= '" . date2sql($_POST['FromDate']) . "'
124         AND gl.tran_date <= '" . date2sql($_POST['ToDate']) . "'
125         AND gl.amount!=0";
126
127 if (isset($_POST['Ref']) && $_POST['Ref'] != "") {
128         $sql .= " AND reference LIKE '%". $_POST['Ref'] . "%'";
129 }
130 if (get_post('filterType') != -1) {
131         $sql .= " AND gl.type=".get_post('filterType');
132 }
133
134 $sql .= " GROUP BY gl.type, gl.type_no";
135
136 $cols = array(
137         _("Date") =>array('name'=>'tran_date','type'=>'date','ord'=>'desc'),
138         _("Type") => array('fun'=>'systype_name'), 
139         _("Trans #") => array('fun'=>'view_link'), 
140         _("Reference"), 
141         _("Amount") => array('type'=>'amount'),
142         _("Memo"),
143         _("View") => array('insert'=>true, 'fun'=>'gl_link'),
144         array('insert'=>true, 'fun'=>'edit_link')
145 );
146
147 $table =& new_db_pager('journal_tbl', $sql, $cols);
148
149 if (get_post('Search')) {
150         $table->set_sql($sql);
151         $table->set_columns($cols);
152 }
153 $table->width = "80%";
154 start_form();
155
156 display_db_pager($table);
157
158 end_form();
159 end_page();
160
161 ?>