fix discounts vs. quantities for prorate packages, RT#23530
authorIvan Kohler <ivan@freeside.biz>
Wed, 3 Jul 2013 03:02:45 +0000 (20:02 -0700)
committerIvan Kohler <ivan@freeside.biz>
Wed, 3 Jul 2013 03:02:45 +0000 (20:02 -0700)
FS/FS/part_pkg/cdr_termination.pm
FS/FS/part_pkg/prorate.pm
FS/FS/part_pkg/prorate_Mixin.pm
FS/FS/part_pkg/sql_external.pm
FS/FS/part_pkg/subscription.pm
FS/FS/part_pkg/voip_cdr.pm
FS/FS/part_pkg/voip_inbound.pm

index 37fa47e..54bce2c 100644 (file)
@@ -182,7 +182,7 @@ sub calc_recur {
     
   # eotermiation calculation
 
-  $charges += $self->calc_recur_Common(@_);
+  $charges += ($cust_pkg->quantity || 1) * $self->calc_recur_Common(@_);
 
   $charges;
 }
index ac86f39..a5f9ef6 100644 (file)
@@ -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 {
index 9efc7e8..e8d42b9 100644 (file)
@@ -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);
 }
 
index 4bf9ecb..813e808 100644 (file)
@@ -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; }
index bf88f51..0dfe049 100644 (file)
@@ -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;
index 21c6a8a..1a97186 100644 (file)
@@ -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'),
index 525db80..811329d 100644 (file)
@@ -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;