[freeside-commits] branch master updated. 15d596e3090f3bde642917b56563736cd1ee2e90

Christopher Burger burgerc at freeside.biz
Tue Feb 6 07:37:09 PST 2018


The branch, master has been updated
       via  15d596e3090f3bde642917b56563736cd1ee2e90 (commit)
      from  633ca08b978e5c9fa061d24ee2a2f78918e218de (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 15d596e3090f3bde642917b56563736cd1ee2e90
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Feb 6 10:36:31 2018 -0500

    RT# 75095 - fixed ooma format to import all charges, and unified import process to allow new formats to be added quickly.  consistant with cdr imports

diff --git a/FS/FS/cust_main/Import_Charges.pm b/FS/FS/cust_main/Import_Charges.pm
index bff2ec2fb..3d2031d45 100644
--- a/FS/FS/cust_main/Import_Charges.pm
+++ b/FS/FS/cust_main/Import_Charges.pm
@@ -8,6 +8,48 @@ use FS::UID qw( dbh );
 use FS::CurrentUser;
 use FS::Record qw( qsearchs );
 use FS::cust_main;
+use FS::Conf;
+
+my $DEBUG = '';
+
+my %import_charges_info;
+foreach my $INC ( @INC ) {
+  warn "globbing $INC/FS/cust_main/import_charges/[a-z]*.pm\n" if $DEBUG;
+  foreach my $file ( glob("$INC/FS/cust_main/import_charges/[a-z]*.pm") ) {
+    warn "attempting to load import charges format info from $file\n" if $DEBUG;
+    $file =~ /\/(\w+)\.pm$/ or do {
+      warn "unrecognized file in $INC/FS/cust_main/import_charges/: $file\n";
+      next;
+    };
+    my $mod = $1;
+    my $info = eval "use FS::cust_main::import_charges::$mod; ".
+                    "\\%FS::cust_main::import_charges::$mod\::info;";
+    if ( $@ ) {
+      die "error using FS::cust_main::import_charges::$mod (skipping): $@\n" if $@;
+      next;
+    }
+    unless ( keys %$info ) {
+      warn "no %info hash found in FS::cust_main::import_charges::$mod, skipping\n";
+      next;
+    }
+    warn "got import charges format info from FS::cust_main::import_charges::$mod: $info\n" if $DEBUG;
+    if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
+      warn "skipping disabled import charges format FS::cust_main::import_charges::$mod" if $DEBUG;
+      next;
+    }
+    $import_charges_info{$mod} = $info;
+  }
+}
+
+tie my %import_formats, 'Tie::IxHash',
+  map  { $_ => $import_charges_info{$_}->{'name'} }
+  sort { $import_charges_info{$a}->{'weight'} <=> $import_charges_info{$b}->{'weight'} }
+  grep { exists($import_charges_info{$_}->{'fields'}) }
+  keys %import_charges_info;
+
+sub import_formats {
+  %import_formats;
+}
 
 =head1 NAME
 
