Skip to content

Instantly share code, notes, and snippets.

@universal
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save universal/e7fa800218d5fff9c331 to your computer and use it in GitHub Desktop.

Select an option

Save universal/e7fa800218d5fff9c331 to your computer and use it in GitHub Desktop.
class Row
attr_accessor :supervisor_name, :name, :emp_pending, :sup_pending, :approved
def to_s
"Test #{@supervisor_name}, #{@name}, #{@emp_pending}, #{@sup_pending}, #{@approved}, #{total}, #{status}"
end
def total
@emp_pending + @sup_pending + @approved
end
def status
if @total == @approved && @total >= 3 then
'C'
elsif @approved == @total && @total < 3 then
'E'
elsif @emp_pending >= 1 then
'E'
elsif @sup_pending >= 1 then
'S'
else
'-'
end
end
def percentage
if (@total.nil?) then
puts "########## No Goals because... Approved: #{approved}. Total: #{total} boolean: #{(@total.nil?) || (@total == 0)}"
puts "########## Total because... emp_pending: #{@emp_pending}. sup_pending: #{@sup_pending}. approved: #{@approved}"
"No Goals"
else
( @approved / @total * 100).round(0).to_s + "%"
end
end
end
require 'to_xls'
resultArr = Array.new
Employee.all.each do |employee|
begin
row = Row.new
row.supervisor_name = User.find_employee(employee.ivantage_employee.SupervisorEmpID).display_name unless employee.ivantage_employee.nil?
row.name = employee.display_name
row.emp_pending = employee.current_year_employee_pending_goals.count
row.sup_pending = employee.current_year_supervisor_pending_goals.count
row.approved = employee.current_year_approved_goals.count
puts "######"
puts "######"
puts "######"
puts "Employee #{row.to_s}"
puts "######"
resultArr << row
rescue
end
end
File.open("output.xls", "w") do |f|
f.write resultArr.to_xls :columns => [:supervisor_name, :name, :emp_pending,
:sup_pending, :approved, :total, :percentage, :status]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment