Permalink
Browse files

WHISTLE-1217: use the channel_status to determine if the call is stil…

…l active, skip active calls...
  • Loading branch information...
1 parent 9ced0ba commit 65c6de0438659dd09a2d1a5b63fa3f4bd919bfe2 @k-anderson k-anderson committed Jul 17, 2012
Showing with 25 additions and 21 deletions.
  1. +25 −21 whistle_apps/apps/jonny5/src/j5_reconciler.erl
@@ -41,7 +41,7 @@ process_account(Account) ->
ViewOptions = [reduce, group],
case couch_mgr:get_results(AccountDb, <<"transactions/reconcile_by_callid">>, ViewOptions) of
{error, _R}=E ->
- lager:debug("unable to fetch unreconciled callids from ~s: ~p", [Account, _R]),
+ lager:debug("unable to fetch unreconciled call ids from ~s: ~p", [Account, _R]),
E;
{ok, JObjs} ->
_ = [correct_discrepancy(AccountDb, wh_json:get_value(<<"key">>, JObj), Amount)
@@ -154,26 +154,30 @@ code_change(_OldVsn, State, _Extra) ->
-spec correct_discrepancy/3 :: (ne_binary(), ne_binary(), integer()) -> {'ok', wh_json:json_object()} |
{'error', _}.
correct_discrepancy(Ledger, CallId, Amount) ->
- LedgerId = wh_util:format_account_id(Ledger, raw),
- LedgerDb = wh_util:format_account_id(Ledger, encoded),
- Timestamp = wh_util:current_tstamp(),
- Id = <<CallId/binary, "-discrepancy">>,
- Type = case Amount > 0 of true -> <<"debit">>; false -> <<"credit">> end,
- Entry = wh_json:from_list([{<<"_id">>, Id}
- ,{<<"reason">>, <<"jonny5 discrepancy correction">>}
- ,{<<"account_id">>, LedgerId}
- ,{<<"call_id">>, CallId}
- ,{<<"amount">>, abs(Amount)}
- ,{<<"pvt_account_id">>, LedgerId}
- ,{<<"pvt_account_db">>, LedgerDb}
- ,{<<"pvt_type">>, wh_util:to_binary(Type)}
- ,{<<"pvt_created">>, Timestamp}
- ,{<<"pvt_modified">>, Timestamp}
- ,{<<"pvt_vsn">>, 1}
- ,{<<"pvt_whapp">>, ?APP_NAME}
- ]),
- io:format("correcting $~p discrepancy for call ~s on ~s~n", [wapi_money:units_to_dollars(Amount), CallId, LedgerId]),
- couch_mgr:save_doc(LedgerDb, Entry).
+ case whapps_call_command:channel_status(CallId) of
+ {ok, _} -> ok;
+ {error, _} ->
+ LedgerId = wh_util:format_account_id(Ledger, raw),
+ LedgerDb = wh_util:format_account_id(Ledger, encoded),
+ Timestamp = wh_util:current_tstamp(),
+ Id = <<CallId/binary, "-discrepancy">>,
+ Type = case Amount > 0 of true -> <<"debit">>; false -> <<"credit">> end,
+ Entry = wh_json:from_list([{<<"_id">>, Id}
+ ,{<<"reason">>, <<"jonny5 discrepancy correction">>}
+ ,{<<"account_id">>, LedgerId}
+ ,{<<"call_id">>, CallId}
+ ,{<<"amount">>, abs(Amount)}
+ ,{<<"pvt_account_id">>, LedgerId}
+ ,{<<"pvt_account_db">>, LedgerDb}
+ ,{<<"pvt_type">>, wh_util:to_binary(Type)}
+ ,{<<"pvt_created">>, Timestamp}
+ ,{<<"pvt_modified">>, Timestamp}
+ ,{<<"pvt_vsn">>, 1}
+ ,{<<"pvt_whapp">>, ?APP_NAME}
+ ]),
+ io:format("correcting $~p discrepancy for call ~s on ~s~n", [wapi_money:units_to_dollars(Amount), CallId, LedgerId]),
+ couch_mgr:save_doc(LedgerDb, Entry)
+ end.
-spec shuffle/1 :: (list()) -> list().
-spec shuffle/2 :: (list(), integer()) -> list().

0 comments on commit 65c6de0

Please sign in to comment.