Created
September 23, 2014 15:42
-
-
Save EminenceHC/cd1c8e3dc01c819e6d0a to your computer and use it in GitHub Desktop.
Merge tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def payroll | |
pay_period | |
if params['pay_period'].present? | |
start_date = params['pay_period'].to_date | |
else | |
start_date = @pay_period | |
end | |
week_one = start_date + 1.week - 1.day | |
week_two = week_one + 1.week | |
runquery = DailyTimeCard.joins(:user) | |
runquery = runquery.where(users: {active: true, id: User.with_role(:employee)}) | |
runquery = runquery.where(date: start_date ..week_one) | |
runquery = runquery.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.regular_hours) AS regular_hours, MIN(daily_time_cards.date) AS date") | |
runquery = runquery.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.overtime_hours) AS overtime_hours, MIN(daily_time_cards.date) AS date") | |
runquery = runquery.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.paid_time_off) AS paid_time_off, MIN(daily_time_cards.date) AS date") | |
runquery = runquery.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.holiday_hours) AS holiday_hours, MIN(daily_time_cards.date) AS date") | |
@reg = runquery | |
runquery2 = DailyTimeCard.joins(:user) | |
runquery2 = runquery2.where(users: {active: true, id: User.with_role(:employee)}) | |
runquery2 = runquery2.where(date: (week_one + 1.day) ..week_two) | |
runquery2 = runquery2.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.regular_hours) AS regular_hours, MIN(daily_time_cards.date) AS date") | |
runquery2 = runquery2.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.overtime_hours) AS overtime_hours, MIN(daily_time_cards.date) AS date") | |
runquery2 = runquery2.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.paid_time_off) AS paid_time_off, MIN(daily_time_cards.date) AS date") | |
runquery2 = runquery2.group(:user_id).select("daily_time_cards.user_id, SUM(daily_time_cards.holiday_hours) AS holiday_hours, MIN(daily_time_cards.date) AS date") | |
@reg2 = runquery2 | |
#raise (week_two).inspect | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="table table-bordered table-striped table-condensed" style="float:left;"> | |
<% @reg.each do |a| %> | |
<tr> | |
<td><%= a.user.loginable.paylocity_id %></td> | |
<td>E</td> | |
<td>REG</td> | |
<td> | |
<% add_to_overtime = [] | |
regsum = [] | |
regsum << a.try(:regular_hours) | |
regsum << a.try(:holiday_hours) | |
regsum = regsum.compact.inject(:+) %> | |
<% if regsum > 40 %> | |
<% reg = 40 %> | |
<% add_to_overtime << (regsum - 40) %> | |
<% add_to_overtime = add_to_overtime.compact.inject(:+) %> | |
<% else %> | |
<% reg = regsum %> | |
<% end %> | |
<%= reg %> | |
</td> | |
</tr> | |
<tr> | |
<td><%= a.user.loginable.paylocity_id %></td> | |
<td>E</td> | |
<td>OT</td> | |
<td> | |
<%= a.try(:overtime_hours).try(:round, 2) + add_to_overtime %> | |
</td> | |
</tr> | |
<% end %> | |
</tbody> | |
</table> | |
<table class="table table-bordered table-striped table-condensed" style="float:left;"> | |
<% @reg2.each do |b| %> | |
<tr> | |
<td><%= b.user.loginable.paylocity_id %></td> | |
<td>E</td> | |
<td>REG</td> | |
<td> | |
<% add_to_overtime = [] | |
regsum = [] | |
regsum << b.try(:regular_hours) | |
regsum << b.try(:holiday_hours) | |
regsum = regsum.compact.inject(:+) %> | |
<% if regsum > 40 %> | |
<% reg = 40 %> | |
<% add_to_overtime << (regsum - 40) %> | |
<% add_to_overtime = add_to_overtime.compact.inject(:+) %> | |
<% else %> | |
<% reg = regsum %> | |
<% end %> | |
<%= reg %> | |
</td> | |
</tr> | |
<tr> | |
<td><%= b.user.loginable.paylocity_id %></td> | |
<td>E</td> | |
<td>OT</td> | |
<td> | |
<%= b.try(:overtime_hours).try(:round, 2) + add_to_overtime %> | |
</td> | |
</tr> | |
<% end %> | |
</tbody> | |
</table> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment