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


function add_project_pl_report_wip_entry($year_code, $month_code, $project_id, $wip_type_id, $value, $department_id)
{
    $updated_by = $_SESSION['wa_current_user']->user;
    $updated_on = date('Y-m-d H:i:s');
    
    $sql = "INSERT INTO ".TB_PREF."project_wip_costs
                    (year_code, month_code,
                        project_id, wip_type_id, 
                        value, department_id, 
                        updated_by, updated_on)        
            VALUES  (".db_escape($year_code).", ".db_escape($month_code).", 
                        ".db_escape($project_id).", ".db_escape($wip_type_id).", 
                        ".db_escape($value).", ".db_escape($department_id).", 
                        ".db_escape($updated_by).", ".db_escape($updated_on).")";
    
    db_query($sql);
}





function delete_project_pl_report_wip_entry($year_code, $month_code, $department_id)
{
    $sql = "DELETE FROM ".TB_PREF."project_wip_costs 
            WHERE department_id=".db_escape($department_id)." 
                    AND year_code =".db_escape($year_code)." 
                    AND month_code =".db_escape($month_code);
    db_query($sql);
    
}


function get_project_pl_report_wip_entries($year_code, $month_code, $department_id)
{    				
    $sql = "SELECT pm.description, 
                    wip.value_name wip_type_name,
                    pm.project_id,
                    wip.id wip_type_id,
                    rwip.value,
                    dm.debtor_ref,
                    dm.name customer_name,  
                    pm.department_id 
            FROM ".TB_PREF."projects_master pm 			
                JOIN ".TB_PREF."list_values wip ON 			
                    wip.list_code = 'PROJECT_WIP_TYPES' 			
                LEFT JOIN ".TB_PREF."project_wip_costs rwip 
                    ON rwip.project_id = pm.project_id  			
                    AND rwip.wip_type_id = wip.id 	
                    AND rwip.year_code =".db_escape($year_code)." 
                    AND rwip.month_code =".db_escape($month_code)." 
                LEFT JOIN ".TB_PREF."debtors_master dm  
                    ON dm.debtor_no = pm.customer_id    
            WHERE pm.department_id =".db_escape($department_id)." 
            ORDER BY pm.description, wip.value_name"; 			
                 
    
    return db_query($sql);

}

function view_project_wip_entries($project_id)
{    				
    $sql = "SELECT pm.description, 
                    wip.value_name wip_type_name,
                    pm.project_id,
                    wip.id wip_type_id,
                    rwip.value 			
            FROM ".TB_PREF."projects_master pm 			
                JOIN ".TB_PREF."list_values wip ON 			
                    wip.list_code = 'PROJECT_WIP_TYPES' 			
                JOIN ".TB_PREF."project_wip_costs rwip ON 			
                    rwip.project_id = pm.project_id AND 			
                    rwip.wip_type_id = wip.id 	
            WHERE rwip.project_id =".db_escape($project_id)." 
            ORDER BY pm.description, wip.value_name"; 			
                 
    
    return db_query($sql);

}

?>