An open source, stand-alone, customisable public spending data web app.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

models.rb 2.5 KiB

14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
14 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. require 'rubygems'
  2. gem "datamapper", "0.9.11"
  3. require 'dm-core'
  4. require 'dm-validations'
  5. require 'dm-timestamps'
  6. require 'dm-aggregates'
  7. SITE_URL = 'http://armchairauditor.co.uk/'
  8. class Payment
  9. include DataMapper::Resource
  10. property :id, Serial
  11. property :created_at, DateTime
  12. property :updated_at, DateTime
  13. property :service_id, Integer, :required => true
  14. property :supplier_id, Integer, :required => true
  15. property :amount, BigDecimal, :precision => 10, :scale => 2, :required => true # ex VAT
  16. property :d, Date, :required => true # "Updated" in RBWM CSV files
  17. belongs_to :service
  18. belongs_to :supplier
  19. has 1, :directorate, { :through => :service }
  20. def url
  21. SITE_URL + "payments/" + @id.to_s
  22. end
  23. end
  24. class Directorate
  25. include DataMapper::Resource
  26. property :id, Serial
  27. property :created_at, DateTime
  28. property :updated_at, DateTime
  29. property :name, String, :length => 255, :required => true
  30. property :slug, String, :length => 255
  31. has n, :payments, { :through => :services, :order => ['d'] }
  32. has n, :services, :order => ['name']
  33. has n, :suppliers, { :through => :services, :order => ['name'] }
  34. before :save, :slugify
  35. def slugify
  36. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  37. end
  38. end
  39. class Service
  40. include DataMapper::Resource
  41. property :id, Serial
  42. property :created_at, DateTime
  43. property :updated_at, DateTime
  44. property :directorate_id, Integer, :required => true
  45. property :name, String, :length => 255, :required => true
  46. property :slug, String, :length => 255
  47. has n, :payments, :order => ['d']
  48. has n, :suppliers, { :through => :payments, :order => ['name'] }
  49. belongs_to :directorate
  50. before :save, :slugify
  51. def slugify
  52. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  53. end
  54. end
  55. class Supplier
  56. include DataMapper::Resource
  57. property :id, Serial
  58. property :created_at, DateTime
  59. property :updated_at, DateTime
  60. property :name, String, :length => 255, :required => true
  61. property :slug, String, :length => 255
  62. has n, :payments, :order => ['d']
  63. has n, :services, { :through => :payments, :order => ['name'] }
  64. has n, :directorates, { :through => :payments }
  65. before :save, :slugify
  66. def slugify
  67. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  68. end
  69. end
  70. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
  71. DataMapper.auto_upgrade!