Added comment to SECURE_ONLY constant.
[fa-stable.git] / fixed_assets / inquiry / stock_inquiry.php
index e60d448fb36d21330731fd6480df9d48eb3f1219..424c97038f492eade656a6ffbb22652bf6afcb2b 100644 (file)
@@ -52,37 +52,61 @@ if(get_post('RefreshInquiry'))
 
 function gl_view($row)
 {
-  $row = get_fixed_asset_move($row['stock_id'], ST_JOURNAL);
+       $row = get_fixed_asset_move($row['stock_id'], ST_JOURNAL);
 
-  //if ($row === false)
-    //return "";
-
-  //return get_journal_trans_view_str(ST_JOURNAL, $row["trans_no"], sql2date($row["tran_date"]));
        return get_gl_view_str(ST_JOURNAL, $row["trans_no"]);
 }
 
+function fa_prepare_row($row) {
+       $purchase = get_fixed_asset_purchase($row['stock_id']);
+       if ($purchase !== false) {
+       $row['purchase_date'] = $purchase['tran_date'];
+       $row['purchase_no'] = $purchase['trans_no'];
+       }
+       else {
+       $row['purchase_date'] = NULL;
+       $row['purchase_no'] = NULL;
+       }
+
+       $disposal = get_fixed_asset_disposal($row['stock_id']);
+       if ($disposal !== false) {
+       $row['disposal_date'] = $disposal['tran_date'];
+       $row['disposal_no'] = $disposal['trans_no'];
+       $row['disposal_type'] = $disposal['type'];
+       }
+       else {
+       $row['disposal_date'] = NULL;
+       $row['disposal_no'] = NULL;
+       $row['disposal_type'] = NULL;
+       }       
+       return $row;
+}
+
 function fa_link($row)
 {
-  $url = "inventory/manage/items.php?FixedAsset=1&stock_id=".$row['stock_id'];
+       $url = "inventory/manage/items.php?FixedAsset=1&stock_id=".$row['stock_id'];
 
-       return viewer_link($row['stock_id'], $url);
+       return viewer_link($row['stock_id'], $url);
 }
 
 function depr_method_title($row) {
-  global $depreciation_methods;
-  return $depreciation_methods[$row['depreciation_method']];
+       global $depreciation_methods;
+       return $depreciation_methods[$row['depreciation_method']];
 }
 
-function depr_rate_title($row) {
-  if ($row['depreciation_method'] == 'S')
-    return $row['depreciation_rate'].' years';
-  else
-    return $row['depreciation_rate'].'%';
+function depr_par($row) {
+       if ($row['depreciation_method'] == 'D')
+               return $row['depreciation_rate']*$row['depreciation_factor'].'%';
+       elseif ($row['depreciation_method'] == 'N')
+               return $row['depreciation_rate'].' '._('years'
+               );
+       else
+               return $row['depreciation_rate'].'%';
 }
 
 function status_title($row) {
 
-       if ($row['inactive'] || ($row['disposal_date'] !== NULL))
+       if ($row['inactive'] || ($row['disposal_date'] !== NULL))
                return _("Disposed"); // disposed or saled
        elseif ($row['purchase_date'] === NULL)
                return _("Purchasable"); // not yet purchased
@@ -94,32 +118,35 @@ function status_title($row) {
 function purchase_link($row)
 {
 
-  if ($row['purchase_date'] === null)
-    return "";
+       if ($row['purchase_date'] === NULL)
+       return "";
 
-  return get_supplier_trans_view_str(ST_SUPPRECEIVE, $row["purchase_no"], sql2date($row["purchase_date"]));
+       return get_supplier_trans_view_str(ST_SUPPRECEIVE, $row["purchase_no"], sql2date($row["purchase_date"]));
 }
 
 function disposal_link($row)
 {
-  switch ($row['disposal_type']) {
-    case ST_INVADJUST:
-      return get_inventory_trans_view_str(ST_INVADJUST, $row["disposal_no"], sql2date($row["disposal_date"]));
-    case ST_CUSTDELIVERY:
-           return get_customer_trans_view_str(ST_CUSTDELIVERY, $row["disposal_no"], sql2date($row["disposal_date"]));
-    default:
-      return "";
-  }
+       if ($row['disposal_date'] === NULL)
+       return "";
+
+       switch ($row['disposal_type']) {
+       case ST_INVADJUST:
+               return get_inventory_trans_view_str(ST_INVADJUST, $row["disposal_no"], sql2date($row["disposal_date"]));
+       case ST_CUSTDELIVERY:
+               return get_customer_trans_view_str(ST_CUSTDELIVERY, $row["disposal_no"], sql2date($row["disposal_date"]));
+       default:
+               return "";
+       }
 }
 
 function amount_link($row)
 {
-    return price_format($row['last_cost']);
+    return price_format($row['purchase_cost']);
 }
 
 function depr_link($row)
 {
-    return price_format($row['last_cost'] - $row['material_cost']);
+    return price_format($row['purchase_cost'] - $row['material_cost']);
 }
 
 function balance_link($row)
@@ -139,13 +166,13 @@ $cols = array(
                        _("Class"), 
                        _("UOM") => array('align' => 'center'), 
                        _("Description"),
-                       _("Rate or Lifecycle") => array('fun' => 'depr_rate_title'), 
+                       _("Rate or Lifecycle") => array('fun' => 'depr_par'), 
                        _("Method") => array('fun' => 'depr_method_title'), 
                        _("Status") => array('fun' => 'status_title'), 
                        _("Purchased") => array('fun' => 'purchase_link'),
-                       _("Amount") => array('align'=>'right', 'fun' => 'amount_link'),
+                       _("Initial") => array('align'=>'right', 'fun' => 'amount_link'),
                        _("Depreciations") => array('align'=>'right', 'fun' => 'depr_link'),
-                       _("Balance") => array('align'=>'right', 'fun' => 'balance_link'),
+                       _("Current") => array('align'=>'right', 'fun' => 'balance_link'),
                        _("Liquidation or Sale") => array('align' => 'center', 'fun' => 'disposal_link'), 
                        //array('insert'=>true, 'fun'=>'gl_view'),
                        //array('insert'=>true, 'fun'=>'rm_link'),
@@ -159,6 +186,7 @@ $cols = array(
 $table =& new_db_pager('fixed_assets_tbl', $sql, $cols);
 
 $table->width = "85%";
+$table->row_fun = "fa_prepare_row";
 
 display_db_pager($table);