qualification address handling changes, RT#7111
authorivan <ivan>
Sun, 13 Mar 2011 02:31:10 +0000 (02:31 +0000)
committerivan <ivan>
Sun, 13 Mar 2011 02:31:10 +0000 (02:31 +0000)
FS/FS/Conf.pm
FS/FS/part_export/ikano.pm
httemplate/edit/elements/edit.html
httemplate/edit/prospect_main.html
httemplate/elements/location.html

index cbfde50..d8f37e5 100644 (file)
@@ -4232,12 +4232,19 @@ and customer address. Include units.',
   },
   
   {
-    'key'         => 'qual-alt-address-format',
+    'key'         => 'qual-alt_address_format',
     'section'     => 'UI',
-    'description' => 'Enable the alternate address format (location type, number, and kind) on qualifications',
+    'description' => 'Enable the alternate address format (location type, number, and kind) for qualifications.',
     'type'        => 'checkbox',
   },
-  
+
+  {
+    'key'         => 'prospect_main-alt_address_format',
+    'section'     => 'UI',
+    'description' => 'Enable the alternate address format (location type, number, and kind) for prospects.  Recommended if qual-alt_address_format is set and the main use of propects is for qualifications.',
+    'type'        => 'checkbox',
+  },
+
   {
     'key'         => 'note-classes',
     'section'     => 'UI',
index 604f47e..63b0ed3 100644 (file)
@@ -42,6 +42,21 @@ sub rebless { shift; }
 
 sub external_pkg_map { 1; }
 
+sub location_types {
+  (
+    ''     => '(None)',
+    'APT'  => 'Apartment',
+    'BLDG' => 'Building',
+    'FLR'  => 'Floor',
+    'LOT'  => 'Lot',
+    'RM'   => 'Room',
+    'SLIP' => 'Slip',
+    'TRLR' => 'Trailer',
+    'UNIT' => 'Unit',
+    'WING' => 'Wing',
+  );
+}
+
 sub dsl_pull {
 # we distinguish between invalid new data (return error) versus data that
 # has legitimately changed (may eventually execute hooks; now just update)
@@ -263,7 +278,6 @@ sub qual {
     my($self,$qual) = (shift,shift);
 
     my %location_hash = $qual->location_hash; 
-    warn Dumper $qual->location_hash;
     return 'No address provided' unless keys %location_hash;
 
     my $svctn = $qual->phonenum;
index b0c27e6..545221a 100644 (file)
@@ -281,51 +281,25 @@ Example:
 %     'disabled'      => $f->{'disabled'},
 %   );
 %
-%   #selectlayers, others?
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}),
-%                  qw( js_only html_only select_only layers_only cell_style);
-%
-%   #select-*
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}), qw( empty_label );
+%   $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
+%     qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
+%     qw( empty_label ),                                   # select-*
+%     qw( value_col ),                                     # select-table
+%     qw( table name_col ),                           #(select,checkboxes)-table
+%     qw( target_table link_table ),                       #checkboxes-table
+%     qw( hashref agent_virt agent_null agent_null_right ),#*-table
+%     qw( formatted_value ),                               #fixed
+%     qw( country ),                                       #select-country
+%     qw( width height ),                                  #htmlarea
+%     qw( alt_format ),                                    #select-cust_location
+%   ;
 %
 %   #select-table
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}), qw( value_col );
 %   $include_common{$_} = ref( $f->{$_} ) eq 'CODE'
 %                           ? &{ $f->{$_} }( $cgi, $object ) #, $f )
 %                           : $f->{$_}
 %     foreach grep exists($f->{$_}), qw( extra_sql );
 %
