<?php




function dashboard_get_gl_budget_account_classes($from_date, $to_date)
{
	$sql = "SELECT DISTINCT cc.* 
                FROM ".TB_PREF."budget_trans bt  
                    JOIN ".TB_PREF."chart_master cm  
                        ON cm.account_code = bt.account 
                    JOIN ".TB_PREF."chart_types ct 
                        ON ct.id = cm.account_type 
                    JOIN ".TB_PREF."chart_class cc 
                        ON cc.cid = ct.class_id  
                WHERE bt.tran_date >= ".db_escape($from_date)." 
                    AND bt.tran_date <= ".db_escape($to_date)."  
                    ORDER BY cc.ctype";

	return db_query($sql, "dashboard_get_gl_budget_account_classes");
}


function dashboard_get_gl_budget_account_types($from_date, $to_date, $class_id)
{
	$sql = "SELECT DISTINCT ct.* 
                FROM ".TB_PREF."budget_trans bt  
                    JOIN ".TB_PREF."chart_master cm  
                        ON cm.account_code = bt.account 
                    JOIN ".TB_PREF."chart_types ct 
                        ON ct.id = cm.account_type  
                WHERE bt.tran_date >= ".db_escape($from_date)." 
                    AND bt.tran_date <= ".db_escape($to_date)."  
                    AND ct.class_id = ".db_escape($class_id)."  
                    ORDER BY ct.position";

	return db_query($sql, "dashboard_get_gl_budget_account_classes");
}


function dashboard_get_gl_budget_accounts($from_date, $to_date, $account_type)
{
	$sql = "SELECT DISTINCT cm.* 
                FROM ".TB_PREF."budget_trans bt  
                    JOIN ".TB_PREF."chart_master cm  
                        ON cm.account_code = bt.account  
                WHERE bt.tran_date >= ".db_escape($from_date)." 
                    AND bt.tran_date <= ".db_escape($to_date)."  
                    AND cm.account_type = ".db_escape($account_type)."  
                    ORDER BY cm.account_code";

	return db_query($sql, "dashboard_get_gl_budget_accounts");
}

//--------------------------------------------------------------------------------

function dashboard_get_gl_budget_account_month_value($from_date, $to_date, $account)
{
	$sql = "SELECT SUM(amount) budget 
                FROM ".TB_PREF."budget_trans
		WHERE account=".db_escape($account)." 
                    AND tran_date >= ".db_escape($from_date)." 
                    AND tran_date <= ".db_escape($to_date);
        
	$result = db_query($sql,"dashboard_get_gl_budget_account_month_value");

	return db_result_value($result, "budget"); 
        
} 
