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