An open source, stand-alone, customisable public spending data web app.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. require 'rubygems'
  2. require 'sinatra'
  3. require 'sinatra-helpers/haml/partials'
  4. require 'haml'
  5. require 'lib/models'
  6. get '/' do
  7. @directorates = Directorate.all( :order => ['name'] )
  8. # @payments_count = Payment.all.size
  9. # @suppliers_count = Supplier.all.size
  10. @results = repository(:default).adapter.query("SELECT COUNT(*) FROM payments")
  11. @payments_count = @results[0]
  12. @results = repository(:default).adapter.query("SELECT COUNT(*) FROM suppliers")
  13. @suppliers_count = @results[0]
  14. @results = repository(:default).adapter.query("SELECT COUNT(*) FROM services")
  15. @services_count = @results[0]
  16. haml :home
  17. end
  18. get '/directorates/:slug' do
  19. @directorate = Directorate.first(:slug => params[:slug])
  20. # @total = @directorate.payments.sum(:amount)
  21. haml :directorate
  22. end
  23. get '/suppliers/:slug.csv' do
  24. @supplier = Supplier.first(:slug => params[:slug])
  25. headers "Content-Disposition" => "attachment;filename=supplier-#{@supplier.slug}.csv",
  26. "Content-Type" => "application/octet-stream"
  27. result = "Date,Ref.,URL,Trans No,Directorate,Service,Amount ex. VAT\n"
  28. for payment in @supplier.payments
  29. result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.service.name},#{sprintf("%0.2f", payment.amount)}\n"
  30. end
  31. result
  32. end
  33. get '/suppliers/:slug' do
  34. @supplier = Supplier.first(:slug => params[:slug])
  35. @total = @supplier.payments.sum(:amount)
  36. @count = @supplier.payments.size
  37. @avg = @supplier.payments.avg(:amount)
  38. @max = @supplier.payments.max(:amount)
  39. @min = @supplier.payments.min(:amount)
  40. haml :supplier
  41. end
  42. get '/suppliers/?' do
  43. @suppliers = Supplier.all( :order => ['name'] )
  44. haml :suppliers
  45. end
  46. get '/services/:slug.csv' do
  47. @service = Service.first(:slug => params[:slug])
  48. headers "Content-Disposition" => "attachment;filename=service-#{@service.slug}.csv",
  49. "Content-Type" => "application/octet-stream"
  50. result = "Date,Ref.,URL,Trans No,Directorate,Supplier,Amount ex. VAT\n"
  51. for payment in @service.payments
  52. result += "#{payment.d.strftime("%d %b %Y")},#{payment.id},#{payment.url},#{payment.trans_no},\"#{payment.directorate.name}\",#{payment.supplier.name},#{sprintf("%0.2f", payment.amount)}\n"
  53. end
  54. result
  55. end
  56. get '/services/:slug' do
  57. @service = Service.first(:slug => params[:slug])
  58. @total = @service.payments.sum(:amount)
  59. @count = @service.payments.size
  60. @avg = @service.payments.avg(:amount)
  61. @max = @service.payments.max(:amount)
  62. @min = @service.payments.min(:amount)
  63. haml :service
  64. end
  65. get '/services/?' do
  66. @services = Service.all( :order => ['name'] )
  67. haml :services
  68. end
  69. get '/payments/:id' do
  70. @payment = Payment.get(params[:id])
  71. haml :payment
  72. end
  73. get '/error' do
  74. haml :error
  75. end
  76. get '/about' do
  77. haml :about
  78. end
  79. not_found do
  80. haml :not_found
  81. end