<?php

function get_boq_item_group_budget_details_with_target_budget_details($from_project_id, $from_boq_group_id, $to_project_id) {
    $sql = "SELECT ptg.id from_task_group_id,
                ptg.code from_budget_group_code,
                ptg.description from_budget_group_description,
                ptg.long_description from_budget_group_long_description,
                ptg.boq_group_id from_boq_group_id,
                ptg.type_id from_boq_group_type_id,
                ptg.start_date,
                ptg.end_date,
                pt.*,
                t_pt.task_id to_task_id,
                t_pt.task_code to_task_code,
                t_pt.description to_description, 
                t_pt.budget to_budget, 
                t_pt.new_budget to_new_budget, 
                t_pt.detail_type_code to_detail_type_code, 
                t_pt.task_group_id to_task_group_id,
                t_cmp.id to_boq_item_componet_id
            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 
                LEFT JOIN ".TB_PREF."project_tasks t_pt 
                    ON t_pt.task_code = pt.task_code 
                        AND t_pt.project_id = ". db_escape($to_project_id)."  
                LEFT JOIN ".TB_PREF."project_boq_item_components t_cmp  
                    ON t_pt.task_id = t_cmp.id 
            WHERE ptg.project_id = ". db_escape($from_project_id)."  
                AND ptg.boq_group_id = ".db_escape($from_boq_group_id)." 
            ORDER BY ptg.code ";
        
	return db_query($sql, "get_boq_item_group_budget_details_with_target_budget_details");
}

?>