[freeside-commits] branch FREESIDE_3_BRANCH updated. 9ffc202e968b54e9b2d5bdbade74416a3b36c0ac
Christopher Burger
burgerc at freeside.biz
Thu Feb 8 06:41:12 PST 2018
The branch, FREESIDE_3_BRANCH has been updated
via 9ffc202e968b54e9b2d5bdbade74416a3b36c0ac (commit)
via 16b53cfc36afc1982d8fd93f0311ff35ac747171 (commit)
via 68f2b6485ee40cbc502ae7ffcebb434544e68547 (commit)
via ad70e57049ee9d0371c60660dff76c99da6646be (commit)
via c86b5f4350dbb63e11e3e88eea38653d24f55e8b (commit)
via 1050e60086386799dbba6e5bbcfc5a29e78eddb5 (commit)
from 51766e3b6bb6188c121d3829614738a927c23a2c (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 9ffc202e968b54e9b2d5bdbade74416a3b36c0ac
Author: Christopher Burger <burgerc at freeside.biz>
Date: Thu Feb 8 09:40:27 2018 -0500
RT# 75095 - Import one time charge V3 fix.
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 76c3000c9..5beb100b7 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -173,6 +173,7 @@ if ( -e $addl_handler_use_file ) {
use FS::h_cust_main;
use FS::cust_main::Search qw(smart_search);
use FS::cust_main::Import;
+ use FS::cust_main::Import_Charges;
use FS::cust_main_county;
use FS::cust_location;
use FS::cust_pay;
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 8cccd1830..7d913b955 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -5179,121 +5179,6 @@ sub search {
=over 4
-=item batch_charge
-
-=cut
-
-sub batch_charge {
- my $param = shift;
- #warn join('-',keys %$param);
- my $fh = $param->{filehandle};
- my $agentnum = $param->{agentnum};
- my $format = $param->{format};
-
- my $extra_sql = ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql;
-
- my @fields;
- if ( $format eq 'simple' ) {
- @fields = qw( custnum agent_custid amount pkg );
- } else {
- die "unknown format $format";
- }
-
- eval "use Text::CSV_XS;";
- die $@ if $@;
-
- my $csv = new Text::CSV_XS;
- #warn $csv;
- #warn $fh;
-
- my $imported = 0;
- #my $columns;
-
- local $SIG{HUP} = 'IGNORE';
- local $SIG{INT} = 'IGNORE';
- local $SIG{QUIT} = 'IGNORE';
- local $SIG{TERM} = 'IGNORE';
- local $SIG{TSTP} = 'IGNORE';
- local $SIG{PIPE} = 'IGNORE';
-
- my $oldAutoCommit = $FS::UID::AutoCommit;
- local $FS::UID::AutoCommit = 0;
- my $dbh = dbh;
-
- #while ( $columns = $csv->getline($fh) ) {
- my $line;
- while ( defined($line=<$fh>) ) {
-
- $csv->parse($line) or do {
- $dbh->rollback if $oldAutoCommit;
- return "can't parse: ". $csv->error_input();
- };
-
- my @columns = $csv->fields();
- #warn join('-', at columns);
-
- my %row = ();
- foreach my $field ( @fields ) {
- $row{$field} = shift @columns;
- }
-
- if ( $row{custnum} && $row{agent_custid} ) {
- dbh->rollback if $oldAutoCommit;
- return "can't specify custnum with agent_custid $row{agent_custid}";
- }
-
- my %hash = ();
- if ( $row{agent_custid} && $agentnum ) {
- %hash = ( 'agent_custid' => $row{agent_custid},
- 'agentnum' => $agentnum,
- );
- }
-
- if ( $row{custnum} ) {
- %hash = ( 'custnum' => $row{custnum} );
- }
-
- unless ( scalar(keys %hash) ) {
- $dbh->rollback if $oldAutoCommit;
- return "can't find customer without custnum or agent_custid and agentnum";
- }
-
- my $cust_main = qsearchs('cust_main', { %hash } );
- unless ( $cust_main ) {
- $dbh->rollback if $oldAutoCommit;
- my $custnum = $row{custnum} || $row{agent_custid};
- return "unknown custnum $custnum";
- }
-
- if ( $row{'amount'} > 0 ) {
- my $error = $cust_main->charge($row{'amount'}, $row{'pkg'});
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
- $imported++;
- } elsif ( $row{'amount'} < 0 ) {
- my $error = $cust_main->credit( sprintf( "%.2f", 0-$row{'amount'} ),
- $row{'pkg'} );
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
- }
- $imported++;
- } else {
- #hmm?
- }
-
- }
-
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;
-
- return "Empty file!" unless $imported;
-
- ''; #no error
-
-}
-
=item notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
Deprecated. Use event notification and message templates
diff --git a/FS/FS/cust_main/Import_Charges.pm b/FS/FS/cust_main/Import_Charges.pm
index 3d2031d45..f194e78de 100644
--- a/FS/FS/cust_main/Import_Charges.pm
+++ b/FS/FS/cust_main/Import_Charges.pm
@@ -5,6 +5,8 @@ package FS::cust_main::Import_Charges;
use strict;
use FS::UID qw( dbh );
+use Storable qw(thaw);
+use MIME::Base64;
use FS::CurrentUser;
use FS::Record qw( qsearchs );
use FS::cust_main;
@@ -81,7 +83,7 @@ Batch customer charging.
sub batch_charge {
my $job = shift;
- my $param = shift;
+ my $param = thaw(decode_base64(shift));
#warn join('-',keys %$param);
my $agentnum = $param->{agentnum};
my $format = $param->{format};
commit 16b53cfc36afc1982d8fd93f0311ff35ac747171
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>
commit 68f2b6485ee40cbc502ae7ffcebb434544e68547
Author: Christopher Burger <burgerc at freeside.biz>
Date: Thu Feb 1 10:23:33 2018 -0500
RT# 75095 - added comment
diff --git a/FS/FS/cust_main/Import_Charges.pm b/FS/FS/cust_main/Import_Charges.pm
index f90e0496f..bff2ec2fb 100644
--- a/FS/FS/cust_main/Import_Charges.pm
+++ b/FS/FS/cust_main/Import_Charges.pm
@@ -68,6 +68,7 @@ sub batch_charge {
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', );
commit ad70e57049ee9d0371c60660dff76c99da6646be
Author: Christopher Burger <burgerc at freeside.biz>
Date: Fri Jan 26 16:24:28 2018 -0500
RT# 75095 - updated mapping of ooma import file format
diff --git a/FS/FS/cust_main/Import_Charges.pm b/FS/FS/cust_main/Import_Charges.pm
index 0a12c8752..f90e0496f 100644
--- a/FS/FS/cust_main/Import_Charges.pm
+++ b/FS/FS/cust_main/Import_Charges.pm
@@ -68,7 +68,9 @@ sub batch_charge {
if ( $format eq 'simple' ) {
@fields = qw( custnum agent_custid amount pkg );
} elsif ( $format eq 'ooma' ) {
- @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', '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',
commit c86b5f4350dbb63e11e3e88eea38653d24f55e8b
Author: Christopher Burger <burgerc at freeside.biz>
Date: Fri Dec 1 16:59:15 2017 -0500
RT# 75095 - Fixed use of a constant warning.
diff --git a/FS/FS/cust_main/Import_Charges.pm b/FS/FS/cust_main/Import_Charges.pm
index 64fcb5ccf..0a12c8752 100644
--- a/FS/FS/cust_main/Import_Charges.pm
+++ b/FS/FS/cust_main/Import_Charges.pm
@@ -169,10 +169,10 @@ sub batch_charge {
if ( $row{agent_custid} && $agentnum ) {
$id = $row{agent_custid};
- $data{$id}{cust} = (
+ $data{$id}{cust} = {
'agent_custid' => $row{agent_custid},
'agentnum' => $agentnum,
- );
+ };
%hash = ( 'agent_custid' => $row{agent_custid},
'agentnum' => $agentnum,
);
commit 1050e60086386799dbba6e5bbcfc5a29e78eddb5
Author: Christopher Burger <burgerc at freeside.biz>
Date: Wed Nov 1 12:56:48 2017 -0400
RT# 75095 - Added Ooma integration to one time charges
Conflicts:
FS/FS/cust_main/Import_Charges.pm
httemplate/misc/process/cust_main-import_charges.cgi
diff --git a/FS/FS/cust_main/Import_Charges.pm b/FS/FS/cust_main/Import_Charges.pm
new file mode 100644
index 000000000..64fcb5ccf
--- /dev/null
+++ b/FS/FS/cust_main/Import_Charges.pm
@@ -0,0 +1,256 @@
+package FS::cust_main::Import_Charges;
+#actually no specific reason it lives under FS::cust_main:: othan than it calls
+# a thing on cust_main objects. not part of the inheritence, just providess a
+# subroutine for misc/process/cust_main-import_charges.cgi
+
+use strict;
+use FS::UID qw( dbh );
+use FS::CurrentUser;
+use FS::Record qw( qsearchs );
+use FS::cust_main;
+
+=head1 NAME
+
+FS::cust_main::Import_Charges - Batch charge importing
+
+=head1 SYNOPSIS
+
+ use FS::cust_main::Import_Charges;
+
+ my $error =
+ FS::cust_main::Import_charges::batch_charge( {
+ filehandle => $fh,
+ 'agentnum' => scalar($cgi->param('agentnum')),
+ 'format' => scalar($cgi->param('format')),
+ } );
+
+=head1 DESCRIPTION
+
+Batch customer charging.
+
+
+=head1 SUBROUTINES
+
+=over 4
+
+=item batch_charge
+
+=cut
+
+sub batch_charge {
+ my $job = shift;
+ my $param = shift;
+ #warn join('-',keys %$param);
+ my $agentnum = $param->{agentnum};
+ my $format = $param->{format};
+
+ my $files = $param->{'uploaded_files'}
+ or die "No files provided.\n";
+
+ my (%files) = map { /^(\w+):([\.\w]+)$/ ? ($1,$2):() } split /,/, $files;
+
+ my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc. '/';
+ my $filename = $dir. $files{'file'};
+
+ my $type;
+ if ( $filename =~ /\.(\w+)$/i ) {
+ $type = lc($1);
+ } else {
+ #or error out???
+ warn "can't parse file type from filename $filename; defaulting to CSV";
+ $type = 'csv';
+ }
+
+ my $extra_sql = ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+ my @fields;
+ my %charges;
+ if ( $format eq 'simple' ) {
+ @fields = qw( custnum agent_custid amount pkg );
+ } elsif ( $format eq 'ooma' ) {
+ @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', );
+ ##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',
+ );
+ } else {
+ die "unknown format $format";
+ }
+
+ my $count;
+ my $parser;
+ my @buffer = ();
+
+ if ( $type eq 'csv' ) {
+
+ eval "use Text::CSV_XS;";
+ eval "use File::Slurp qw( slurp );";
+ die $@ if $@;
+
+ $parser = new Text::CSV_XS;
+
+ @buffer = split(/\r?\n/, slurp($filename) );
+ $count = scalar(@buffer);
+
+ } elsif ( $type eq 'xls' ) {
+ eval "use Spreadsheet::ParseExcel;";
+ die $@ if $@;
+
+ my $excel = Spreadsheet::ParseExcel::Workbook->new->Parse($filename);
+ $parser = $excel->{Worksheet}[0]; #first sheet
+
+ $count = $parser->{MaxRow} || $parser->{MinRow};
+ $count++;
+
+ } else {
+ die "Unknown file type $type\n";
+ }
+
+ my $imported = 0;
+ #my $columns;
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my $line;
+ my $row = 0;
+ my %data = ();
+ my( $last, $min_sec ) = ( time, 5 ); #progressbar foo
+ while (1) {
+ my @columns = ();
+
+ if ( $type eq 'csv' ) {
+
+ last unless scalar(@buffer);
+ $line = shift(@buffer);
+
+ $parser->parse($line) or do {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't parse: ". $parser->error_input();
+ };
+ @columns = $parser->fields();
+
+ } elsif ( $type eq 'xls' ) {
+ last if $row > ($parser->{MaxRow} || $parser->{MinRow})
+ || ! $parser->{Cells}[$row];
+
+ my @row = @{ $parser->{Cells}[$row] };
+ @columns = map $_->{Val}, @row;
+
+ } else {
+ die "Unknown file type $type\n";
+ }
+
+ #warn join('-', at columns);
+
+ my %row = ();
+ foreach my $field ( @fields ) {
+ $row{$field} = shift @columns;
+ }
+
+ if ( $row{custnum} && $row{agent_custid} ) {
+ dbh->rollback if $oldAutoCommit;
+ return "can't specify custnum with agent_custid $row{agent_custid}";
+ }
+
+ my $id;
+ my %hash = ();
+
+ if ( $row{agent_custid} && $agentnum ) {
+ $id = $row{agent_custid};
+ $data{$id}{cust} = (
+ 'agent_custid' => $row{agent_custid},
+ 'agentnum' => $agentnum,
+ );
+ %hash = ( 'agent_custid' => $row{agent_custid},
+ 'agentnum' => $agentnum,
+ );
+ }
+
+ if ( $row{custnum} ) {
+ $id = $row{custnum};
+ $data{$id}{cust} = {
+ 'custnum' => $row{custnum},
+ 'testnum' => 'test',
+ };
+ %hash = ( 'custnum' => $row{custnum} );
+ }
+
+ unless ( scalar(keys %hash) ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't find customer without custnum or agent_custid and agentnum";
+ }
+
+ ## add new pkg data or upate existing by adding new amount for custnum
+ $data{$id}{pkg}{$row{pkg}} = $data{$id}{pkg}{$row{pkg}} ? $data{$id}{pkg}{$row{pkg}} + $row{'amount'} : $row{'amount'};
+
+ $row++;
+
+ if ( $job && time - $min_sec > $last ) { #progress bar
+ $job->update_statustext( int(100 * $row / $count) );
+ $last = time;
+ }
+
+ }
+
+ ### run through data hash to post all charges.
+ foreach my $k (keys %data) {
+ my %pkg_hash = %{$data{$k}{pkg}};
+ my %cust_hash = %{$data{$k}{cust}};
+
+ my $cust_main = qsearchs('cust_main', { %cust_hash } );
+ unless ( $cust_main ) {
+ $dbh->rollback if $oldAutoCommit;
+ my $custnum = $cust_hash{custnum} || $cust_hash{agent_custid};
+ return "unknown custnum $custnum";
+ }
+
+ foreach my $pkg_key (keys %pkg_hash) {
+ my $pkg = $pkg_key;
+ my $amount = $pkg_hash{$pkg_key};
+
+ if (%charges) { next unless $charges{$pkg}; }
+
+ if ( $amount > 0 ) {
+ my $error = $cust_main->charge($amount, $pkg);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $imported++;
+ } elsif ( $amount < 0 ) {
+ my $error = $cust_main->credit( sprintf( "%.2f", 0-$amount ), $pkg );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $imported++;
+ } else {
+ #hmm?
+ }
+ }
+
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ unlink $filename;
+
+ return "Empty file!" unless $imported;
+
+ ''; #no error
+
+}
+
+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 065506369..4eacce13a 100644
--- a/httemplate/misc/cust_main-import_charges.cgi
+++ b/httemplate/misc/cust_main-import_charges.cgi
@@ -3,7 +3,15 @@
Import a CSV file containing customer charges.
<BR><BR>
-<FORM ACTION="process/cust_main-import_charges.cgi" METHOD="post" ENCTYPE="multipart/form-data">
+<& /elements/form-file_upload.html,
+ 'name' => 'OneTimeChargeImportForm',
+ 'action' => 'process/cust_main-import_charges.cgi',
+ 'num_files' => 1,
+ 'fields' => [ 'agentnum', 'custbatch', 'format' ],
+ 'message' => 'One time charge batch import successful',
+ 'url' => $p."misc/cust_main-import_charges.cgi",
+ 'onsubmit' => "document.OneTimeChargeImportForm.submitButton.disabled=true;",
+&>
<% &ntable("#cccccc", 2) %>
@@ -14,23 +22,35 @@ Import a CSV file containing customer charges.
)
%>
+<INPUT TYPE="hidden" NAME="custbatch" VALUE="<% $custbatch %>"%>
+
<TR>
<TH ALIGN="right">Format</TH>
<TD>
<SELECT NAME="format">
<OPTION VALUE="simple">Simple
+ <OPTION VALUE="ooma">Ooma
<!-- <OPTION VALUE="extended" SELECTED>Extended -->
</SELECT>
</TD>
</TR>
+ <% include( '/elements/file-upload.html',
+ 'field' => 'file',
+ 'label' => 'Filename',
+ )
+ %>
+
<TR>
- <TH ALIGN="right">CSV filename</TH>
- <TD><INPUT TYPE="file" NAME="csvfile"></TD>
+ <TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px">
+ <INPUT TYPE = "submit"
+ NAME = "submitButton"
+ ID = "submitButton"
+ VALUE = "Import file"
+ >
+ </TD>
</TR>
-<TR><TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px"><INPUT TYPE="submit" VALUE="Import CSV file"></TD></TR>
-
</TABLE>
</FORM>
@@ -59,11 +79,22 @@ Field information:
<BR>
+<b>Ooma</b> format has the following field order: <i>Description, Description2, Record Type, Customer Number, Billing Phone Number or Zip Code, Bus/Res Indicator, Invoice Date, Invoice Number, Group, Item, Revenue<%$req%>, LineCount, Exempt, ExemptList, State, City, Zipcode, OfferingPK, Offering name<%$req%>, Quantity, AccountNo<%$req%>, Status, Cust Created, PartnerID</i>
+<BR><BR>
+
+
<% include('/elements/footer.html') %>
+
+<%once>
+ my $req = qq!<font color="#ff0000">*</font>!;
+</%once>
+
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Import');
+ my $custbatch = time2str('webimport-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
+
</%init>
diff --git a/httemplate/misc/process/cust_main-import_charges.cgi b/httemplate/misc/process/cust_main-import_charges.cgi
index bda3e3b70..42ca82592 100644
--- a/httemplate/misc/process/cust_main-import_charges.cgi
+++ b/httemplate/misc/process/cust_main-import_charges.cgi
@@ -1,24 +1,10 @@
-% if ( $error ) {
-% errorpage($error);
-% } else {
- <% include('/elements/header.html','Import successful') %>
- <% include('/elements/footer.html') %>
-% }
+<% $server->process %>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Import');
-my $fh = $cgi->upload('csvfile');
-#warn $cgi;
-#warn $fh;
-
-my $error = defined($fh)
- ? FS::cust_main::batch_charge( {
- filehandle => $fh,
- 'agentnum' => scalar($cgi->param('agentnum')),
- 'format' => scalar($cgi->param('format')),
- } )
- : 'No file';
+my $server =
+ new FS::UI::Web::JSRPC 'FS::cust_main::Import_Charges::batch_charge', $cgi;
</%init>
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Mason.pm | 1 +
FS/FS/cust_main.pm | 115 --------
FS/FS/cust_main/Import_Charges.pm | 293 +++++++++++++++++++++
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 | 47 +++-
.../misc/process/cust_main-import_charges.cgi | 20 +-
8 files changed, 405 insertions(+), 139 deletions(-)
create mode 100644 FS/FS/cust_main/Import_Charges.pm
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