3 # Copyright (c) 2004 Kristian Hoffmann <khoff@fire2wire.com>
4 # Based on the original RT::URI::base and RT::URI::fsck_com_rt.
6 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
8 # (Except where explictly superceded by other copyright notices)
10 # This work is made available to you under the terms of Version 2 of
11 # the GNU General Public License. A copy of that license should have
12 # been provided with this software, but in any event can be snarfed
15 # This work is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # General Public License for more details.
20 # Unless otherwise specified, all modifications, corrections or
21 # extensions to this work which alter its source code become the
22 # property of Best Practical Solutions, LLC when submitted for
23 # inclusion in the work.
29 no warnings qw(redefine);
35 use FS::CGI qw(popurl);
36 use FS::UI::Web::small_custview;
38 use FS::Record qw(qsearchs qsearch dbdef);
45 FS::UID->install_callback(
46 sub { @RT::URI::freeside::svc_tables = FS::part_svc->svc_tables() }
51 RT::URI::freeside::Internal
55 Overlay for the RT::URI::freeside URI handler implementing the Internal integration type.
57 See L<RT::URI::freeside> for public/private interface documentation.
63 sub _FreesideGetRecord {
66 my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
68 $RT::Logger->debug("Called _FreesideGetRecord()");
70 #eval "use FS::$table;";
74 $RT::Logger->error("Using Internal freeside integration type, ".
75 "but it doesn't look like we're running under ".
76 "freeside's Mason handler.");
80 my $pkeyfield = $dbdef->table($table)->primary_key;
82 $RT::Logger->error("No primary key for freeside table '$table'");
86 my $fsrec = qsearchs($table, { $pkeyfield => $pkey });
88 $RT::Logger->error("Record with '$pkeyfield' == '$pkey' does " .
89 "not exist in table $table");
93 return { $fsrec->hash, '_object' => $fsrec };
103 sub FreesideGetConfig {
105 #$conf = new FS::Conf unless ref($conf);
106 my $conf = new FS::Conf;
108 return scalar($conf->config(@_));
112 sub smart_search { #Subroutine
114 return map { { $_->hash } } &FS::cust_main::Search::smart_search(@_);
121 my $cust_pkg = $_->cust_pkg;
122 my $custnum = $cust_pkg->custnum if $cust_pkg;
123 my $label = join(': ',($_->label)[0, 1]);
127 'custnum' => $custnum, # so that it's smart_searchable...
130 } &FS::cust_svc::smart_search(@_);
134 sub email_search { #Subroutine
136 return map { { $_->hash } } &FS::cust_main::Search::email_search(@_);
142 return &FS::UI::Web::small_custview::small_custview(@_);
150 my $table = $self->{'fstable'};
152 if ( $table eq 'cust_main' ) {
154 my $rec = $self->_FreesideGetRecord();
155 return '<A HREF="' . $self->HREF . '">' .
156 small_custview( $rec->{'_object'},
157 scalar(FS::Conf->new->config('countrydefault')),
161 } elsif ( $table eq 'cust_svc' ) {
164 my $cust = $self->CustomerResolver;
166 # the customer's small_custview
167 $string = $cust->AsStringLong();
169 # + the service label and link
170 $string .= $self->ShortLink;
175 return $self->SUPER::AsStringLong;
182 # because I don't want AsString to sometimes return a hunk of HTML, but
183 # on the other hand AsStringLong does something specific.
185 '<B><A HREF="'.$self->HREF.'">' . $self->_FreesideURILabel . '</A></B>';
188 sub CustomerResolver {
190 if ( $self->{fstable} eq 'cust_main' ) {
193 elsif ( $self->{fstable} eq 'cust_svc' ) {
194 my $rec = $self->_FreesideGetRecord();
196 my $cust_pkg = $rec->{'_object'}->cust_pkg;
198 my $URI = RT::URI->new($self->CurrentUser);
199 $URI->FromURI('freeside://freeside/cust_main/'.$cust_pkg->custnum);
200 return $URI->Resolver;
208 $self = $self->CustomerResolver or return;
209 my $rec = $self->_FreesideGetRecord() or return;
210 my $cust_main = delete $rec->{_object};
211 my $agent = $cust_main->agent;
212 my $class = $cust_main->cust_class;
213 my $referral = qsearchs('part_referral', { refnum => $cust_main->refnum });
214 my @part_tags = $cust_main->part_tag;
216 return $self->{CustomerInfo} ||= {
219 AgentName => ($agent ? ($agent->agentnum.': '.$agent->agent) : ''),
220 CustomerClass => ($class ? $class->classname : ''),
222 sort { $a->{'name'} <=> $b->{'name'} }
224 { name => $_->tagname, desc => $_->tagdesc, color => $_->tagcolor }
227 Referral => ($referral ? $referral->referral : ''),
228 InvoiceEmail => $cust_main->invoicing_list_emailonly_scalar,
229 BillingType => FS::payby->longname($cust_main->payby),
235 $self->{fstable} eq 'cust_svc' or return;
236 my $rec = $self->_FreesideGetRecord() or return;
237 my $cust_svc = $rec->{'_object'};
238 my $svc_x = $cust_svc->svc_x;
239 my $part_svc = $cust_svc->part_svc;
240 return $self->{ServiceInfo} ||= {
243 ServiceType => $part_svc->svc,
244 Label => $self->AsString,