X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=3e36ae2422902d5304e548f9089693abbd3b3df9;hb=7b3d074cbb694330334469510548d98eebe196ed;hp=689ffedd0f24a5ade8d1018bcaa824b63082bb33;hpb=633c48448d9468690b7ad77eb6ff7c660a286658;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 689ffedd0..3e36ae242 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -2,6 +2,7 @@ package FS::cust_pkg; use strict; use vars qw(@ISA $disable_agentcheck $DEBUG); +use List::Util qw(max); use Tie::IxHash; use FS::UID qw( getotaker dbh ); use FS::Misc qw( send_email ); @@ -17,6 +18,7 @@ use FS::h_cust_svc; use FS::reg_code; use FS::part_svc; use FS::cust_pkg_reason; +use FS::reason; # need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend, # setup } @@ -29,7 +31,7 @@ use FS::svc_forward; # for sending cancel emails in sub cancel use FS::Conf; -@ISA = qw( FS::cust_main_Mixin FS::Record ); +@ISA = qw( FS::cust_main_Mixin FS::option_Common FS::Record ); $DEBUG = 0; @@ -173,7 +175,7 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->SUPER::insert; + my $error = $self->SUPER::insert($options{options} ? %{$options{options}} : ()); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -317,7 +319,9 @@ sub replace { } - my $error = $new->SUPER::replace($old); + my $error = $new->SUPER::replace($old, + $options{options} ? ${options{options}} : () + ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -482,7 +486,7 @@ sub cancel { my %hash = $self->hash; $hash{'cancel'} = time; my $new = new FS::cust_pkg ( \%hash ); - $error = $new->replace($self); + $error = $new->replace( $self, options => { $self->options } ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -567,7 +571,7 @@ sub suspend { my %hash = $self->hash; $hash{'susp'} = time; my $new = new FS::cust_pkg ( \%hash ); - $error = $new->replace($self); + $error = $new->replace( $self, options => { $self->options } ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -648,7 +652,7 @@ sub unsuspend { $hash{'susp'} = ''; my $new = new FS::cust_pkg ( \%hash ); - $error = $new->replace($self); + $error = $new->replace( $self, options => { $self->options } ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -689,7 +693,7 @@ sub last_reason { my $cust_pkg_reason = qsearchs( { 'table' => 'cust_pkg_reason', 'hashref' => { 'pkgnum' => $self->pkgnum, }, - 'extra_sql'=> 'ORDER BY date DESC', + 'extra_sql'=> 'ORDER BY date DESC LIMIT 1', } ); qsearchs ( 'reason', { 'reasonnum' => $cust_pkg_reason->reasonnum } ) if $cust_pkg_reason; @@ -898,7 +902,8 @@ sub part_svc { my $part_svc = $pkg_svc->part_svc; my $num_cust_svc = $self->num_cust_svc($part_svc->svcpart); $part_svc->{'Hash'}{'num_cust_svc'} = $num_cust_svc; #more evil - $part_svc->{'Hash'}{'num_avail'} = $pkg_svc->quantity - $num_cust_svc; + $part_svc->{'Hash'}{'num_avail'} = + max( 0, $pkg_svc->quantity - $num_cust_svc ); $part_svc->{'Hash'}{'cust_pkg_svc'} = [ $self->cust_svc($part_svc->svcpart) ]; $part_svc; } $self->part_pkg->pkg_svc; @@ -1524,9 +1529,7 @@ sub order { sub insert_reason { my ($self, %options) = @_; - my $otaker = $FS::CurrentUser::CurrentUser->name; - $otaker = $FS::CurrentUser::CurrentUser->username - if (($otaker) eq "User, Legacy"); + my $otaker = $FS::CurrentUser::CurrentUser->username; my $cust_pkg_reason = new FS::cust_pkg_reason({ 'pkgnum' => $self->pkgnum,