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


function add_project_task_detail_type($detail_type_code, $category_id, $debit_account, $credit_account)
{	                
    $updated_by = $_SESSION['wa_current_user']->user;
    $updated_on = date('Y-m-d H:i:s');
     	
    $sql = "INSERT INTO ".TB_PREF."project_task_detail_types(
                        detail_type_code, category_id,       
                        debit_account, credit_account,
                        updated_by, updated_on)
            VALUES(".db_escape($detail_type_code)."," .db_escape($category_id).", "        
                    .db_escape($debit_account)."," .db_escape($credit_account).", "        
                    .db_escape($updated_by).", ".db_escape($updated_on).")";
	
	db_query($sql,"Project task detail type categories could not be updated");		
}


function get_project_task_detail_types()
{  	
    $sql = "SELECT dtn.id, 
                    dtn.value_code, 
                    dtn.value_name detail_type_name,
                    dt.category_id detail_type_category_id,
                    dt.debit_account,
                    dt.credit_account  

            FROM ".TB_PREF."list_values dtn  
                LEFT JOIN ".TB_PREF."project_task_detail_types dt ON 
                    dtn.value_code = dt.detail_type_code 

            WHERE dtn.list_code = 'PROJECT_TASK_DETAIL_TYPES' 

            ORDER BY dtn.value_name";


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


function delete_project_task_detail_types()
{
	$sql = "DELETE FROM ".TB_PREF."project_task_detail_types " ;   
                
	
	db_query($sql,"project_task_detail_type_category could not be deleted");

}

function get_task_category_summary($Project_id)
{
    $sql = "SELECT SUM(pt.budget) total_budget, 
                    SUM(pt.new_budget) total_new_budget, 
                    SUM(pt.budget_used) total_budget_used, 
                    SUM(pt.budget_allocated) total_budget_allocated, 
                    cn.value_name category_name 
            FROM ".TB_PREF."list_values cn 
                    JOIN ".TB_PREF."project_task_detail_types dt 
                            ON cn.id = dt.category_id  
                    LEFT JOIN ".TB_PREF."project_tasks pt 
                            ON pt.detail_type_code = dt.detail_type_code 
                                AND pt.project_id = ". db_escape($Project_id)." 
            GROUP by dt.category_id
            ORDER BY cn.value_name";
    
    return db_query($sql,"get_task_category_summary");
}
?>