Skip to content

Instantly share code, notes, and snippets.

@adamrneary
Created August 8, 2013 21:44
Show Gist options
  • Save adamrneary/6189061 to your computer and use it in GitHub Desktop.
Save adamrneary/6189061 to your computer and use it in GitHub Desktop.
calculate: (periodId) =>
# we use a 1 character variable for the return value since calculations are
# reused so many times for other calculations
r =
periodUnix: app.periods.idToUnix(periodId)
# regardless of plan/actual, beginning cash is last month's ending cash
beginningCash: @get(app.periods.prevId(periodId))?.endingCash
# a subset of the keys only apply to forecast periods because we aren't yet
# able to calculate what historical cash was spent on. we just know the
# total burn rate with revenue (beginning - ending)
if app.periods.notPast(periodId)
# the next 5 keys represent specific cash flow (in or out) for the period
s = app.scenario.toJSON()
keys = ['revenue', 'cogs', 'custAcq', 'team', 'vendor']
_.each keys, (key) =>
# first we allocate the p&l values based on timing sensitivities
days = if key is 'custAcq' then s.cust_acq_days else s["#{key}_days"]
val = @_periodCash periodId, (days ? 0), "#{key}Plan"
# then we scale them based on amount sensitivities
multiplier = if key is 'custAcq'
s.cust_acq_multiplier
else s["#{key}_multiplier"]
val *= (1 + (multiplier ? 0)/100)
# then we record the result for that key
r["#{key}Plan"] = val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment