[freeside-commits] branch master updated. 6635b3ee826a8dcd8755c4a1277f3ae268889f1e

Ivan Kohler ivan at freeside.biz
Tue Feb 27 14:38:48 PST 2018


The branch, master has been updated
       via  6635b3ee826a8dcd8755c4a1277f3ae268889f1e (commit)
      from  3b927eb362d26b62d3dc399e6a4eebea064578b6 (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 6635b3ee826a8dcd8755c4a1277f3ae268889f1e
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Feb 27 14:38:47 2018 -0800

    duplicate tax rates from one state to others, RT#79635

diff --git a/bin/copy-cust_main_county b/bin/copy-cust_main_county
new file mode 100644
index 000000000..1a15e84f8
--- /dev/null
+++ b/bin/copy-cust_main_county
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FS::UID qw( adminsuidsetup dbh );
+use FS::Record qw( qsearch );
+use FS::cust_main_county;
+
+adminsuidsetup shift or die "Usage: copy-cust_main_county username\n";
+
+my $from_state = 'XX'; #XXX
+
+$FS::UID::AutoCommit = 0;
+
+my @from_cust_main_county = qsearch({
+  'table'     => 'cust_main_county',
+  'hashref'   => { 'state'   => $from_state,
+                   'country' => 'US',
+                 },
+  'extra_sql' => "AND taxname LIKE 'FED%'",
+});
+
+#select distinct state from cust_main_county where country = 'US'
+#and then exclude the one other state?
+#my @to_states = ();
+#no, just find the target records directly.  there should be one per state?
+my @to_cust_main_county = qsearchs({
+  'table'   => 'cust_main_county',
+  'hashref' => { 'taxclass' => '',
+                 'country'  => 'US',
+                 'taxname'  => '',
+                 'tax'      => 0,
+               },
+});
+
+foreach my $to_cust_main_county (@to_cust_main_county) {
+
+  foreach my $from_cust_main_county (@from_cust_main_county) {
+
+    my $new = new FS::cust_main_county {
+                'state'   => $to_cust_main_county->state,
+                'country' => 'US',
+                map { $_ => $from_cust_main_county->$_ }
+                  qw( tax taxclass taxname setuptax recurtax ),
+                 
+              };
+    my $error = $new->insert;
+    if ( $error ) {
+      dbh->rollback;
+      die $error;
+    }
+
+  }
+
+  my $error = $to_cust_main_county->delete;
+  if ( $error ) {
+    dbh->rollback;
+    die $error;
+  }
+
+}
+
+dbh->rollback or die dbh->errstr;
+#dbh->commit or die dbh->errstr;
+
+1;
+

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

Summary of changes:
 bin/copy-cust_main_county | 67 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 bin/copy-cust_main_county




More information about the freeside-commits mailing list