Skip to content
Browse files

employee leave reset bug fix

git-svn-id: file:///svn/fedena2.1/branches/fedena2.1_i18n@1778 1b8ff446-76f8-11e0-a33c-ba5893e5f458
  • Loading branch information...
1 parent 4b1a54a commit f66df821388aa206fdf489b6ece82609068c8830 @foradian foradian committed
Showing with 86 additions and 237 deletions.
  1. +13 −102 app/controllers/employee_attendance_controller.rb
  2. +73 −135 lib/auto_leave_reset.rb
View
115 app/controllers/employee_attendance_controller.rb
@@ -84,7 +84,6 @@ def leave_reset_settings
def update_employee_leave_reset_all
@leave_count = EmployeeLeave.all
@leave_count.each do |e|
- attendance = EmployeeAttendance.find_all_by_employee_id(e.employee_id, :conditions=> "employee_leave_type_id = '#{e.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" )
@leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id)
if @leave_type.status
default_leave_count = @leave_type.max_leave_count
@@ -96,48 +95,15 @@ def update_employee_leave_reset_all
available_leave = balance_leave.to_f
available_leave += default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
else
available_leave = default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
end
else
available_leave = default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
end
end
@@ -171,7 +137,7 @@ def update_department_leave_reset
@employee.each do |e|
@leave_count = EmployeeLeave.find_all_by_employee_id(e)
@leave_count.each do |c|
- attendance = EmployeeAttendance.find_all_by_employee_id(e, :conditions=> "employee_leave_type_id = '#{c.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" )
+ #attendance = EmployeeAttendance.find_all_by_employee_id(e, :conditions=> "employee_leave_type_id = '#{c.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" )
@leave_type = EmployeeLeaveType.find_by_id(c.employee_leave_type_id)
if @leave_type.status
default_leave_count = @leave_type.max_leave_count
@@ -183,48 +149,26 @@ def update_department_leave_reset
available_leave = balance_leave.to_f
available_leave += default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
+# unless attendance.blank?
+# attendance.each do |a|
+# if a.is_half_day
+# leave_taken += (0.5).to_f
+#
+# else
+# leave_taken += (1).to_f
+#
+# end
+# end
+# end
c.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
else
available_leave = default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
c.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
end
else
available_leave = default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
c.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
end
end
@@ -286,7 +230,7 @@ def employee_wise_leave_reset
@employee = Employee.find_by_id(params[:id])
@leave_count = EmployeeLeave.find_all_by_employee_id(@employee.id)
@leave_count.each do |e|
- attendance = EmployeeAttendance.find_all_by_employee_id(@employee.id, :conditions=> "employee_leave_type_id = '#{e.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" )
+ #attendance = EmployeeAttendance.find_all_by_employee_id(@employee.id, :conditions=> "employee_leave_type_id = '#{e.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" )
@leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id)
if @leave_type.status
default_leave_count = @leave_type.max_leave_count
@@ -298,48 +242,15 @@ def employee_wise_leave_reset
available_leave = balance_leave.to_f
available_leave += default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
else
available_leave = default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
end
else
available_leave = default_leave_count.to_f
leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
-
- else
- leave_taken += (1).to_f
-
- end
- end
- end
e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
end
end
View
208 lib/auto_leave_reset.rb
@@ -1,145 +1,83 @@
class AutoLeaveReset
- def auto_leave_reset
- reset_status = Configuration.find_by_config_key("AutomaticLeaveReset")
- last_reset = Configuration.find_by_config_key("LastAutoLeaveReset")
- reset_period = Configuration.find_by_config_key("LeaveResetPeriod")
- if reset_status.config_value == '1'
- if last_reset.config_value.nil?
- start_date = Configuration.find_by_config_key("FinancialYearStartDate")
- reset_date = start_date.config_value.to_date + reset_period.config_value.to_i.months
- if reset_date <= Date.today.to_date
- leave_count = EmployeeLeave.all
- leave_count.each do |e|
- attendance = EmployeeAttendance.find_all_by_employee_id(e.employee_id, :conditions=> "employee_leave_type_id = '#{e.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" )
- leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id)
- if leave_type.status
- default_leave_count = leave_type.max_leave_count
- if leave_type.carry_forward
- leave_taken = e.leave_taken
- available_leave = e.leave_count
- if leave_taken <= available_leave
- balance_leave = available_leave - leave_taken
- available_leave = balance_leave.to_f
- available_leave += default_leave_count.to_f
- leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
- available_leave += (0.5).to_f
- else
- leave_taken += (1).to_f
- available_leave += (1).to_f
- end
- end
- end
- e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
- else
- available_leave = default_leave_count.to_f
- leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
- available_leave += (0.5).to_f
- else
- leave_taken += (1).to_f
- available_leave += (1).to_f
- end
- end
- end
- e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
- end
- else
- available_leave = default_leave_count.to_f
- leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
- available_leave += (0.5).to_f
- else
- leave_taken += (1).to_f
- available_leave += (1).to_f
- end
- end
- end
- e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
- end
- end
- end
- last_reset.update_attributes(:config_value => Date.today.to_date)
-
+ def auto_leave_reset
+ reset_status = Configuration.find_by_config_key("AutomaticLeaveReset")
+ last_reset = Configuration.find_by_config_key("LastAutoLeaveReset")
+ reset_period = Configuration.find_by_config_key("LeaveResetPeriod")
+ if reset_status.config_value == '1'
+ if last_reset.config_value.nil?
+ start_date = Configuration.find_by_config_key("FinancialYearStartDate")
+ reset_date = start_date.config_value.to_date + reset_period.config_value.to_i.months
+ if reset_date <= Date.today.to_date
+ leave_count = EmployeeLeave.all
+ leave_count.each do |e|
+ leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id)
+ if leave_type.status
+ default_leave_count = leave_type.max_leave_count
+ if leave_type.carry_forward
+ leave_taken = e.leave_taken
+ available_leave = e.leave_count
+ if leave_taken <= available_leave
+ balance_leave = available_leave - leave_taken
+ available_leave = balance_leave.to_f
+ available_leave += default_leave_count.to_f
+ leave_taken = 0
+
+ e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
+ else
+ available_leave = default_leave_count.to_f
+ leave_taken = 0
+
+ e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
end
- else
- reset_date = last_reset.config_value.to_date + reset_period.config_value.to_i.months
- if reset_date <= Date.today.to_date
- leave_count = EmployeeLeave.all
- leave_count.each do |e|
- attendance = EmployeeAttendance.find_all_by_employee_id(e.employee_id, :conditions=> "employee_leave_type_id = '#{e.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" )
- leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id)
- if leave_type.status
- default_leave_count = leave_type.max_leave_count
- if leave_type.carry_forward
- leave_taken = e.leave_taken
- available_leave = e.leave_count
- if leave_taken <= available_leave
- balance_leave = available_leave - leave_taken
- available_leave = balance_leave.to_f
- available_leave += default_leave_count.to_f
- leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
- available_leave += (0.5).to_f
- else
- leave_taken += (1).to_f
- available_leave += (1).to_f
- end
- end
- end
- e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
- else
- available_leave = default_leave_count.to_f
- leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
- available_leave += (0.5).to_f
- else
- leave_taken += (1).to_f
- available_leave += (1).to_f
- end
- end
- end
- e.update_attributes(:leave_taken => 0.0,:leave_count => available_leave, :reset_date => Date.today)
- end
- else
- available_leave = default_leave_count.to_f
- leave_taken = 0
- unless attendance.blank?
- attendance.each do |a|
- if a.is_half_day
- leave_taken += (0.5).to_f
- available_leave += (0.5).to_f
- else
- leave_taken += (1).to_f
- available_leave += (1).to_f
- end
- end
- end
- e.update_attributes(:leave_taken => 0.0,:leave_count => available_leave, :reset_date => Date.today)
- end
- end
- end
- last_reset.update_attributes(:config_value => Date.today.to_date)
+ else
+ available_leave = default_leave_count.to_f
+ leave_taken = 0
+
+ e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
+ end
+ end
+ end
+ last_reset.update_attributes(:config_value => Date.today.to_date)
+
+ end
+ else
+ reset_date = last_reset.config_value.to_date + reset_period.config_value.to_i.months
+ if reset_date <= Date.today.to_date
+ leave_count = EmployeeLeave.all
+ leave_count.each do |e|
+ leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id)
+ if leave_type.status
+ default_leave_count = leave_type.max_leave_count
+ if leave_type.carry_forward
+ leave_taken = e.leave_taken
+ available_leave = e.leave_count
+ if leave_taken <= available_leave
+ balance_leave = available_leave - leave_taken
+ available_leave = balance_leave.to_f
+ available_leave += default_leave_count.to_f
+ leave_taken = 0
+
+ e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today)
+ else
+ available_leave = default_leave_count.to_f
+ leave_taken = 0
+
+ e.update_attributes(:leave_taken => 0.0,:leave_count => available_leave, :reset_date => Date.today)
end
+ else
+ available_leave = default_leave_count.to_f
+ leave_taken = 0
+
+ e.update_attributes(:leave_taken => 0.0,:leave_count => available_leave, :reset_date => Date.today)
+ end
end
+ end
+ last_reset.update_attributes(:config_value => Date.today.to_date)
end
+ end
end
+ end
end

0 comments on commit f66df82

Please sign in to comment.
Something went wrong with that request. Please try again.