[freeside-commits] branch FREESIDE_4_BRANCH updated. 14cfadee1f1cbd670a807e616f3dd5b7dff48176

Christopher Burger burgerc at freeside.biz
Tue Dec 11 15:53:46 PST 2018


The branch, FREESIDE_4_BRANCH has been updated
       via  14cfadee1f1cbd670a807e616f3dd5b7dff48176 (commit)
       via  4d53eaf45d3ca27507b892db52f58312d2404a20 (commit)
      from  8f04fd3c76b61242f2fb22e28b78e90a8d12d577 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 14cfadee1f1cbd670a807e616f3dd5b7dff48176
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Dec 11 18:45:36 2018 -0500

    RT# 74693 - Added city select when using tax classes

diff --git a/httemplate/elements/select-city.html b/httemplate/elements/select-city.html
new file mode 100644
index 000000000..09e28dd48
--- /dev/null
+++ b/httemplate/elements/select-city.html
@@ -0,0 +1,176 @@
+<%doc>
+
+Example:
+
+ <& /elements/select-city.html,
+    #recommended
+    country    => $current_country,
+    state      => $current_state,
+    county     => $current_county,
+    city       => $current_city,
+
+    #optional
+    prefix        => $optional_unique_prefix,
+    onchange      => $javascript,
+    disabled      => 0, #bool
+    disable_empty => 1, #defaults to 1, set to 0 to disable the empty option
+    empty_label   => 'all', #label for empty option
+    style         => [ 'attribute:value', 'another:value' ],
+  &>
+
+</%doc>
+% if ( $cityflag ) { 
+
+  <% include('/elements/xmlhttp.html',
+                'url'  => $p.'misc/cities.cgi',
+                'subs' => [ $pre. 'get_cities' ],
+             )
+  %>
+  
+  <SCRIPT TYPE="text/javascript">
+  
+    function opt(what,value,text) {
+      var optionName = new Option(text, value, false, false);
+      var length = what.length;
+      what.options[length] = optionName;
+    }
+  
+    function <% $pre %>county_changed(what, callback) {
+
+      what.form.<% $pre %>city.disabled = 'disabled';
+
+      county = what.form.<% $pre %>county.options[what.form.<% $pre %>county.selectedIndex].value;
+      state = what.options[what.selectedIndex].value;
+      country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
+  
+      function <% $pre %>update_cities(cities) {
+
+        // blank the current city list
+        for ( var i = what.form.<% $pre %>city.length; i >= 0; i-- )
+            what.form.<% $pre %>city.options[i] = null;
+
+%       unless ( $opt{disable_empty} ) {
+          opt( what.form.<% $pre %>city, '', <% $opt{empty_label} |js_string %> );
+%       }
+  
+        // add the new cities
+        var citiesArray = eval('(' + cities + ')' );
+        for ( var s = 0; s < citiesArray.length; s++ ) {
+            var cityLabel = citiesArray[s];
+            if ( cityLabel == "" )
+                cityLabel = '(n/a)';
+            opt(what.form.<% $pre %>city, citiesArray[s], cityLabel);
+        }
+
+        var cityFormLabel = document.getElementById('<% $pre %>citylabel');
+
+        if ( citiesArray.length > 1 ) { 
+          what.form.<% $pre %>city.style.display = '';
+          if ( cityFormLabel )  {
+            //cityFormLabel.style.visibility = 'visible';
+            cityFormLabel.style.display = '';
+          }
+        } else {
+          what.form.<% $pre %>city.style.display = 'none';
+          if ( cityFormLabel ) {
+            //cityFormLabel.style.visibility = 'hidden';
+            cityFormLabel.style.display = 'none';
+          }
+        }
+
+        what.form.<% $pre %>city.disabled = '';
+
+        //run the callback
+        if ( callback != null )  {
+          callback();
+        } else {
+          <% $pre %>city_changed(what.form.<% $pre %>city);
+        }
+      }
+  
+      // go get the new cities
+      <% $pre %>get_cities( state, country, <% $pre %>update_cities );
+  
+    }
+  
+  </SCRIPT>
+
+  <SELECT NAME    = "<% $pre %>city"
+          ID      = "<% $pre %>city"
+          onChange= "<% $onchange %>"
+          <% $opt{'disabled'} %>
+          <% $style %>
+  >
+
+% unless ( $opt{'disable_empty'} ) {
+  <OPTION VALUE="" <% $opt{county} eq '' ? 'SELECTED' : '' %>><% $opt{empty_label} %>
+% }
+
+% foreach my $city ( @cities ) {
+
+    <OPTION VALUE="<% $city |h %>"
+            <% $city eq $opt{'city'} ? 'SELECTED' : '' %>
+    ><% $city eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $city %>
+
+% } 
+
+  </SELECT>
+
+% } else { 
+
+  <SCRIPT TYPE="text/javascript">
+    function <% $pre %>city_changed(what) {
+    }
+  </SCRIPT>
+
+  <SELECT NAME  = "<% $pre %>city"
+           ID   = "<% $pre %>city"
+          STYLE = "display:none"
+  >
+    <OPTION SELECTED VALUE="<% $opt{'city'} |h %>">
+  </SELECT>
+
+% } 
+
+<%init>
+
+my %opt = @_;
+foreach my $opt (qw( city county state country prefix onchange disabled
+                     empty_value )) {
+  $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
+}
+
+$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
+
+my $pre = $opt{'prefix'};
+
+my $onchange = $opt{'onchange'};
+
+my $city_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
+
+my @cities = ();
+if ( $cityflag ) {
+
+  @cities = map { length($_) ? $_ : $opt{'empty_data_value'} }
+                  cities( $opt{'county'}, $opt{'state'}, $opt{'country'} );
+
+  push @$city_style, 'display:none'
+    unless scalar(@cities) > 1;
+
+}
+
+my $style =
+  scalar(@$city_style)
+    ? 'STYLE="'. join(';', @$city_style). '"'
+    : '';
+
+</%init>
+<%once>
+
+my $sql = "SELECT COUNT(*) FROM cust_main_county".
+          " WHERE city IS NOT NULL AND city != ''";
+my $sth = dbh->prepare($sql) or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+my $cityflag = $sth->fetchrow_arrayref->[0];
+
+</%once>
\ No newline at end of file

