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


function get_sql_for_stock_asset_transfers_inquiry($ami_id, $project_id, $from_date, $to_date, $asset_id)
{
    $sql = "SELECT ami.*,
                    am.asset_code,
                    am.description asset_description,
                    sm.description stock_description,
                    pm.description project_description,
                    pt.description task_description
                    
                    
            FROM ".TB_PREF."stock_asset_transfers ami
                LEFT JOIN ".TB_PREF."asset_master am ON
                    ami.asset_id = am.asset_id
                    
                LEFT JOIN ".TB_PREF."stock_master sm ON
                    ami.stock_id = sm.stock_id
                    
                LEFT JOIN ".TB_PREF."projects_master pm ON
                    ami.asset_project_id = pm.project_id
                    
                LEFT JOIN ".TB_PREF."project_tasks pt ON
                    ami.asset_task_id = pt.task_id

                                                                         
            WHERE ami.tran_date >=".db_escape(date2sql($from_date))." AND  ami.tran_date <=".db_escape(date2sql($to_date));    
            
   
    if($ami_id > 0){
        $sql .= "AND ami.id=".db_escape($ami_id);
    }
    
    if($project_id > 0){
        $sql .= "AND ami.asset_project_id=".db_escape($project_id);
    }
    
    if($asset_id > 0){
        $sql .= "AND ami.asset_task_id=".db_escape($asset_id);
    }    
    
    return $sql;    
}
        

function view_stock_asset_transfer($asset_material_issue_id)
{
    $sql = "SELECT ami.*,
                    am.asset_id, 
                    am.asset_code,
                    am.description asset_description,
                    apm.description asset_project_description,
                    apt.description asset_task_description,
                    sm.description stock_description,
                    spm.description stock_project_description,
                    spt.description stock_task_description,
                    au.name tran_unit_name,
                    slo.location_name stock_location_name,
                    alo.location_name asset_location_name,
                    dn.value_name department_name,
                    ps.description site_description

            
            FROM ".TB_PREF."stock_asset_transfers ami
                JOIN ".TB_PREF."asset_master am ON
                    ami.asset_id = am.asset_id
                    
                JOIN ".TB_PREF."projects_master apm ON
                    ami.asset_project_id = apm.project_id
                    
                JOIN ".TB_PREF."project_tasks apt ON
                    ami.asset_task_id = apt.task_id
                    
                JOIN ".TB_PREF."stock_master sm ON 
                    ami.stock_id = sm.stock_id
                    
                JOIN ".TB_PREF."projects_master spm ON
                    ami.stock_project_id = spm.project_id
                    
                JOIN ".TB_PREF."project_tasks spt ON
                    ami.stock_task_id = spt.task_id
                    
                JOIN ".TB_PREF."item_units au ON
                    ami.tran_unit = au.abbr
                    
                JOIN ".TB_PREF."asset_locations slo ON
                    ami.stock_location = slo.loc_code 
                    
                JOIN ".TB_PREF."asset_locations alo ON
                    ami.asset_location = alo.loc_code
                    
                JOIN ".TB_PREF."list_values dn ON
                    ami.asset_department_id = dn.id 
                    
                LEFT JOIN ".TB_PREF."project_sites ps ON
                    ami.site_id = ps.id
              
            WHERE ami.id=".db_escape($asset_material_issue_id);
    
    $result = db_query($sql);
    return db_fetch($result);

}



 
 
?>