<?php
/**********************************************************************
***********************************************************************/
function view_task_group_header($task_group_id)
{

		$sql = "SELECT tg.*,
                        tn.value_name type_name,
                        boqg.code boq_group_code,
                        boqg.description boq_group_description 
                FROM ".TB_PREF."project_task_groups tg 
                        LEFT JOIN ".TB_PREF."list_values tn ON 
                                tg.type_id = tn.id 
                        LEFT JOIN ".TB_PREF."project_boq_item_groups boqg ON 
                                tg.boq_group_id = boqg.id 
                        
                WHERE tg.id = ".db_escape($task_group_id);

	$result = db_query($sql,"Could not view_task_group_header");
    
    return db_fetch($result);
}


function view_boq_item_header($boq_item_id)
{

		$sql = "SELECT i.*,
                        tn.value_name type_name,
                        boqg.code boq_group_code,
                        boqg.description boq_group_description,
                        tx.name tax_group_name 
                FROM ".TB_PREF."project_boq_items i  
                        LEFT JOIN ".TB_PREF."list_values tn ON 
                                i.type_id = tn.id 
                        LEFT JOIN ".TB_PREF."tax_groups tx ON 
                                i.tax_group_id = tx.id 
                        LEFT JOIN ".TB_PREF."project_boq_item_groups boqg ON 
                                i.group_id = boqg.id 
                        
                WHERE i.id = ".db_escape($boq_item_id);

	$result = db_query($sql,"Could not view_task_group_header");
    
    return db_fetch($result);
}


function view_boq_item_components($boq_item_id)
{

    $sql = "SELECT c.*,
                    dtn.value_name detail_type_name,
                    dtn.value_code 
            FROM ".TB_PREF."list_values dtn  
                    LEFT JOIN ".TB_PREF."project_boq_item_components c ON 
                            c.detail_type_code = dtn.value_code AND 
                            c.boq_item_id = ".db_escape($boq_item_id)."                                 
            WHERE dtn.list_code = 'PROJECT_TASK_DETAIL_TYPES' 
            ORDER BY dtn.value_name "; 

        
	return db_query($sql,"Could not get_boq_item_components");
    
}




function get_boq_item_group_budget_details($project_id, $boq_group_id)
{
 
        $sql = "SELECT ptg.code budget_group_code,
                        ptg.description budget_group_description,
                        pt.* 
                FROM ".TB_PREF."project_task_groups ptg 
                    JOIN ".TB_PREF."project_tasks pt 
                        ON pt.task_group_id = ptg.id 
                        AND pt.project_id = ptg.project_id  
                WHERE ptg.project_id =". db_escape($project_id)." AND 
                        ptg.boq_group_id=".  db_escape($boq_group_id);          
        
	return db_query($sql,"get_boq_item_group_budget_details");
    
}

