X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=3800e94691ec2002958407edd45ec5d731365d8a;hb=3846acae1c2a7ecb275e400cf3802ada6bc89ed2;hp=07e02f92c77815856631a8977e751f0c9ca0164e;hpb=5894069e99fa3579a76e6ede96e5262de9ac32c4;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 07e02f92c..3800e9469 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -1404,31 +1404,34 @@ sub suspend { } } - my @labels = (); - - foreach my $cust_svc ( - qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } ) - ) { - my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $cust_svc->svcpart } ); - - $part_svc->svcdb =~ /^([\w\-]+)$/ or do { - $dbh->rollback if $oldAutoCommit; - return "Illegal svcdb value in part_svc!"; - }; - my $svcdb = $1; - require "FS/$svcdb.pm"; - - my $svc = qsearchs( $svcdb, { 'svcnum' => $cust_svc->svcnum } ); - if ($svc) { - $error = $svc->suspend; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } - my( $label, $value ) = $cust_svc->label; - push @labels, "$label: $value"; + my @cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } ); + + #attempt ordering ala cust_svc_suspend_cascade (without infinite-looping + # on the circular dep case) + # (this is too simple for multi-level deps, we need to use something + # to resolve the DAG properly when possible) + my %svcpart = (); + $svcpart{$_->svcpart} = 0 foreach @cust_svc; + foreach my $svcpart ( keys %svcpart ) { + foreach my $part_svc_link ( + FS::part_svc_link->by_agentnum($self->cust_main->agentnum, + src_svcpart => $svcpart, + link_type => 'cust_svc_suspend_cascade' + ) + ) { + $svcpart{$part_svc_link->dst_svcpart} = max( + $svcpart{$part_svc_link->dst_svcpart}, + $svcpart{$part_svc_link->src_svcpart} + 1 + ); } } + @cust_svc = sort { $svcpart{ $a->svcpart } <=> $svcpart{ $b->svcpart } } + @cust_svc; + + my @labels = (); + foreach my $cust_svc ( @cust_svc ) { + $cust_svc->suspend( 'labels_arrayref' => \@labels ); + } # suspension fees: if there is a feepart, and it's not an unsuspend fee, # and this is not a suspend-before-cancel @@ -4975,6 +4978,78 @@ sub bulk_change { ''; } +=item forward_emails + +Returns a hash of svcnums and corresponding email addresses +for svc_acct services that can be used as source or dest +for svc_forward services provisioned in this package. + +Accepts options I OR I for a svc_forward +service; if included, will ensure the current values of the +specified service are included in the list, even if for some +other reason they wouldn't be. If called as a class method +with a specified service, returns only these current values. + +Caution: does not actually check if svc_forward services are +available to be provisioned on this package. + +=cut + +sub forward_emails { + my $self = shift; + my %opt = @_; + + #load optional service, thoroughly validated + die "Use svcnum or svc_forward, not both" + if $opt{'svcnum'} && $opt{'svc_forward'}; + my $svc_forward = $opt{'svc_forward'}; + $svc_forward ||= qsearchs('svc_forward',{ 'svcnum' => $opt{'svcnum'} }) + if $opt{'svcnum'}; + die "Specified service is not a forward service" + if $svc_forward && (ref($svc_forward) ne 'FS::svc_forward'); + die "Specified service not found" + if ($opt{'svcnum'} || $opt{'svc_forward'}) && !$svc_forward; + + my %email; + + ## everything below was basically copied from httemplate/edit/svc_forward.cgi + ## with minimal refactoring, not sure why we can't just load all svc_accts for this custnum + + #add current values from specified service, if there was one + if ($svc_forward) { + foreach my $method (qw( srcsvc_acct dstsvc_acct )) { + my $svc_acct = $svc_forward->$method(); + $email{$svc_acct->svcnum} = $svc_acct->email if $svc_acct; + } + } + + if (ref($self) eq 'FS::cust_pkg') { + + #and including the rest for this customer + my($u_part_svc,@u_acct_svcparts); + foreach $u_part_svc ( qsearch('part_svc',{'svcdb'=>'svc_acct'}) ) { + push @u_acct_svcparts,$u_part_svc->getfield('svcpart'); + } + + my $custnum = $self->getfield('custnum'); + foreach my $i_cust_pkg ( qsearch('cust_pkg',{'custnum'=>$custnum}) ) { + my $cust_pkgnum = $i_cust_pkg->getfield('pkgnum'); + #now find the corresponding record(s) in cust_svc (for this pkgnum!) + foreach my $acct_svcpart (@u_acct_svcparts) { + foreach my $i_cust_svc ( + qsearch( 'cust_svc', { 'pkgnum' => $cust_pkgnum, + 'svcpart' => $acct_svcpart } ) + ) { + my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $i_cust_svc->svcnum } ); + $email{$svc_acct->svcnum} = $svc_acct->email; + } + } + } + } + + return %email; +} + # Used by FS::Upgrade to migrate to a new database. sub _upgrade_data { # class method my ($class, %opts) = @_;