Fixed layout, changes, bugs and improvements to Fixed Assets application.
[fa-stable.git] / fixed_assets / inquiry / stock_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 $page_security = 'SA_ASSETSANALYTIC';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include($path_to_root . "/includes/session.inc");
16
17 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
18 include($path_to_root . "/reporting/includes/reporting.inc");
19 include($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc");
20
21 $js = "";
22 if ($SysPrefs->use_popup_windows)
23         $js .= get_js_open_window(900, 500);
24 if (user_use_date_picker())
25         $js .= get_js_date_picker();
26 page(_($help_context = "Fixed Assets Inquiry"), false, false, "", $js);
27
28 if (isset($_GET['location'])) 
29 {
30         $_POST['location'] = $_GET['location'];
31 }
32
33 //------------------------------------------------------------------------------------------------
34
35 start_form();
36
37 start_table(TABLESTYLE_NOBORDER);
38 start_row();
39 //locations_list_cells(_("From Location:"), 'location', null, false, false, true);
40 check_cells( _("Show inactive:"), 'show_inactive', null);
41 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
42 end_row();
43
44 end_table();
45
46 //------------------------------------------------------------------------------------------------
47
48 if(get_post('RefreshInquiry'))
49 {
50         $Ajax->activate('totals_tbl');
51 }
52
53 function gl_view($row)
54 {
55   $row = get_fixed_asset_move($row['stock_id'], ST_JOURNAL);
56
57   //if ($row === false)
58     //return "";
59
60   //return get_journal_trans_view_str(ST_JOURNAL, $row["trans_no"], sql2date($row["tran_date"]));
61         return get_gl_view_str(ST_JOURNAL, $row["trans_no"]);
62 }
63
64 function fa_link($row)
65 {
66   $url = "inventory/manage/items.php?FixedAsset=1&stock_id=".$row['stock_id'];
67
68         return viewer_link($row['stock_id'], $url);
69 }
70
71 function depr_method_title($row) {
72   global $depreciation_methods;
73   return $depreciation_methods[$row['depreciation_method']];
74 }
75
76 function depr_rate_title($row) {
77   if ($row['depreciation_method'] == 'S')
78     return $row['depreciation_rate'].' years';
79   else
80     return $row['depreciation_rate'].'%';
81 }
82
83 function status_title($row) {
84
85         if ($row['inactive'] || ($row['disposal_date'] !== NULL))
86                 return _("Disposed"); // disposed or saled
87         elseif ($row['purchase_date'] === NULL)
88                 return _("Purchasable"); // not yet purchased
89     else
90         return _("Active");  // purchased
91
92 }
93
94 function purchase_link($row)
95 {
96
97   if ($row['purchase_date'] === null)
98     return "";
99
100   return get_supplier_trans_view_str(ST_SUPPRECEIVE, $row["purchase_no"], sql2date($row["purchase_date"]));
101 }
102
103 function disposal_link($row)
104 {
105   switch ($row['disposal_type']) {
106     case ST_INVADJUST:
107       return get_inventory_trans_view_str(ST_INVADJUST, $row["disposal_no"], sql2date($row["disposal_date"]));
108     case ST_CUSTDELIVERY:
109             return get_customer_trans_view_str(ST_CUSTDELIVERY, $row["disposal_no"], sql2date($row["disposal_date"]));
110     default:
111       return "";
112   }
113 }
114
115 function amount_link($row)
116 {
117     return price_format($row['last_cost']);
118 }
119
120 function depr_link($row)
121 {
122     return price_format($row['last_cost'] - $row['material_cost']);
123 }
124
125 function balance_link($row)
126 {
127     return price_format($row['material_cost']);
128 }
129
130
131 //------------------------------------------------------------------------------------------------
132
133 $sql = get_sql_for_fixed_assets(get_post('show_inactive'));
134
135 $cols = array(
136                         //_("Type") => array('fun'=>'systype_name', 'ord'=>''), 
137                         //_("#") => array('fun'=>'trans_view', 'ord'=>''), 
138                         _("#") => array('fun' => 'fa_link'), 
139                         _("Class"), 
140                         _("UOM") => array('align' => 'center'), 
141                         _("Description"),
142                         _("Rate or Lifecycle") => array('fun' => 'depr_rate_title'), 
143                         _("Method") => array('fun' => 'depr_method_title'), 
144                         _("Status") => array('fun' => 'status_title'), 
145                         _("Purchased") => array('fun' => 'purchase_link'),
146                         _("Amount") => array('align'=>'right', 'fun' => 'amount_link'),
147                         _("Depreciations") => array('align'=>'right', 'fun' => 'depr_link'),
148                         _("Balance") => array('align'=>'right', 'fun' => 'balance_link'),
149                         _("Liquidation or Sale") => array('align' => 'center', 'fun' => 'disposal_link'), 
150                         //array('insert'=>true, 'fun'=>'gl_view'),
151                         //array('insert'=>true, 'fun'=>'rm_link'),
152                         //array('insert'=>true, 'fun'=>'edit_link'),
153                         //array('insert'=>true, 'fun'=>'prt_link'),
154                         );
155
156 //------------------------------------------------------------------------------------------------
157
158 /*show a table of the transactions returned by the sql */
159 $table =& new_db_pager('fixed_assets_tbl', $sql, $cols);
160
161 $table->width = "85%";
162
163 display_db_pager($table);
164
165 end_form();
166 end_page();