commit 4d53eaf45d3ca27507b892db52f58312d2404a20
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Dec 11 18:01:30 2018 -0500

    RT# 74693 - Added Bulk edit of rates only
    
    Conflicts:
            httemplate/browse/cust_main_county.cgi

diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi
index 26a3e21b9..9df8fed0b 100755
--- a/httemplate/browse/cust_main_county.cgi
+++ b/httemplate/browse/cust_main_county.cgi
@@ -260,6 +260,21 @@ if ( $country && $state &&
 }
 $cgi->delete('county');
 
+my $city = '';
+if ( $country && $state && $county &&
+     $cgi->param('city') =~
+       /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/
+   )
+{
+  $city = $1;
+  if ( $city eq '__NONE__' ) {
+    $title = "No city, $title";
+  } else {
+    $title = "$city city, $title";
+  }
+}
+$cgi->delete('city');
+
 $title = " for $title" if $title;
 
 my $taxclass = '';
@@ -279,12 +294,18 @@ my $filter_change =
   "window.location = '". $cgi->self_url.
   ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ".
   "';state='   + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +".
-  "';county='  + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );";
+  "';county='  + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value )";
+
+$filter_change .= " +';city='  + encodeURIComponent( document.getElementById('city').options[document.getElementById('city').selectedIndex].value )"
+  if $conf->exists('enable_taxclasses');
+
+$filter_change .= ";";
 
 #restore this so pagination works
 $cgi->param('country',  $country) if $country;
 $cgi->param('state',    $state  ) if $state;
 $cgi->param('county',   $county ) if $county;
+$cgi->param('city',     $city )   if $city;
 $cgi->param('taxclass', $county ) if $taxclass;
 
 my $html_posttotal =
@@ -338,6 +359,31 @@ if ( scalar(@counties) > 1 ) {
     '</SELECT>';
 }
 
+if ( $conf->exists('enable_taxclasses') ) {
+  my @cities = ( $country && $state && $county ) ? cities($county, $state, $country) : ();
+  if ( scalar(@cities) > 1 ) {
+    $html_posttotal .=
+      ' show city: '.
+      include('/elements/select-city.html',
+              'country'              => $country,
+              'state'                => $state,
+              'county'               => $county,
+              'city'                 => $city,
+              'onchange'             => $filter_change,
+              'empty_label'          => '(all)',
+              'empty_data_label'     => '(none)',
+              'empty_data_value'     => '__NONE__',
+              'disable_empty'        => 0,
+              'disable_cityupdate'   => 1,
+      );
+  } else {
+    $html_posttotal .=
+      '<SELECT NAME="city" ID="city" STYLE="display:none">'.
+      '  <OPTION VALUE="" SELECTED>'.
+      '</SELECT>';
+  }
+}
+
 $html_posttotal .= ' )';
 
 my $bulk_popup_link = 
@@ -411,7 +457,8 @@ my $html_foot = <<END;
 <A HREF="javascript:void(0);" onClick="bulkPopup('add');">Add new tax to selected</A>
 |
 <A HREF="javascript:void(0);" onClick="bulkPopup('edit');">Bulk edit selected</A>
-
+|
+<A HREF="javascript:void(0);" onClick="bulkPopup('edit_rate_only');">Bulk edit rate only selected</A>
 END
 
 my $hashref = {};
@@ -433,6 +480,15 @@ if ( $county ) {
     $count_query .= ' AND county  = '. dbh->quote($county);
   }
 }
