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

function insert_payroll_settings($payroll_id, $rounding_off_reference_id, $rounding_off_to_amount, $brought_forward_value_id, 
                                    $rounded_off_salary_id, $carried_forward_value_id)
{
        $created_by = $_SESSION['wa_current_user']->user;
        $created_on = date('Y-m-d H:i:s');
        
        
	$sql = "INSERT INTO ".TB_PREF."payroll_settings(
                        payroll_id, rounding_off_reference_id,
                        rounding_off_to_amount, brought_forward_value_id, 
                        rounded_off_salary_id, carried_forward_value_id, 
                        created_by, created_on) 
                VALUES ("
                        .db_escape($payroll_id).", ".db_escape($rounding_off_reference_id). ", "
                        .db_escape($rounding_off_to_amount). ", ".db_escape($brought_forward_value_id). ", "
                        .db_escape($rounded_off_salary_id). ", ".db_escape($carried_forward_value_id). ", "
                        .db_escape($created_by).", ".db_escape($created_on).")";

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

function update_payroll_settings($selected_id, $payroll_id, $rounding_off_reference_id, $rounding_off_to_amount, $brought_forward_value_id, 
                                    $rounded_off_salary_id, $carried_forward_value_id)
{
        $updated_by = $_SESSION['wa_current_user']->user;
        $updated_on = date('Y-m-d H:i:s');
    
        $sql = "UPDATE ".TB_PREF."payroll_settings 
                SET 
                    rounding_off_reference_id=".$rounding_off_reference_id.",
                    rounding_off_to_amount=".$rounding_off_to_amount.",
                    brought_forward_value_id=".$brought_forward_value_id.",
                    rounded_off_salary_id=".$rounded_off_salary_id.",
                    carried_forward_value_id=".$carried_forward_value_id.",
                    updated_by=".db_escape($updated_by).",
                    updated_on=".db_escape($updated_on)." 
		WHERE id=".db_escape($selected_id)." AND 
                    payroll_id = ".db_escape($payroll_id);
        
	db_query($sql,"Payroll settings could not be updated");
}

function get_payroll_settings($payroll_id)
{
   $sql = "SELECT * FROM ".TB_PREF."payroll_settings WHERE payroll_id =".  db_escape($payroll_id);
                    
    $result =  db_query($sql, "Payroll settings could not be retrieved");
    
    return db_fetch($result);
}


?>