@@ -4,6 +4,12 @@ require 'sinatra-helpers/haml/partials' | |||||
require 'haml' | require 'haml' | ||||
require 'lib/models' | require 'lib/models' | ||||
helpers do | |||||
def commify(amount) | |||||
amount.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') | |||||
end | |||||
end | |||||
get '/' do | get '/' do | ||||
@directorates = Directorate.all( :order => ['name'] ) | @directorates = Directorate.all( :order => ['name'] ) | ||||
@results = repository(:default).adapter.query("SELECT COUNT(*) FROM payments") | @results = repository(:default).adapter.query("SELECT COUNT(*) FROM payments") | ||||
@@ -67,6 +73,12 @@ get '/services/:slug.csv' do | |||||
end | end | ||||
get '/services/:slug.json' do | |||||
@service = Service.first(:slug => params[:slug]) | |||||
headers "Content-Type" => "application/json" | |||||
@service.to_json(:relationships => { :payments => { :include => :all }, :directorate => { :include => :all } }) | |||||
end | |||||
get '/services/:slug' do | get '/services/:slug' do | ||||
@service = Service.first(:slug => params[:slug]) | @service = Service.first(:slug => params[:slug]) | ||||
@total = @service.payments.sum(:amount) | @total = @service.payments.sum(:amount) | ||||
@@ -3,6 +3,7 @@ require 'dm-core' | |||||
require 'dm-validations' | require 'dm-validations' | ||||
require 'dm-timestamps' | require 'dm-timestamps' | ||||
require 'dm-aggregates' | require 'dm-aggregates' | ||||
require 'dm-serializer' | |||||
SITE_URL = 'http://armchairauditor.co.uk/' | SITE_URL = 'http://armchairauditor.co.uk/' | ||||
@@ -22,7 +22,7 @@ | |||||
= @payment.supplier.name | = @payment.supplier.name | ||||
%tr | %tr | ||||
%td Amount £ | %td Amount £ | ||||
%td= sprintf("%0.2f", @payment.amount) | |||||
%td= commify(sprintf("%0.2f", @payment.amount)) | |||||
.clear | .clear | ||||
<div class="grid_9 noprint"> | <div class="grid_9 noprint"> | ||||
= haml_partial "comment_header" | = haml_partial "comment_header" | ||||
@@ -34,11 +34,11 @@ | |||||
%th.right Average | %th.right Average | ||||
%tr | %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= commify(@count) | |||||
%td.right= commify(sprintf("£%0d", @total)) | |||||
%td.right= commify(sprintf("£%0d", @max)) | |||||
%td.right= commify(sprintf("£%0d", @min)) | |||||
%td.right= commify(sprintf("£%0d", @avg)) | |||||
%p | %p | ||||
@@ -54,7 +54,7 @@ | |||||
%td | %td | ||||
%a{ :href => "/suppliers/#{row['supplier_slug']}" } | %a{ :href => "/suppliers/#{row['supplier_slug']}" } | ||||
= row['supplier_name'] | = row['supplier_name'] | ||||
%td.right= sprintf("%0d", row['total']) | |||||
%td.right= commify(sprintf("%0d", row['total'])) | |||||
%td.right= sprintf("%0.1f", row['total'] / @total * 100) | %td.right= sprintf("%0.1f", row['total'] / @total * 100) | ||||
%p | %p | ||||
@@ -77,14 +77,14 @@ | |||||
%td | %td | ||||
%a{ :href => '/suppliers/' + payment.supplier.slug } | %a{ :href => '/suppliers/' + payment.supplier.slug } | ||||
= payment.supplier.name | = payment.supplier.name | ||||
%td.right= sprintf("%0d", payment.amount) | |||||
%td.right= commify(sprintf("%0d", payment.amount)) | |||||
%tr | %tr | ||||
%td | %td | ||||
%td | %td | ||||
%td | %td | ||||
%strong TOTAL | %strong TOTAL | ||||
%td.right= sprintf("%0d", @total) | |||||
%td.right= commify(sprintf("%0d", @total)) | |||||
.clear | .clear | ||||
<div class="grid_9 noprint"> | <div class="grid_9 noprint"> | ||||
@@ -29,11 +29,11 @@ | |||||
%th.right Average £ | %th.right Average £ | ||||
%tr | %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= commify(@count) | |||||
%td.right= commify(sprintf("%0d", @total)) | |||||
%td.right= commify(sprintf("%0d", @max)) | |||||
%td.right= commify(sprintf("%0d", @min)) | |||||
%td.right= commify(sprintf("%0d", @avg)) | |||||
%h3 Payments from the Council | %h3 Payments from the Council | ||||
@@ -57,7 +57,7 @@ | |||||
%td | %td | ||||
%a{ :href => '/services/' + payment.service.slug } | %a{ :href => '/services/' + payment.service.slug } | ||||
= payment.service.name | = payment.service.name | ||||
%td.right= sprintf("%0d", payment.amount) | |||||
%td.right= commify(sprintf("%0d", payment.amount)) | |||||
%tr | %tr | ||||
%td | %td | ||||
@@ -65,7 +65,7 @@ | |||||
%td | %td | ||||
%td | %td | ||||
%strong TOTAL | %strong TOTAL | ||||
%td.right= sprintf("%0d", @total) | |||||
%td.right= commify(sprintf("%0d", @total)) | |||||
.clear | .clear | ||||
<div class="grid_9 noprint"> | <div class="grid_9 noprint"> | ||||