An open source, stand-alone, customisable public spending data web app.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

114 rader
3.5 KiB

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