0003871: [Fixed Assets] new patch fix for: 0003866, 0003869
[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         return get_gl_view_str(ST_JOURNAL, $row["trans_no"]);
58 }
59
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'];
65         }
66         else {
67         $row['purchase_date'] = NULL;
68         $row['purchase_no'] = NULL;
69         }
70
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'];
76         }
77         else {
78         $row['disposal_date'] = NULL;
79         $row['disposal_no'] = NULL;
80         $row['disposal_type'] = NULL;
81         }       
82         return $row;
83 }
84
85 function fa_link($row)
86 {
87         $url = "inventory/manage/items.php?FixedAsset=1&stock_id=".$row['stock_id'];
88
89         return viewer_link($row['stock_id'], $url);
90 }
91
92 function depr_method_title($row) {
93         global $depreciation_methods;
94         return $depreciation_methods[$row['depreciation_method']];
95 }
96
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'
102                 );
103         else
104                 return $row['depreciation_rate'].'%';
105 }
106
107 function status_title($row) {
108
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
113     else
114         return _("Active");  // purchased
115
116 }
117
118 function purchase_link($row)
119 {
120
121         if ($row['purchase_date'] === NULL)
122         return "";
123
124         return get_supplier_trans_view_str(ST_SUPPRECEIVE, $row["purchase_no"], sql2date($row["purchase_date"]));
125 }
126
127 function disposal_link($row)
128 {
129         if ($row['disposal_date'] === NULL)
130         return "";
131
132         switch ($row['disposal_type']) {
133         case ST_INVADJUST:
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"]));
137         default:
138                 return "";
139         }
140 }
141
142 function amount_link($row)
143 {
144     return price_format($row['purchase_cost']);
145 }
146
147 function depr_link($row)
148 {
149     return price_format($row['purchase_cost'] - $row['material_cost']);
150 }
151
152 function balance_link($row)
153 {
154     return price_format($row['material_cost']);
155 }
156
157
158 //------------------------------------------------------------------------------------------------
159
160 $sql = get_sql_for_fixed_assets(get_post('show_inactive'));
161
162 $cols = array(
163                         //_("Type") => array('fun'=>'systype_name', 'ord'=>''), 
164                         //_("#") => array('fun'=>'trans_view', 'ord'=>''), 
165                         _("#") => array('fun' => 'fa_link'), 
166                         _("Class"), 
167                         _("UOM") => array('align' => 'center'), 
168                         _("Description"),
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'),
181                         );
182
183 //------------------------------------------------------------------------------------------------
184
185 /*show a table of the transactions returned by the sql */
186 $table =& new_db_pager('fixed_assets_tbl', $sql, $cols);
187
188 $table->width = "85%";
189 $table->row_fun = "fa_prepare_row";
190
191 display_db_pager($table);
192
193 end_form();
194 end_page();