Merge branch 'patch-8' of https://github.com/gjones2/Freeside (#13854 as this bug...
[freeside.git] / FS / FS / prospect_main.pm
index 78e865a..b5d51d3 100644 (file)
@@ -1,13 +1,14 @@
 package FS::prospect_main;
 
 use strict;
-use base qw( FS::o2m_Common FS::Record );
+use base qw( FS::Quotable_Mixin FS::o2m_Common FS::Record );
 use vars qw( $DEBUG );
 use Scalar::Util qw( blessed );
-use FS::Record qw( dbh qsearch ); #qsearchs );
+use FS::Record qw( dbh qsearch qsearchs );
 use FS::agent;
 use FS::cust_location;
 use FS::contact;
+use FS::qual;
 
 $DEBUG = 0;
 
@@ -203,7 +204,7 @@ 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;
 
@@ -212,11 +213,19 @@ sub check {
 
 =item name
 
+Returns a name for this prospect, as a string (company name for commercial
+prospects, contact name for residential prospects).
+
 =cut
 
 sub name {
   my $self = shift;
-  $self->company; #at least until this is nullable
+  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
@@ -238,7 +247,30 @@ Returns the locations (see L<FS::cust_location>) associated with this prospect.
 
 sub cust_location {
   my $self = shift;
-  qsearch( 'cust_location', { 'prospectnum' => $self->prospectnum } );
+  qsearch( 'cust_location', { 'prospectnum' => $self->prospectnum,
+                              'custnum'     => '' } );
+}
+
+=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 agent
+
+Returns the agent (see L<FS::agent>) for this customer.
+
+=cut
+
+sub agent {
+  my $self = shift;
+  qsearchs( 'agent', { 'agentnum' => $self->agentnum } );
 }
 
 =item search HASHREF