anchor.diff:  		Reason :: term().
   %% @doc Apply recurring charges to all subscriptions.
   product_charge() ->
  -	case get_offers() of
  -		{error, Reason} ->
  -			{error, Reason};
  -		Offers ->
  -			Now = erlang:system_time(?MILLISECOND),
  -			product_charge1(get_product(start), Now, frp(Offers))
  -	end.
  -%% @hidden
  -product_charge1('$end_of_table', _Now, _Offers) ->
  +	Now = erlang:system_time(?MILLISECOND),
  +	product_charge1(get_product(start), Now).
  +%% @hidden
  +product_charge1('$end_of_table', _Now) ->
   	ok;
  -product_charge1(ProdRef, Now, Offers) ->
  +product_charge1(ProdRef, Now) ->
   	F = fun() ->
   			case mnesia:read(product, ProdRef, write) of
   				[#product{product = OfferId,
   						payment = Payments,
   						balance = BucketRefs} = Product] ->
  -					case if_recur(OfferId, Offers) of
  -						{true, Offer} ->
  -							case if_dues(Payments, Now) of
  +					case mnesia:read(offer, OfferId, read) of
  +						[#offer{name = OfferId, price = Prices} = Offer] ->
  +							case if_recur(Prices) of
   								true ->
  -									Buckets1 = lists:flatten([mnesia:select(bucket,
  -											[{'$1',
  -											[
  -												{'==', Id, {element, #bucket.id, '$1'}}
  -											],
  -											['$1']}]) || Id <- BucketRefs]),
  -									{NewProduct1, Buckets3} = ocs:subscription(Product, Offer,
  -											Buckets1, false),
  -									NewBRefs = update_buckets(BucketRefs, Buckets1, Buckets3),
  -									NewProduct2 = NewProduct1#product{balance = NewBRefs},
  -									ok = mnesia:write(NewProduct2);
  +									case if_dues(Payments, Now) of
  +										true ->
  +											Buckets1 = lists:flatten([mnesia:select(bucket,
  +													[{'$1',
  +													[
  +														{'==', Id, {element, #bucket.id, '$1'}}
  +													],
  +													['$1']}]) || Id <- BucketRefs]),
  +											{NewProduct1, Buckets3} = ocs:subscription(Product, Offer,
  +													Buckets1, false),
  +											NewBRefs = update_buckets(BucketRefs, Buckets1, Buckets3),
  +											NewProduct2 = NewProduct1#product{balance = NewBRefs},
  +											ok = mnesia:write(NewProduct2);
  +										false ->
  +											ok
  +									end;
   								false ->
   									ok
   							end;
  -						false ->
  -							ok
  +						[] ->
  +							throw(offer_not_found)
   					end;
   				[] ->
  -					throw(product_ref_nof_found)
  +					throw(product_ref_not_found)
   			end
   	end,
   	case mnesia:transaction(F) of
   		{atomic, ok} ->
  -			product_charge1(get_product(ProdRef), Now, Offers);
  +			product_charge1(get_product(ProdRef), Now);
   		{aborted, Reason} ->
   			error_logger:error_report("Scheduler Update Failed",
   					[{module, ?MODULE}, {product_id, ProdRef},
   					{time, erlang:system_time(?MILLISECOND)},
   					{reason, Reason}]),
  -			product_charge1(get_product(ProdRef), Now, Offers)
  +			product_charge1(get_product(ProdRef), Now)
   	end.
   
   %%----------------------------------------------------------------------
  
positive.code: if_dues([], _Now)  ->
  	false.
  
  %% @private
  if_recur(OfferId, Offers) ->
  	case lists:keyfind(OfferId, 1, Offers) of
  		{_, Offer} ->
  			{true, Offer};
  		false ->
  			false
  	end.
  
  %% @private
  
negative.code: %% @doc Scheduled function runs recurring charging and reschedules itself.
  %% @private
  run_recurring() ->
  	ok = product_charge(),
  	{ok, ScheduledTime} = application:get_env(ocs, charging_scheduler_time),
  	{ok, Interval} = application:get_env(ocs, charging_interval),
  	StartDelay = start_delay(ScheduledTime, Interval),
  	case timer:apply_after(StartDelay, ?MODULE, run_recurring, []) of
  		{ok, _TRef} ->
  			ok;
  		{error, Reason} ->
  			error_logger:error_report(["Scheduler Failed",
  					{module, ?MODULE}, {delay, StartDelay},
  					{interval, Interval}, {error, Reason}])
  	end.
  
  %%----------------------------------------------------------------------
  