anchor.diff:  -module(onbill_notifications).
   
  --export([send_account_update/1
  +-export([send_account_update/3
  +         ,mrc_approaching_databag/1
           ,maybe_send_account_updates/2
           ,mrc_approaching_sent/1, set_mrc_approaching_sent/1, reset_mrc_approaching_sent/1
           ,mrc_approaching_enabled/1, set_mrc_approaching_enabled/1, reset_mrc_approaching_enabled/1
  
positive.code:     Timestamp = kz_time:current_tstamp(),
      {StartYear, StartMonth, StartDay} = onbill_util:period_start_date(AccountId, Timestamp),
      case onbill_util:days_left_in_period(StartYear, StartMonth, StartDay, Timestamp) of
          DaysLeft when DaysLeft < 5 ->
              case onbill_bk_util:current_usage_amount_in_units(AccountId)
                  > wht_util:current_balance(AccountId) * 0.9
              of
                  'true' ->
                      maybe_send_new_billing_period_approaching_update(AccountId, AccountJObj, mrc_approaching_enabled(AccountJObj));
                  _ -> 'ok'
              end;
          _ -> 'ok'
      end.
  
negative.code:             Diff = kz_time:current_tstamp() - MRC_ApproachingSent,
              case Diff >= Cycle of
                 'true' ->
                     'ok' = send_account_update(AccountId, ?MRC_APPROACHING_TEMPLATE, mrc_approaching_databag(AccountId)),
                     update_account_mrc_approaching_sent(AccountJObj);
                 'false' ->
                     lager:debug("mrc approaching alert sent ~w seconds ago, repeats every ~w", [Diff, Cycle])
              end;
          _Else ->
              'ok' = send_account_update(AccountId, ?MRC_APPROACHING_TEMPLATE, mrc_approaching_databag(AccountId)),
              update_account_mrc_approaching_sent(AccountJObj)
      end,
      'ok';
  maybe_send_new_billing_period_approaching_update(AccountId, _AccountJObj, 'false') ->
      lager:debug("mrc approaching alert disabled for Account: ~p", [AccountId]).
  
  -spec mrc_approaching_databag(ne_binary()) -> kz_json:object().
  mrc_approaching_databag(AccountId) ->
      Values = [{<<"reseller">>, reseller_info_databag(AccountId)}
               ,{<<"account">>, account_info_databag(AccountId)}
               ],
      kz_json:set_values(Values, kz_json:new()).
  
  -spec reseller_info_databag(ne_binary()) -> kz_json:object().
  reseller_info_databag(AccountId) ->
      ResellerId = kz_services:find_reseller_id(AccountId),
      {'ok', ResellerDoc} = kz_account:fetch(ResellerId),
      Values = [{<<"name">>, kz_account:name(ResellerDoc)}
               ],
      kz_json:set_values(Values, kz_json:new()).
  
  -spec account_info_databag(ne_binary()) -> kz_json:object().
  account_info_databag(AccountId) ->
      {'ok', AccountDoc} = kz_account:fetch(AccountId),
      Values = [{<<"name">>, kz_account:name(AccountDoc)}
               ],
      kz_json:set_values(Values, kz_json:new()).
  
  -spec update_account_mrc_approaching_sent(kz_account:doc()) -> 'ok'.
  update_account_mrc_approaching_sent(AccountJObj0) ->
  