Skip to content

Commit

Permalink
Fixed date calculation for Uppbokning
Browse files Browse the repository at this point in the history
  • Loading branch information
martent committed May 16, 2019
1 parent c8a3120 commit 31f3c51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/reports/economy_uppbokning_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def per_rate_category(refugees, *categories)

next if rates.empty?

{ refugee: refugee, rates: as_formula(rates) }
{ refugee: refugee, rates: as_formula(rates), days: sum_days(rates) }
end.reject(&:blank?)
end

Expand Down Expand Up @@ -127,6 +127,12 @@ def as_formula(rates)
end.compact.join('+')
end

def sum_days(rates)
rates.map do |rate|
rate[:days] if days_hash?(rate)
end.compact.sum
end

def days_hash?(hash)
test_hash([hash[:days], hash[:amount]], hash[:days])
end
Expand All @@ -139,7 +145,7 @@ def po_cost_hash?(hash)
test_hash([hash[:months], hash[:fee], hash[:po_cost]], hash[:months])
end

def test_hash(hash, time)
!hash.include?(nil) && time.positive?
def test_hash(arr, int)
arr.is_a?(Array) && !arr.include?(nil) && int.positive?
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
status[:records].each_with_index do |record, row|
refugee = record[:refugee]

sheet.add_row(
[
refugee.dossier_number,
Expand All @@ -8,7 +9,7 @@ status[:records].each_with_index do |record, row|
refugee.ssns.map(&:full_ssn).join(', '),
refugee.municipality&.name,
sum_formula(record[:rates]),
"=(#{record[:rates]&.sum { |x| x[:days] || 0 }})"
"=(#{record[:days]})"
],
style: @style.normal
)
Expand Down

0 comments on commit 31f3c51

Please sign in to comment.