[freeside-commits] freeside/FS/FS cust_main.pm, 1.271.2.43, 1.271.2.44 cust_main_invoice.pm, 1.18, 1.18.2.1

Ivan,,, ivan at wavetail.420.am
Tue Apr 1 01:43:43 PDT 2008


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv16837/FS/FS

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	cust_main.pm cust_main_invoice.pm 
Log Message:
last bit of magic for RT ticket customer auto-association: look for requestor email addresses in cust_main_invoice and svc_acct, closes; RT#1160

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.271.2.43
retrieving revision 1.271.2.44
diff -u -d -r1.271.2.43 -r1.271.2.44
--- cust_main.pm	14 Mar 2008 20:11:47 -0000	1.271.2.43
+++ cust_main.pm	1 Apr 2008 08:43:40 -0000	1.271.2.44
@@ -4942,6 +4942,72 @@
 
 }
 
+=item email_search
+
+Accepts the following options: I<email>, the email address to search for.  The
+email address will be searched for as an email invoice destination and as an
+svc_acct account.
+
+#Any additional options are treated as an additional qualifier on the search
+#(i.e. I<agentnum>).
+
+Returns a (possibly empty) array of FS::cust_main objects (but usually just
+none or one).
+
+=cut
+
+sub email_search {
+  my %options = @_;
+
+  local($DEBUG) = 1;
+
+  my $email = delete $options{'email'};
+
+  #we're only being used by RT at the moment... no agent virtualization yet
+  #my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+  my @cust_main = ();
+
+  if ( $email =~ /([^@]+)\@([^@]+)/ ) {
+
+    my ( $user, $domain ) = ( $1, $2 );
+
+    warn "$me smart_search: searching for $user in domain $domain"
+      if $DEBUG;
+
+    push @cust_main,
+      map $_->cust_main,
+          qsearch( {
+                     'table'     => 'cust_main_invoice',
+                     'hashref'   => { 'dest' => $email },
+                   }
+                 );
+
+    push @cust_main,
+      map  $_->cust_main,
+      grep $_,
+      map  $_->cust_svc->cust_pkg,
+          qsearch( {
+                     'table'     => 'svc_acct',
+                     'hashref'   => { 'username' => $user, },
+                     'extra_sql' =>
+                       'AND ( SELECT domain FROM svc_domain
+                                WHERE svc_acct.domsvc = svc_domain.svcnum
+                            ) = '. dbh->quote($domain),
+                   }
+                 );
+  }
+
+  my %saw = ();
+  @cust_main = grep { !$saw{$_->custnum}++ } @cust_main;
+
+  warn "$me smart_search: found ". scalar(@cust_main). " unique customers"
+    if $DEBUG;
+
+  @cust_main;
+
+}
+
 =item check_and_rebuild_fuzzyfiles
 
 =cut

Index: cust_main_invoice.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main_invoice.pm,v
retrieving revision 1.18
retrieving revision 1.18.2.1
diff -u -d -r1.18 -r1.18.2.1
--- cust_main_invoice.pm	3 Oct 2006 15:59:06 -0000	1.18
+++ cust_main_invoice.pm	1 Apr 2008 08:43:40 -0000	1.18.2.1
@@ -159,6 +159,17 @@
   }
 }
 
+=item cust_main
+
+Returns the parent customer object (see L<FS::cust_main>).
+
+=cut
+
+sub cust_main {
+  my $self = shift;
+  qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
+}
+
 =back
 
 =head1 BUGS



More information about the freeside-commits mailing list