summaryrefslogtreecommitdiff
path: root/rt/lib/RT
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT')
-rw-r--r--rt/lib/RT/Tickets_Overlay.pm117
-rw-r--r--rt/lib/RT/URI/freeside.pm38
-rw-r--r--rt/lib/RT/URI/freeside/Internal.pm54
3 files changed, 94 insertions, 115 deletions
diff --git a/rt/lib/RT/Tickets_Overlay.pm b/rt/lib/RT/Tickets_Overlay.pm
index 76a57b8ce..a5d37a378 100644
--- a/rt/lib/RT/Tickets_Overlay.pm
+++ b/rt/lib/RT/Tickets_Overlay.pm
@@ -146,10 +146,11 @@ our %FIELD_METADATA = (
HasAttribute => [ 'HASATTRIBUTE', 1 ],
HasNoAttribute => [ 'HASATTRIBUTE', 0 ],
#freeside
- Agentnum => [ 'FREESIDEFIELD', ],
- Classnum => [ 'FREESIDEFIELD', ],
- Refnum => [ 'FREESIDEFIELD', ],
- Tagnum => [ 'FREESIDEFIELD', 'cust_tag' ],
+ Customer => [ 'FREESIDEFIELD', ],
+# Agentnum => [ 'FREESIDEFIELD', ],
+# Classnum => [ 'FREESIDEFIELD', ],
+# Refnum => [ 'FREESIDEFIELD', ],
+# Tagnum => [ 'FREESIDEFIELD', 'cust_tag' ],
WillResolve => [ 'DATE' => 'WillResolve', ], #loc_left_pair
);
@@ -1804,36 +1805,23 @@ sub OrderByCols {
push @res, { %$row, FIELD => "Priority", ORDER => $order } ;
} elsif ( $field eq 'Customer' ) { #Freeside
- if ( $subkey eq 'Number' ) {
- my ($linkalias, $custnum_sql) = $self->JoinToCustLinks;
- push @res, { %$row,
- ALIAS => '',
- FIELD => $custnum_sql,
- };
+ # OrderBy(FIELD => expression) doesn't work, it has to be
+ # an actual field, so we have to do the join even if sorting
+ # by custnum
+ my $custalias = $self->JoinToCustomer;
+ my $cust_field = lc($subkey);
+ if ( !$cust_field or $cust_field eq 'number' ) {
+ $cust_field = 'custnum';
}
- else {
- my $custalias = $self->JoinToCustomer;
- my $field;
- if ( $subkey eq 'Name' ) {
- $field = "COALESCE( $custalias.company,
- $custalias.last || ', ' || $custalias.first
- )";
- }
- elsif ( $subkey eq 'Class' ) {
- $field = "$custalias.classnum";
- }
- elsif ( $subkey eq 'Agent' ) {
- $field = "$custalias.agentnum";
- }
- elsif ( $subkey eq 'Referral' ) {
- $field = "$custalias.refnum";
- }
- else {
- # no other cases exist yet, but for obviousness:
- $field = $subkey;
- }
- push @res, { %$row, ALIAS => '', FIELD => $field };
+ elsif ( $cust_field eq 'name' ) {
+ $cust_field = "COALESCE( $custalias.company,
+ $custalias.last || ', ' || $custalias.first
+ )";
}
+ else { # order by cust_main fields directly: 'Customer.agentnum'
+ $cust_field = $subkey;
+ }
+ push @res, { %$row, ALIAS => $custalias, FIELD => $cust_field };
} #Freeside
@@ -1853,26 +1841,31 @@ sub JoinToCustLinks {
# Return the linkalias for further join/limit action,
# and an sql expression to retrieve the custnum.
my $self = shift;
- my $linkalias = $self->Join(
- TYPE => 'LEFT',
- ALIAS1 => 'main',
- FIELD1 => 'id',
- TABLE2 => 'Links',
- FIELD2 => 'LocalBase',
- );
+ # only join once for each RT::Tickets object
+ my $linkalias = $self->{cust_linkalias};
+ if (!$linkalias) {
+ $linkalias = $self->Join(
+ TYPE => 'LEFT',
+ ALIAS1 => 'main',
+ FIELD1 => 'id',
+ TABLE2 => 'Links',
+ FIELD2 => 'LocalBase',
+ );
- $self->SUPER::Limit(
- LEFTJOIN => $linkalias,
- FIELD => 'Type',
- OPERATOR => '=',
- VALUE => 'MemberOf',
- );
- $self->SUPER::Limit(
- LEFTJOIN => $linkalias,
- FIELD => 'Target',
- OPERATOR => 'STARTSWITH',
- VALUE => 'freeside://freeside/cust_main/',
- );
+ $self->SUPER::Limit(
+ LEFTJOIN => $linkalias,
+ FIELD => 'Type',
+ OPERATOR => '=',
+ VALUE => 'MemberOf',
+ );
+ $self->SUPER::Limit(
+ LEFTJOIN => $linkalias,
+ FIELD => 'Target',
+ OPERATOR => 'STARTSWITH',
+ VALUE => 'freeside://freeside/cust_main/',
+ );
+ $self->{cust_linkalias} = $linkalias;
+ }
my $custnum_sql = "CAST(SUBSTR($linkalias.Target,31) AS ";
if ( RT->Config->Get('DatabaseType') eq 'mysql' ) {
$custnum_sql .= 'SIGNED INTEGER)';
@@ -1886,7 +1879,8 @@ sub JoinToCustLinks {
sub JoinToCustomer {
my $self = shift;
my ($linkalias, $custnum_sql) = $self->JoinToCustLinks;
-
+ # don't reuse this join, though--negative queries need
+ # independent joins
my $custalias = $self->Join(
TYPE => 'LEFT',
EXPRESSION => $custnum_sql,
@@ -1908,20 +1902,29 @@ sub _FreesideFieldLimit {
$op = '=' if $op eq '!=';
$op =~ s/\bNOT\b//;
}
- my $meta = $FIELD_METADATA{$field};
- if ( $meta->[1] ) {
+
+ my $cust_field = $rest{SUBKEY} || 'custnum';
+ my $table2;
+ # compound subkey: separate into table name and field in that table
+ # (must be linked by custnum)
+ ($table2, $cust_field) = ($1, $2) if $cust_field =~ /^(\w+)?\.(\w+)$/;
+
+ $cust_field = lc($cust_field);
+ $cust_field = 'custnum' if !$cust_field or $cust_field eq 'number';
+
+ if ( $table2 ) {
$alias = $self->Join(
TYPE => 'LEFT',
ALIAS1 => $alias,
FIELD1 => 'custnum',
- TABLE2 => $meta->[1],
+ TABLE2 => $table2,
FIELD2 => 'custnum',
);
}
$self->SUPER::Limit(
LEFTJOIN => $alias,
- FIELD => lc($field),
+ FIELD => $cust_field,
OPERATOR => $op,
VALUE => $value,
ENTRYAGGREGATOR => 'AND',
@@ -1929,7 +1932,7 @@ sub _FreesideFieldLimit {
$self->_SQLLimit(
%rest,
ALIAS => $alias,
- FIELD => lc($field),
+ FIELD => 'custnum',
OPERATOR => $is_negative ? 'IS' : 'IS NOT',
VALUE => 'NULL',
QUOTEVALUE => 0,
diff --git a/rt/lib/RT/URI/freeside.pm b/rt/lib/RT/URI/freeside.pm
index 0e1834f47..64fb377fd 100644
--- a/rt/lib/RT/URI/freeside.pm
+++ b/rt/lib/RT/URI/freeside.pm
@@ -299,39 +299,19 @@ if ($@ &&
die $@;
};
-=item AgentName
+=item CustomerInfo
-Return the name of the customer's agent.
+Return a hashref of customer information, including all fields from
+C<cust_main> as well as:
-=cut
-
-sub AgentName { undef }
-
-=item CustomerClass
-
-Return the name of the customer's class.
-
-=cut
-
-sub CustomerClass { undef }
-
-=item CustomerTags
-
-Return the list of tags attached to the customer. Each tag is returned
-as a hashref with keys "name", "desc", and "color".
-
-=cut
-
-sub CustomerTags { ( ) }
-
-=back
-
-=item Referral
-
-Return the customer's advertising source, as a string.
+- AgentName: the name of the customer's agent
+- CustomerClass: the name of the customer's class
+- CustomerTags: an arrayref of tags attached to the customer, each
+ as a hashref with keys "name", "desc", and "color".
+- Referral: the name of the customer's advertising source.
=cut
-sub Referral { undef }
+sub CustomerInfo { {} }
1;
diff --git a/rt/lib/RT/URI/freeside/Internal.pm b/rt/lib/RT/URI/freeside/Internal.pm
index 4069b87af..5656a51d8 100644
--- a/rt/lib/RT/URI/freeside/Internal.pm
+++ b/rt/lib/RT/URI/freeside/Internal.pm
@@ -38,6 +38,7 @@ use FS::Conf;
use FS::Record qw(qsearchs qsearch dbdef);
use FS::cust_main;
use FS::cust_svc;
+use FS::payby;
=head1 NAME
@@ -53,7 +54,7 @@ See L<RT::URI::freeside> for public/private interface documentation.
-sub _FreesideGetRecord { # cache this?
+sub _FreesideGetRecord {
my $self = shift;
my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
@@ -142,36 +143,31 @@ sub _FreesideURILabelLong {
}
-sub AgentName {
+# no need to have a separate wrapper method for every one of these things
+sub CustomerInfo {
my $self = shift;
my $rec = $self->_FreesideGetRecord() or return;
- my $agent = $rec->{'_object'}->agent or return;
- return $agent->agentnum . ': ' . $agent->agent;
-}
-
-sub CustomerClass {
- my $self = shift;
- my $rec = $self->_FreesideGetRecord() or return;
- my $cust_class = $rec->{'_object'}->cust_class or return;
- return $cust_class->classname;
-}
-
-sub CustomerTags {
- my $self = shift;
- my $rec = $self->_FreesideGetRecord() or return;
- my @part_tag = $rec->{'_object'}->part_tag;
- return map {
- { 'name' => $_->tagname,
- 'desc' => $_->tagdesc,
- 'color' => $_->tagcolor }
- } @part_tag;
-}
-
-sub Referral {
- my $self = shift;
- my $rec = $self->_FreesideGetRecord() or return;
- my $ref = qsearchs('part_referral', { refnum => $rec->{'_object'}->refnum });
- $ref ? $ref->referral : ''
+ my $cust_main = $rec->{'_object'};
+ my $agent = $cust_main->agent;
+ my $class = $cust_main->cust_class;
+ my $referral = qsearchs('part_referral', { refnum => $cust_main->refnum });
+ my @part_tags = $cust_main->part_tag;
+
+ return $self->{CustomerInfo} ||= {
+ $cust_main->hash,
+
+ AgentName => ($agent ? ($agent->agentnum.': '.$agent->agent) : ''),
+ CustomerClass => ($class ? $class->classname : ''),
+ CustomerTags => [
+ sort { $a->{'name'} <=> $b->{'name'} }
+ map {
+ { name => $_->tagname, desc => $_->tagdesc, color => $_->tagcolor }
+ } @part_tags
+ ],
+ Referral => ($referral ? $referral->referral : ''),
+ InvoiceEmail => $cust_main->invoicing_list_emailonly_scalar,
+ BillingType => FS::payby->longname($cust_main->payby),
+ }
}
1;