Permalink
Browse files

Add total_spend and queries

  • Loading branch information...
1 parent 6b5d0b2 commit 26ddfe33e1f30d902e4c23e3b4bf7f5b2d525a57 @delitescere delitescere committed with Pairing Workstation Sears Jun 4, 2010
Showing with 34 additions and 11 deletions.
  1. +2 −0 app/models/client.rb
  2. +13 −0 app/views/clients/_client_list.html.haml
  3. +17 −9 app/views/clients/index.html.haml
  4. +2 −2 db/seeds.rb
@@ -10,6 +10,8 @@ class Client < ActiveRecord::Base
has_many :users, :dependent => :destroy
scope :recent, where("created_at > ?", 1.year.ago).order("created_at desc")
+ scope :by_spend, :order => "total_spend desc"
+ scope :by_hottest_spend_day, :group => "hottest_spend_day, total_spend, code", :order => "hottest_spend_day, total_spend desc"
validates_presence_of :name
@@ -0,0 +1,13 @@
+%tr[client]
+%td
+%td= client.name
+%td= client.code
+%td $#{client.total_spend}
+%td.draft_timesheets_count
+ - if client.timesheets.draft.count > 3
+ %span.drafts-overlimit WARNING!
+ %br
+ = client.timesheets.draft.count
+%td= link_to 'Show', client_path(client)
+%td= link_to 'Edit', edit_client_path(client)
+%td= link_to 'Destroy', client_path(client), :confirm => 'Are you sure?', :method => :delete
@@ -5,18 +5,26 @@
%table#clients_list
%tr
+
+ - if (1..4).include? Date.today.wday # Sun - Thu
+ %th
%th Name
%th Code
+ %th Spend
%th Draft Timesheets
-
- - for client in @clients
- %tr[client]
- %td= client.name
- %td= client.code
- %td.draft_timesheets_count= client.timesheets.draft.count
- %td= link_to 'Show', client_path(client)
- %td= link_to 'Edit', edit_client_path(client)
- %td= link_to 'Destroy', client_path(client), :confirm => 'Are you sure?', :method => :delete
+ - for client in @clients
+ = render :partial => "client_list", :locals => {:client => client}
+ - else
+ %th Day
+ %th Name
+ %th Code
+ %th Spend
+ %th Draft Timesheets
+ - for wday in (Date.today.wday..6).to_a + (0...Date.today.wday).to_a
+ %tr
+ %td= Date::DAYNAMES[wday]
+ - for client in Client.by_hottest_spend_day.where(:hottest_spend_day => wday)
+ = render :partial => "client_list", :locals => {:client => client}
%br
= link_to 'New client', new_client_path
View
@@ -1,6 +1,6 @@
Client.delete_all
-Client.create(:name => 'Aardworkers', :code => 'AARD', :created_at => 2.years.ago)
-client = Client.create(:name => 'Zorganization', :code => 'ZORG')
+Client.create(:name => 'Aardworkers', :code => 'AARD', :created_at => 2.years.ago, :total_spend => 4321, :hottest_spend_day => Date::DAYNAMES.index("Saturday"))
+client = Client.create(:name => 'Zorganization', :code => 'ZORG', :total_spend => 9999, :hottest_spend_day => Date::DAYNAMES.index("Wednesday"))
User.delete_all
admin = User.create(:login => 'admin',

0 comments on commit 26ddfe3

Please sign in to comment.