<?php
/**********************************************************************
***********************************************************************/


function save_asset_details($asset_id, $asset_code, $description, $long_description, $multiple_items, $asset_type_name,
                            $asset_group_name, $asset_subgroup_name, $asset_category_name, $hired, $rate_category_name,
                            $asset_serial, $make, $model, $useful_life, $extended_life, 
                            $po_number, $purchase_value, $current_value, $owner_project_name, $inactive, $message='')
{
    $sql = "INSERT INTO import_assets
            (asset_id, asset_code, description, 
            long_description, multiple_items, asset_type_name,
            asset_group_name, asset_subgroup_name, asset_category_name, 
            hired, rate_category_name,
            asset_serial, make, model, useful_life, extended_life, po_number,
            purchase_value, current_value, inactive,
            owner_project_name, message)
            
        VALUES
        (".db_escape($asset_id).", ".db_escape($asset_code).", ".db_escape($description).",
            ".db_escape($long_description).",".db_escape($multiple_items).",".db_escape($asset_type_name).",
            ".db_escape($asset_group_name).",".db_escape($asset_subgroup_name).",".db_escape($asset_category_name).",  
            ".db_escape($hired).",".db_escape($rate_category_name).",
            ".db_escape($asset_serial).",".db_escape($make).", 
            ".db_escape($model).",".db_escape($useful_life).",
            ".db_escape($extended_life).",".db_escape($po_number).", 
            ".db_escape($purchase_value).",".db_escape($current_value).",".db_escape($inactive).",        
            ".db_escape($owner_project_name).",".db_escape($message).")";
    
    db_query($sql);
    
}


function delete_existing_assets()
{
    $sql = "DELETE FROM import_assets";
    
    db_query($sql);
    
}


function get_assets_data()
{
    $sql = "SELECT *
            FROM import_assets
            WHERE 1=1";
    
    return db_query($sql);    
}


function get_project_id_by_name($owner_project_name)
{
    $sql = "SELECT *
            FROM ".TB_PREF."projects_master
            WHERE description=".db_escape($owner_project_name);
    
    $result = db_query($sql);
   // return db_fetch($result);
      if(db_num_rows($result) > 0){
        $row = db_fetch($result);
        return array("success" => true, "message" => $row['project_id']);
    }
	
	return array("success" => false, "message" => "Unknown project name $owner_project_name");
}
    

function get_project_id_by_id($owner_project_name)
{
    $sql = "SELECT *
            FROM ".TB_PREF."projects_master
            WHERE project_id = ".db_escape($owner_project_name);
    
    $result = db_query($sql);
   // return db_fetch($result);
      if(db_num_rows($result) > 0){
        $row = db_fetch($result);
        return array("success" => true, "message" => $row['project_id']);
    }
	
	return array("success" => false, "message" => "Unknown project id $owner_project_name");
}
    




?>