From bf6252dc2e9c45b2d28c144ae4b9084a79c25c9d Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Wed, 16 Jun 2010 14:35:48 +0100 Subject: [PATCH] =?UTF-8?q?Simplified=20/=20using=20dm-aggregates.=20Set?= =?UTF-8?q?=20payments=20filter=20minimum=20to=20=C2=A31000.=20Restored=20?= =?UTF-8?q?comments=20to=20payments=20to=20suppliers=20detail=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.rb | 17 ++++++++--------- views/servicepayments.haml | 34 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/app.rb b/app.rb index caf1d0a..2bcfdd2 100644 --- a/app.rb +++ b/app.rb @@ -4,6 +4,8 @@ require 'sinatra-helpers/haml/partials' require 'haml' require 'lib/models' +PAYMENTS_FILTER_MIN = 1000 + helpers do def commify(amount) amount.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse @@ -12,12 +14,9 @@ end get '/' do @directorates = Directorate.all( :order => ['name'] ) - @results = repository(:default).adapter.query("SELECT COUNT(*) FROM payments") - @payments_count = @results[0] - @results = repository(:default).adapter.query("SELECT COUNT(*) FROM suppliers") - @suppliers_count = @results[0] - @results = repository(:default).adapter.query("SELECT COUNT(*) FROM services") - @services_count = @results[0] + @payments_count = Payment.count + @suppliers_count = Supplier.count + @services_count = Service.count haml :home end @@ -45,7 +44,7 @@ end get '/suppliers/:slug' do @supplier = Supplier.first(:slug => params[:slug]) @total = @supplier.payments.sum(:amount) - @count = @supplier.payments.size + @count = @supplier.payments.size # Payment.count(:supplier_id => @supplier.id) ? @avg = @supplier.payments.avg(:amount) @max = @supplier.payments.max(:amount) @min = @supplier.payments.min(:amount) @@ -100,14 +99,14 @@ end get '/services/:slug/payments' do @service = Service.first(:slug => params[:slug]) - @payments = Payment.all(:service_id => @service.id, :amount.gte => 0, :order => [ 'd' ]) + @payments = Payment.all(:service_id => @service.id, :amount.gte => PAYMENTS_FILTER_MIN, :order => [ 'd' ]) @total = @payments.sum(:amount) haml :servicepayments end get '/services/:slug/paymentsdetail' do @service = Service.first(:slug => params[:slug]) - min = 500 + min = PAYMENTS_FILTER_MIN if params[:min].to_i > 0 min = params[:min].to_i end diff --git a/views/servicepayments.haml b/views/servicepayments.haml index 2f3f687..05e0023 100644 --- a/views/servicepayments.haml +++ b/views/servicepayments.haml @@ -51,9 +51,9 @@ %img.spinner{ :src => "/spinner.gif" } %p.filter - %a#min500.filter_selected{:href => '#'} + %a#min500{:href => '#'} £500 - %a#min1000{:href => '#'} + %a#min1000.filter_selected{:href => '#'} £1,000 %a#min2500{:href => '#'} £2,500 @@ -65,18 +65,18 @@ #payments= haml :servicepaymentsdetail, :layout => false .clear --# -
- = haml_partial "comment_header" -
- - - Comments powered by Disqus -
+ +
+= haml_partial "comment_header" +
+ + +Comments powered by Disqus +