Moved all SQL statements from PHP files into relevant *_db.inc files.
[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 = 'SA_GLANALYTIC';
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(_($help_context = "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(_("Type:"), "filterType");
48 date_cells(_("From:"), 'FromDate', '', null, 0, -1, 0);
49 date_cells(_("To:"), 'ToDate');
50
51 check_cells( _("Show closed:"), 'AlsoClosed', null);
52
53 submit_cells('Search', _("Search"), '', '', 'default');
54
55 end_row();
56 end_table();
57
58 function journal_pos($row)
59 {
60         return $row['gl_seq'] ? $row['gl_seq'] : '-';
61 }
62
63 function systype_name($dummy, $type)
64 {
65         global $systypes_array;
66         
67         return $systypes_array[$type];
68 }
69
70 function view_link($row) 
71 {
72         return get_trans_view_str($row["type"], $row["type_no"]);
73 }
74
75 function gl_link($row) 
76 {
77         return get_gl_view_str($row["type"], $row["type_no"]);
78 }
79
80 $editors = array(
81         0 => "/gl/gl_journal.php?ModifyGL=Yes&trans_no=%d&trans_type=%d",
82 //      1=> Bank Payment,
83 //      2=> Bank Deposit,
84 //      4=> Funds Transfer,
85    ST_SALESINVOICE => "/sales/customer_invoice.php?ModifyInvoice=%d",
86 //   11=>
87 // free hand (debtors_trans.order_==0)
88 //      "/sales/credit_note_entry.php?ModifyCredit=%d"
89 // credit invoice
90 //      "/sales/customer_credit_invoice.php?ModifyCredit=%d"
91 //       12=> Customer Payment,
92    ST_CUSTDELIVERY => "/sales/customer_delivery.php?ModifyDelivery=%d",
93 //   16=> Location Transfer,
94 //   17=> Inventory Adjustment,
95 //   20=> Supplier Invoice,
96 //   21=> Supplier Credit Note,
97 //   22=> Supplier Payment,
98 //   25=> Purchase Order Delivery,
99 //   28=> Work Order Issue,
100 //   29=> Work Order Production",
101 //   35=> Cost Update,
102 );
103
104 function edit_link($row)
105 {
106         global $editors;
107
108         return isset($editors[$row["type"]]) && !is_closed_trans($row["type"], $row["type_no"]) ? 
109                 pager_link(_("Edit"), 
110                         sprintf($editors[$row["type"]], $row["type_no"], $row["type"]),
111                         ICON_EDIT) : '';
112 }
113
114 $sql = get_sql_for_journal_inquiry();
115
116 $cols = array(
117         _("#") => array('fun'=>'journal_pos', 'align'=>'center'), 
118         _("Date") =>array('name'=>'tran_date','type'=>'date','ord'=>'desc'),
119         _("Type") => array('fun'=>'systype_name'), 
120         _("Trans #") => array('fun'=>'view_link'), 
121         _("Reference"), 
122         _("Amount") => array('type'=>'amount'),
123         _("Memo"),
124         _("User"),
125         _("View") => array('insert'=>true, 'fun'=>'gl_link'),
126         array('insert'=>true, 'fun'=>'edit_link')
127 );
128
129 if (!check_value('AlsoClosed')) {
130         $cols[_("#")] = 'skip';
131 }
132
133 $table =& new_db_pager('journal_tbl', $sql, $cols);
134
135 $table->width = "80%";
136
137 display_db_pager($table);
138
139 end_form();
140 end_page();
141
142 ?>