X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=583e728c55b9857afe6028425e408cffa5532fe5;hp=0fdcbdf8d138ced2d71e0c645989c4f3115b86d2;hb=b2f85194e8e090dd6fb05acbe4575dd9440be134;hpb=b125fa567b6557aaa2f9574db8ec5dacd063ab8f diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 0fdcbdf8d..583e728c5 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -577,25 +577,19 @@ sub parse_number { Rates this CDR according and sets the status to 'rated'. -Available options are: part_pkg, svcnum, single_price_included_minutes, region_group, region_group_included_minutes. +Available options are: part_pkg, svcnum, plan_included_min, +detail_included_min_hashref. part_pkg is required. If svcnum is specified, will also associate this CDR with the specified svcnum. -single_price_included_minutes is requried for single_price price plans -(otherwise unused/ignored). It should be set to a scalar reference of the -number of included minutes and will be decremented by the rated minutes of this +plan_included_min should be set to a scalar reference of the number of +included minutes and will be decremented by the rated minutes of this CDR. -region_group_included_minutes is required for prefix price plans which have -included minutes (otherwise unused/ignored). It should be set to a scalar -reference of the number of included minutes and will be decremented by the -rated minutes of this CDR. - -region_group_included_minutes_hashref is required for prefix price plans which -have included minues (otherwise unused/ignored). It should be set to an empty -hashref at the start of a month's rating and then preserved across CDRs. +detail_included_min_hashref should be set to an empty hashref at the +start of a month's rating and then preserved across CDRs. =cut @@ -897,20 +891,19 @@ sub rate_prefix { $seconds += $charge_sec; if ( $rate_detail->min_included ) { - # the old, kind of deprecated way to do this - my $included_min = $opt{'region_group_included_min_hashref'} || {}; + # the old, kind of deprecated way to do this: + # + # The rate detail itself has included minutes. We MUST have a place + # to track them. + my $included_min = $opt{'detail_included_min_hashref'} + or die "unable to rate CDR: rate detail has included minutes, but ". + "no detail_included_min_hashref provided.\n"; # by default, set the included minutes for this region/time to # what's in the rate_detail $included_min->{$regionnum}{$ratetimenum} = $rate_detail->min_included unless exists $included_min->{$regionnum}{$ratetimenum}; - # the way that doesn't work - #my $region_group = ($part_pkg->option_cacheable('min_included') || 0) > 0; - - #${$opt{region_group_included_min}} -= $minutes - # if $region_group && $rate_detail->region_group; - if ( $included_min->{$regionnum}{$ratetimenum} >= $minutes ) { $charge_sec = 0; $included_min->{$regionnum}{$ratetimenum} -= $minutes; @@ -918,6 +911,18 @@ sub rate_prefix { $charge_sec -= ($included_min->{$regionnum}{$ratetimenum} * 60); $included_min->{$regionnum}{$ratetimenum} = 0; } + } elsif ( ${ $opt{'plan_included_min'} } > 0 ) { + # The package definition has included minutes, but only for in-group + # rate details. Decrement them if this is an in-group call. + if ( $rate_detail->region_group ) { + if ( ${ $opt{'plan_included_min'} } >= $minutes ) { + $charge_sec = 0; + ${ $opt{'plan_included_min'} } -= $minutes; + } else { + $charge_sec -= (${ $opt{'plan_included_min'} } * 60); + ${ $opt{'plan_included_min'} } = 0; + } + } } else { # the new way! my $applied_min = $cust_pkg->apply_usage( @@ -1020,12 +1025,12 @@ sub rate_single_price { my $charge_min = $minutes; - ${$opt{single_price_included_min}} -= $minutes; - if ( ${$opt{single_price_included_min}} > 0 ) { + ${$opt{plan_included_min}} -= $minutes; + if ( ${$opt{plan_included_min}} > 0 ) { $charge_min = 0; } else { - $charge_min = 0 - ${$opt{single_price_included_min}}; - ${$opt{single_price_included_min}} = 0; + $charge_min = 0 - ${$opt{plan_included_min}}; + ${$opt{plan_included_min}} = 0; } my $charge =