prospect qualifications default to prospect address if there's one, other UI cleanups...
authorivan <ivan>
Fri, 11 Mar 2011 00:45:53 +0000 (00:45 +0000)
committerivan <ivan>
Fri, 11 Mar 2011 00:45:53 +0000 (00:45 +0000)
FS/FS/prospect_main.pm
httemplate/elements/tr-select-cust_location.html
httemplate/elements/tr-td-label.html
httemplate/misc/qual.html

index 369029b..bace1f0 100644 (file)
@@ -41,14 +41,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
 
@@ -222,6 +221,17 @@ 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 search HASHREF
 
 (Class method)
index 5802f4e..bb10a83 100644 (file)
@@ -160,14 +160,8 @@ Example:
 % if ( $opt{'is_optional'} ) {
     <OPTION VALUE="-2" <% $locationnum == -2 ? 'SELECTED' : ''%>><% $opt{'optional_label'} || '(not required)' |h %>
 % }
-%     my @locations = $cust_main ? $cust_main->cust_location : ();
-%     @locations = qsearch('cust_location', 
-%                          { 'prospectnum' => $prospect_main->prospectnum } ) 
-%          if $prospect_main;
-%     push @locations, $cust_location
-%       if !$cust_main && $cust_location && $cust_location->locationnum>0;
-%     foreach my $loc ( sort $location_sort @locations ) {
-%       next if $loc->disabled;
+%
+%     foreach my $loc ( @cust_location ) {
         <OPTION VALUE="<% $loc->locationnum %>"
                 <% $locationnum == $loc->locationnum ? 'SELECTED' : '' %>
         ><% $loc->line |h %>
@@ -200,18 +194,26 @@ my $statedefault = $conf->config('statedefault')
 
 my %opt = @_;
 my $cgi           = $opt{'cgi'};
-my $cust_pkg     = $opt{'cust_pkg'};
+my $cust_pkg      = $opt{'cust_pkg'};
 my $cust_main     = $opt{'cust_main'};
 my $prospect_main = $opt{'prospect_main'};
 
 my $prefix = ($cust_main && length($cust_main->ship_last)) ? 'ship_' : '';
 
-my $locationnum;
-if ( length($opt{'curr_value'}) ) {
-  $locationnum = $opt{'curr_value'};
-} else {
+my $locationnum = '';
+if ( $cgi->param('error') ) {
   $cgi->param('locationnum') =~ /^(\-?\d*)$/ or die "illegal locationnum";
   $locationnum = $1;
+} else {
+  if ( length($opt{'curr_value'}) ) {
+    $locationnum = $opt{'curr_value'};
+  } elsif ($prospect_main) {
+    my @cust_location = $prospect_main->cust_location;
+    $locationnum = $cust_location[0]->locationnum if scalar(@cust_location)==1;
+  } else { #?
+    $cgi->param('locationnum') =~ /^(\-?\d*)$/ or die "illegal locationnum";
+    $locationnum = $1;
+  }
 }
 
 #probably could use explicit controls
@@ -248,9 +250,22 @@ my $location_sort = sub {
   or lc($a->address2) cmp lc($b->address2)
 };
 
-my $disabled = ( $locationnum < 0 || ($editable && $locationnum) )
-                 ? ''
-                 : 'DISABLED';
+my @cust_location = ();
+push @cust_location, $cust_main->cust_location if $cust_main;
+push @cust_location, $prospect_main->cust_location if $prospect_main;
+push @cust_location, $cust_location
+  if !$cust_main && $cust_location && $cust_location->locationnum > 0
+  && ! grep { $_->locationnum == $cust_location->locationnum } @cust_location;
+
+@cust_location = sort $location_sort grep !$_->disabled, @cust_location;
+
+my $disabled =
+  ( $locationnum < 0
+    || ( $editable && $locationnum )
+    || ( $prospect_main && !$opt{'is_optional'} && !@cust_location && $addnew )
+  )
+    ? ''
+    : 'DISABLED';
 
 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
 
index 77c0484..f847389 100644 (file)
@@ -1,10 +1,10 @@
 <TR>
 
-  <TD ALIGN="right" VALIGN="top" STYLE="<% $style %>" ID="<% $opt{label_id} || $opt{id}. '_label0' %>">
-
-    <% $opt{label} %>
-
-  </TD>
+  <TD ALIGN  = "right"
+      VALIGN = "<% $opt{'valign'} || 'top' %>"
+      STYLE  = "<% $style %>"
+      ID     = "<% $opt{label_id} || $opt{id}. '_label0' %>"
+  ><% $opt{label} %></TD>
 
 <%init>
 
index 69a5f8b..7af2590 100644 (file)
@@ -9,39 +9,47 @@
 <% ntable("#cccccc", 2) %>
 
 <% include('/elements/tr-td-label.html',
-             'cgi'       => $cgi,
-            'label'    => 'Qualify using',
-            'cell_style' => 'font-weight: bold',
-            'id' => 'exportnum',
-         )
+             'cgi'        => $cgi,
+             'label'      => 'Qualify using',
+             #'cell_style' => 'font-weight: bold',
+             'id'         => 'exportnum',
+          )
 %>
 <TD>
 <% include('/elements/select.html',
-             'cgi'       => $cgi,
-            'field'    => 'exportnum',
-            'options'  => \@export_options,
-            'labels'   => $export_labels,
-            'curr_value' => $cgi->param('exportnum'),
-         )
+             'cgi'        => $cgi,
+             'field'      => 'exportnum',
+             'options'    => \@export_options,
+             'labels'     => $export_labels,
+             'curr_value' => $exportnum,
+          )
 %>
 </TD>
 </TR>
 
 <% include('/elements/tr-input-text.html',
-             'cgi'       => $cgi,
-            'label'    => 'Service Telephone Number',
-            'field'    => 'phonenum',
-            'size'     => '12',
-            'value'    => $cgi->param('phonenum'),
+             'cgi'     => $cgi,
+             'label'   => 'Service Telephone Number',
+             'field'   => 'phonenum',
+             'size'    => '12',
+             'value'   => scalar($cgi->param('phonenum')),
+
+             'valign'  => 'middle',
+             'colspan' => 6,
+             'prefix'  => '<TABLE><TR><TD>',
+             'postfix' => '</TD><TD><FONT SIZE="-2">'. join('<BR>',
+                 'Line-share (non dry loops) - always fill in',
+                 'Dry loops - always leave empty',
+               ). '</FONT></TD></TR></TABLE>',
           )
 %>
 
 <% include('/elements/tr-select-cust_location.html',
-             'cgi'       => $cgi,
-            $table => $cust_main_or_prospect_main,
-            'alt_format' => $conf->exists('qual-alt-address-format') ? 1 : 0,
-            'is_optional' => 1,
-            'no_bold' => 1,
+             'cgi'         => $cgi,
+             $table        => $cust_main_or_prospect_main,
+             'alt_format'  => $conf->exists('qual-alt-address-format') ? 1 : 0,
+             'no_bold'     => 1,
+             #required for ikano.. config? 'is_optional' => 1,
           )
 %>
 </TABLE>
@@ -84,5 +92,10 @@ foreach my $export ( @exports ) {
     push @export_options, $export->exportnum;
     $export_labels->{$export->exportnum} = $export->exportname;
 }
+my $exportnum = $cgi->param('error')
+                  ? scalar($cgi->param('exportnum'))
+                  : scalar(@exports) == 1
+                    ? $exports[0]->exportnum
+                    : '';
 
 </%init>