mirror of
https://github.com/fspc/BikeShed-1.git
synced 2025-02-28 08:43:23 -05:00
User#completed_build_bikes method, and stats page list
This commit is contained in:
parent
1defca3668
commit
2c548ff63c
@ -2,15 +2,26 @@ class UserStats < Netzke::Base
|
|||||||
|
|
||||||
def body_content(user)
|
def body_content(user)
|
||||||
bike = user.bike
|
bike = user.bike
|
||||||
%Q(
|
completed = user.completed_build_bikes
|
||||||
<div id="user_stats_page">
|
#I think it's time to switch to a template
|
||||||
|
body = ""
|
||||||
|
body += %Q(<div id="user_stats_page">)
|
||||||
|
body += %Q(
|
||||||
<p>Username: #{user.username}</p>
|
<p>Username: #{user.username}</p>
|
||||||
<p>Total Hours Worked: #{user.total_hours}</p>
|
<p>Total Hours Worked: #{user.total_hours}</p>
|
||||||
<p>Hours worked in #{Time.now.strftime('%B')}: #{user.current_month_hours}</p>
|
<p>Hours worked in #{Time.now.strftime('%B')}: #{user.current_month_hours}</p>
|
||||||
<p>Current bike Shop ID: #{bike.shop_id if bike}</p>
|
<p>Current bike Shop ID: #{bike.shop_id if bike}</p>
|
||||||
<p>Current bike S/N: #{bike.serial_number if bike}</p>
|
<p>Current bike S/N: #{bike.serial_number if bike}</p>
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
|
unless completed.empty?
|
||||||
|
body += %Q(<p>Previously built bikes (#{completed.count}):</p>)
|
||||||
|
body += %Q(<ul>)
|
||||||
|
completed.each do |b|
|
||||||
|
body += %Q(<li>#{b.shop_id}</li>)
|
||||||
|
end
|
||||||
|
body += %Q(</ul>)
|
||||||
|
end
|
||||||
|
body += %Q(</div>)
|
||||||
end
|
end
|
||||||
|
|
||||||
js_configure do |c|
|
js_configure do |c|
|
||||||
|
@ -43,6 +43,19 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
### TODO methods below probably belong somewhere else
|
### TODO methods below probably belong somewhere else
|
||||||
|
|
||||||
|
def completed_build_bikes
|
||||||
|
status_id = BikeStatus.find_by_status("BUILDBIKE").id
|
||||||
|
Bike.find_by_sql("
|
||||||
|
SELECT *
|
||||||
|
FROM bikes
|
||||||
|
LEFT JOIN(
|
||||||
|
SELECT *
|
||||||
|
FROM transactions
|
||||||
|
WHERE customer_id = #{self.id}
|
||||||
|
) AS transactions ON bikes.id = transactions.bike_id
|
||||||
|
WHERE bike_status_id = #{status_id}")
|
||||||
|
end
|
||||||
|
|
||||||
def total_hours
|
def total_hours
|
||||||
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN")
|
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN")
|
||||||
logs.where("log_action_id != ? AND log_action_type = ?", log_action.id, log_action.class.to_s).sum { |l| (l.end_date - l.start_date)/3600 }.round(2)
|
logs.where("log_action_id != ? AND log_action_type = ?", log_action.id, log_action.class.to_s).sum { |l| (l.end_date - l.start_date)/3600 }.round(2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user