summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorivan <ivan>2004-12-02 09:59:48 +0000
committerivan <ivan>2004-12-02 09:59:48 +0000
commit0d1d2630e726ab4ce32bab9c3e4a889eee43fcb4 (patch)
tree34d6d7d9dc3ed2ab2bd5fafb585330fc20355b53 /FS/FS
parentb81d94452ba28c79036ab417bd32df54a583f324 (diff)
second big RT integration checkin, customer linking/delinking interface
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/CGI.pm8
-rw-r--r--FS/FS/ClientAPI/Agent.pm69
-rw-r--r--FS/FS/Conf.pm14
-rw-r--r--FS/FS/TicketSystem.pm30
-rw-r--r--FS/FS/TicketSystem/RT_Internal.pm9
-rw-r--r--FS/FS/TicketSystem/RT_Libs.pm1
-rw-r--r--FS/FS/cust_main.pm93
7 files changed, 156 insertions, 68 deletions
diff --git a/FS/FS/CGI.pm b/FS/FS/CGI.pm
index 9b406d3..a4fc42f 100644
--- a/FS/FS/CGI.pm
+++ b/FS/FS/CGI.pm
@@ -277,7 +277,7 @@ sub ntable {
}
-=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 @@ sub small_custview {
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 @@ sub small_custview {
$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?
diff --git a/FS/FS/ClientAPI/Agent.pm b/FS/FS/ClientAPI/Agent.pm
index 1cc11d5..f534a86 100644
--- a/FS/FS/ClientAPI/Agent.pm
+++ b/FS/FS/ClientAPI/Agent.pm
@@ -6,9 +6,9 @@ use strict;
use vars qw($cache);
use Digest::MD5 qw(md5_hex);
use Cache::SharedMemoryCache; #store in db?
-use FS::Record qw(qsearchs qsearch dbdef dbh);
+use FS::Record qw(qsearchs); # qsearch dbdef dbh);
use FS::agent;
-use FS::cust_main;
+use FS::cust_main qw(smart_search);
use FS::ClientAPI;
FS::ClientAPI->register_handlers(
@@ -102,68 +102,9 @@ sub agent_list_customers {
my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } )
or return { 'error' => "unknown agentnum $agentnum" };
- my @cust_main = ();
-
- #warn $p->{'search'};
- if ( $p->{'search'} =~ /^\s*(\d+)\s*$/ ) { # customer # search
- push @cust_main, qsearch('cust_main', { 'agentnum' => $agentnum,
- 'custnum' => $1 } );
- } elsif ( $p->{'search'} =~ /^\s*(\S.*\S)\s*$/ ) { #value search
- my $value = lc($1);
- my $q_value = dbh->quote($value);
-
- #exact
- my $sql = " AND ( 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',
- { 'agentnum' => $agentnum },
- '',
- $sql
- );
-
- unless ( @cust_main ) {
- warn "no exact match, trying substring/fuzzy\n";
-
- #still some false laziness w/ search/cust_main.cgi
-
- #substring
- push @cust_main, qsearch( 'cust_main',
- { 'agentnum' => $agentnum,
- 'last' => { 'op' => 'ILIKE',
- 'value' => "%$q_value%" } } );
-
- push @cust_main, qsearch( 'cust_main',
- { 'agentnum' => $agentnum,
- 'ship_last' => { 'op' => 'ILIKE',
- 'value' => "%$q_value%" } } )
- if defined dbdef->table('cust_main')->column('ship_last');
-
- push @cust_main, qsearch( 'cust_main',
- { 'agentnum' => $agentnum,
- 'company' => { 'op' => 'ILIKE',
- 'value' => "%$q_value%" } } );
-
- push @cust_main, qsearch( 'cust_main',
- { 'agentnum' => $agentnum,
- 'ship_company' => { 'op' => 'ILIKE',
- 'value' => "%$q_value%" } } )
- if defined dbdef->table('cust_main')->column('ship_last');
-
- #fuzzy
- push @cust_main, FS::cust_main->fuzzy_search(
- { 'last' => $value },
- { 'agentnum' => $agentnum }
- );
- push @cust_main, FS::cust_main->fuzzy_search(
- { 'company' => $value },
- { 'agentnum' => $agentnum }
- );
-
- }
- }
+ my @cust_main = smart_search( 'search' => $p->{'search'},
+ 'agentnum' => $agentnum,
+ );
#aggregate searches
push @cust_main,
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index ccad607..1346796 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1328,6 +1328,20 @@ httemplate/docs/config.html
'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;
diff --git a/FS/FS/TicketSystem.pm b/FS/FS/TicketSystem.pm
new file mode 100644
index 0000000..2a5c68f
--- /dev/null
+++ b/FS/FS/TicketSystem.pm
@@ -0,0 +1,30 @@
+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;
diff --git a/FS/FS/TicketSystem/RT_Internal.pm b/FS/FS/TicketSystem/RT_Internal.pm
index a4ecd6a..ec0c3f7 100644
--- a/FS/FS/TicketSystem/RT_Internal.pm
+++ b/FS/FS/TicketSystem/RT_Internal.pm
@@ -1,8 +1,17 @@
package FS::TicketSystem::RT_Internal;
use strict;
+use vars qw( @ISA );
@ISA = qw( FS::TicketSystem::RT_Libs );
+sub sql_customer_tickets {
+ "( select count(*) from tickets
+ join links on ( tickets.id = links.localbase )
+ where ( status = 'new' or status = 'open' or status = 'stalled' )
+ and target = 'freeside://freeside/cust_main/' || custnum
+ )";
+}
+
1;
diff --git a/FS/FS/TicketSystem/RT_Libs.pm b/FS/FS/TicketSystem/RT_Libs.pm
index b717632..aba783f 100644
--- a/FS/FS/TicketSystem/RT_Libs.pm
+++ b/FS/FS/TicketSystem/RT_Libs.pm
@@ -1,6 +1,7 @@
package FS::TicketSystem::RT_Libs.pm
use strict;
+use vars qw( @ISA );
@ISA = qw( FS::TicketSystem::RT_External );
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index d8dbd52..27f97f3 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -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 @@ use FS::Msgcat qw(gettext);
@ISA = qw( FS::Record );
+@EXPORT_OK = qw( smart_search );
+
$realtime_bop_decline_quiet = 0;
$DEBUG = 0;
@@ -2977,6 +2980,94 @@ sub fuzzy_search {
=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
=cut