X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_svc.pm;h=8cce7afb40694292bd2762b23dcf1528cffff4a7;hp=320f78aa0167a82050e60bf20eed38923fbc15ca;hb=b5c4237a34aef94976bc343c8d9e138664fc3984;hpb=1c4c7cf9e2c1b4baae0453d844e23391cda7dfbb diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index 320f78aa0..8cce7afb4 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -109,7 +109,7 @@ If there is an error, returns the error, otherwise returns false. =cut sub cancel { - my $self = shift; + my($self,%opt) = @_; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -133,19 +133,26 @@ sub cancel { my $svc = $self->svc_x; if ($svc) { - - my $error = $svc->cancel; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "Error canceling service: $error"; - } - $error = $svc->delete; #this deletes this cust_svc record as well - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "Error deleting service: $error"; + if ( %opt && $opt{'date'} ) { + my $error = $svc->expire($opt{'date'}); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "Error expiring service: $error"; + } + } else { + my $error = $svc->cancel; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "Error canceling service: $error"; + } + $error = $svc->delete; #this deletes this cust_svc record as well + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "Error deleting service: $error"; + } } - } else { + } elsif ( !%opt ) { #huh? warn "WARNING: no svc_ record found for svcnum ". $self->svcnum. @@ -251,6 +258,18 @@ sub replace { } } +# #trigger a re-export on pkgnum changes? +# # (of prepaid packages), for Expiration RADIUS attribute +# if ( $new->pkgnum != $old->pkgnum && $new->cust_pkg->part_pkg->is_prepaid ) { +# my $svc_x = $new->svc_x; +# local($FS::Record::nowarn_identical) = 1; +# my $error = $svc_x->export('replace'); +# if ( $error ) { +# $dbh->rollback if $oldAutoCommit; +# return $error if $error; +# } +# } + #my $error = $new->SUPER::replace($old, @_); my $error = $new->SUPER::replace($old); if ( $error ) { @@ -288,22 +307,11 @@ sub check { if ( $self->pkgnum ) { my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } ); return "Unknown pkgnum" unless $cust_pkg; - my $pkg_svc = qsearchs( 'pkg_svc', { - 'pkgpart' => $cust_pkg->pkgpart, - 'svcpart' => $self->svcpart, - }); - # or new FS::pkg_svc ( { 'pkgpart' => $cust_pkg->pkgpart, - # 'svcpart' => $self->svcpart, - # 'quantity' => 0 } ); - my $quantity = $pkg_svc ? $pkg_svc->quantity : 0; - - my @cust_svc = qsearch('cust_svc', { - 'pkgnum' => $self->pkgnum, - 'svcpart' => $self->svcpart, - }); - return "Already ". scalar(@cust_svc). " ". $part_svc->svc. + ($part_svc) = grep { $_->svcpart == $self->svcpart } $cust_pkg->part_svc; + + return "Already ". $part_svc->get('num_cust_svc'). " ". $part_svc->svc. " services for pkgnum ". $self->pkgnum - if scalar(@cust_svc) >= $quantity && !$ignore_quantity; + if $part_svc->get('num_avail') == 0 and !$ignore_quantity; } $self->SUPER::check; @@ -363,6 +371,20 @@ sub date_inserted { $self->h_date('insert'); } +=item pkg_cancel_date + +Returns the date this service's package was canceled. This normally only +exists for a service that's been preserved through cancellation with the +part_pkg.preserve flag. + +=cut + +sub pkg_cancel_date { + my $self = shift; + my $cust_pkg = $self->cust_pkg or return; + return $cust_pkg->getfield('cancel') || ''; +} + =item label Returns a list consisting of: @@ -375,23 +397,34 @@ Usage example: my($label, $value, $svcdb) = $cust_svc->label; +=item label_long + +Like the B