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 RT::URI::freeside::Internal
49 Overlay for the RT::URI::freeside URI handler implementing the Internal integration type.
51 See L<RT::URI::freeside> for public/private interface documentation.
57 sub _FreesideGetRecord {
60 my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
62 $RT::Logger->debug("Called _FreesideGetRecord()");
64 #eval "use FS::$table;";
68 $RT::Logger->error("Using Internal freeside integration type, ".
69 "but it doesn't look like we're running under ".
70 "freeside's Mason handler.");
74 my $pkeyfield = $dbdef->table($table)->primary_key;
76 $RT::Logger->error("No primary key for freeside table '$table'");
80 my $fsrec = qsearchs($table, { $pkeyfield => $pkey });
82 $RT::Logger->error("Record with '$pkeyfield' == '$pkey' does " .
83 "not exist in table $table");
87 return { $fsrec->hash, '_object' => $fsrec };
97 sub FreesideGetConfig {
99 #$conf = new FS::Conf unless ref($conf);
100 my $conf = new FS::Conf;
102 return scalar($conf->config(@_));
106 sub smart_search { #Subroutine
108 return map { { $_->hash } } &FS::cust_main::Search::smart_search(@_);
112 sub email_search { #Subroutine
114 return map { { $_->hash } } &FS::cust_main::Search::email_search(@_);
120 return &FS::UI::Web::small_custview::small_custview(@_);
124 sub _FreesideURILabelLong {
128 my $table = $self->{'fstable'};
130 if ( $table eq 'cust_main' ) {
132 my $rec = $self->_FreesideGetRecord();
133 return small_custview( $rec->{'_object'},
134 scalar(FS::Conf->new->config('countrydefault')),
140 return $self->_FreesideURILabel();
146 # no need to have a separate wrapper method for every one of these things
149 my $rec = $self->_FreesideGetRecord() or return;
150 my $cust_main = $rec->{'_object'};
151 my $agent = $cust_main->agent;
152 my $class = $cust_main->cust_class;
153 my $referral = qsearchs('part_referral', { refnum => $cust_main->refnum });
154 my @part_tags = $cust_main->part_tag;
156 return $self->{CustomerInfo} ||= {
159 AgentName => ($agent ? ($agent->agentnum.': '.$agent->agent) : ''),
160 CustomerClass => ($class ? $class->classname : ''),
162 sort { $a->{'name'} <=> $b->{'name'} }
164 { name => $_->tagname, desc => $_->tagdesc, color => $_->tagcolor }
167 Referral => ($referral ? $referral->referral : ''),
168 InvoiceEmail => $cust_main->invoicing_list_emailonly_scalar,
169 BillingType => FS::payby->longname($cust_main->payby),