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

function get_payroll_attendance_details($selected_id){
    	$sql = "SELECT pas.* ,
                        em.initials, em.first_name, em.middle_name, em.last_name,
                        lv.value_code, lv.value_name,
                        st.value_name status_name 
                FROM ".TB_PREF."payroll_attendance_summary pas, 
                        ".TB_PREF."employee_master em,
                        ".TB_PREF."list_values lv,  
                        ".TB_PREF."list_values st  
                WHERE payroll_run_id = ".db_escape($selected_id)." AND 
                        pas.employee_code = em.employee_code AND 
                        lv.list_code = 'ATTENDANCE_ALLOWANCES' AND 
                        pas.component = lv.value_code AND 
                        pas.status_code = st.value_code AND st.list_code = 'ATTENDANCE_STATUS' ";
	
            return db_query($sql,"Could not retrieve payroll attendance summary");	
    
}

function update_payroll_attendance($id, $granted_days, $comments, $approved)
{
         $updated_by = $_SESSION['wa_current_user']->user;
         $updated_on = date('Y-m-d H:i:s');
         
   
    $sql = "UPDATE ".TB_PREF."payroll_attendance_summary  
                SET 
                comment = ".db_escape($comments).",
                granted_days = ".db_escape($granted_days).",
                status_code = ".db_escape($approved).",
                updated_by = ".db_escape($updated_by).",
                updated_on = ".db_escape($updated_on)."
                WHERE id = ".db_escape($id);

        db_query($sql,"Payroll attendance summary could not be updated.");

        return db_num_affected_rows(); 
}
function approve_payroll_attendance($id)
{
    $id_user = $_SESSION['wa_current_user']->user;
    $datetime = date('Y-m-d H:i:s');
    
	$sql = "UPDATE ".TB_PREF."payroll_attendance_summary 
            SET status_code = ".db_escape(ATD_APPROVED).", 
                approved_by = ".db_escape($id_user).",
                approved_on = ".db_escape($datetime)."
        	WHERE id = ".db_escape($id)." " ;

	db_query($sql,"Payroll attendance summary could not be updated");        
}
?>