add maximum "caps" to RADIUS usage charges
authorivan <ivan>
Mon, 19 Dec 2005 04:18:43 +0000 (04:18 +0000)
committerivan <ivan>
Mon, 19 Dec 2005 04:18:43 +0000 (04:18 +0000)
Changes.1.5.8
FS/FS/part_pkg/sqlradacct_hour.pm

index fbcfb91..1dc9c8e 100644 (file)
@@ -23,3 +23,6 @@
 - redo quick payment entry page with ajax magic
 - explicit payment types for cash and (optionally) western union
 - bulk svcpart change
 - redo quick payment entry page with ajax magic
 - explicit payment types for cash and (optionally) western union
 - bulk svcpart change
+- tax report updated and all items now clickable
+- direct radiator export
+- added maximum "cap" options to RADIUS usage charges
index 19887ea..e54a8a5 100644 (file)
@@ -13,19 +13,26 @@ use FS::part_pkg::flat;
     'setup_fee' => { 'name' => 'Setup fee for this package',
                      'default' => 0,
                    },
     'setup_fee' => { 'name' => 'Setup fee for this package',
                      'default' => 0,
                    },
-    'recur_flat' => { 'name' => 'Base monthly charge for this package',
+    'recur_flat' => { 'name' => 'Base recurring fee for this package',
                       'default' => 0,
                     },
     'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
                                    ' of service at cancellation',
                          'type' => 'checkbox',
                        },
                       'default' => 0,
                     },
     'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
                                    ' of service at cancellation',
                          'type' => 'checkbox',
                        },
+
     'recur_included_hours' => { 'name' => 'Hours included',
                                 'default' => 0,
                               },
     'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
                                'default' => 0,
                              },
     'recur_included_hours' => { 'name' => 'Hours included',
                                 'default' => 0,
                               },
     'recur_hourly_charge' => { 'name' => 'Additional charge per hour',
                                'default' => 0,
                              },
+    'recur_hourly_cap'    => { 'name' => 'Maximum overage charge for hours'.
+                                         ' (0 means no cap)',
+
+                               'default' => 0,
+                             },
+
     'recur_included_input' => { 'name' => 'Upload megabytes included',
                                 'default' => 0,
                               },
     'recur_included_input' => { 'name' => 'Upload megabytes included',
                                 'default' => 0,
                               },
@@ -33,6 +40,11 @@ use FS::part_pkg::flat;
                                       'Additional charge per megabyte upload',
                               'default' => 0,
                             },
                                       'Additional charge per megabyte upload',
                               'default' => 0,
                             },
+    'recur_input_cap'    => { 'name' => 'Maximum overage charge for upload'.
+                                         ' (0 means no cap)',
+                               'default' => 0,
+                             },
+
     'recur_included_output' => { 'name' => 'Download megabytes included',
                                  'default' => 0,
                               },
     'recur_included_output' => { 'name' => 'Download megabytes included',
                                  'default' => 0,
                               },
@@ -40,6 +52,11 @@ use FS::part_pkg::flat;
                                      'Additional charge per megabyte download',
                               'default' => 0,
                             },
                                      'Additional charge per megabyte download',
                               'default' => 0,
                             },
+    'recur_output_cap'    => { 'name' => 'Maximum overage charge for download'.
+                                         ' (0 means no cap)',
+                               'default' => 0,
+                             },
+
     'recur_included_total' => { 'name' =>
                                      'Total megabytes included',
                                 'default' => 0,
     'recur_included_total' => { 'name' =>
                                      'Total megabytes included',
                                 'default' => 0,
@@ -48,8 +65,18 @@ use FS::part_pkg::flat;
                                'Additional charge per megabyte total',
                               'default' => 0,
                             },
                                'Additional charge per megabyte total',
                               'default' => 0,
                             },
+    'recur_total_cap'    => { 'name' => 'Maximum overage charge for total'.
+                                        ' megabytes (0 means no cap)',
+                               'default' => 0,
+                             },
+
+    'global_cap'         => { 'name' => 'Global cap on all overage charges'.
+                                        ' (0 means no cap)',
+                              'default' => 0,
+                            },
+
   },
   },
