[freeside-commits] branch master updated. a495aa8d41e752490fff8d61aa190601c51a2cb1

Mitch Jackson mitch at freeside.biz
Sun Jan 20 13:28:14 PST 2019


The branch, master has been updated
       via  a495aa8d41e752490fff8d61aa190601c51a2cb1 (commit)
       via  078dc41cbf3edc2fa0a61b9c307921b0aaaf3cbe (commit)
       via  3d893fd09ed3408cb3680a4a752a3f137f6d5468 (commit)
      from  569f676f4a06512a46120e12edc6a6410e93ff93 (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 a495aa8d41e752490fff8d61aa190601c51a2cb1
Author: Mitch Jackson <mitch at freeside.biz>
Date:   Sun Jan 20 16:25:50 2019 -0500

    RT# 80488 Banner on customer page when missing tax districts

diff --git a/httemplate/elements/header-cust_main.html b/httemplate/elements/header-cust_main.html
index f29f32567..7af7dffd5 100644
--- a/httemplate/elements/header-cust_main.html
+++ b/httemplate/elements/header-cust_main.html
@@ -33,6 +33,57 @@ Examples:
 %   }
 </TABLE>
 % }
+% if ( scalar @cust_locations_missing_district ) {
+  <div style="margin: 0 1em; padding: 1em; border: solid 1px #999; background-color: #fee;">
+    <h4 style="margin: 0; border-bottom: solid 1px #aaa; color: red;">Customer will not be billed:</h4>
+    <p style="margin: .5em;">
+    The following customer locations are missing tax districts for Washington State.<br>
+    Sales taxes cannot be calculated for this customer.<br>
+    Correct the address information, or enter a tax district number.
+    <ul>
+%   for my $cust_location ( @cust_locations_missing_district ) {
+      <li>
+        (<a href="#" onclick="overlib_edit_location(<% $cust_location->locationnum %>);">
+          EDIT
+        </a>)
+        <% $cust_location->address1 %>
+        <% $cust_location->city %>
+        <% $cust_location->state %>
+        <% $cust_location->zip %>
+        (<% $cust_location->locationnum %>)
+      </li>
+%   } # /for my $cust_location
+    </ul>
+  </div>
+  <script>
+    function overlib_edit_location(locationnum) {
+      overlib(
+        OLiframeContent(
+          '<% $fsurl %>edit/cust_location.cgi?locationnum=' + locationnum,
+          700, 355,
+          'popup-1548013977-3901-3256727185.50958',
+          0,
+          'auto'
+        ),
+        CAPTION, 'Edit location',
+        STICKY,
+        AUTOSTATUSCAP,
+        MIDX, 0,
+        MIDY, 0,
+        DRAGGABLE,
+        CLOSECLICK,
+        TEXTPADDING, 0,
+        BASE, 0,
+        BGCOLOR, '#333399',
+        CGCOLOR, '#333399',
+        FGCOLOR, '#f8f8f8',
+        CLOSETEXT, 'Close'
+      );
+      return false;
+    }
+  </script>
+  <br>
+% } # /if @cust_locations_missing_district
 <& /view/cust_main/menu.html, cust_main => $cust_main, show => $opt{'view'} &>
 <BR>
 
@@ -85,4 +136,10 @@ $status .= ' (Cancelled)' if $cust_main->is_status_delay_cancel;
 $title_noescape .= ' (<B><FONT COLOR="#'. $cust_main->statuscolor. '">'. $status.  '</FONT></B>)';
 $title .= " ($status)";
 
+my @cust_locations_missing_district;
+my $tax_district_method = $conf->config('tax_district_method');
+if ( $tax_district_method && $tax_district_method eq 'wa_sales' ) {
+  @cust_locations_missing_district = $cust_main->cust_locations_missing_district();
+}
+
 </%init>

commit 078dc41cbf3edc2fa0a61b9c307921b0aaaf3cbe
Author: Mitch Jackson <mitch at freeside.biz>
Date:   Sun Jan 20 16:22:50 2019 -0500

    RT# 80488 Block billing for customer missing tax district

diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 920f4d413..061fd69a3 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -5434,6 +5434,51 @@ sub pending_invoice_count {
   FS::cust_bill->count( 'custnum = '.shift->custnum."AND pending = 'Y'" );
 }
 
