Show more relevant info in CounterPart Field, 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 = '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 ($SysPrefs->use_popup_windows)
23         $js .= get_js_open_window(800, 500);
24 if (user_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(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, -user_transaction_days());
49 date_cells(_("To:"), 'ToDate');
50
51 end_row();
52 start_row();
53 ref_cells(_("Memo:"), 'Memo', '',null, _('Enter memo fragment or leave empty'));
54 users_list_cells(_("User:"), 'userid', null, false);
55 if (get_company_pref('use_dimension') && isset($_POST['dimension'])) // display dimension only, when started in dimension mode
56         dimensions_list_cells(_('Dimension:'), 'dimension', null, true, null, true);
57 check_cells( _("Show closed:"), 'AlsoClosed', null);
58 submit_cells('Search', _("Search"), '', '', 'default');
59 end_row();
60 end_table();
61
62 function journal_pos($row)
63 {
64         return $row['gl_seq'] ? $row['gl_seq'] : '-';
65 }
66
67 function systype_name($dummy, $type)
68 {
69         global $systypes_array;
70         
71         return $systypes_array[$type];
72 }
73
74 function person_link($row) 
75 {
76     return payment_person_name($row["person_type_id"],$row["person_id"]);
77 }
78
79 function view_link($row) 
80 {
81         return get_trans_view_str($row["trans_type"], $row["trans_no"]);
82 }
83
84 function gl_link($row) 
85 {
86         return get_gl_view_str($row["trans_type"], $row["trans_no"]);
87 }
88
89 function edit_link($row)
90 {
91
92         $ok = true;
93         if ($row['trans_type'] == ST_SALESINVOICE)
94         {
95                 $myrow = get_customer_trans($row["trans_no"], $row["trans_type"]);
96                 if ($myrow['alloc'] != $myrow['Total'] || get_voided_entry(ST_SALESINVOICE, $row["trans_no"]) !== false)
97                         $ok = false;
98         }
99         
100         return $ok ? trans_editor_link( $row["trans_type"], $row["trans_no"]) : '--';
101 }
102
103 function invoice_supp_reference($row)
104 {
105         return $row['supp_reference'];
106 }
107
108 $sql = get_sql_for_journal_inquiry(get_post('filterType', -1), get_post('FromDate'),
109         get_post('ToDate'), get_post('Ref'), get_post('Memo'), check_value('AlsoClosed'), get_post('userid'));
110
111 $cols = array(
112         _("#") => array('fun'=>'journal_pos', 'align'=>'center'), 
113         _("Date") =>array('name'=>'tran_date','type'=>'date','ord'=>'desc'),
114         _("Type") => array('fun'=>'systype_name'), 
115         _("Trans #") => array('fun'=>'view_link'), 
116         _("Counterparty") => array('fun' => 'person_link'),
117         _("Supplier's Reference") => 'skip',
118         _("Reference"), 
119         _("Amount") => array('type'=>'amount'),
120         _("Memo"),
121         _("User"),
122         _("View") => array('insert'=>true, 'fun'=>'gl_link'),
123         array('insert'=>true, 'fun'=>'edit_link')
124 );
125
126 if (!check_value('AlsoClosed')) {
127         $cols[_("#")] = 'skip';
128 }
129
130 if($_POST['filterType'] == ST_SUPPINVOICE) //add the payment column if shown supplier invoices only
131 {
132         $cols[_("Supplier's Reference")] = array('fun'=>'invoice_supp_reference', 'align'=>'center');
133 }
134
135 $table =& new_db_pager('journal_tbl', $sql, $cols);
136
137 $table->width = "80%";
138
139 display_db_pager($table);
140
141 end_form();
142 end_page();
143