diff --git a/app/assets/javascripts/darkswarm/services/orders.js.coffee b/app/assets/javascripts/darkswarm/services/orders.js.coffee index 2cc169ebfe..baa46a3d96 100644 --- a/app/assets/javascripts/darkswarm/services/orders.js.coffee +++ b/app/assets/javascripts/darkswarm/services/orders.js.coffee @@ -4,3 +4,11 @@ Darkswarm.factory 'Orders', (orders_by_distributor, currencyConfig, CurrentHub, # Populate Orders.orders from json in page. @orders_by_distributor = orders_by_distributor @currency_symbol = currencyConfig.symbol + + for distributor in @orders_by_distributor + console.log distributor + for order, i in distributor.distributed_orders + balances = distributor.distributed_orders.slice(i,distributor.distributed_orders.length).map (o) -> parseFloat(o.outstanding_balance) + running_balance = balances.reduce (a,b) -> a+b + order.running_balance = running_balance.toFixed(2) + console.log order diff --git a/app/views/spree/users/_fat.html.haml b/app/views/spree/users/_fat.html.haml index 769810d546..b4000ca594 100644 --- a/app/views/spree/users/_fat.html.haml +++ b/app/views/spree/users/_fat.html.haml @@ -8,6 +8,7 @@ %th.order4{"bo-text" => "'shipping_state' | t"} %th.order5.text-right{"bo-text" => "'value' | t"} %th.order6.text-right{"bo-text" => "'balance' | t"} + %th.order6.text-right{"bo-text" => "'running_balance' | t"} %tbody.transaction-group{"ng-repeat" => "order in distributor.distributed_orders", "ng-class-odd"=>"'odd'", "ng-class-even"=>"'even'"} %tr.order-row %td.order1 @@ -17,6 +18,7 @@ %td.order4{"bo-text" => "order.shipment_state | t"} %td.order5.text-right{"bo-text" => "order.total | localizeCurrency"} %td.order6.text-right{"ng-class" => "{'credit' : order.outstanding_balance < 0, 'debit' : order.outstanding_balance > 0, 'paid' : order.outstanding_balance == 0}", "bo-text" => "order.outstanding_balance | localizeCurrency"} + %td.order7.text-right{"ng-class" => "{'credit' : order.running_balance < 0, 'debit' : order.running_balance > 0, 'paid' : order.running_balance == 0}", "bo-text" => "order.running_balance | localizeCurrency"} %tr.payment-row{"ng-repeat" => "payment in order.payments"} %td.order1{"bo-text" => "()'payment' | t) + ' ' + payment.identifier"} %td.order2{"bo-text" => "payment.updated_at"} @@ -24,3 +26,4 @@ %td.order4 %td.order5.text-right{"bo-text" => "payment.amount | localizeCurrency"} %td.order6 + %td.order7 diff --git a/config/locales/en.yml b/config/locales/en.yml index e673d6bfd9..a1675f951b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -687,3 +687,4 @@ Please follow the instructions there to make your enterprise visible on the Open Paid: "Paid" Ready: "Ready" you_have_no_orders_yet: "You have no orders yet" + running_balance: "Running balance"