+=item cust_locations_missing_district
+
+Always returns empty list, unless tax_district_method eq 'wa_sales'
+
+Return cust_location rows for this customer, associated with active
+customer packages, where tax district column is empty.  Presense of
+these rows should block billing, because invoice would be generated
+with incorrect taxes
+
+=cut
+
+sub cust_locations_missing_district {
+  my ( $self ) = @_;
+
+  my $tax_district_method = FS::Conf->new->config('tax_district_method');
+
+  return ()
+    unless $tax_district_method
+        && $tax_district_method eq 'wa_sales';
+
+  qsearch({
+    table => 'cust_location',
+    select => 'cust_location.*',
+    addl_from => '
+      LEFT JOIN cust_main USING (custnum)
+      LEFT JOIN cust_pkg ON cust_location.locationnum = cust_pkg.locationnum
+    ',
+    extra_sql => sprintf(q{
+        WHERE cust_location.state = 'WA'
+        AND   cust_location.custnum = %s
+        AND (
+             cust_location.district IS NULL
+          or cust_location.district = ''
+        )
+        AND cust_pkg.pkgnum IS NOT NULL
+        AND (
+             cust_pkg.cancel > %s
+          OR cust_pkg.cancel IS NULL
+        )
+      },
+      $self->custnum, time()
+    ),
+  });
+}
+
 #starting to take quite a while for big dbs
 #   (JRNL: journaled so it only happens once per database)
 # - seq scan of h_cust_main (yuck), but not going to index paycvv, so
diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm
index 1be7d39f9..5f8dd9b4c 100644
--- a/FS/FS/cust_main/Billing.pm
+++ b/FS/FS/cust_main/Billing.pm
@@ -152,6 +152,41 @@ sub bill_and_collect {
     else                                                     { die    $error; }
   }
 
+  my $tax_district_method = $conf->config('tax_district_method');
+  if ( $tax_district_method && $tax_district_method eq 'wa_sales' ) {
+    # When using Washington State Sales Tax Districts,
+    # Bail out of billing customer if sales tax district for location is missing
+
+    $log->debug('checking cust_location tax districts', %logopt);
+
+    if (
+      my @cust_locations_missing_district =
+        $self->cust_locations_missing_district
+    ) {
+      $error = sprintf
+        'cust_location missing tax district: '.
+        join( ', ' => (
+          map(
+            {
+              sprintf
+                'locationnum(%s) %s %s %s %s',
+                 $_->locationnum,
+                 $_->address1,
+                 $_->city,
+                 $_->state,
+                 $_->zip
+            }
+            @cust_locations_missing_district
+          )
+        ));
+    }
+  }
+  if ( $error ) {
+    $error = "Error calculating taxes ".$self->custnum. ": $error";
+    if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
+    else                                                     { die    $error; }
+  }
+
   $job->update_statustext('20,billing packages') if $job;
   $log->debug('billing packages', %logopt);
   $error = $self->bill( %options );

commit 3d893fd09ed3408cb3680a4a752a3f137f6d5468
Author: Mitch Jackson <mitch at freeside.biz>
Date:   Sun Jan 20 16:14:12 2019 -0500

    RT# 80488 Validation on cust_location.district values

diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm
index 63492dd33..21bf92feb 100644
--- a/FS/FS/cust_location.pm
+++ b/FS/FS/cust_location.pm
@@ -443,6 +443,26 @@ sub check {
     && $conf->exists('prospect_main-alt_address_format')
     && ! $self->location_kind;
 
+  # Do not allow bad tax district values in cust_location when
+  # using Washington State district sales tax calculation - would result
+  # in incorrect or missing sales tax on invoices.
+  my $tax_district_method = FS::Conf->new->config('tax_district_method');
+  if (
+    $tax_district_method
+    && $tax_district_method eq 'wa_sales'
+    && $self->district
+  ) {
+    my $cust_main_county = qsearchs(
+      cust_main_county => { district => $self->district }
+    );
+    unless ( ref $cust_main_county ) {
+      return sprintf (
+        'WA State tax district %s does not exist in tax table',
+        $self->district
+      );
+    }
+  }
+
   unless ( $import or qsearch('cust_main_county', {
     'country' => $self->country,
     'state'   => '',

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

Summary of changes:
 FS/FS/cust_location.pm                    | 20 +++++++++++
 FS/FS/cust_main.pm                        | 45 ++++++++++++++++++++++++
 FS/FS/cust_main/Billing.pm                | 35 +++++++++++++++++++
 httemplate/elements/header-cust_main.html | 57 +++++++++++++++++++++++++++++++
 4 files changed, 157 insertions(+)




More information about the freeside-commits mailing list