From d62206a94d9d49ef96640e0a8ec492679f8345e9 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 2 Jul 2013 20:02:45 -0700 Subject: [PATCH] fix discounts vs. quantities for prorate packages, RT#23530 --- FS/FS/part_pkg/cdr_termination.pm | 2 +- FS/FS/part_pkg/prorate.pm | 8 ++++++-- FS/FS/part_pkg/prorate_Mixin.pm | 3 --- FS/FS/part_pkg/sql_external.pm | 2 +- FS/FS/part_pkg/subscription.pm | 2 +- FS/FS/part_pkg/voip_cdr.pm | 19 +++++++++++++++++-- FS/FS/part_pkg/voip_inbound.pm | 2 +- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/FS/FS/part_pkg/cdr_termination.pm b/FS/FS/part_pkg/cdr_termination.pm index 37fa47e98..54bce2c1d 100644 --- a/FS/FS/part_pkg/cdr_termination.pm +++ b/FS/FS/part_pkg/cdr_termination.pm @@ -182,7 +182,7 @@ sub calc_recur { # eotermiation calculation - $charges += $self->calc_recur_Common(@_); + $charges += ($cust_pkg->quantity || 1) * $self->calc_recur_Common(@_); $charges; } diff --git a/FS/FS/part_pkg/prorate.pm b/FS/FS/part_pkg/prorate.pm index ac86f3918..a5f9ef6b6 100644 --- a/FS/FS/part_pkg/prorate.pm +++ b/FS/FS/part_pkg/prorate.pm @@ -45,8 +45,12 @@ use FS::part_pkg::flat; sub calc_recur { my $self = shift; my $cust_pkg = $_[0]; - $self->calc_prorate(@_, $self->cutoff_day($cust_pkg)) - - $self->calc_discount(@_); + + my $charge = $self->calc_prorate(@_, $self->cutoff_day($cust_pkg)); + my $discount = $self->calc_discount(@_); + + sprintf( '%.2f', ($cust_pkg->quantity || 1) * ($charge - $discount) ); + } sub cutoff_day { diff --git a/FS/FS/part_pkg/prorate_Mixin.pm b/FS/FS/part_pkg/prorate_Mixin.pm index 9efc7e89d..e8d42b9ca 100644 --- a/FS/FS/part_pkg/prorate_Mixin.pm +++ b/FS/FS/part_pkg/prorate_Mixin.pm @@ -169,9 +169,6 @@ sub calc_prorate { #so 1.005 rounds to 1.01 $charge = sprintf('%.2f', $permonth * $months + 0.00000001 ); - my $quantity = $cust_pkg->quantity || 1; - $charge *= $quantity; - return sprintf('%.2f', $charge); } diff --git a/FS/FS/part_pkg/sql_external.pm b/FS/FS/part_pkg/sql_external.pm index 4bf9ecbe7..813e8085c 100644 --- a/FS/FS/part_pkg/sql_external.pm +++ b/FS/FS/part_pkg/sql_external.pm @@ -71,7 +71,7 @@ sub calc_recur { } $param->{'override_charges'} = $price; - $self->calc_recur_Common($cust_pkg,$sdate,$details,$param); + ($cust_pkg->quantity || 1) * $self->calc_recur_Common($cust_pkg,$sdate,$details,$param); } sub can_discount { 1; } diff --git a/FS/FS/part_pkg/subscription.pm b/FS/FS/part_pkg/subscription.pm index bf88f516f..0dfe049fe 100644 --- a/FS/FS/part_pkg/subscription.pm +++ b/FS/FS/part_pkg/subscription.pm @@ -102,7 +102,7 @@ sub calc_recur { my $discount = $self->calc_discount($cust_pkg, $sdate, $details, $param); - sprintf('%.2f', $br - $discount); + sprintf('%.2f', ($cust_pkg->quantity || 1) * ($br - $discount) ); } 1; diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index 21c6a8a2c..1a9718641 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -31,6 +31,11 @@ tie my %rating_method, 'Tie::IxHash', 'single_price' => 'A single price per minute for all calls.', ; +tie my %rounding, 'Tie::IxHash', + '2' => 'Two decimal places (cent)', + '4' => 'Four decimal places (100th of a cent)', +; + #tie my %cdr_location, 'Tie::IxHash', # 'internal' => 'Internal: CDR records imported into the internal CDR table', # 'external' => 'External: CDR records queried directly from an external '. @@ -92,6 +97,11 @@ tie my %detail_formats, 'Tie::IxHash', 'options' => \%rating_method, }, + 'rounding' => { 'name' => 'Rounding for destination prefix rating', + 'type' => 'select', + 'select_options' => \%rounding, + }, + 'ratenum' => { 'name' => 'Rate plan', 'type' => 'select', 'select_table' => 'rate', @@ -304,7 +314,7 @@ tie my %detail_formats, 'Tie::IxHash', FS::part_pkg::prorate_Mixin::fieldorder, qw( cdr_svc_method - rating_method ratenum intrastate_ratenum + rating_method rounding ratenum intrastate_ratenum calls_included min_charge min_included sec_granularity ignore_unrateable @@ -352,7 +362,7 @@ sub calc_recur { my $charges = 0; $charges += $self->calc_usage(@_); - $charges += $self->calc_recur_Common(@_); + $charges += ($cust_pkg->quantity || 1) * $self->calc_recur_Common(@_); $charges; @@ -423,6 +433,11 @@ sub calc_usage { $svc_x = $cust_svc->svc_x; } + unless ( $svc_x ) { + my $h = $self->option('bill_inactive_svcs',1) ? 'h_' : ''; + warn "WARNING: no $h$svc_table for svcnum ". $cust_svc->svcnum. "\n"; + } + my %options = ( 'disable_src' => $self->option('disable_src'), 'default_prefix' => $self->option('default_prefix'), diff --git a/FS/FS/part_pkg/voip_inbound.pm b/FS/FS/part_pkg/voip_inbound.pm index 525db804d..811329d9f 100644 --- a/FS/FS/part_pkg/voip_inbound.pm +++ b/FS/FS/part_pkg/voip_inbound.pm @@ -179,7 +179,7 @@ sub calc_recur { my $charges = 0; $charges += $self->calc_usage(@_); - $charges += $self->calc_recur_Common(@_); + $charges += ($cust_pkg->quantity || 1) * $self->calc_recur_Common(@_); $charges; -- 2.11.0