Просмотр исходного кода

Added comma separators for amounts

pull/3/head
Adrian Short 14 лет назад
Родитель
Сommit
5b097cc1e4
5 измененных файлов: 29 добавлений и 16 удалений
  1. +12
    -0
      app.rb
  2. +1
    -0
      lib/models.rb
  3. +1
    -1
      views/payment.haml
  4. +8
    -8
      views/service.haml
  5. +7
    -7
      views/supplier.haml

+ 12
- 0
app.rb Просмотреть файл

@@ -4,6 +4,12 @@ require 'sinatra-helpers/haml/partials'
require 'haml'
require 'lib/models'

helpers do
def commify(amount)
amount.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,')
end
end

get '/' do
@directorates = Directorate.all( :order => ['name'] )
@results = repository(:default).adapter.query("SELECT COUNT(*) FROM payments")
@@ -67,6 +73,12 @@ get '/services/:slug.csv' do
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
@service = Service.first(:slug => params[:slug])
@total = @service.payments.sum(:amount)


+ 1
- 0
lib/models.rb Просмотреть файл

@@ -3,6 +3,7 @@ require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
require 'dm-aggregates'
require 'dm-serializer'

SITE_URL = 'http://armchairauditor.co.uk/'



+ 1
- 1
views/payment.haml Просмотреть файл

@@ -22,7 +22,7 @@
= @payment.supplier.name
%tr
%td Amount £
%td= sprintf("%0.2f", @payment.amount)
%td= commify(sprintf("%0.2f", @payment.amount))
.clear
<div class="grid_9 noprint">
= haml_partial "comment_header"


+ 8
- 8
views/service.haml Просмотреть файл

@@ -34,11 +34,11 @@
%th.right Average

%tr
%td.right= @count
%td.right= sprintf("&pound;%0d", @total)
%td.right= sprintf("&pound;%0d", @max)
%td.right= sprintf("&pound;%0d", @min)
%td.right= sprintf("&pound;%0d", @avg)
%td.right= commify(@count)
%td.right= commify(sprintf("&pound;%0d", @total))
%td.right= commify(sprintf("&pound;%0d", @max))
%td.right= commify(sprintf("&pound;%0d", @min))
%td.right= commify(sprintf("&pound;%0d", @avg))

%p
@@ -54,7 +54,7 @@
%td
%a{ :href => "/suppliers/#{row['supplier_slug']}" }
= 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)

%p
@@ -77,14 +77,14 @@
%td
%a{ :href => '/suppliers/' + payment.supplier.slug }
= payment.supplier.name
%td.right= sprintf("%0d", payment.amount)
%td.right= commify(sprintf("%0d", payment.amount))
%tr
%td
%td
%td
%strong TOTAL
%td.right= sprintf("%0d", @total)
%td.right= commify(sprintf("%0d", @total))
.clear
<div class="grid_9 noprint">


+ 7
- 7
views/supplier.haml Просмотреть файл

@@ -29,11 +29,11 @@
%th.right Average &pound;

%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
@@ -57,7 +57,7 @@
%td
%a{ :href => '/services/' + payment.service.slug }
= payment.service.name
%td.right= sprintf("%0d", payment.amount)
%td.right= commify(sprintf("%0d", payment.amount))
%tr
%td
@@ -65,7 +65,7 @@
%td
%td
%strong TOTAL
%td.right= sprintf("%0d", @total)
%td.right= commify(sprintf("%0d", @total))
.clear
<div class="grid_9 noprint">


Загрузка…
Отмена
Сохранить