[freeside-commits] freeside/FS/FS svc_acct.pm, 1.217.2.20, 1.217.2.21 cust_pkg.pm, 1.73.2.27, 1.73.2.28
Jeff Finucane,420,,
jeff at wavetail.420.am
Mon Mar 23 21:36:18 PDT 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv353/FS/FS
Modified Files:
Tag: FREESIDE_1_7_BRANCH
svc_acct.pm cust_pkg.pm
Log Message:
more DTRT with usage on service transfer between packages and recharges RT #2884, #5040
Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.217.2.20
retrieving revision 1.217.2.21
diff -u -d -r1.217.2.20 -r1.217.2.21
--- svc_acct.pm 23 Mar 2009 17:02:34 -0000 1.217.2.20
+++ svc_acct.pm 24 Mar 2009 04:36:15 -0000 1.217.2.21
@@ -26,6 +26,7 @@
use FS::Record qw( qsearch qsearchs fields dbh dbdef );
use FS::Msgcat qw(gettext);
use FS::UI::bytecount;
+use FS::part_pkg;
use FS::svc_Common;
use FS::cust_svc;
use FS::part_svc;
@@ -290,6 +291,7 @@
type => 'text',
disable_inventory => 1,
disable_select => 1,
+ disable_part_svc_column => 1,
},
'upbytes' => { label => 'Upload',
type => 'text',
@@ -297,6 +299,7 @@
disable_select => 1,
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
+ disable_part_svc_column => 1,
},
'downbytes' => { label => 'Download',
type => 'text',
@@ -304,6 +307,7 @@
disable_select => 1,
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
+ disable_part_svc_column => 1,
},
'totalbytes'=> { label => 'Total up and download',
type => 'text',
@@ -311,11 +315,13 @@
disable_select => 1,
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
+ disable_part_svc_column => 1,
},
'seconds_threshold' => { label => 'Seconds threshold',
type => 'text',
disable_inventory => 1,
disable_select => 1,
+ disable_part_svc_column => 1,
},
'upbytes_threshold' => { label => 'Upload threshold',
type => 'text',
@@ -323,6 +329,7 @@
disable_select => 1,
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
+ disable_part_svc_column => 1,
},
'downbytes_threshold' => { label => 'Download threshold',
type => 'text',
@@ -330,6 +337,7 @@
disable_select => 1,
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
+ disable_part_svc_column => 1,
},
'totalbytes_threshold'=> { label => 'Total up and download threshold',
type => 'text',
@@ -337,6 +345,7 @@
disable_select => 1,
'format' => \&FS::UI::bytecount::display_bytecount,
'parse' => \&FS::UI::bytecount::parse_bytecount,
+ disable_part_svc_column => 1,
},
'last_login'=> {
label => 'Last login',
@@ -535,6 +544,26 @@
return $error;
}
+ # set usage fields and thresholds if unset but set in a package def
+ if ( $self->pkgnum ) {
+ my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
+ my $part_pkg = $cust_pkg->part_pkg if $cust_pkg;
+ if ( $part_pkg && $part_pkg->can('usage_valuehash') ) {
+
+ my %values = $part_pkg->usage_valuehash;
+ my $multiplier = $conf->exists('svc_acct-usage_threshold')
+ ? 1 - $conf->config('svc_acct-usage_threshold')/100
+ : 0.20;
+
+ foreach ( keys %values ) {
+ next if $self->getfield($_);
+ $self->setfield( $_, $values{$_} );
+ $self->setfield( $_. '_threshold', int( $values{$_} * $multiplier ) );
+ }
+
+ }
+ }
+
my @jobnums;
$error = $self->SUPER::insert(
'jobnums' => \@jobnums,
@@ -1720,7 +1749,7 @@
}
sub set_usage {
- my( $self, $valueref ) = @_;
+ my( $self, $valueref, %options ) = @_;
warn "$me set_usage called for svcnum ". $self->svcnum.
' ('. $self->email. "): ".
@@ -1741,6 +1770,11 @@
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});
@@ -1759,8 +1793,8 @@
#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;
@@ -1768,7 +1802,7 @@
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
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.73.2.27
retrieving revision 1.73.2.28
diff -u -d -r1.73.2.27 -r1.73.2.28
--- cust_pkg.pm 12 Mar 2009 01:14:57 -0000 1.73.2.27
+++ cust_pkg.pm 24 Mar 2009 04:36:15 -0000 1.73.2.28
@@ -2153,6 +2153,22 @@
$dbh->rollback if $oldAutoCommit;
return "Unable to transfer all services from package ".$old_pkg->pkgnum;
}
+
+ #reset usage if changing pkgpart
+ if ($old_pkg->pkgpart != $new_pkg->pkgpart) {
+ my $part_pkg = $new_pkg->part_pkg;
+ $error = $part_pkg->reset_usage($new_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";
+ }
+ }
+
$error = $old_pkg->cancel( quiet=>1 );
if ($error) {
$dbh->rollback;
@@ -2298,11 +2314,11 @@
=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");
}
}
More information about the freeside-commits
mailing list