-  'fieldorder' => [qw( setup_fee recur_flat unused_credit recur_included_hours recur_hourly_charge recur_included_input recur_input_charge recur_included_output recur_output_charge recur_included_total recur_total_charge )],
+  'fieldorder' => [qw( setup_fee recur_flat unused_credit recur_included_hours recur_hourly_charge recur_hourly_cap recur_included_input recur_input_charge recur_input_cap recur_included_output recur_output_charge recur_output_cap recur_included_total recur_total_charge recur_total_cap global_cap )],
   #'setup' => 'what.setup_fee.value',
   #'recur' => '\'my $last_bill = $cust_pkg->last_bill; my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $sdate ) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; my $input = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctInputOctets\" ) / 1048576; my $output = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctOutputOctets\" ) / 1048576; my $total = $input + $output - \' + what.recur_included_total.value + \'; $total = 0 if $total < 0; my $input = $input - \' + what.recur_included_input.value + \'; $input = 0 if $input < 0; my $output = $output - \' + what.recur_included_output.value + \'; $output = 0 if $output < 0; my $totalcharge = sprintf(\"%.2f\", \' + what.recur_total_charge.value + \' * $total); my $inputcharge = sprintf(\"%.2f\", \' + what.recur_input_charge.value + \' * $input); my $outputcharge = sprintf(\"%.2f\", \' + what.recur_output_charge.value + \' * $output); my $hourscharge = sprintf(\"%.2f\", \' + what.recur_hourly_charge.value + \' * $hours); if ( \' + what.recur_total_charge.value + \' > 0 ) { push @details, \"Last month\\\'s data \". sprintf(\"%.1f\", $total). \" megs: \\\$$totalcharge\" } if ( \' + what.recur_input_charge.value + \' > 0 ) { push @details, \"Last month\\\'s download \". sprintf(\"%.1f\", $input). \" megs: \\\$$inputcharge\" } if ( \' + what.recur_output_charge.value + \' > 0 ) { push @details, \"Last month\\\'s upload \". sprintf(\"%.1f\", $output). \" megs: \\\$$outputcharge\" } if ( \' + what.recur_hourly_charge.value + \' > 0 ) { push @details, \"Last month\\\'s time \". sprintf(\"%.1f\", $hours). \" hours: \\\$$hourscharge\"; } \' + what.recur_flat.value + \' + $hourscharge + $inputcharge + $outputcharge + $totalcharge ;\'',
   'weight' => 40,
   #'setup' => 'what.setup_fee.value',
   #'recur' => '\'my $last_bill = $cust_pkg->last_bill; my $hours = $cust_pkg->seconds_since_sqlradacct($last_bill, $sdate ) / 3600 - \' + what.recur_included_hours.value + \'; $hours = 0 if $hours < 0; my $input = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctInputOctets\" ) / 1048576; my $output = $cust_pkg->attribute_since_sqlradacct($last_bill, $sdate, \"AcctOutputOctets\" ) / 1048576; my $total = $input + $output - \' + what.recur_included_total.value + \'; $total = 0 if $total < 0; my $input = $input - \' + what.recur_included_input.value + \'; $input = 0 if $input < 0; my $output = $output - \' + what.recur_included_output.value + \'; $output = 0 if $output < 0; my $totalcharge = sprintf(\"%.2f\", \' + what.recur_total_charge.value + \' * $total); my $inputcharge = sprintf(\"%.2f\", \' + what.recur_input_charge.value + \' * $input); my $outputcharge = sprintf(\"%.2f\", \' + what.recur_output_charge.value + \' * $output); my $hourscharge = sprintf(\"%.2f\", \' + what.recur_hourly_charge.value + \' * $hours); if ( \' + what.recur_total_charge.value + \' > 0 ) { push @details, \"Last month\\\'s data \". sprintf(\"%.1f\", $total). \" megs: \\\$$totalcharge\" } if ( \' + what.recur_input_charge.value + \' > 0 ) { push @details, \"Last month\\\'s download \". sprintf(\"%.1f\", $input). \" megs: \\\$$inputcharge\" } if ( \' + what.recur_output_charge.value + \' > 0 ) { push @details, \"Last month\\\'s upload \". sprintf(\"%.1f\", $output). \" megs: \\\$$outputcharge\" } if ( \' + what.recur_hourly_charge.value + \' > 0 ) { push @details, \"Last month\\\'s time \". sprintf(\"%.1f\", $hours). \" hours: \\\$$hourscharge\"; } \' + what.recur_flat.value + \' + $hourscharge + $inputcharge + $outputcharge + $totalcharge ;\'',
   'weight' => 40,
@@ -82,13 +109,27 @@ sub calc_recur {
 
   my $totalcharge =
     $total  * sprintf('%.2f', $self->option('recur_total_charge'));
 
   my $totalcharge =
     $total  * sprintf('%.2f', $self->option('recur_total_charge'));
+  $totalcharge = $self->option('recur_total_cap')
+    if $self->option('recur_total_cap')
+    && $totalcharge > $self->option('recur_total_cap');
+
   my $inputcharge =
     $input  * sprintf('%.2f', $self->option('recur_input_charge'));
   my $inputcharge =
     $input  * sprintf('%.2f', $self->option('recur_input_charge'));
+  $inputcharge = $self->option('recur_input_cap')
+    if $self->option('recur_input_cap')
+    && $inputcharge > $self->option('recur_input_cap');
+
   my $outputcharge = 
     $output * sprintf('%.2f', $self->option('recur_output_charge'));
   my $outputcharge = 
     $output * sprintf('%.2f', $self->option('recur_output_charge'));
+  $outputcharge = $self->option('recur_output_cap')
+    if $self->option('recur_output_cap')
+    && $outputcharge > $self->option('recur_output_cap');
 
   my $hourscharge =
     $hours * sprintf('%.2f', $self->option('recur_hourly_charge'));
 
   my $hourscharge =
     $hours * sprintf('%.2f', $self->option('recur_hourly_charge'));
+  $hourscharge = $self->option('recur_hours_cap')
+    if $self->option('recur_hours_cap')
+    && $hourscharge > $self->option('recur_hours_cap');
 
   if ( $self->option('recur_total_charge') > 0 ) {
     push @$details, "Last month's data ".
 
   if ( $self->option('recur_total_charge') > 0 ) {
     push @$details, "Last month's data ".
@@ -107,8 +148,13 @@ sub calc_recur {
                    sprintf('%.1f', $hours). " hours: $hourscharge";
   }
 
                    sprintf('%.1f', $hours). " hours: $hourscharge";
   }
 
-  $self->option('recur_flat')
-    + $hourscharge + $inputcharge + $outputcharge + $totalcharge;
+  my $charges = $hourscharge + $inputcharge + $outputcharge + $totalcharge;
+  if ( $self->option('global_cap') && $charges > $self->option('global_cap') ) {
+    $charges = $self->option('global_cap');
+    push @$details, "Usage charges capped at: $charges";
+  }
+
+  $self->option('recur_flat') + $charges;
 }
 
 sub is_free_options {
 }
 
 sub is_free_options {