An open source, stand-alone, customisable public spending data web app.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.rb 3.3 KiB

14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
14 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. class Payment
  2. include DataMapper::Resource
  3. property :id, Serial
  4. property :created_at, DateTime
  5. property :updated_at, DateTime
  6. property :service_id, Integer, :required => true
  7. property :supplier_id, Integer, :required => true
  8. property :amount, Decimal, :precision => 10, :scale => 2, :required => true # ex VAT
  9. property :d, Date, :required => true # transaction date
  10. property :transaction_id, Integer # May not be unique per payment as one transaction could have several payments
  11. belongs_to :service
  12. belongs_to :supplier
  13. has 1, :directorate, { :through => :service }
  14. def url
  15. SETTING.site_url + "payments/" + @id.to_s
  16. end
  17. end
  18. class Directorate
  19. include DataMapper::Resource
  20. property :id, Serial
  21. property :created_at, DateTime
  22. property :updated_at, DateTime
  23. property :name, String, :length => 255, :required => true
  24. property :slug, String, :length => 255, :required => true
  25. has n, :services, :order => ['name']
  26. has n, :suppliers, { :through => :services, :order => ['name'] }
  27. # before :save, :slugify
  28. #
  29. # def slugify
  30. # @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  31. # puts "I've just been slugified"
  32. # end
  33. end
  34. class Service
  35. include DataMapper::Resource
  36. property :id, Serial
  37. property :created_at, DateTime
  38. property :updated_at, DateTime
  39. property :directorate_id, Integer
  40. property :name, String, :length => 255, :required => true
  41. property :slug, String, :length => 255, :required => true
  42. has n, :payments, :order => ['d']
  43. has n, :suppliers, { :through => :payments, :order => ['name'] }
  44. belongs_to :directorate, :required => false
  45. # before :save, :slugify
  46. #
  47. # def slugify
  48. # @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  49. # puts "I've just been slugified"
  50. # end
  51. end
  52. class Supplier
  53. include DataMapper::Resource
  54. property :id, Serial
  55. property :created_at, DateTime
  56. property :updated_at, DateTime
  57. property :name, String, :length => 255, :required => true
  58. property :slug, String, :length => 255, :required => true
  59. has n, :payments, :order => ['d']
  60. has n, :services, { :through => :payments, :order => ['name'] }
  61. has n, :directorates, { :through => :payments }
  62. # before :save, :slugify
  63. #
  64. # def slugify
  65. # @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  66. # end
  67. end
  68. # This is a singleton. We only use the first row in the settings table.
  69. class Setting
  70. include DataMapper::Resource
  71. property :id, Serial
  72. property :site_name, String, :length => 255, :required => true
  73. property :site_tagline, String, :length => 255
  74. property :site_url, String, :length => 255
  75. property :org_name, String, :length => 255
  76. property :org_url, String, :length => 255
  77. property :data_url, String, :length => 255
  78. property :disqus_shortname, String, :length => 255
  79. property :google_analytics_id, String, :length => 255
  80. end
  81. # DataMapper.setup(:default, ENV['DATABASE_URL'] || "mysql://root@localhost/armchairauditor_sutton")
  82. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
  83. DataMapper.auto_upgrade!