fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / prospect_main.pm
index 369029b..5a4048f 100644 (file)
@@ -8,6 +8,7 @@ use FS::Record qw( dbh qsearch ); #qsearchs );
 use FS::agent;
 use FS::cust_location;
 use FS::contact;
+use FS::qual;
 
 $DEBUG = 0;
 
@@ -41,14 +42,13 @@ from FS::Record.  The following fields are currently supported:
 
 primary key
 
-=item company
-
-company
+=item agentnum
 
-=item locationnum
+Agent
 
-locationnum
+=item company
 
+company
 
 =back
 
@@ -204,13 +204,27 @@ sub check {
   my $error = 
     $self->ut_numbern('prospectnum')
     || $self->ut_foreign_key('agentnum', 'agent', 'agentnum' )
-    || $self->ut_text('company')
+    || $self->ut_textn('company')
   ;
   return $error if $error;
 
   $self->SUPER::check;
 }
 
+=item name
+
+=cut
+
+sub name {
+  my $self = shift;
+  return $self->company if $self->company;
+
+  my $contact = ($self->contact)[0]; #first contact?  good enough for now
+  return $contact->line if $contact;
+
+  'Prospect #'. $self->prospectnum;
+}
+
 =item contact
 
 Returns the contacts (see L<FS::contact>) associated with this prospect.
@@ -222,6 +236,29 @@ sub contact {
   qsearch( 'contact', { 'prospectnum' => $self->prospectnum } );
 }
 
+=item cust_location
+
+Returns the locations (see L<FS::cust_location>) associated with this prospect.
+
+=cut
+
+sub cust_location {
+  my $self = shift;
+  qsearch( 'cust_location', { 'prospectnum' => $self->prospectnum } );
+}
+
+=item qual
+
+Returns the qualifications (see L<FS::qual>) associated with this prospect.
+
+=cut
+
+sub qual {
+  my $self = shift;
+  qsearch( 'qual', { 'prospectnum' => $self->prospectnum } );
+}
+
+
 =item search HASHREF
 
 (Class method)