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


function get_sql_for_task_revisions_inq($created_on_from, $created_on_to, $project_id, $task_id = 0)
{

            $sql = "SELECT
                        boqg.description boq_group_description,
                        pt.task_id,
                        pt.description task_description,
                        tbr.old_budget,
                        tbr.budget_allocated,
                        tbr.budget_used, 
                        tbr.new_budget,
                        u.real_name approved_by,
                        tbr.approved_on 
                        
                    FROM ".TB_PREF."task_budget_revisions tbr 
                            JOIN ".TB_PREF."users u ON 
                                tbr.approved_by = u.id  
                            JOIN ".TB_PREF."project_tasks pt ON 
                                pt.task_id = tbr.task_id   
                            JOIN ".TB_PREF."project_task_groups ptg ON 
                                pt.task_group_id = ptg.id  
                            LEFT JOIN ".TB_PREF."project_boq_item_groups boqg ON 
                                ptg.boq_group_id = boqg.id  
                            
                             
                    WHERE  
                        tbr.approved_on >= ".db_escape(date2sql($created_on_from))." AND
                        tbr.approved_on	 <= ".db_escape(date2sql($created_on_to))." AND 
                        pt.project_id = ".db_escape($project_id);
            if($task_id > 0){
                $sql .= " AND tbr.task_id = ".db_escape($task_id);
            }
            
            $sql .= " ORDER BY tbr.id";
        

	return $sql;
}


?>