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

function add_production_schedule($description,   
                    $period_start_date, $period_end_date, 
                    $status)
{
        $created_by = $_SESSION['wa_current_user']->user;
        $created_on = date('Y-m-d H:i:s');
        
        
	$sql = "INSERT INTO ".TB_PREF."production_schedule (
                    description,   
                    period_start_date, period_end_date, 
                    status, 
                    created_by, created_on) 
                VALUES ("
                    .db_escape($description).", "
                    .db_escape($period_start_date). ", ".db_escape($period_end_date).", "
                    .db_escape($status).", "
                    .db_escape($created_by).", ".db_escape($created_on).")";
        
        db_query($sql,"Payroll run could not be added");

}


function update_production_schedule($rec_id, $description, 
                    $period_start_date, $period_end_date, 
                    $status)
{
         $updated_by = $_SESSION['wa_current_user']->user;
         $updated_on = date('Y-m-d H:i:s');

        $sql = "UPDATE ".TB_PREF."production_schedule 
                SET 
                    description=".db_escape($description).",
                    period_start_date =".db_escape($period_start_date).",
                    period_end_date =".db_escape($period_end_date).",
                    status =".db_escape($status).",
                    updated_by=".db_escape($updated_by).",
                    updated_on=".db_escape($updated_on)." 
                WHERE id=".db_escape($rec_id);

        db_query($sql,"Payroll run could not be added");
            
}

function get_production_schedules(){
    	$sql = "SELECT pr.*,                        
                        lv1.value_name production_schedule_status_name,
                        IF(pr.run_by = 0, '', (SELECT real_name 
                                                FROM ".TB_PREF."users u 
                                                WHERE pr.run_by = u.id)) real_name 
                FROM ".TB_PREF."production_schedule pr,                     
                        ".TB_PREF."list_values lv1 
                WHERE pr.status = lv1.value_code AND lv1.list_code = 'PAYROLL_RUN_STATUS' 
                ORDER BY id ";
	
	$result = db_query($sql,"Could not retrieve production schedules");	
        
        return $result;
    
}

function get_production_schedule_run($selected_id){
    	$sql = "SELECT pr.*   
                FROM ".TB_PREF."production_schedule pr
                WHERE pr.id = ".db_escape($selected_id);
	
	$result = db_query($sql,"Could not get_production_schedule_run");	
        
        return db_fetch($result);
    
}

function delete_production_schedule($selected_id)
{
        $sql = "DELETE    
                FROM ".TB_PREF."production_schedule 
                WHERE id = ".db_escape($selected_id);
	
	$result = db_query($sql,"Could not delete_production_schedule");	
        
       // return db_fetch($result);
    
}



?>