<?php
/**********************************************************************
***********************************************************************/
function add_statutory_deduction($payroll_type, $short_name, 
                        $description, $effective_date, $end_date,
                        $table_id, $inactive)
{
	$created_by = $_SESSION['wa_current_user']->user;
	$created_on = date('Y-m-d H:i:s');
        
        $sql = "INSERT INTO ".TB_PREF."statutory_deductions (
                    payroll_type, short_name, 
                    description, effective_date, end_date,
                    table_id, inactive, 
                    created_by, created_on) 
		VALUES ("
                    .db_escape($payroll_type).",".db_escape($short_name).", "
                    .db_escape($description).", ".db_escape(date2sql($effective_date)).", ".db_escape(date2sql($end_date)).", "
                    .db_escape($table_id).", ".db_escape($inactive).", "
                    .db_escape($created_by).", ".db_escape($created_on).")";
	
	db_query($sql,"Statutory deduction record could not be added");		
}

function update_statutory_deduction($selected_id, $short_name, 
                        $description, $effective_date, $end_date,
                        $table_id, $inactive)
{
	                
    $updated_by = $_SESSION['wa_current_user']->user;
    $updated_on = date('Y-m-d H:i:s');
     	
    $sql = "UPDATE ".TB_PREF."statutory_deductions "
                . "SET "
                    . "short_name=".db_escape($short_name).", "
                    . "description=".db_escape($description).", "
                    . "effective_date=".db_escape(date2sql($effective_date)).","
                    . "end_date=".db_escape(date2sql($end_date)).","
                    . "table_id=".db_escape($table_id).","
                    . "inactive=".db_escape($inactive).","
                    . "updated_by=".db_escape($updated_by).","
                    . "updated_on=".db_escape($updated_on)
                . "WHERE "
                    . "id=".db_escape($selected_id);
	
	db_query($sql,"Statutory deduction could not be updated");		
}

function get_statutory_deductions($payroll_type)
{
	$sql = "SELECT *    
		FROM "
                    .TB_PREF."statutory_deductions   
                WHERE 
                    payroll_type=".db_escape($payroll_type)."   
                ORDER BY effective_date DESC";	
	
	return db_query($sql,"Statutory deductions could not be retreived");
}

function get_statutory_deduction_detail($selected_id)
{
	$sql = "SELECT *    
		FROM "
                    .TB_PREF."statutory_deductions   
                WHERE 
                    id = ".db_escape($selected_id);	
	
	$result = db_query($sql,"Statutory deduction detail could not be retreived");
        return db_fetch($result);
}

function delete_statutory_deduction($id)
{

    $sql="DELETE FROM ".TB_PREF."statutory_deductions WHERE id=".db_escape($id);
    
    db_query($sql,"Table value could not be deleted");
}


?>