Files
openfoodnetwork/app/assets/javascripts/admin/subscriptions/services/subscription_functions.js.coffee
Rob Harrington 2e94654f91 Create factory to hold auxillary functions for subscriptions
NOTE: Moved estimatedSubtotal and estimatedTotal functions to the new factory from the subscription line items controller
2018-02-22 16:13:29 +11:00

13 lines
473 B
CoffeeScript

# Provides additional auxillary functions to instances of SubsciptionResource
# Used to extend the prototype of the subscription resource created by SubscriptionResource
angular.module("admin.subscriptions").factory 'SubscriptionFunctions', ->
estimatedSubtotal: ->
@subscription_line_items.reduce (subtotal, item) ->
return subtotal if item._destroy
subtotal += item.price_estimate * item.quantity
, 0
estimatedTotal: ->
@estimatedSubtotal()