<?php


function get_sql_for_job_cost_adjustments_inquiry($filter, $from, $to, $ref='', $tran_id=0) 
{
    $sql = "SELECT  jca.* 
            FROM ".TB_PREF."job_cost_additions as jca 
            WHERE jca.tran_date >= ". db_escape(date2sql($from)). "'
            AND jca.tran_date <= '" . db_escape(date2sql($to)) ; 
    
    
    if ($ref) {
        $sql .= " AND jca.reference LIKE ". db_escape("%$ref%");
    }
    if ($tran_id > 0) {
        $sql .= " AND jca.trans_no = ". db_escape($tran_id);
    }
    if ($filter > 0) {
        $sql .= " AND jca.type=".db_escape($filter);
    }
    


//    $sql .= " GROUP BY gl.tran_date, a.gl_seq, gl.type, gl.type_no";
    return $sql;
}


function view_job_cost_adjustment_header($type, $trans_no)
{

    $sql = "SELECT jca.*,
                pm.description project_description,
                ps.description site_description 
               
            FROM ".TB_PREF."job_cost_additions jca  
                JOIN ".TB_PREF."projects_master pm   
                    ON pm.project_id = jca.project_id 
                JOIN ".TB_PREF."project_sites ps   
                    ON ps.id = jca.project_site_id 
            WHERE jca.type = ".db_escape($type)." 
                AND jca.trans_no = ".db_escape($trans_no);
    
        $result = db_query($sql, "view_job_cost_adjustment_header");
        return db_fetch($result);
}


function view_job_cost_adjustment_details($trans_no, $type) {
    $sql = "SELECT ard.* 
            FROM ".TB_PREF."job_cost_addition_details ard  
            WHERE ard.trans_no = ".db_escape($trans_no)." 
                AND ard.type = ".db_escape($type);
    
        return db_query($sql, "get_job_cost_addition_details");
}