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");
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");
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);
28 if (isset($_GET['location']))
30 $_POST['location'] = $_GET['location'];
33 //------------------------------------------------------------------------------------------------
37 start_table(TABLESTYLE_NOBORDER);
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');
46 //------------------------------------------------------------------------------------------------
48 if(get_post('RefreshInquiry'))
50 $Ajax->activate('totals_tbl');
53 function gl_view($row)
55 $row = get_fixed_asset_move($row['stock_id'], ST_JOURNAL);
57 return get_gl_view_str(ST_JOURNAL, $row["trans_no"]);
60 function fa_prepare_row($row) {
61 $purchase = get_fixed_asset_purchase($row['stock_id']);
62 if ($purchase !== false) {
63 $row['purchase_date'] = $purchase['tran_date'];
64 $row['purchase_no'] = $purchase['trans_no'];
67 $row['purchase_date'] = NULL;
68 $row['purchase_no'] = NULL;
71 $disposal = get_fixed_asset_disposal($row['stock_id']);
72 if ($disposal !== false) {
73 $row['disposal_date'] = $disposal['tran_date'];
74 $row['disposal_no'] = $disposal['trans_no'];
75 $row['disposal_type'] = $disposal['type'];
78 $row['disposal_date'] = NULL;
79 $row['disposal_no'] = NULL;
80 $row['disposal_type'] = NULL;
85 function fa_link($row)
87 $url = "inventory/manage/items.php?FixedAsset=1&stock_id=".$row['stock_id'];
89 return viewer_link($row['stock_id'], $url);
92 function depr_method_title($row) {
93 global $depreciation_methods;
94 return $depreciation_methods[$row['depreciation_method']];
97 function depr_par($row) {
98 if ($row['depreciation_method'] == 'D')
99 return $row['depreciation_rate']*$row['depreciation_factor'].'%';
100 elseif ($row['depreciation_method'] == 'N')
101 return $row['depreciation_rate'].' '._('years'
104 return $row['depreciation_rate'].'%';
107 function status_title($row) {
109 if ($row['inactive'] || ($row['disposal_date'] !== NULL))
110 return _("Disposed"); // disposed or saled
111 elseif ($row['purchase_date'] === NULL)
112 return _("Purchasable"); // not yet purchased
114 return _("Active"); // purchased
118 function purchase_link($row)
121 if ($row['purchase_date'] === NULL)
124 return get_supplier_trans_view_str(ST_SUPPRECEIVE, $row["purchase_no"], sql2date($row["purchase_date"]));
127 function disposal_link($row)
129 if ($row['disposal_date'] === NULL)
132 switch ($row['disposal_type']) {
134 return get_inventory_trans_view_str(ST_INVADJUST, $row["disposal_no"], sql2date($row["disposal_date"]));
135 case ST_CUSTDELIVERY:
136 return get_customer_trans_view_str(ST_CUSTDELIVERY, $row["disposal_no"], sql2date($row["disposal_date"]));
142 function amount_link($row)
144 return price_format($row['purchase_cost']);
147 function depr_link($row)
149 return price_format($row['purchase_cost'] - $row['material_cost']);
152 function balance_link($row)
154 return price_format($row['material_cost']);
158 //------------------------------------------------------------------------------------------------
160 $sql = get_sql_for_fixed_assets(get_post('show_inactive'));
163 //_("Type") => array('fun'=>'systype_name', 'ord'=>''),
164 //_("#") => array('fun'=>'trans_view', 'ord'=>''),
165 _("#") => array('fun' => 'fa_link'),
167 _("UOM") => array('align' => 'center'),
169 _("Rate or Lifecycle") => array('fun' => 'depr_par'),
170 _("Method") => array('fun' => 'depr_method_title'),
171 _("Status") => array('fun' => 'status_title'),
172 _("Purchased") => array('fun' => 'purchase_link'),
173 _("Initial") => array('align'=>'right', 'fun' => 'amount_link'),
174 _("Depreciations") => array('align'=>'right', 'fun' => 'depr_link'),
175 _("Current") => array('align'=>'right', 'fun' => 'balance_link'),
176 _("Liquidation or Sale") => array('align' => 'center', 'fun' => 'disposal_link'),
177 //array('insert'=>true, 'fun'=>'gl_view'),
178 //array('insert'=>true, 'fun'=>'rm_link'),
179 //array('insert'=>true, 'fun'=>'edit_link'),
180 //array('insert'=>true, 'fun'=>'prt_link'),
183 //------------------------------------------------------------------------------------------------
185 /*show a table of the transactions returned by the sql */
186 $table =& new_db_pager('fixed_assets_tbl', $sql, $cols);
188 $table->width = "85%";
189 $table->row_fun = "fa_prepare_row";
191 display_db_pager($table);