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


function get_sql_for_pca_view($project_id = null, $task_id = null, $filterType = null, 
            $updated_on_from = null, $updated_on_to = null, $budject_id=0)
{
        $filter = "";

        if(!($project_id > 0))
        {
                $project_id = 0;        
        }
        
        if($task_id > 0)
        {
                $filter .= " AND pca.task_id = ".db_escape($task_id);            
        }
        
        if($budject_id > 0)
        {
                $filter .= " AND pca.task_id = ".db_escape($budject_id);            
        }
        
        if ($filterType > 0)
        {
                $filter .= " AND pca.tran_type = ".db_escape($filterType); 
        }

        //$filter = "";

            $sql = "SELECT pca.id,
                        boqg.description boq_item_group_description,
                        pca.task_id,
                        pt.description task_description,
                        pca.tran_type,
                        pca.tran_no,
                        pca.updated_on,
                        pca.amount
                    FROM 
                        ".TB_PREF."task_cost_allocations pca 
                            JOIN ".TB_PREF."project_tasks pt ON 
                                pca.task_id = pt.task_id 
                            JOIN ".TB_PREF."projects_master pm ON 
                                pt.project_id = pm.project_id 
                            JOIN ".TB_PREF."project_task_groups ptg ON 
                                pt.task_group_id = ptg.id 
                            LEFT JOIN ".TB_PREF."project_boq_item_groups boqg ON 
                                ptg.boq_group_id = boqg.id 
                    WHERE  
                        pca.updated_on >= ".db_escape(date2sql($updated_on_from))."AND
                        pca.updated_on <= ".db_escape(date2sql($updated_on_to))."AND 
                        pt.project_id = ".db_escape($project_id)." "
                        .$filter." 
                    ORDER BY
                        pca.id";
        

	return $sql;
}



function view_project_cost_allocation_adjustment($cost_id)
{
  
       $sql = "SELECT
                        pm.description project_description,
                        lv.value_name task_description ,
                        pc.ref_tran_type,
                        pc.ref_tran_no,
                        pc.deduction,
                        pc.tran_date,
                        pc.amount,
                        pc.comment
                    FROM 
                        ".TB_PREF."task_allocation_adjustments pc,
                        ".TB_PREF."projects_master pm,
                        ".TB_PREF."project_tasks pt, 
                        ".TB_PREF."list_values lv 
                    WHERE 
                        pc.task_id = pt.task_id AND 
                        pt.type_id = lv.id AND
                        pt.project_id = pm.project_id AND 
                        pc.id = ".db_escape($cost_id);
        
        //$filter = "";
        $result = db_query($sql,"Cound not view_project_cost_allocation_details");
	return db_fetch($result);
}


function view_project_cost_allocation_details($task_id)
{
    $sql = "SELECT
                tca.id,
                tca.tran_type,
                tca.tran_no,
                tca.updated_on,
                tca.amount,
                tca.total_allocation 

            FROM 
                ".TB_PREF."task_cost_allocations tca   

            WHERE  tca.task_id = ".$task_id."
            ORDER BY
                tca.updated_on";
        
    return db_query($sql,"view_project_cost_allocation_details");
}

?>