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


function select_nopay_references($payroll_id)
{
   $sql = "SELECT pnr.*, 
                lv.value_name emp_type, 
                lv1.value_name ref_value
       FROM ".TB_PREF."payroll_nopay_references pnr, 
           ".TB_PREF."list_values lv, 
              ".TB_PREF."list_values lv1 
           WHERE payroll_id =".  db_escape($payroll_id)." AND 
               lv.list_code = 'EMPLOYMENT_TYPES' AND 
               pnr.employment_type_id = lv.id AND 
               lv1.list_code = 'SALARY_TOTALS' AND 
               pnr.nopay_reference_value_id = lv1.id 
               ";
   
                    
    return  db_query($sql, "Nopay reference could not be retrieved");
    
}

function get_nopay_refercnce_details($id)
{
	$sql="SELECT * FROM ".TB_PREF."payroll_nopay_references WHERE id=".db_escape($id);

	$result = db_query($sql,"Nopay reference could not be retrieved");

	return db_fetch($result);
}


function write_nopay_reference($selected_id, $employment_type_id, $nopay_reference_value_id, $days_factor, $payroll_id)
{
            $user = $_SESSION['wa_current_user']->user;
            $date = date('Y-m-d H:i:s');
    
    if($selected_id > 0){
        $sql = "UPDATE ".TB_PREF."payroll_nopay_references SET
                employment_type_id = ".db_escape($employment_type_id).",
                nopay_reference_value_id = ".db_escape($nopay_reference_value_id).",
                days_factor = ".db_escape($days_factor).", 
                    updated_by=".db_escape($user).",
                    updated_on=".db_escape($date)."     
        	WHERE id = ".db_escape($selected_id);
    }
    else{
        $sql = "INSERT INTO ".TB_PREF."payroll_nopay_references
			(employment_type_id, nopay_reference_value_id, days_factor, payroll_id, created_by, created_on) 
                        VALUES( ".db_escape($employment_type_id).", ".db_escape($nopay_reference_value_id).","
                            .db_escape($days_factor).",".db_escape($payroll_id).","
                            .db_escape($user).", ".db_escape($date)."
                            )";
    }
		
    db_query($sql,"Nopay reference could not be updated");
}

function delete_nopay_reference($id)
{
	$sql="DELETE FROM ".TB_PREF."payroll_nopay_references WHERE id=".db_escape($id);

	db_query($sql,"Nopay reference could not be deleted");
}
?>