summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorjeff <jeff>2009-03-23 23:33:04 +0000
committerjeff <jeff>2009-03-23 23:33:04 +0000
commit42682206b4ba30de01c82743042f5fb9d48a93ed (patch)
tree878abeade328c14d9273474f9fd6c4abeca7ec28 /FS
parentad57c5c8513d0980165e3088518ddddeba0db633 (diff)
more DTRT with usage on service transfer between packages and recharges RT #2884, #5040 + #4995 fallout
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_pkg.pm19
-rw-r--r--FS/FS/part_pkg/flat.pm2
-rw-r--r--FS/FS/svc_acct.pm13
3 files changed, 27 insertions, 7 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 7c8656c09..f2c3cccf5 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1135,6 +1135,21 @@ sub change {
return "Unable to transfer all services from package ". $self->pkgnum;
}
+ #reset usage if changing pkgpart
+ if ($self->pkgpart != $cust_pkg->pkgpart) {
+ my $part_pkg = $cust_pkg->part_pkg;
+ $error = $part_pkg->reset_usage($cust_pkg, $part_pkg->is_prepaid
+ ? ()
+ : ( 'null' => 1 )
+ )
+ if $part_pkg->can('reset_usage');
+
+ if ($error) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error setting usage values: $error";
+ }
+ }
+
#Good to go, cancel old package.
$error = $self->cancel( quiet=>1 );
if ($error) {
@@ -2712,11 +2727,11 @@ All svc_accts which are part of this package have their values reset.
=cut
sub set_usage {
- my ($self, $valueref) = @_;
+ my ($self, $valueref, %opt) = @_;
foreach my $cust_svc ($self->cust_svc){
my $svc_x = $cust_svc->svc_x;
- $svc_x->set_usage($valueref)
+ $svc_x->set_usage($valueref, %opt)
if $svc_x->can("set_usage");
}
}
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index 8fd028650..009e54c78 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -209,7 +209,7 @@ sub reset_usage {
if ($self->option('usage_rollover', 1)) {
$cust_pkg->recharge(\%values);
}else{
- $cust_pkg->set_usage(\%values);
+ $cust_pkg->set_usage(\%values, %opt);
}
}
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index fcd73ac3c..c6857e29a 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -1821,7 +1821,7 @@ sub _op_usage {
}
sub set_usage {
- my( $self, $valueref ) = @_;
+ my( $self, $valueref, %options ) = @_;
warn "$me set_usage called for svcnum ". $self->svcnum.
' ('. $self->email. "): ".
@@ -1842,6 +1842,11 @@ sub set_usage {
my $reset = 0;
my %handyhash = ();
+ if ( $options{null} ) {
+ %handyhash = ( map { ( $_ => 'NULL', $_."_threshold" => 'NULL' ) }
+ qw( seconds upbytes downbytes totalbytes )
+ );
+ }
foreach my $field (keys %$valueref){
$reset = 1 if $valueref->{$field};
$self->setfield($field, $valueref->{$field});
@@ -1860,8 +1865,8 @@ sub set_usage {
#die $error if $error; #services not explicity changed via the UI
my $sql = "UPDATE svc_acct SET " .
- join (',', map { "$_ = ?" } (keys %handyhash) ).
- " WHERE svcnum = ?";
+ join (',', map { "$_ = $handyhash{$_}" } (keys %handyhash) ).
+ " WHERE svcnum = ". $self->svcnum;
warn "$me $sql\n"
if $DEBUG;
@@ -1869,7 +1874,7 @@ sub set_usage {
if (scalar(keys %handyhash)) {
my $sth = $dbh->prepare( $sql )
or die "Error preparing $sql: ". $dbh->errstr;
- my $rv = $sth->execute((values %handyhash), $self->svcnum);
+ my $rv = $sth->execute();
die "Error executing $sql: ". $sth->errstr
unless defined($rv);
die "Can't update usage for svcnum ". $self->svcnum