residential prospects, RT#7111
authorivan <ivan>
Mon, 21 Mar 2011 00:55:12 +0000 (00:55 +0000)
committerivan <ivan>
Mon, 21 Mar 2011 00:55:12 +0000 (00:55 +0000)
FS/FS/Schema.pm
FS/FS/prospect_main.pm
httemplate/edit/elements/edit.html
httemplate/edit/prospect_main.html
httemplate/elements/radio.html [new file with mode: 0644]
httemplate/elements/tr-radio.html [new file with mode: 0644]
httemplate/search/prospect_main.html
httemplate/view/prospect_main.html

index 2bfe11a..6d4fb03 100644 (file)
@@ -982,12 +982,14 @@ sub tables_hashref {
       'columns' => [
         'prospectnum',  'serial',     '',      '', '', '',
         'agentnum',        'int',     '',      '', '', '',
-        'company',     'varchar',     '', $char_d, '', '',
-        #'disabled',     'char', 'NULL',       1, '', '', 
+        'company',     'varchar', 'NULL', $char_d, '', '',
+        'add_date',   @date_type,                  '', '', 
+        'disabled',       'char', 'NULL',       1, '', '', 
+        'custnum',         'int', 'NULL',      '', '', '',
       ],
       'primary_key' => 'prospectnum',
       'unique'      => [],
-      'index'       => [ [ 'company' ], [ 'agentnum' ], ],
+      'index'       => [ [ 'company' ], [ 'agentnum' ], [ 'disabled' ] ],
     },
 
     #eventually use for billing & ship from cust_main too
index 78e865a..079ad25 100644 (file)
@@ -203,7 +203,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;
 
@@ -216,7 +216,12 @@ sub check {
 
 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;
+
+  $self->prospectnum;
 }
 
 =item contact
index 975f8fb..1ed75c3 100644 (file)
@@ -379,6 +379,7 @@ Example:
 %     $g_row = 1 if $type eq 'tablebreak-tr-title';
 %     $g_row++;
 %     $g_row++ if $type eq 'title';
