From d94fac495d9dfbf68d82a950be3f3a36c606b27a Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Thu, 10 Jun 2010 12:24:37 +0100 Subject: [PATCH] Added Suppliers by Spend table to service view --- app.rb | 8 ++++++++ public/style.css | 1 + views/service.haml | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app.rb b/app.rb index 3fd6557..1b2f9a9 100644 --- a/app.rb +++ b/app.rb @@ -74,6 +74,14 @@ get '/services/:slug' do @avg = @service.payments.avg(:amount) @max = @service.payments.max(:amount) @min = @service.payments.min(:amount) + + @results = repository(:default).adapter.query(" + SELECT s.id, s.name AS supplier_name, s.slug AS supplier_slug, SUM(p.amount) AS total + FROM payments p, suppliers s + WHERE p.supplier_id = s.id + AND p.service_id = #{@service.id} + GROUP BY s.id + ORDER BY total DESC") haml :service end diff --git a/public/style.css b/public/style.css index 6134c61..7e701a2 100644 --- a/public/style.css +++ b/public/style.css @@ -93,6 +93,7 @@ strong table { border-collapse: collapse; + margin-bottom: 30px 0; } td, th diff --git a/views/service.haml b/views/service.haml index c4716a9..00b34ec 100644 --- a/views/service.haml +++ b/views/service.haml @@ -19,24 +19,46 @@ %p.noprint.download %a{ :href => "/services/#{@service.slug}.csv" } Download data as CSV + + %p + %h3 Summary %table %tr %th.right Payments - %th.right Total £ - %th.right Max £ - %th.right Min £ - %th.right Average £ + %th.right Total + %th.right Max + %th.right Min + %th.right Average %tr %td.right= @count - %td.right= sprintf("%0d", @total) - %td.right= sprintf("%0d", @max) - %td.right= sprintf("%0d", @min) - %td.right= sprintf("%0d", @avg) + %td.right= sprintf("£%0d", @total) + %td.right= sprintf("£%0d", @max) + %td.right= sprintf("£%0d", @min) + %td.right= sprintf("£%0d", @avg) + %p + + %h3 Suppliers by Spend + + %table + %tr + %th Supplier + %th Total £ + %th Total % + - for row in @results + %tr + %td + %a{ :href => "/suppliers/#{row['supplier_slug']}" } + = row['supplier_name'] + %td.right= sprintf("%0d", row['total']) + %td.right= sprintf("%0.1f", row['total'] / @total * 100) + + %p + %h3 Payments to Suppliers %table