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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_budget.rb', line 16
def self.build(aFunding)
@Namespace = ADIWG::Mdtranslator::Writers::SbJson
hBudget = {}
hBudget[:parts] = []
hBudget[:totalFunds] = 0.0
hBudget[:annualBudgets] = []
hBudget[:className] = 'gov.sciencebase.catalog.item.facet.BudgetFacet'
aFunding.each do |hFunding|
hAnnualBudget = {}
aFundingSources = []
total = 0.0
hFunding[:allocations].each do |hAllocation|
hSource = {}
hSource[:amount] = hAllocation[:amount] unless hAllocation[:amount].nil?
total += hAllocation[:amount] unless hAllocation[:amount].nil?
hSource[:matching] = hAllocation[:matching].to_s
unless hAllocation[:id].nil?
hAgreement = {}
hAgreement[:type] = 'Agreement Number'
hAgreement[:value] = hAllocation[:id]
hBudget[:parts] << hAgreement
end
unless hAllocation[:recipientId].nil?
hContact = @Namespace.get_contact_by_id(hAllocation[:recipientId])
unless hContact.empty?
hSource[:recipient] = hContact[:name]
end
end
unless hAllocation[:sourceId].nil?
hContact = @Namespace.get_contact_by_id(hAllocation[:sourceId])
unless hContact.empty?
hSource[:source] = hContact[:name]
end
end
aFundingSources << hSource
end
unless aFundingSources.empty?
hAnnualBudget[:fundingSources] = aFundingSources
end
unless total == 0.0
hAnnualBudget[:totalFunds] = total
hBudget[:totalFunds] += total
end
startMonth = nil
startYear = nil
endMonth = nil
endYear = nil
unless hFunding[:timePeriod].empty?
unless hFunding[:timePeriod][:startDateTime].empty?
startDateTime = hFunding[:timePeriod][:startDateTime][:dateTime]
date = startDateTime.to_date + 1
startMonth = date.month
startYear = date.year
end
unless hFunding[:timePeriod][:endDateTime].empty?
endDateTime = hFunding[:timePeriod][:endDateTime][:dateTime]
date = endDateTime.to_date - 1
endMonth = date.month
endYear = date.year
end
if endYear.nil?
month = startMonth
year = startYear
else
month = endMonth
year = endYear
end
if month > 9
year += 1
end
hAnnualBudget[:year] = year.to_s
end
hBudget[:annualBudgets] << hAnnualBudget
end
return hBudget
end
|