c456d792823c86c248a316db7eaf6540d2095785
[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_par($row) {
77         if ($row['depreciation_method'] == 'D')
78                 return $row['depreciation_rate']*$row['depreciation_factor'].'%';
79         elseif ($row['depreciation_method'] == 'N')
80                 return $row['depreciation_rate'].' '._('years'
81                 );
82         else
83                 return $row['depreciation_rate'].'%';
84 }
85
86 function status_title($row) {
87
88         if ($row['inactive'] || ($row['disposal_date'] !== NULL))
89                 return _("Disposed"); // disposed or saled
90         elseif ($row['purchase_date'] === NULL)
91                 return _("Purchasable"); // not yet purchased
92     else
93         return _("Active");  // purchased
94
95 }
96
97 function purchase_link($row)
98 {
99
100   if ($row['purchase_date'] === null)
101     return "";
102
103   return get_supplier_trans_view_str(ST_SUPPRECEIVE, $row["purchase_no"], sql2date($row["purchase_date"]));
104 }
105
106 function disposal_link($row)
107 {
108   switch ($row['disposal_type']) {
109     case ST_INVADJUST:
110       return get_inventory_trans_view_str(ST_INVADJUST, $row["disposal_no"], sql2date($row["disposal_date"]));
111     case ST_CUSTDELIVERY:
112             return get_customer_trans_view_str(ST_CUSTDELIVERY, $row["disposal_no"], sql2date($row["disposal_date"]));
113     default:
114       return "";
115   }
116 }
117
118 function amount_link($row)
119 {
120     return price_format($row['purchase_cost']);
121 }
122
123 function depr_link($row)
124 {
125     return price_format($row['purchase_cost'] - $row['material_cost']);
126 }
127
128 function balance_link($row)
129 {
130     return price_format($row['material_cost']);
131 }
132
133
134 //------------------------------------------------------------------------------------------------
135
136 $sql = get_sql_for_fixed_assets(get_post('show_inactive'));
137
138 $cols = array(
139                         //_("Type") => array('fun'=>'systype_name', 'ord'=>''), 
140                         //_("#") => array('fun'=>'trans_view', 'ord'=>''), 
141                         _("#") => array('fun' => 'fa_link'), 
142                         _("Class"), 
143                         _("UOM") => array('align' => 'center'), 
144                         _("Description"),
145                         _("Rate or Lifecycle") => array('fun' => 'depr_par'), 
146                         _("Method") => array('fun' => 'depr_method_title'), 
147                         _("Status") => array('fun' => 'status_title'), 
148                         _("Purchased") => array('fun' => 'purchase_link'),
149                         _("Initial") => array('align'=>'right', 'fun' => 'amount_link'),
150                         _("Depreciations") => array('align'=>'right', 'fun' => 'depr_link'),
151                         _("Current") => array('align'=>'right', 'fun' => 'balance_link'),
152                         _("Liquidation or Sale") => array('align' => 'center', 'fun' => 'disposal_link'), 
153                         //array('insert'=>true, 'fun'=>'gl_view'),
154                         //array('insert'=>true, 'fun'=>'rm_link'),
155                         //array('insert'=>true, 'fun'=>'edit_link'),
156                         //array('insert'=>true, 'fun'=>'prt_link'),
157                         );
158
159 //------------------------------------------------------------------------------------------------
160
161 /*show a table of the transactions returned by the sql */
162 $table =& new_db_pager('fixed_assets_tbl', $sql, $cols);
163
164 $table->width = "85%";
165
166 display_db_pager($table);
167
168 end_form();
169 end_page();