-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.rb
72 lines (48 loc) · 1.75 KB
/
model.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
require 'dm-core'
require 'dm-aggregates'
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/presu.sqlite")
class Jurisdiccion
include DataMapper::Resource
property :id, Serial
property :nombre, String, :length => 128
has n, :servicios
end
class Caracter
include DataMapper::Resource
property :id, Serial
property :nombre, String, :length => 128
end
# SAF
class Servicio
include DataMapper::Resource
property :id, Serial, :key => true
property :nombre, String, :length => 128
belongs_to :jurisdiccion
belongs_to :caracter
def variacion
total_credito_inicial = Registro.sum(:credito, :conditions => ['servicio_id = ? AND fecha = ?',
id,
Registro.first(:servicio => self, :order => [:fecha.asc]).fecha])
total_credito = Registro.sum(:credito, :conditions => ['servicio_id = ? AND fecha = ?',
id,
Registro.last(:servicio => self, :order => [:fecha.asc]).fecha])
return total_credito - total_credito_inicial
end
end
class Programa
include DataMapper::Resource
property :id, Integer, :key => true
property :nombre, String, :length => 128
belongs_to :servicio, :key => true
end
class Registro
include DataMapper::Resource
property :id, Serial, :key => true
property :fecha, Date, :key => true
property :credito, Float
property :compromiso, Float
property :devengado, Float
property :pagado, Float
property :programa_name, String, :length => 128
belongs_to :servicio, 'Servicio', :key => true
end