+if ( $city ) {
+  if ( $city eq '__NONE__' ) {
+    $hashref->{'city'} = '';
+    $count_query .= " AND ( city = '' OR city IS NULL ) ";
+  } else {
+    $hashref->{'city'} = $city;
+    $count_query .= ' AND city  = '. dbh->quote($city);
+  }
+}
 if ( $taxclass ) {
   $hashref->{'taxclass'} = $taxclass;
   $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
diff --git a/httemplate/edit/bulk-cust_main_county.html b/httemplate/edit/bulk-cust_main_county.html
index 8b1234825..650fa7857 100644
--- a/httemplate/edit/bulk-cust_main_county.html
+++ b/httemplate/edit/bulk-cust_main_county.html
@@ -3,6 +3,7 @@
 <FORM ACTION="<% popurl(1)."process/bulk-cust_main_county.html" %>" METHOD="POST">
 
 <INPUT TYPE="hidden" NAME="action" VALUE="<% $action %>">
+<INPUT TYPE="hidden" NAME="rate_only" VALUE="<% $rate_only %>">
 <INPUT TYPE="hidden" NAME="taxnum" VALUE="<% join(',', @taxnum) %>">
 
 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
@@ -45,11 +46,13 @@
   </TR>
 % }
 
-<% include('/elements/tr-input-text.html',
+% unless ($rate_only) {
+  <% include('/elements/tr-input-text.html',
              'field' => 'taxname',
              'label' => 'Tax name'
           )
-%>
+  %>
+% }
 
 <% include('/elements/tr-input-percentage.html',
              'field' => 'tax',
@@ -57,27 +60,29 @@
           )
 %>
 
-<% include('/elements/tablebreak-tr-title.html', value=>'Exemptions' ) %>
+% unless ($rate_only) {
+  <% include('/elements/tablebreak-tr-title.html', value=>'Exemptions' ) %>
 
-<% include('/elements/tr-checkbox.html',
+  <% include('/elements/tr-checkbox.html',
              'field' => 'setuptax',
              'value' => 'Y',
              'label' => 'This tax not applicable to setup fees',
           )
-%>
+  %>
 
-<% include('/elements/tr-checkbox.html',
+  <% include('/elements/tr-checkbox.html',
              'field' => 'recurtax',
              'value' => 'Y',
              'label' => 'This tax not applicable to recurring fees',
           )
-%>
+  %>
 
-<% include('/elements/tr-input-money.html',
+  <% include('/elements/tr-input-money.html',
              'field' => 'exempt_amount',
              'label' => 'Monthly exemption per customer ($25 "Texas tax")',
           )
-%>
+  %>
+% }
 
 </TABLE>
 
@@ -97,8 +102,13 @@ $cgi->param('taxnum') =~ /^([\d,]+)$/
    or $m->comp('/elements/errorpage-popup.html', $cgi->param('error') || 'Nothing selected');
 my @taxnum = split(',', $1);
 
-$cgi->param('action') =~ /^(add|edit)$/ or die "unknown action";
+$cgi->param('action') =~ /^(add|edit|edit_rate_only)$/ or die "unknown action";
 my $action = $1;
+my $rate_only;
+if ($action eq "edit_rate_only") {
+  $action = "edit";
+  $rate_only = 1;
+}
 my $title = "Bulk $action tax rate";
 
 my @cust_main_county =
diff --git a/httemplate/edit/process/bulk-cust_main_county.html b/httemplate/edit/process/bulk-cust_main_county.html
index b5a0258b1..55832e9c5 100644
--- a/httemplate/edit/process/bulk-cust_main_county.html
+++ b/httemplate/edit/process/bulk-cust_main_county.html
@@ -27,6 +27,8 @@ my @taxnum = split(',', $1);
 $cgi->param('action') =~ /^(add|edit)$/ or die "unknown action";
 my $action = $1;
 
+my $rate_only = $cgi->param('rate_only') if $cgi->param('rate_only');
+
 my $error = '';
 foreach my $taxnum ( @taxnum ) {
 
@@ -35,8 +37,13 @@ foreach my $taxnum ( @taxnum ) {
 
   if ( $action eq 'edit' || $cust_main_county->tax == 0 ) { #let's replace
 
-    foreach (qw( taxname tax exempt_amount setuptax recurtax )) {
-      $cust_main_county->set( $_ => scalar($cgi->param($_)) )
+    if ($rate_only) {
+      $cust_main_county->set( tax => scalar($cgi->param('tax')) );
+    }
+    else {
+      foreach (qw( taxname tax exempt_amount setuptax recurtax )) {
+        $cust_main_county->set( $_ => scalar($cgi->param($_)) )
+      }
     }
 
     $error = $cust_main_county->replace and last;

-----------------------------------------------------------------------

Summary of changes:
 httemplate/browse/cust_main_county.cgi             |  60 ++++++-
 httemplate/edit/bulk-cust_main_county.html         |  30 ++--
 httemplate/edit/process/bulk-cust_main_county.html |  11 +-
 httemplate/elements/select-city.html               | 176 +++++++++++++++++++++
 4 files changed, 263 insertions(+), 14 deletions(-)
 create mode 100644 httemplate/elements/select-city.html




More information about the freeside-commits mailing list