-%   #select-table, checkboxes-table
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}), qw( table name_col  );
-%
-%   #checkboxes-table
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}), qw( target_table link_table );
-%
-%   #*-table
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}),
-%       qw( hashref agent_virt agent_null agent_null_right );
-%
-%   # fixed
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}),
-%       qw( formatted_value );
-%
-%   # select-country
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}),
-%       qw( country );
-%
-%   #htmlarea
-%   $include_common{$_} = $f->{$_}
-%     foreach grep exists($f->{$_}), qw( width height );
-%
-%
 %   if ( $type eq 'tablebreak-tr-title' ) {
 %     $include_common{'table_id'} = 'TableNumber'. $tablenum++;
 %   }
index c260eb8..eb3e4d6 100644 (file)
        { 'field'             => 'contactnum',
          'type'              => 'contact',
          'colspan'           => 6,
-         ##actually o2m, but this seems to be working for edit so far
-         #'m2name_table'      => 'contact',
-         #'m2name_namecol'    => 'contactnum',
-         #'m2_label'          => 'Contact',
-         #'m2_error_callback' => $m2_error_callback,
-
          'o2m_table'      => 'contact',
          'm2_label'       => 'Contact',
          'm2_error_callback' => $m2_error_callback,
@@ -33,6 +27,7 @@
        { 'field'       => 'locationnum',
          'type'        => 'select-cust_location',
          'empty_label' => 'No address',
+         'alt_format'  => $conf->exists('prospect_main-alt_address_format'),
        },
      ],
      'new_callback'    => $new_callback,
@@ -44,6 +39,7 @@
 <%init>
 
 my $curuser = $FS::CurrentUser::CurrentUser;
