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 1.9 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require 'rubygems'
  2. require 'dm-core'
  3. require 'dm-validations'
  4. require 'dm-timestamps'
  5. require 'dm-aggregates'
  6. class Payment
  7. include DataMapper::Resource
  8. property :id, Serial
  9. property :trans_no, Integer, :required => false # "TransNo" in RBWM CSV files
  10. property :directorate_id, Integer, :required => true
  11. property :service_id, Integer, :required => true
  12. property :supplier_id, Integer, :required => true
  13. property :cost_centre, String, :required => false
  14. property :amount, BigDecimal, :precision => 10, :scale => 2, :required => true # ex VAT
  15. property :d, Date, :required => true # "Updated" in RBWM CSV files
  16. property :tyype, String, :required => true # Capital or Revenue
  17. belongs_to :directorate
  18. belongs_to :service
  19. belongs_to :supplier
  20. end
  21. class Directorate
  22. include DataMapper::Resource
  23. property :id, Serial
  24. property :name, String, :length => 255, :required => true
  25. property :slug, String, :length => 255
  26. has n, :payments, :order => ['d']
  27. def self.slugify(name)
  28. name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  29. end
  30. end
  31. class Service
  32. include DataMapper::Resource
  33. property :id, Serial
  34. property :name, String, :length => 255, :required => true
  35. property :slug, String, :length => 255
  36. has n, :payments, :order => ['d']
  37. def self.slugify(name)
  38. name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  39. end
  40. end
  41. class Supplier
  42. include DataMapper::Resource
  43. property :id, Serial
  44. property :name, String, :length => 255, :required => true
  45. property :slug, String, :length => 255
  46. has n, :payments, :order => ['d']
  47. def self.slugify(name)
  48. name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  49. end
  50. end
  51. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
  52. DataMapper.auto_upgrade!