mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
fix: Transfers should always total to zero (#1859)
This commit is contained in:
@@ -154,7 +154,7 @@ module ApplicationHelper
|
||||
|
||||
def totals_by_currency(collection:, money_method:, separator: " | ", negate: false)
|
||||
collection.group_by(&:currency)
|
||||
.transform_values { |item| negate ? item.sum(&money_method) * -1 : item.sum(&money_method) }
|
||||
.transform_values { |item| calculate_total(item, money_method, negate) }
|
||||
.map { |_currency, money| format_money(money) }
|
||||
.join(separator)
|
||||
end
|
||||
@@ -166,4 +166,12 @@ module ApplicationHelper
|
||||
|
||||
cookies[:admin] == "true"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def calculate_total(item, money_method, negate)
|
||||
items = item.reject { |i| i.respond_to?(:entryable) && i.entryable.transfer? }
|
||||
total = items.sum(&money_method)
|
||||
negate ? -total : total
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
</div>
|
||||
|
||||
<% if totals %>
|
||||
<%= totals_by_currency(collection: entries, money_method: :amount_money, negate: true) %>
|
||||
<div id="entry-group-<%= date %>-totals">
|
||||
<%= totals_by_currency(collection: entries, money_method: :amount_money, negate: true) %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="bg-white shadow-xs rounded-md border border-alpha-black-25 divide-y divide-alpha-black-50">
|
||||
|
||||
Reference in New Issue
Block a user