+my $conf = new FS::Conf;
 
 my $prospectnum;
 if ( $cgi->param('error') ) {
@@ -139,7 +135,7 @@ my $m2_error_callback = sub {
           my $num = $1;
           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
             my $x = new FS::contact {
-              'contactnum' => $cgi->param("contactnum$num"),
+              'contactnum' => scalar($cgi->param("contactnum$num")),
               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
             };
             $x;
index b5f7640..5304c37 100644 (file)
@@ -17,6 +17,27 @@ Example:
 
 </%doc>
 
+% if ( $opt{'alt_format'} ) {
+
+<TR>
+    <<%$th%> ALIGN="right">Locatiopn type</<%$th%>>
+    <TD>
+    <% include('/elements/select.html',
+                 'cgi'        => $cgi,
+                 'field'      => 'location_kind',
+                 'disabled'   => $disabled,
+                 'style'      => $style, 
+                 'options'    => \@location_kind_options,
+                 'labels'     => $location_kind_labels,
+                 'curr_value' => scalar($cgi->param('location_kind'))
+                                   || $object->get($pre.'location_kind'),
+              )
+    %>
+    </TD>
+  </TR>
+
+% } 
+
 <TR>
   <<%$th%> ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></<%$th%>>
   <TD COLSPAN=7>
@@ -31,61 +52,105 @@ Example:
     >
   </TD>
 </TR>
+
+% if ( ! $opt{'alt_format'} ) { #regular format
+
 <TR>
       <TD ALIGN="right"><FONT ID="<% $pre %>address2_required" color="#ff0000" <% $address2_label_style %>>*</FONT>&nbsp;<FONT ID="<% $pre %>address2_label" <% $address2_label_style %>><B>Unit&nbsp;#</B></FONT></TD>
       <TD COLSPAN=7>
-       <INPUT TYPE     = "text"
-              NAME     = "<%$pre%>address2"
-              ID       = "<%$pre%>address2"
-              VALUE    = "<% $object->get($pre.'address2') |h %>"
-              SIZE     = 54
-              onChange = "<% $onchange %>"
-              <% $disabled %>
-              <% $style %>
-       >
+        <INPUT TYPE     = "text"
+               NAME     = "<%$pre%>address2"
+               ID       = "<%$pre%>address2"
+               VALUE    = "<% $object->get($pre.'address2') |h %>"
+               SIZE     = 54
+               onChange = "<% $onchange %>"
+               <% $disabled %>
+               <% $style %>
+        >
       </TD>
 </TR>
 
+% } else { # alternate format
+
+      <INPUT TYPE  = "hidden"
+             NAME  = "<%$pre%>address2"
+             VALUE = "<% $object->get($pre.'address2') |h %>"
+      >
 
-% if ( $opt{'alt_format'} ) { 
 <TR>
-    <<%$th%> ALIGN="right">Location Type</<%$th%>>
-    <TD><INPUT         TYPE="text" 
-               NAME="location_type" 
-               ID="location_type"
-               VALUE="<% $object->get('location_type') |h %>"
-               SIZE="10"
-              <% $disabled %>
-              <% $style %>
-       >
-    </TD>
-    <TD></TD>
-    <<%$th%> ALIGN="right">Number</<%$th%>>
-    <TD><INPUT TYPE="text" 
-               NAME="location_number"
-               ID="location_number"
-               VALUE="<% $object->get('location_number') |h %>"
-               SIZE="5"
-              <% $disabled %>
-              <% $style %>
-       >
-    </TD>
-    <<%$th%> ALIGN="right">Kind</<%$th%>>
-    <TD>
-    <% include('/elements/select.html',
-             'cgi'       => $cgi,
-            'field'    => 'location_kind',
-            'disabled' => $disabled,
-            'style' => $style, 
-            'options'  => \@location_kind_options,
-            'labels'   => $location_kind_labels,
-            'curr_value' => $cgi->param('location_kind'),
-         )
-    %>
+    <<%$th%> ALIGN="right">Unit Type and #</<%$th%>>
+    <TD COLSPAN=7>
+
+%     my $location_type = scalar($cgi->param('location_type'))
+%                           || $object->get($pre.'location_type');
+%     #my $location_number = scalar($cgi->param('location_number'))
+%     #                        || $object->get($pre.'location_number');
+%
+%   if ( $object->get($pre.'address2') && ! $location_type ) {
+%   }
+%
+%     if ( 1 ) { #ikano, switch on via config
+%       tie my %location_types, 'Tie::IxHash',
+%         FS::part_export::ikano->location_types;
+        <% include('/elements/select.html',
+                     'cgi'        => $cgi,
+                     'field'      => 'location_type',
+                     'disabled'   => $disabled,
+                     'style'      => $style,
+                     'options'    => [ keys %location_types ],
+                     'labels'     => \%location_types,
+                     'curr_value' => $location_type,
+                     'onchange'   => 'location_type_changed',
+                  )
+        %>
+        <SCRIPT TYPE="text/javascript">
+          function location_type_changed (what) {
+            if ( what.options[what.selectedIndex].value == '' ) {
+              what.form.location_number.disabled = true;
+              what.form.location_number.style.backgroundColor = '#dddddd';
+            } else {
+              what.form.location_number.disabled = false;
+              what.form.location_number.style.backgroundColor = '#ffffff';
+            }
+          }
+        </SCRIPT>
+%     } else {
+        <INPUT TYPE  = "text" 
+               NAME  = "location_type" 
+               ID    = "location_type"
+               VALUE = "<% $location_type |h %>"
+               SIZE  = "10"
+               <% $disabled %>
+               <% $style %>
+        >
+%     }
+
+    <INPUT TYPE="text" 
+               NAME="location_number"
+               ID="location_number"
+               VALUE="<% scalar($cgi->param('location_number')) || $object->get($pre.'location_number') |h %>"
+               SIZE="5"
+               <% $disabled || ($location_type ? '' : 'DISABLED') %>
+               <% $style %>
+        >
+
+%   if ( $object->get($pre.'address2') ) {
+
+%     #XXX try to parse first
+%     if ( 0 ) {
+%     } else {
+        Can't parse unit type and number from <B><% $object->get($pre.'address2') |h %></B>
+%    }
+
+% }
+
     </TD>
+
 </TR>
+
 % } 
 
+
 <TR>
   <<%$th%> ALIGN="right"><%$r%>City</<%$th%>>
   <TD WIDTH="1"><% include('/elements/city.html', %select_hash) %></TD>