+%     $g_row += scalar( @{ $f->{options} } )-1 if $type eq 'radio';
 %   } else {
 %     if ( $type eq 'columnstart' ) {
 %       push @g_row_stack, $g_row;
index 4495cab..ab01930 100644 (file)
          'empty_label' => 'Select agent',
          'colspan'     => 6,
        },
-       { 'field'   => 'company',
-         'type'    => 'text',
-         'size'    => 50,
-         'colspan' => 6,
+       { 'field'    => 'residential_commercial',
+         'type'     => 'radio',
+         'options'  => [ 'Residential', 'Commercial', ],
+         'onchange' => 'rescom_changed',
+       },
+       { 'field'    => 'company',
+         'type'     => 'text',
+         'size'     => 50,
+         'colspan'  => 6,
        },
        { 'field'             => 'contactnum',
          'type'              => 'contact',
      ],
      'new_callback'    => $new_callback,
      'edit_callback'   => $edit_callback,
-     'error_callbacck' => $error_callback,
+     'error_callback'  => $error_callback,
      'agent_virt'      => 1,
+     'html_bottom'     => $javascript,
+     'body_etc'        => 'onLoad="rescom_changed()"',
    )
 %>
 <%init>
@@ -103,6 +110,9 @@ my $new_callback = sub {
 
   }
 
+  #config to default to commercial and/or disable residential when someone needs
+  $prospect_main->set('residential_commercial', 'Residential');
+
 };
 
 my $edit_callback = sub {
@@ -115,6 +125,12 @@ my $edit_callback = sub {
   $prospect_main->set('locationnum', $cust_location[0]->locationnum)
     if scalar(@cust_location);
   #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum');
+
+  $prospect_main->set('residential_commercial',
+    length($prospect_main->company)
+      ? 'Commercial'
+      : 'Residential'
+  );
 };
 
 my $error_callback = sub {
@@ -124,6 +140,13 @@ my $error_callback = sub {
     or die 'illegal locationnum '. $cgi->param('locationnum');
   my $locationnum = $1;
   $prospect_main->set('locationnum', $locationnum);
+
+  $prospect_main->set('residential_commercial',
+    ($cgi->param('residential_commercial') eq 'Commercial')
+      ? 'Commercial'
+      : 'Residential'
+  );
+
 };
 
 my $m2_error_callback = sub {
@@ -154,4 +177,18 @@ my $m2_error_callback = sub {
 
 #my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;
 
+my $javascript = <<END;
+  <SCRIPT TYPE="text/javascript">
+    function rescom_changed() {
+      var f = document.edit_topform;
+      var c = f.company;
+      if        ( f.residential_commercial_Residential.checked ) {
+        c.disabled = true;
+      } else if ( f.residential_commercial_Commercial.checked ) {
+        c.disabled = false;
+      }
+    }
+  </SCRIPT>
+END
+
 </%init>
diff --git a/httemplate/elements/radio.html b/httemplate/elements/radio.html
new file mode 100644 (file)
index 0000000..9af5332
--- /dev/null
@@ -0,0 +1,19 @@
+<% $opt{'prefix'} %><INPUT TYPE  = "radio"
+                           NAME  = "<% $opt{field} %>"
+                           ID    = "<% $opt{id}.'_'.$opt{value} %>"
+                           VALUE = "<% $opt{value} %>"
+                           <% $opt{curr_value} eq $opt{value}
+                                ? ' CHECKED'
+                                : ''
+                           %>
+                           <% $onchange %>
+                    ><% $opt{'postfix'} %>
+<%init>
+
+my %opt = @_;
+
+my $onchange = $opt{'onchange'}
+                 ? 'onChange="'. $opt{'onchange'}. '(this)"'
+                 : '';
+
+</%init>
diff --git a/httemplate/elements/tr-radio.html b/httemplate/elements/tr-radio.html
new file mode 100644 (file)
index 0000000..b5a2afa
--- /dev/null
@@ -0,0 +1,21 @@
+% foreach my $option ( @{ $opt{options} } ) { #just arrayref for now
+
+  <% include('tr-td-label.html', @_, label=> $labels->{$option} || $option ) %>
+
+    <TD <% $style %>>
+      <% include('radio.html', @_, value=> $option ) %>
+    </TD>
+
+  </TR>
+
+% }
+<%init>
+
+my %opt = @_;
+
+my $labels = $opt{'option_labels'} || $opt{'labels'};
+
+my $style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+
+</%init>
+
index 12e3e18..328d120 100644 (file)
@@ -8,7 +8,7 @@
                                   'Contact(s)',
                                 ],
              'fields'        => [ 'prospectnum',
-                                  'company',
+                                  'name',
                                   sub {
                                     my $pm = shift;
                                     [ map {
index f4b2f58..d92d270 100644 (file)
    </TR>
 %}
 
-<TR>
-  <TD ALIGN="right">Company</TD>
-  <TD BGCOLOR="#FFFFFF"><B><% $prospect_main->company |h %></B></TD>
-</TR>
+% if ( $prospect_main->company ) { 
+  <TR>
+    <TD ALIGN="right">Company</TD>
+    <TD BGCOLOR="#FFFFFF"><B><% $prospect_main->company |h %></B></TD>
+  </TR>
+% }
 
 % foreach my $contact ( $prospect_main->contact ) {
     <TR>
 
 % if ( $curuser->access_right('Qualify service') ) { 
 <% include( '/elements/popup_link-prospect_main.html',
-              'action'      => $p. 'misc/qual.html',
-              'label'       => 'New&nbsp;Qualification',
-              'actionlabel' => 'New Qualification',
-              'color'       => '#333399',
-              'prospect_main'   => $prospect_main,
-              'closetext'   => 'Close',
-              'width'       => 763,
-              'height'      => 436,
+              'action'        => $p. 'misc/qual.html',
+              'label'         => 'New&nbsp;Qualification',
+              'actionlabel'   => 'New Qualification',
+              'color'         => '#333399',
+              'prospect_main' => $prospect_main,
+              'closetext'     => 'Close',
+              'width'         => 763,
+              'height'        => 436,
           )
 %>
   | <A HREF="<%$p%>search/qual.cgi?prospectnum=<% $prospect_main->prospectnum %>">View Qualifications</A>