new 'jsearch' call for big joined searches & caching support
[freeside.git] / FS / FS / cust_svc.pm
index cbc4d91..c398e5e 100644 (file)
@@ -10,9 +10,21 @@ use FS::part_svc;
 use FS::svc_acct;
 use FS::svc_acct_sm;
 use FS::svc_domain;
+use FS::svc_forward;
 
 @ISA = qw( FS::Record );
 
+sub _cache {
+  my $self = shift;
+  my ( $hashref, $cache ) = @_;
+  if ( $hashref->{'username'} ) {
+    $self->{'_svc_acct'} = FS::svc_acct->new($hashref, '');
+  }
+  if ( $hashref->{'svc'} ) {
+    $self->{'_svcpart'} = FS::part_svc->new($hashref);
+  }
+}
+
 =head1 NAME
 
 FS::cust_svc - Object method for cust_svc objects
@@ -57,7 +69,7 @@ The following fields are currently supported:
 
 Creates a new service.  To add the refund to the database, see L<"insert">.
 Services are normally created by creating FS::svc_ objects (see
-L<FS::svc_acct>, L<FS::svc_domain>, and L<FS::svc_acct_sm>, among others).
+L<FS::svc_acct>, L<FS::svc_domain>, and L<FS::svc_forward>, among others).
 
 =cut
 
@@ -108,6 +120,20 @@ sub check {
   ''; #no error
 }
 
+=item part_svc
+
+Returns the definition for this service, as a FS::part_svc object (see
+L<FS::part_svc>).
+
+=cut
+
+sub part_svc {
+  my $self = shift;
+  $self->{'_svcpart'}
+    ? $self->{'_svcpart'}
+    : qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
+}
+
 =item label
 
 Returns a list consisting of:
@@ -119,32 +145,45 @@ Returns a list consisting of:
 
 sub label {
   my $self = shift;
-  my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
-  my $svcdb = $part_svc->svcdb;
-  my $svc_x = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } );
-  my $svc = $part_svc->svc;
+  my $svcdb = $self->part_svc->svcdb;
+  my $svc_x;
+  if ( $svcdb eq 'svc_acct' && $self->{'_svc_acct'} ) {
+    $svc_x = $self->{'_svc_acct'};
+  } else {
+    $svc_x = qsearchs( $svcdb, { 'svcnum' => $self->svcnum } )
+      or die "can't find $svcdb.svcnum ". $self->svcnum;
+  }
   my $tag;
   if ( $svcdb eq 'svc_acct' ) {
-    $tag = $svc_x->getfield('username');
+    $tag = $svc_x->email;
   } elsif ( $svcdb eq 'svc_acct_sm' ) {
     my $domuser = $svc_x->domuser eq '*' ? '(anything)' : $svc_x->domuser;
     my $svc_domain = qsearchs ( 'svc_domain', { 'svcnum' => $svc_x->domsvc } );
     my $domain = $svc_domain->domain;
     $tag = "$domuser\@$domain";
+  } elsif ( $svcdb eq 'svc_forward' ) {
+    my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $svc_x->srcsvc } );
+    $tag = $svc_acct->email. '->';
+    if ( $svc_x->dstsvc ) {
+      $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $svc_x->dstsvc } );
+      $tag .= $svc_acct->email;
+    } else {
+      $tag .= $svc_x->dst;
+    }
   } elsif ( $svcdb eq 'svc_domain' ) {
     $tag = $svc_x->getfield('domain');
   } else {
     cluck "warning: asked for label of unsupported svcdb; using svcnum";
     $tag = $svc_x->getfield('svcnum');
   }
-  $svc, $tag, $svcdb;
+  $self->part_svc->svc, $tag, $svcdb;
 }
 
 =back
 
 =head1 VERSION
 
-$Id: cust_svc.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $
+$Id: cust_svc.pm,v 1.6 2001-11-03 17:49:52 ivan Exp $
 
 =head1 BUGS