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

           
function get_sql_for_approve_vehicle_requests($current_user_id)
{        
        $sql = "SELECT 
                        vr.id,
                        p.description project,
                        lv.value_name vehicle_type,
                        vp.description vahicle_package,
                        vh.plate_number,
                        vr.from_date_time,
                        vr.to_date_time,
                        c.real_name requestor_name,
                        vr.created_on,
                        vr.approval_status,
                        vr.closed 
                       
                    FROM ".TB_PREF."vehicle_requests vr                             
                            INNER JOIN ".TB_PREF."approvers as apr ON 
                                    vr.next_approval_group_id = apr.approval_group_id  
                            INNER JOIN ".TB_PREF."users c ON  
                                    vr.created_by = c.id  
                            INNER JOIN ".TB_PREF."projects_master p ON
                                    p.project_id = vr.project_id  
                            INNER JOIN ".TB_PREF."user_data_access_groups as udag ON
                                    p.dag_id = udag.dag_id AND 
                                    udag.user_id = apr.user_id   
                            INNER JOIN ".TB_PREF."users u ON 
                                    apr.user_id = u.id                  
                            LEFT JOIN ".TB_PREF."vehicles vh ON
                                    vr.vehicle_id=vh.id 
                            LEFT JOIN ".TB_PREF."list_values lv ON
                                    lv.id=vr.vehicle_type_id
                            LEFT JOIN ".TB_PREF."vehicle_packages vp ON
                                    vp.id=vr.package_id
                        
                    WHERE (vr.approval_status = ".AS_WITH_THE_APPROVER." OR vr.approval_status = ".AS_AWAITING_APPROVAL.") AND 
                            vr.closed = 0 AND apr.user_id = ".$current_user_id;

       
        $sql .= " ORDER BY vr.id ";   
	return $sql;
}


?>