anchor.diff:       ,kz_json:get_value([<<"plan">>,<<"periodic_fees">>,Key,<<"rate">>],JObj)
        ], Keys}.
   
  --spec import_periodic_fees(kz_tasks:extra_args(), kz_tasks:iterator(), kz_tasks:args()) ->
  -                    {kz_tasks:return(), sets:set()}.
  -import_periodic_fees(ExtraArgs=#{account_id := ResellerId}, init, Args) ->
  -    remove_periodic_fees_from_db(get_descendants(ResellerId)),
  -    kz_datamgr:suppress_change_notice(),
  -    IterValue = sets:new(),
  -    import_periodic_fees(ExtraArgs, IterValue, Args);
  -import_periodic_fees(_
  -                    ,_
  -                    ,#{<<"account_id">> := AccountId
  -                      ,<<"service_id">> := <<"phone_line_649">>
  -                      ,<<"quantity">> := Quantity
  -                      }
  -      ) ->
  -    DbName = kz_util:format_account_id(AccountId, 'encoded'),
  -    case kz_datamgr:open_doc(DbName, <<"limits">>) of
  -        {ok, Doc} ->
  -            NewDoc = kz_json:set_value(<<"twoway_trunks">>, kz_term:to_integer(Quantity), Doc),
  -            kz_datamgr:ensure_saved(DbName, NewDoc),
  -            AccountId;
  -        {'error', 'not_found'} ->
  -            Values =
  -                props:filter_undefined(
  -                    [{<<"_id">>, <<"limits">>}
  -                    ,{<<"pvt_type">>, <<"limits">>}
  -                    ,{<<"twoway_trunks">>, kz_term:to_integer(Quantity)}
  -                    ]),
  -            NewDoc = kz_json:set_values(Values ,kz_json:new()),
  -            kz_datamgr:ensure_saved(DbName, NewDoc),
  -            AccountId;
  -        _ ->
  -            'onbill_data_not_added'
  -    end;
  -import_periodic_fees(_
  -                    ,_
  -                    ,#{<<"account_id">> := AccountId
  -                      ,<<"service_id">> := ServiceId
  -                      ,<<"quantity">> := Quantity
  -                      }
  -      ) ->
  -    DbName = kz_util:format_account_id(AccountId, 'encoded'),
  -    ServiceStarts = calendar:datetime_to_gregorian_seconds({onbill_util:period_start_date(AccountId), {0,0,0}}),
  -    Values =
  -        props:filter_undefined(
  -            [{<<"_id">>, kz_datamgr:get_uuid()}
  -            ,{<<"pvt_type">>, <<"periodic_fee">>}
  -            ,{<<"service_id">>, ServiceId}
  -            ,{<<"quantity">>, Quantity}
  -            ,{<<"service_starts">>, ServiceStarts}
  -            ]),
  -    kz_datamgr:save_doc(DbName,kz_json:from_list(Values)),
  -    AccountId.
  -
  --spec import_accounts(kz_tasks:extra_args(), kz_tasks:iterator(), kz_tasks:args()) ->
  -                    {kz_tasks:return(), sets:set()}.
  -import_accounts(ExtraArgs, init, Args) ->
  -    kz_datamgr:suppress_change_notice(),
  -    IterValue = sets:new(),
  -    import_accounts(ExtraArgs, IterValue, Args);
  -import_accounts(#{account_id := ResellerId
  -        ,auth_account_id := _AuthAccountId
  -        }
  -      ,_AccountIds
  -      ,_Args=#{<<"account_name">> := AccountName
  -             ,<<"users">> := UserString
  -             }
  -      ) ->
  -    Realm = <<AccountName/binary, ".", (?ACCOUNT_REALM_SUFFIX)/binary>>,
  -    Context = create_account(ResellerId, AccountName, Realm),
  -    case cb_context:resp_status(Context) of
  -        'success' ->
  -            kz_util:spawn(fun cb_onbill_signup:create_default_callflow/1, [Context]),
  -            RespData = cb_context:resp_data(Context),
  -            AccountId = kz_json:get_value(<<"id">>, RespData),
  -            case UserString of
  -                'undefined' ->
  -                    AccountId;
  -                _ ->
  -                    Users = binary:split(re:replace(UserString, "\\s+", "", [global,{return,binary}])
  -                                        ,[<<",">>,<<";">>]),
  -                    create_users(AccountId, Users, Context),
  -                    AccountId
  -            end;
  -        _ ->
  -            'account_not_created'
  -    end.
  -
  --spec import_onbill_data1(kz_tasks:extra_args(), kz_tasks:iterator(), kz_tasks:args()) ->
  -                    {kz_tasks:return(), sets:set()}.
  -import_onbill_data1(ExtraArgs, init, Args) ->
  -    case is_allowed(ExtraArgs) of
  -        'true' ->
  -            lager:info("import_onbill_data1 is allowed, continuing"),
  -            kz_datamgr:suppress_change_notice(),
  -            IterValue = sets:new(),
  -            import_onbill_data1(ExtraArgs, IterValue, Args);
  -        'false' ->
  -            lager:warning("import_onbill_data1 is forbidden for account ~s, auth account ~s"
  -                         ,[maps:get('account_id', ExtraArgs)
  -                          ,maps:get('auth_account_id', ExtraArgs)
  -                          ]
  -                         ),
  -            {<<"task execution is forbidden">>, 'stop'}
  -    end;
  -import_onbill_data1(#{account_id := _ResellerId
  -        ,auth_account_id := _AuthAccountId
  -        }
  -      ,_AccountIds
  -      ,_Args=#{<<"account_id">> := AccountId
  -              ,<<"account_name">> := AccountName
  -              ,<<"account_inn">> := AccountINN
  -              ,<<"account_kpp">> := AccountKPP
  -              ,<<"prepaid">> := _Prepaid
  -              ,<<"billing_address">> := BillingAddress
  -              ,<<"agrm_number">> := AgrmNumber
  -              ,<<"agrm_date">> := AgrmDate
  -              ,<<"agrm_type_id">> := AgrmTypeId
  -              }
  -      ) ->
  -    case binary:split(BillingAddress, [<<"^*^">>], [global]) of
  -        [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11] -> ok;
  -        [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, _, A11] -> ok
  -    end,
  -    AA4 = case A2 == A4 of
  -              'true' -> <<>>;
  -              'false' -> A4
  -          end,
  -    Values = props:filter_empty(
  -        [{<<"_id">>, ?ONBILL_DOC}
  -        ,{<<"pvt_type">>, ?ONBILL_DOC}
  -        ,{<<"pvt_account_id">>, AccountId}
  -        ,{<<"account_name">>, AccountName}
  -        ,{<<"account_inn">>, AccountINN}
  -        ,{<<"account_kpp">>, AccountKPP}
  -        ,{[<<"billing_address">>,<<"line1">>]
  -         ,maybe_format_address_element([A1, A2], A11)
  -         }
  -        ,{[<<"billing_address">>,<<"line2">>]
  -         ,maybe_format_address_element([AA4, A5, A6], A3)
  -         }
  -        ,{[<<"billing_address">>,<<"line3">>]
  -         ,maybe_format_address_element([A8, A9, A10], A7)
  -         }
  -        ] ++ agrm_vals(AgrmNumber, AgrmDate, AgrmTypeId)),
  -    DbName = kz_util:format_account_id(AccountId,'encoded'),
  -    case kz_datamgr:open_doc(DbName, ?ONBILL_DOC) of
  -        {ok, Doc} ->
  -            NewDoc = kz_json:set_values(Values, Doc),
  -            kz_datamgr:ensure_saved(DbName, NewDoc),
  -            AccountId;
  -        {'error', 'not_found'} ->
  -            NewDoc = kz_json:set_values(Values ,kz_json:new()),
  -            kz_datamgr:ensure_saved(DbName, NewDoc),
  -            AccountId;
  -        _ ->
  -            'onbill_data_not_added'
  -    end.
  -
   -spec generate_docs(kz_tasks:extra_args(), kz_tasks:iterator()) -> kz_tasks:iterator().
   generate_docs(#{account_id := AccountId}, init) ->
       {'ok', get_children(AccountId)};
  
positive.code: -define(CATEGORY, "onbill").
  -define(ACTIONS, [<<"current_state">>
                   ,<<"periodic_fees">>
                   ,<<"import_periodic_fees">>
                   ,<<"import_accounts">>
                   ,<<"import_onbill_data1">>
                   ,<<"generate_docs">>
                   ,<<"sync_onbills">>
                   ]).
  
  -define(IMPORT_PERIODIC_FEES_DOC_FIELDS
         ,[<<"account_id">>
          ,<<"service_id">>
          ,<<"quantity">>
          ]).
  
  -define(IMPORT_PERIODIC_FEES_MANDATORY_FIELDS
         ,[<<"account_id">>
          ,<<"service_id">>
          ,<<"quantity">>
          ]).
  
  
  -define(IMPORT_ACCOUNTS_DOC_FIELDS
         ,[<<"account_name">>
          ,<<"realm">>
          ,<<"users">>
          ]).
  
  -define(IMPORT_ACCOUNTS_MANDATORY_FIELDS
         ,[<<"account_name">>
          ]).
  
  -define(IMPORT_ONBILL_DATA1
         ,[<<"account_id">>
          ,<<"account_name">>
          ,<<"account_inn">>
          ,<<"account_kpp">>
          ,<<"prepaid">>
          ,<<"billing_address_line1">>
          ,<<"billing_address_line2">>
          ,<<"billing_address_line3">>
          ,<<"agrm_number">>
          ,<<"agrm_date">>
          ,<<"agrm_type_id">>
          ]).
  
  -define(IMPORT_MANDATORY_ONBILL_DATA1
         ,[<<"account_id">>
          ]).
  
  -define(ACCOUNT_REALM_SUFFIX
         ,kapps_config:get_binary(<<"crossbar.accounts">>, <<"account_realm_suffix">>, <<"sip.onnet.su">>)).
  
  -define(MK_USER,
      {[{<<"call_forward">>,
         {[{<<"substitute">>,false},
           {<<"enabled">>,false},
           {<<"require_keypress">>,false},
           {<<"keep_caller_id">>,false},
           {<<"direct_calls_only">>,false}]}},
        {<<"enabled">>, 'true'},
        {<<"priv_level">>,<<"user">>},
        {<<"vm_to_email_enabled">>,true},
        {<<"fax_to_email_enabled">>,true},
        {<<"verified">>,false},
        {<<"timezone">>,<<"UTC">>},
        {<<"record_call">>,false}
       ]}).
  
  %%%===================================================================
  %%% API
  
negative.code:     ,{<<"doc">>, <<"Just an experimentsl feature.\n"
                     "No additional parametres needed.\n"
                   >>}
      ];
  
  action(<<"generate_docs">>) ->
  