mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
17 lines
724 B
CoffeeScript
17 lines
724 B
CoffeeScript
Darkswarm.factory 'Orders', (orders_by_distributor, currencyConfig, CurrentHub, Taxons, Dereferencer, visibleFilter, Matcher, Geo, $rootScope)->
|
|
new class Orders
|
|
constructor: ->
|
|
# Populate Orders.orders from json in page.
|
|
@orders_by_distributor = orders_by_distributor
|
|
@currency_symbol = currencyConfig.symbol
|
|
|
|
for distributor in @orders_by_distributor
|
|
@updateRunningBalance(distributor.distributed_orders)
|
|
|
|
|
|
updateRunningBalance: (orders) ->
|
|
for order, i in orders
|
|
balances = orders.slice(i,orders.length).map (o) -> parseFloat(o.outstanding_balance)
|
|
running_balance = balances.reduce (a,b) -> a+b
|
|
order.running_balance = running_balance.toFixed(2)
|