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


function get_sql_for_project_revisions_inq($created_on_from, $created_on_to, $project_id)
{

        if(!($project_id > 0))
        {
                $project_id = 0;  
        }

            $sql = "SELECT
                        pm.description project_description,
                        pr.start_date,
                        pr.end_date,
                        pr.project_value,
                        pr.approved_cost_budgets_total,
                        pr.approved_overhead_budgets_total,
                        CONCAT(pr.revenue_account, ' - ', ra.account_name) revenue_account,
                        CONCAT(pr.cost_account, ' - ', ca.account_name) cost_account,
                        u.real_name approved_by,
                        pr.created_on approved_on 
                        
                    FROM 
                        ".TB_PREF."project_revisions pr 
                            JOIN ".TB_PREF."projects_master pm ON 
                                pm.project_id = pr.project_id  
                            JOIN ".TB_PREF."users u ON 
                                pr.created_by = u.id  
                            LEFT JOIN ".TB_PREF."chart_master ra ON 
                                pr.revenue_account = ra.account_code  
                            LEFT JOIN ".TB_PREF."chart_master ca ON 
                                pr.cost_account = ca.account_code  
                    WHERE  
                        pr.created_on >= ".db_escape(date2sql($created_on_from))." AND
                        pr.created_on <= ".db_escape(date2sql($created_on_to));
                    
//            if(isset($project_id) && $project_id > 0){
                $sql .= " AND pr.project_id = ".db_escape($project_id);
//            }
            
            $sql .= " ORDER BY pr.id";
        

	return $sql;
}


?>