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

function get_payroll_work_time_deficit_details($selected_id){
    	$sql = "SELECT pwds.*,
                        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_worktime_deficit_summary pwds,
                        ".TB_PREF."employee_master em,
                        ".TB_PREF."list_values lv,  
                        ".TB_PREF."list_values st 
                WHERE payroll_run_id = ".db_escape($selected_id)." AND 
                        pwds.employee_code = em.employee_code AND 
                        lv.list_code = 'WORKTIME_DEFICITS' AND 
                        pwds.component = lv.value_code AND 
                        pwds.status_code = st.value_code AND st.list_code = 'ATTENDANCE_STATUS' ";
	
            return db_query($sql,"Could not retrieve payroll worktime deficit summary");	
    
}

function update_payroll_work_time_deficits($id, $deducted_time ,$comments, $approved)
{
         $updated_by = $_SESSION['wa_current_user']->user;
         $updated_on = date('Y-m-d H:i:s');
        
    $sql = "UPDATE ".TB_PREF."payroll_worktime_deficit_summary 
                SET 
                comment = ".db_escape($comments).",
                deducted_time = ".db_escape($deducted_time).",
                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 worktime deficit summary could not be updated.");

        return db_num_affected_rows(); 
}

function approve_payroll_work_time_deficits($id)
{
    $id_user = $_SESSION['wa_current_user']->user;
    $datetime = date('Y-m-d H:i:s');
    
	$sql = "UPDATE ".TB_PREF."payroll_worktime_deficit_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");        
}
?>