freeside/FS/FS TicketSystem.pm,NONE,1.1 cust_main.pm,1.164,1.165 Conf.pm,1.111,1.112 CGI.pm,1.27,1.28

ivan ivan at pouncequick.420.am
Thu Dec 2 01:59:52 PST 2004


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv24319/FS/FS

Modified Files:
	cust_main.pm Conf.pm CGI.pm 
Added Files:
	TicketSystem.pm 
Log Message:
second big RT integration checkin, customer linking/delinking interface


Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- cust_main.pm	9 Nov 2004 08:14:39 -0000	1.164
+++ cust_main.pm	2 Dec 2004 09:59:47 -0000	1.165
@@ -1,10 +1,11 @@
 package FS::cust_main;
 
 use strict;
-use vars qw( @ISA $conf $DEBUG $import );
+use vars qw( @ISA @EXPORT_OK $conf $DEBUG $import );
 use vars qw( $realtime_bop_decline_quiet ); #ugh
 use Safe;
 use Carp;
+use Exporter;
 BEGIN {
   eval "use Time::Local;";
   die "Time::Local minimum version 1.05 required with Perl versions before 5.6"
@@ -43,6 +44,8 @@
 
 @ISA = qw( FS::Record );
 
+ at EXPORT_OK = qw( smart_search );
+
 $realtime_bop_decline_quiet = 0;
 
 $DEBUG = 0;
@@ -2976,6 +2979,94 @@
 =head1 SUBROUTINES
 
 =over 4
+
+=item smart_search OPTION => VALUE ...
+
+Accepts the following options: I<search>, the string to search for.  The string
+will be searched for as a customer number, last name or company name, first
+searching for an exact match then fuzzy and substring matches.
+
+Any additional options treated as an additional qualifier on the search
+(i.e. I<agentnum>).
+
+Returns a (possibly empty) array of FS::cust_main objects.
+
+=cut
+
+sub smart_search {
+  my %options = @_;
+  my $search = delete $options{'search'};
+  my @cust_main = ();
+
+  if ( $search =~ /^\s*(\d+)\s*$/ ) { # customer # search
+
+    push @cust_main, qsearch('cust_main', { 'custnum' => $1, %options } );
+
+  } elsif ( $search =~ /^\s*(\S.*\S)\s*$/ ) { #value search
+
+    my $value = lc($1);
+    my $q_value = dbh->quote($value);
+
+    #exact
+    my $sql = scalar(keys %options) ? ' AND ' : ' WHERE ';
+    $sql .= " ( LOWER(last) = $q_value OR LOWER(company) = $q_value";
+    $sql .= " OR LOWER(ship_last) = $q_value OR LOWER(ship_company) = $q_value"
+      if defined dbdef->table('cust_main')->column('ship_last');
+    $sql .= ' )';
+
+    push @cust_main, qsearch( 'cust_main', \%options, '', $sql );
+
+    unless ( @cust_main ) {  #no exact match, trying substring/fuzzy
+
+      #still some false laziness w/ search/cust_main.cgi
+
+      #substring
+      push @cust_main, qsearch( 'cust_main',
+                                { 'last'     => { 'op'    => 'ILIKE',
+                                                  'value' => "%$q_value%" },
+                                  %options,
+                                }
+                              );
+      push @cust_main, qsearch( 'cust_main',
+                                { 'ship_last' => { 'op'    => 'ILIKE',
+                                                   'value' => "%$q_value%" },
+                                  %options,
+
+                                }
+                              )
+        if defined dbdef->table('cust_main')->column('ship_last');
+
+      push @cust_main, qsearch( 'cust_main',
+                                { 'company'  => { 'op'    => 'ILIKE',
+                                                  'value' => "%$q_value%" },
+                                  %options,
+                                }
+                              );
+      push @cust_main, qsearch( 'cust_main',
+                                { 'ship_company' => { 'op' => 'ILIKE',
+                                                   'value' => "%$q_value%" },
+                                  %options,
+                                }
+                              )
+        if defined dbdef->table('cust_main')->column('ship_last');
+
+      #fuzzy
+      push @cust_main, FS::cust_main->fuzzy_search(
+        { 'last'     => $value },
+        \%options,
+      );
+      push @cust_main, FS::cust_main->fuzzy_search(
+        { 'company'  => $value },
+        \%options,
+      );
+
+    }
+
+  }
+
+  @cust_main;
+
+}
 
 =item check_and_rebuild_fuzzyfiles
 

Index: CGI.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/CGI.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- CGI.pm	26 Oct 2004 11:26:33 -0000	1.27
+++ CGI.pm	2 Dec 2004 09:59:47 -0000	1.28
@@ -277,7 +277,7 @@
 
 }
 
-=item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT
+=item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT, NOBALANCE_FLAG
 
 Sheesh. I should just switch to Mason.
 
@@ -289,12 +289,13 @@
 
   my $arg = shift;
   my $countrydefault = shift || 'US';
+  my $nobalance = shift;
 
   my $cust_main = ref($arg) ? $arg
                   : qsearchs('cust_main', { 'custnum' => $arg } )
     or die "unknown custnum $arg";
 
-  my $html = 'Customer #<B>'. $cust_main->custnum. '</B>'.
+  my $html = 'Customer #<B>'. $cust_main->custnum. '</B></A>'.
     ' - <B><FONT COLOR="'. $cust_main->statuscolor. '">'.
     ucfirst($cust_main->status). '</FONT></B>'.
     ntable('#e8e8e8'). '<TR><TD>'. ntable("#cccccc",2).
@@ -366,7 +367,8 @@
 
   $html .= '</TR></TABLE>';
 
-  $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>';
+  $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>'
+    unless $nobalance;
 
   # last payment might be good here too?
 

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -d -r1.111 -r1.112
--- Conf.pm	27 Nov 2004 19:09:46 -0000	1.111
+++ Conf.pm	2 Dec 2004 09:59:47 -0000	1.112
@@ -1328,6 +1328,20 @@
     'select_enum' => [ '', qw(RT_Internal RT_Libs RT_External) ],
   },
 
+  {
+    'key'         => 'ticket_system-custom_priority_field',
+    'section'     => '',
+    'description' => 'Custom field from the ticketing system to use as a custom priority classification.',
+    'type'        => 'text',
+  },
+
+  {
+    'key'         => 'company_name',
+    'section'     => 'required',
+    'description' => 'Your company name',
+    'type'        => 'text',
+  },
+
 );
 
 1;

--- NEW FILE: TicketSystem.pm ---
package FS::TicketSystem;

use strict;
use vars qw( $system $AUTOLOAD );
use FS::Conf;
use FS::UID;

install_callback FS::UID sub { 
  my $conf = new FS::Conf;
  $system = $conf->config('ticket_system');
};

sub AUTOLOAD {
  my $self = shift;

  my($sub)=$AUTOLOAD;
  $sub =~ s/.*://;

  my $conf = new FS::Conf;
  die "FS::TicketSystem::$AUTOLOAD called, but no ticket system configured\n"
    unless $system;

  eval "use FS::TicketSystem::$system;";
  die $@ if $@;

  $self .= "::$system";
  $self->$sub(@_);
}

1;




More information about the freeside-commits mailing list