Ahmed.zain

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in calculate leaves on yearly basis

Employee is allowed 15 leaves in year for example. My function is calculating the total leaves of allover . But I want to calculate the since joining date and when year is complete since joining date the allowed leaves is update to 15.The method which is calculating total leaves of employee
def calculate_availed_leave
taken_leaves = self.employee.leaves.where(status: "Approved").count
availed_leaves = self.employee.allowed_leaves - taken_leaves
self.employee.update(availed_leaves: availed_leaves)
end
but i want to calcule on yearly basis