X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FURI%2Ffreeside%2FInternal.pm;h=2b09c879b29f2ce6d9eb09fbe72f7ae15a169dfe;hb=974347d88d264c60e65cbd22ac52553931b25ab8;hp=7b8efa0d36a9d9f18339f3db35ad1f687324711c;hpb=5495068bd26326467f674cf85a16a35088be7487;p=freeside.git diff --git a/rt/lib/RT/URI/freeside/Internal.pm b/rt/lib/RT/URI/freeside/Internal.pm index 7b8efa0d3..2b09c879b 100644 --- a/rt/lib/RT/URI/freeside/Internal.pm +++ b/rt/lib/RT/URI/freeside/Internal.pm @@ -38,6 +38,13 @@ use FS::Conf; use FS::Record qw(qsearchs qsearch dbdef); use FS::cust_main; use FS::cust_svc; +use FS::part_svc; +use FS::payby; + +#can I do this? +FS::UID->install_callback( + sub { @RT::URI::freeside::svc_tables = FS::part_svc->svc_tables() } +); =head1 NAME @@ -104,7 +111,23 @@ sub FreesideGetConfig { sub smart_search { #Subroutine - return map { { $_->hash } } &FS::cust_main::Search::smart_search(@_); + return map { { $_->hash } } &FS::cust_main::Search::smart_search(@_); + +} + +sub service_search { + + return map { + my $cust_pkg = $_->cust_pkg; + my $custnum = $cust_pkg->custnum if $cust_pkg; + my $label = join(': ',($_->label)[0, 1]); + my %hash = ( + $_->hash, + 'label' => $label, + 'custnum' => $custnum, # so that it's smart_searchable... + ); + \%hash + } &FS::cust_svc::smart_search(@_); } @@ -120,7 +143,7 @@ sub small_custview { } -sub _FreesideURILabelLong { +sub AsStringLong { my $self = shift; @@ -129,42 +152,142 @@ sub _FreesideURILabelLong { if ( $table eq 'cust_main' ) { my $rec = $self->_FreesideGetRecord(); - return small_custview( $rec->{'_object'}, + if (!$rec) { + return 'Customer #'.$self->{'fspkey'}.' (not found)'; + } + return '' . + small_custview( $rec->{'_object'}, scalar(FS::Conf->new->config('countrydefault')), - 1 #nobalance - ); + 1, #nobalance + ) . ''; + + } elsif ( $table eq 'cust_svc' ) { + + my $string = ''; + my $cust = $self->CustomerResolver; + if ( $cust ) { + # the customer's small_custview + $string = $cust->AsStringLong(); + } + # + the service label and link + $string .= $self->ShortLink; + return $string; } else { - return $self->_FreesideURILabel(); + return $self->SUPER::AsStringLong; } } -sub AgentName { +sub ShortLink { + # because I don't want AsString to sometimes return a hunk of HTML, but + # on the other hand AsStringLong does something specific. my $self = shift; - my $rec = $self->_FreesideGetRecord() or return; - my $agent = $rec->{'_object'}->agent or return; - return $agent->agentnum . ': ' . $agent->agent; + '' . $self->_FreesideURILabel . ''; } -sub CustomerClass { +sub CustomerResolver { my $self = shift; - my $rec = $self->_FreesideGetRecord() or return; - my $cust_class = $rec->{'_object'}->cust_class or return; - return $cust_class->classname; + if ( $self->{fstable} eq 'cust_main' ) { + return $self; + } + elsif ( $self->{fstable} eq 'cust_svc' ) { + my $rec = $self->_FreesideGetRecord(); + if ($rec) { + my $cust_pkg = $rec->{'_object'}->cust_pkg; + if ( $cust_pkg ) { + my $URI = RT::URI->new($self->CurrentUser); + $URI->FromURI('freeside://freeside/cust_main/'.$cust_pkg->custnum); + return $URI->Resolver; + } + } + return; + } + return; } - -sub CustomerTags { + +sub CustomerInfo { my $self = shift; + return $self->{CustomerInfo} if $self->{CustomerInfo}; + $self = $self->CustomerResolver; + + my $rec = $self->_FreesideGetRecord() if $self; + if (!$rec) { + # AsStringLong will report an error; + # here, just avoid breaking things + my $error = { + AgentName => '', + CustomerClass => '', + CustomerTags => [], + Referral => '', + InvoiceEmail => '', + BillingType => '', + }; + return $error; + } + + my $cust_main = delete $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; + + my @lf = $cust_main->location_fields; + my $bill_location = $cust_main->bill_location; + my $ship_location = $cust_main->ship_location; + + my $info = { + %$rec, + + 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), + }; + + foreach my $field (@lf) { + $info->{"bill_$field"} = $bill_location->get($field); + $info->{"ship_$field"} = $ship_location->get($field); + } + $info->{"bill_location"} = $bill_location->location_label(no_prefix => 1); + $info->{"ship_location"} = $ship_location->location_label(no_prefix => 1); + + return $self->{CustomerInfo} = $info; +} + +sub ServiceInfo { + my $self = shift; + $self->{fstable} eq 'cust_svc' or return; + return $self->{ServiceInfo} if $self->{ServiceInfo}; + my $rec = $self->_FreesideGetRecord() or return; - my @part_tag = $rec->{'_object'}->part_tag; - return map { - { 'name' => $_->tagname, - 'desc' => $_->tagdesc, - 'color' => $_->tagcolor } - } @part_tag; + my $cust_svc = $rec->{'_object'}; + my $svc_x = $cust_svc->svc_x; + my $part_svc = $cust_svc->part_svc; + my $locationnum = $cust_svc->cust_pkg->locationnum; + my $cust_location = qsearchs('cust_location', { locationnum => $locationnum}); + my @lf = FS::cust_main->location_fields; + + # location fields are not prefixed + my $info = { + $cust_svc->hash, + $svc_x->hash, + $cust_location->hash, + ServiceType => $part_svc->svc, + Label => $self->AsString, + }; + $info->{'location'} = $cust_location->location_label(no_prefix => 1); + + return $self->{ServiceInfo} = $info; } 1;