- eval {
- use FS::UID qw(dbh);
- use FS::Record qw(qsearchs qsearch dbdef);
- eval "use FS::$table;";
- use FS::cust_svc;
-
- my $dbdef = dbdef or die "No dbdef";
- my $pkeyfield = $dbdef->table($table)->primary_key
- or die "No primary key for table $table";
-
- my $rec = qsearchs($table, { $pkeyfield => $pkey })
- or die "Record with $pkeyfield == $pkey does not exist in table $table";
-
- if ($table =~ /^svc_/) {
- #if ($rec->can('cust_svc')) {
- # my $cust_svc = $rec->cust_svc or die '$rec->cust_svc failed';
- # my ($svc, $tag, $svcdb) = $cust_svc->label;
- # $label = "Freeside service ${svc}: ${tag}";
- #}
- $label = '';
- } elsif ($table eq 'cust_main') {
- use FS::CGI qw(small_custview);
- $label = small_custview( $rec,
- scalar(FS::Conf->new->config('countrydefault')),
- 1 #nobalance
- );
- } else {
- #$label = "Freeside ${table}, ${pkeyfield} == ${pkey}";
- $label = '';
- }
-
- #... other cases
-
- };
+ #if ($table ne 'cust_main') {
+ # warn "FS::${table} not currently supported";
+ # return;
+ #}
+
+ my $rec = $self->_FreesideGetRecord();
+
+ if (ref($rec) eq 'HASH' && $table eq 'cust_main') {
+ my $name = $rec->{'last'} . ', ' . $rec->{'first'};
+ $name = $rec->{'company'} . " ($name)" if $rec->{'company'};
+ $label = "$pkey: $name";
+ } elsif ( $table eq 'cust_svc' && ref($rec) && $rec->{'_object'} ) {
+ #Internal only
+ my($l,$v) = $rec->{'_object'}->label;
+ $label = "$l: $v";
+ } else {
+ $label = "$pkey: $table";
+ }