@@ -65,20 +107,10 @@ sub batch_charge {
 
   my @fields;
   my %charges;
-  if ( $format eq 'simple' ) {
-    @fields = qw( custnum agent_custid amount pkg );
-  } elsif ( $format eq 'ooma' ) {
-    #below is gcet file.
-    #@fields = ( 'userfield1', 'userfield2', 'userfield3', 'userfield4', 'userfield5', 'userfield6', 'userfield7', 'userfield8', 'userfield9', 'userfield10', 'amount', 'userfield12', 'userfield13', 'userfield14', 'userfield15', 'userfield16', 'userfield17', 'userfield18', 'pkg', 'userfield20', 'custnum', 'userfield22', 'userfield23', 'userfield24', 'userfield25', );
-    @fields = ( 'userfield1', 'userfield2', 'userfield3', 'userfield4', 'userfield5', 'userfield6', 'userfield7', 'userfield8', 'amount', 'userfield10', 'userfield11', 'userfield12', 'userfield13', 'userfield14', 'userfield15', 'userfield16', 'pkg', 'userfield18', 'custnum', 'userfield20', 'userfield21', 'userfield22', 'userfield23', 'userfield24', 'userfield25', );
-
-  ##should charges to charge be a config option?
-    %charges = (
-      'DISABILITY ACCESS/ENHANCED 911 SERVICES SURCHARGE' => '1',
-      'FEDERAL TRS FUND'                                  => '1',
-      'FEDERAL UNIVERSAL SERVICE FUND'                    => '1',
-      'STATE SALES TAX'                                   => '1',
-    );
+
+  if ( $import_charges_info{$format} ) {
+    @fields = @{$import_charges_info{$format}->{'fields'}};
+    %charges = %{$import_charges_info{$format}->{'charges'}};
   } else {
     die "unknown format $format";
   }
diff --git a/FS/FS/cust_main/import_charges/gcet.pm b/FS/FS/cust_main/import_charges/gcet.pm
new file mode 100644
index 000000000..83f956545
--- /dev/null
+++ b/FS/FS/cust_main/import_charges/gcet.pm
@@ -0,0 +1,26 @@
+package FS::cust_main::import_charges::gcet;
+
+use strict;
+use base qw( FS::cust_main::Import_Charges );
+use vars qw ( %info );
+
+# gcet fields.
+my @fields = ( 'userfield1', 'userfield2', 'userfield3', 'userfield4', 'userfield5', 'userfield6', 'userfield7', 'userfield8', 'userfield9', 'userfield10', 'amount', 'userfield12', 'userfield13', 'userfield14', 'userfield15', 'userfield16', 'userfield17', 'userfield18', 'pkg', 'userfield20', 'custnum', 'userfield22', 'userfield23', 'userfield24', 'userfield25', );
+# hash of charges (pkg) to charge.  if empty charge them all.
+# '911 services' => '1',
+my $charges = {
+  'DISABILITY ACCESS/ENHANCED 911 SERVICES SURCHARGE' => '1',
+  'FEDERAL TRS FUND'                                  => '1',
+  'FEDERAL UNIVERSAL SERVICE FUND'                    => '1',
+  'STATE SALES TAX'                                   => '1',
+};
+
+%info = (
+  'fields'   => [@fields],
+  'charges'  => $charges,
+  'name'     => 'Gcet',
+  'weight'   => '30',
+  'disabled' => '1',
+);
+
+1;
\ No newline at end of file
diff --git a/FS/FS/cust_main/import_charges/ooma.pm b/FS/FS/cust_main/import_charges/ooma.pm
new file mode 100644
index 000000000..a43def239
--- /dev/null
+++ b/FS/FS/cust_main/import_charges/ooma.pm
@@ -0,0 +1,21 @@
+package FS::cust_main::import_charges::ooma;
+
+use strict;
+use base qw( FS::cust_main::Import_Charges );
+use vars qw ( %info );
+
+# ooma fields
+my @fields =  ('userfield1', 'userfield2', 'userfield3', 'userfield4', 'userfield5', 'userfield6', 'userfield7', 'userfield8', 'amount', 'userfield10', 'userfield11', 'userfield12', 'userfield13', 'userfield14', 'userfield15', 'userfield16', 'pkg', 'userfield18', 'custnum', 'userfield20', 'userfield21', 'userfield22', 'userfield23', 'userfield24', 'userfield25', );
+# hash of charges (pkg) to charge.  if empty charge them all.
+# '911 services' => '1',
+my $charges = {};
+
+%info = (
+  'fields'   => [@fields],
+  'charges'  => $charges,
+  'name'     => 'Ooma',
+  'weight'   => '10',
+  'disabled' => '',	
+);
+
+1;
\ No newline at end of file
diff --git a/FS/FS/cust_main/import_charges/simple.pm b/FS/FS/cust_main/import_charges/simple.pm
new file mode 100644
index 000000000..e039328ba
--- /dev/null
+++ b/FS/FS/cust_main/import_charges/simple.pm
@@ -0,0 +1,21 @@
+package FS::cust_main::import_charges::simple;
+
+use strict;
+use base qw( FS::cust_main::Import_Charges );
+use vars qw ( %info );
+
+# simple field format
+my @fields =  ('custnum', 'agent_custid', 'amount', 'pkg');
+# hash of charges (pkg) to charge.  if empty charge them all.
+# '911 services' => '1',
+my $charges = {};
+
+%info = (
+  'fields'   => [@fields],
+  'charges'  => $charges,
+  'name'     => 'Simple',
+  'weight'   => '1',
+  'disabled' => '',
+);
+
+1;
\ No newline at end of file
diff --git a/httemplate/misc/cust_main-import_charges.cgi b/httemplate/misc/cust_main-import_charges.cgi
index 4eacce13a..215cc4c9d 100644
--- a/httemplate/misc/cust_main-import_charges.cgi
+++ b/httemplate/misc/cust_main-import_charges.cgi
@@ -28,9 +28,9 @@ Import a CSV file containing customer charges.
   <TH ALIGN="right">Format</TH>
   <TD>
     <SELECT NAME="format">
-      <OPTION VALUE="simple">Simple
-      <OPTION VALUE="ooma">Ooma
-<!--      <OPTION VALUE="extended" SELECTED>Extended -->
+%       foreach my $format ( keys %formats ) {
+         <OPTION VALUE="<% $format %>"><% $formats{$format} %></OPTION>
+%       }
     </SELECT>
   </TD>
 </TR>
@@ -94,6 +94,8 @@ Field information:
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Import');
 
+  tie my %formats, 'Tie::IxHash', FS::cust_main::Import_Charges->import_formats;
+
   my $custbatch = time2str('webimport-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
 
 </%init>

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

Summary of changes:
 FS/FS/cust_main/Import_Charges.pm            | 60 +++++++++++++++++++++-------
 FS/FS/cust_main/import_charges/gcet.pm       | 26 ++++++++++++
 FS/FS/cust_main/import_charges/ooma.pm       | 21 ++++++++++
 FS/FS/cust_main/import_charges/simple.pm     | 21 ++++++++++
 httemplate/misc/cust_main-import_charges.cgi |  8 ++--
 5 files changed, 119 insertions(+), 17 deletions(-)
 create mode 100644 FS/FS/cust_main/import_charges/gcet.pm
 create mode 100644 FS/FS/cust_main/import_charges/ooma.pm
 create mode 100644 FS/FS/cust_main/import_charges/simple.pm




More information about the freeside-commits mailing list