Ver a proveniência

Added Suppliers by Spend table to service view

pull/3/head
Adrian Short há 14 anos
ascendente
cometimento
d94fac495d
3 ficheiros alterados com 39 adições e 8 eliminações
  1. +8
    -0
      app.rb
  2. +1
    -0
      public/style.css
  3. +30
    -8
      views/service.haml

+ 8
- 0
app.rb Ver ficheiro

@@ -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


+ 1
- 0
public/style.css Ver ficheiro

@@ -93,6 +93,7 @@ strong
table
{
border-collapse: collapse;
margin-bottom: 30px 0;
}

td, th


+ 30
- 8
views/service.haml Ver ficheiro

@@ -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


Carregando…
Cancelar
Guardar