allow assignment of auto recharge values AND rollover
authorjeff <jeff>
Tue, 18 Sep 2007 06:32:51 +0000 (06:32 +0000)
committerjeff <jeff>
Tue, 18 Sep 2007 06:32:51 +0000 (06:32 +0000)
FS/FS/cust_pkg.pm
FS/FS/part_pkg/base_rate.pm
FS/FS/part_pkg/flat.pm
FS/FS/part_pkg/prorate.pm
FS/FS/part_pkg/subscription.pm

index 77438c1..a37abe2 100644 (file)
@@ -1754,6 +1754,26 @@ sub set_usage {
   }
 }
 
+=item recharge USAGE_VALUE_HASHREF 
+
+USAGE_VALUE_HASHREF is a hashref of svc_acct usage columns and the amounts
+to which they should be set (see L<FS::svc_acct>).  Currently seconds,
+upbytes, downbytes, and totalbytes are appropriate keys.
+
+All svc_accts which are part of this package have their values incremented.
+
+=cut
+
+sub recharge {
+  my ($self, $valueref) = @_;
+
+  foreach my $cust_svc ($self->cust_svc){
+    my $svc_x = $cust_svc->svc_x;
+    $svc_x->recharge($valueref)
+      if $svc_x->can("recharge");
+  }
+}
+
 =back
 
 =head1 BUGS
index 9e64184..04896e0 100644 (file)
@@ -43,7 +43,6 @@ sub calc_setup {
 
 sub calc_recur {
   my($self, $cust_pkg) = @_;
-  $self->reset_usage($cust_pkg);
   $self->base_recur($cust_pkg);
 }
 
@@ -91,12 +90,4 @@ sub is_prepaid {
   0; #no, we're postpaid
 }
 
-sub reset_usage {
-  my($self, $cust_pkg) = @_;
-  my %values = map { $_, $self->option($_) } 
-    grep { $self->option($_, 'hush') } 
-    qw(seconds upbytes downbytes totalbytes);
-  $cust_pkg->set_usage(\%values);
-}
-
 1;
index 6d1fbde..471f216 100644 (file)
@@ -63,12 +63,16 @@ use FS::part_pkg;
                          'format' => \&FS::UI::bytecount::display_bytecount,
                          'parse' => \&FS::UI::bytecount::parse_bytecount,
                        },
+    'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
+                                    ' over into current period',
+                          'type' => 'checkbox',
+                        },
   },
   'fieldorder' => [ 'setup_fee', 'recur_fee', 'unused_credit', 
                     'seconds', 'upbytes', 'downbytes', 'totalbytes',
                     'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
                     'recharge_downbytes', 'recharge_totalbytes',
-                    'externalid' ],
+                    'usage_rollover', 'externalid' ],
   'weight' => 10,
 );
 
@@ -141,7 +145,11 @@ sub reset_usage {
   my %values = map { $_, $self->option($_) } 
     grep { $self->option($_, 'hush') } 
     qw(seconds upbytes downbytes totalbytes);
-  $cust_pkg->set_usage(\%values);
+  if ($self->option('usage_rollover', 1)) {
+    $cust_pkg->recharge(\%values);
+  }else{
+    $cust_pkg->set_usage(\%values);
+  }
 }
 
 1;
index 02ce6b9..6b7c615 100644 (file)
@@ -61,6 +61,10 @@ use FS::part_pkg::flat;
                         'format' => \&FS::UI::bytecount::display_bytecount,
                         'parse' => \&FS::UI::bytecount::parse_bytecount,
                        },
+    'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
+                                   'over into current period',
+                         'type' => 'checkbox',
+                        },
     #it would be better if this had to be turned on, its confusing
     'externalid' => { 'name'   => 'Optional External ID',
                       'default' => '',
@@ -70,7 +74,7 @@ use FS::part_pkg::flat;
                     'seconds', 'upbyte', 'downbytes', 'totalbytes',
                     'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
                     'recharge_downbytes', 'recharge_totalbytes',
-                    'externalid', ],
+                    'usage_rollover', 'externalid', ],
   'freq' => 'm',
   'weight' => 20,
 );
@@ -83,8 +87,6 @@ sub calc_recur {
   my $mend;
   my $mstart;
   
-  $self->reset_usage($cust_pkg);
-
   if ( $mday >= $cutoff_day ) {
     $mend =
       timelocal(0,0,0,$cutoff_day, $mon == 11 ? 0 : $mon+1, $year+($mon==11));
index 00d15cd..7f4dbca 100644 (file)
@@ -57,6 +57,10 @@ use FS::part_pkg::flat;
                         'format' => \&FS::UI::bytecount::display_bytecount,
                         'parse' => \&FS::UI::bytecount::parse_bytecount,
                        },
+    'usage_rollover' => { 'name' => 'Allow usage from previous period to roll '.
+                                   'over into current period',
+                         'type' => 'checkbox',
+                        },
     #it would be better if this had to be turned on, its confusing
     'externalid' => { 'name'   => 'Optional External ID',
                       'default' => '',
@@ -71,6 +75,7 @@ use FS::part_pkg::flat;
                     'upbytes', 'downbytes', 'totalbytes',
                     'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
                     'recharge_downbytes', 'recharge_totalbytes',
+                    'usage_rollover',
                    ],
   'freq' => 'm',
   'weight' => 30,