summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS.pm2
-rw-r--r--FS/FS/Mason.pm1
-rw-r--r--FS/FS/Record.pm62
-rw-r--r--FS/FS/Schema.pm25
-rw-r--r--FS/FS/Upgrade.pm3
-rw-r--r--FS/FS/cdr.pm8
-rw-r--r--FS/MANIFEST2
-rwxr-xr-xFS/bin/freeside-cdr-sftp_and_import8
-rwxr-xr-xbin/cdr-transnexus.import8
-rwxr-xr-xbin/cdr.http_and_import8
-rw-r--r--bin/cdr.import6
-rw-r--r--httemplate/elements/select-cdrbatch.html42
-rw-r--r--httemplate/elements/tr-select-cdrbatch.html18
-rw-r--r--httemplate/search/cdr.html26
-rw-r--r--httemplate/search/report_cdr.html2
-rw-r--r--httemplate/view/svc_phone.cgi4
16 files changed, 124 insertions, 101 deletions
diff --git a/FS/FS.pm b/FS/FS.pm
index 9ec2602cd..c6f9eceaf 100644
--- a/FS/FS.pm
+++ b/FS/FS.pm
@@ -150,6 +150,8 @@ L<FS::phone_avail> - Phone number availability cache
L<FS::cdr> - Call Detail Record class
+L<FS::cdr_batch> - Call Detail Record batch class
+
L<FS::cdr_calltype> - CDR calltype class
L<FS::cdr_carrier> - CDR carrier class
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 460e1c334..bef005881 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -185,6 +185,7 @@ if ( -e $addl_handler_use_file ) {
use FS::XMLRPC;
use FS::payby;
use FS::cdr;
+ use FS::cdr_batch;
use FS::inventory_class;
use FS::inventory_item;
use FS::pkg_category;
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 88d8ca9a3..e02a2cff8 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -1547,7 +1547,7 @@ sub process_batch_import {
my($job, $opt) = ( shift, shift );
my $table = $opt->{table};
- my @pass_params = @{ $opt->{params} };
+ my @pass_params = $opt->{params} ? @{ $opt->{params} } : ();
my %formats = %{ $opt->{formats} };
my $param = thaw(decode_base64(shift));
@@ -1561,24 +1561,30 @@ sub process_batch_import {
my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc. '/';
my $file = $dir. $files{'file'};
- my $error =
- FS::Record::batch_import( {
- #class-static
- table => $table,
- formats => \%formats,
- format_types => $opt->{format_types},
- format_headers => $opt->{format_headers},
- format_sep_chars => $opt->{format_sep_chars},
- format_fixedlength_formats => $opt->{format_fixedlength_formats},
- #per-import
- job => $job,
- file => $file,
- #type => $type,
- format => $param->{format},
- params => { map { $_ => $param->{$_} } @pass_params },
- #?
- default_csv => $opt->{default_csv},
- } );
+ my %iopt = (
+ #class-static
+ table => $table,
+ formats => \%formats,
+ format_types => $opt->{format_types},
+ format_headers => $opt->{format_headers},
+ format_sep_chars => $opt->{format_sep_chars},
+ format_fixedlength_formats => $opt->{format_fixedlength_formats},
+ #per-import
+ job => $job,
+ file => $file,
+ #type => $type,
+ format => $param->{format},
+ params => { map { $_ => $param->{$_} } @pass_params },
+ #?
+ default_csv => $opt->{default_csv},
+ );
+
+ if ( $opt->{'batch_namecol'} ) {
+ $iopt{'batch_namevalue'} = $param->{ $opt->{'batch_namecol'} };
+ $iopt{$_} = $opt->{$_} foreach qw( batch_keycol batch_table batch_namecol );
+ }
+
+ my $error = FS::Record::batch_import( \%iopt );
unlink $file;
@@ -1731,6 +1737,24 @@ sub batch_import {
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+
+ if ( $param->{'batch_namecol'} && $param->{'batch_namevalue'} ) {
+ my $batch_col = $param->{'batch_keycol'};
+
+ my $batch_class = 'FS::'. $param->{'batch_table'};
+ my $batch = $batch_class->new({
+ $param->{'batch_namecol'} => $param->{'batch_namevalue'}
+ });
+ my $error = $batch->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't insert batch record: $error";
+ }
+ #primary key via dbdef? (so the column names don't have to match)
+ my $batch_value = $batch->get( $param->{'batch_keycol'} );
+
+ $params->{ $batch_col } = $batch_value;
+ }
my $line;
my $imported = 0;
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 2910c170c..f4cbe1d30 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2235,9 +2235,10 @@ sub tables_hashref {
#an indexed place to put big numbers
'cdrid', 'bigint', 'NULL', '', '', '',
- #i should become a table
+ #old
'cdrbatch', 'varchar', 'NULL', 255, '', '',
- #'cdrbatchnum', 'int', 'NULL', '', '', '',
+ #new
+ 'cdrbatchnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'acctid',
@@ -2250,16 +2251,16 @@ sub tables_hashref {
],
},
- #'cdr_batch' => {
- # 'columns' => [
- # 'cdrbatchnum', 'serial', '', '', '', '',
- # 'cdrbatch', 'varchar', 'NULL', 255, '', '',
- # '_date', @date_type, '', '',
- # ],
- # 'primary_key' => 'cdrbatchnum',
- # 'unique' => [ [ 'cdrbatch' ] ],
- # 'index' => [],
- #},
+ 'cdr_batch' => {
+ 'columns' => [
+ 'cdrbatchnum', 'serial', '', '', '', '',
+ 'cdrbatch', 'varchar', 'NULL', 255, '', '',
+ '_date', @date_type, '', '',
+ ],
+ 'primary_key' => 'cdrbatchnum',
+ 'unique' => [ [ 'cdrbatch' ] ],
+ 'index' => [],
+ },
'cdr_termination' => {
'columns' => [
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index e5cd5d32b..c39680ef7 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -138,6 +138,9 @@ sub upgrade_data {
#add weights to pkg_category
'pkg_category' => [],
+ #cdrbatch fixes
+ 'cdr' => [],
+
;
\%hash;
diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index cd4285428..b9a4e41db 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -763,7 +763,11 @@ Set true to prevent throwing an error on empty imports
=cut
my %import_options = (
- 'table' => 'cdr',
+ 'table' => 'cdr',
+
+ 'batch_keycol' => 'cdrbatchnum',
+ 'batch_table' => 'cdr_batch',
+ 'batch_namecol' => 'cdrbatch',
'formats' => { map { $_ => $cdr_info{$_}->{'import_fields'}; }
keys %cdr_info
@@ -810,7 +814,7 @@ sub process_batch_import {
my $job = shift;
my $opt = _import_options;
- $opt->{'params'} = [ 'format', 'cdrbatch' ];
+# $opt->{'params'} = [ 'format', 'cdrbatch' ];
FS::Record::process_batch_import( $job, $opt, @_ );
diff --git a/FS/MANIFEST b/FS/MANIFEST
index b84ba525b..8a02a1338 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -453,6 +453,8 @@ FS/cust_attachment.pm
t/cust_attachment.t
FS/cust_statement.pm
t/cust_statement.t
+FS/cdr_batch.pm
+t/cdr_batch.t
FS/cust_class.pm
t/cust_class.t
FS/cust_category.pm
diff --git a/FS/bin/freeside-cdr-sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import
index e87698fc5..d90695f8f 100755
--- a/FS/bin/freeside-cdr-sftp_and_import
+++ b/FS/bin/freeside-cdr-sftp_and_import
@@ -84,10 +84,10 @@ foreach my $filename ( @$ls ) {
warn "Processing $filename\n" if $opt_v;
my $error = FS::cdr::batch_import( {
- 'file' => "$cachedir/$filename",
- 'format' => $format,
- 'params' => { 'cdrbatch' => $filename, },
- 'empty_ok' => 1,
+ 'file' => "$cachedir/$filename",
+ 'format' => $format,
+ 'batch_namevalue' => $filename,
+ 'empty_ok' => 1,
} );
die $error if $error;
diff --git a/bin/cdr-transnexus.import b/bin/cdr-transnexus.import
index 9686f7d2f..b9fe41ab1 100755
--- a/bin/cdr-transnexus.import
+++ b/bin/cdr-transnexus.import
@@ -66,10 +66,10 @@ foreach my $dir ( @$lsdir ) {
warn "Processing $filename\n" if $opt_v;
my $error = FS::cdr::batch_import( {
- 'file' => "$cachedir/$filename",
- 'format' => $format,
- 'params' => { 'cdrbatch' => $filename, },
- 'empty_ok' => 1,
+ 'file' => "$cachedir/$filename",
+ 'format' => $format,
+ 'batch_namevalue' => $filename,
+ 'empty_ok' => 1,
} );
die $error if $error;
diff --git a/bin/cdr.http_and_import b/bin/cdr.http_and_import
index 5637fa526..8910eece6 100755
--- a/bin/cdr.http_and_import
+++ b/bin/cdr.http_and_import
@@ -85,10 +85,10 @@ foreach my $file ( @files ) {
warn "Processing $filename\n" if $opt_v;
my $error = FS::cdr::batch_import( {
- 'file' => "$cachedir/$filename",
- 'format' => $format,
- 'params' => { 'cdrbatch' => $filename },
- 'empty_ok' => 1,
+ 'file' => "$cachedir/$filename",
+ 'format' => $format,
+ 'batch_namevalue' => $filename,
+ 'empty_ok' => 1,
} );
die $error if $error;
diff --git a/bin/cdr.import b/bin/cdr.import
index a17417b85..36266efbf 100644
--- a/bin/cdr.import
+++ b/bin/cdr.import
@@ -16,9 +16,9 @@ my $format = shift or die &usage;
my $file = shift;
my $error = FS::cdr::batch_import( {
- 'file' => $file,
- 'format' => $format,
- 'params' => { 'cdrbatch' => $file },
+ 'file' => $file,
+ 'format' => $format,
+ 'batch_namevalue' => $file,
} );
die $error if $error;
diff --git a/httemplate/elements/select-cdrbatch.html b/httemplate/elements/select-cdrbatch.html
index 866ba2516..034db3afd 100644
--- a/httemplate/elements/select-cdrbatch.html
+++ b/httemplate/elements/select-cdrbatch.html
@@ -1,38 +1,14 @@
-% if ( scalar(@{ $opt{'cdrbatches'} }) ) {
-
- <SELECT NAME="<% $opt{'name'} || 'cdrbatch' %>">
-
- <OPTION VALUE="__ALL__">All
- <OPTION VALUE="">(blank)
-
-% foreach my $cdrbatch ( @{ $opt{'cdrbatches'} } ) {
- <OPTION VALUE="<% $cdrbatch %>"<% $cdrbatch eq $selected_cdrbatch ? ' SELECTED' : '' %>><% $cdrbatch %>
-% }
-
- </SELECT>
-
-% } else {
-
- <INPUT TYPE="hidden" NAME="cdrbatch" VALUE="__ALL__">
-
-% }
-
+<% include( '/elements/select-table.html',
+ 'table' => 'cdr_batch',
+ 'name_col' => 'cdrbatch',
+ 'curr_value' => $cdrbatchnum,
+ 'empty_label' => '(none)',
+ 'pre_options' => [ '__ALL__' => 'All' ],
+ )
+%>
<%init>
my %opt = @_;
-my $selected_cdrbatch = $opt{'curr_value'}; # || $opt{'value'} necessary?
-
-my $conf = new FS::Conf;
-
-unless ( $opt{'cdrbatches'} ) {
-
- my $sth = dbh->prepare('SELECT DISTINCT cdrbatch FROM cdr')
- or die dbh->errstr;
- $sth->execute or die $sth->errstr;
- my %cdrbatches = map { $_->[0] => 1 } @{$sth->fetchall_arrayref};
- @{ $opt{'cdrbatches'} } = grep $_, keys %cdrbatches;
-
-}
+my $cdrbatchnum = $opt{'curr_value'}; # || $opt{'value'} necessary?
</%init>
-
diff --git a/httemplate/elements/tr-select-cdrbatch.html b/httemplate/elements/tr-select-cdrbatch.html
index 21cd00462..d080e2439 100644
--- a/httemplate/elements/tr-select-cdrbatch.html
+++ b/httemplate/elements/tr-select-cdrbatch.html
@@ -1,6 +1,6 @@
-% if ( ! scalar(@{ $opt{'cdrbatches'} }) ) {
+% if ( ! $show ) {
- <INPUT TYPE="hidden" NAME="<% $opt{'element_name'} || $opt{'field'} || 'cdrbatch' %>" VALUE="<% $selected_cdrbatch %>">
+ <INPUT TYPE="hidden" NAME="<% $opt{'element_name'} || $opt{'field'} || 'cdrbatchnum' %>" VALUE="__ALL__">
% } else {
@@ -18,15 +18,13 @@ my( %opt ) = @_;
my $conf = new FS::Conf;
my $selected_cdrbatch = $opt{'curr_value'}; # || $opt{'value'} necessary?
-unless ( $opt{'cdrbatches'} ) {
+$opt{'records'} = delete $opt{'cdr_batch'}
+ if $opt{'cdr_batch'};
- my $sth = dbh->prepare('SELECT cdrbatch FROM cdr')
- or die dbh->errstr;
- $sth->execute or die $sth->errstr;
- my %cdrbatches = map { $_->[0] => 1 } @{$sth->fetchall_arrayref};
- @{ $opt{'cdrbatches'} } = grep $_, keys %cdrbatches;
-
-}
+my $sth = dbh->prepare('SELECT COUNT(*) FROM cdr_batch LIMIT 1')
+ or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+my $show = $sth->fetchrow_arrayref->[0];
</%init>
diff --git a/httemplate/search/cdr.html b/httemplate/search/cdr.html
index d1f68c5c6..cfbc5ed5d 100644
--- a/httemplate/search/cdr.html
+++ b/httemplate/search/cdr.html
@@ -179,18 +179,30 @@ if ( $cgi->param('charged_party') =~ /^\s*([\d\-\+\ ]+)\s*$/ ) {
}
###
-# cdrbatch
+# cdrbatchnum (or legacy cdrbatch)
###
-if ( $cgi->param('cdrbatch') ne '__ALL__' ) {
- if ( $cgi->param('cdrbatch') eq '' ) {
- my $search = "( cdrbatch IS NULL OR cdrbatch = '' )";
+if ( $cgi->param('cdrbatch') ) {
+
+ my $cdr_batch =
+ qsearchs('cdr_batch', { 'cdrbatch' => scalar($cgi->param('cdrbatch')) } );
+ if ( $cdr_batch ) {
+ push @search, 'cdrbatchnum = '. $cdr_batch->cdrbatchnum;
+ } else {
+ die "unknown cdrbatch ". $cgi->param('cdrbatch');
+ }
+
+} elsif ( $cgi->param('cdrbatchnum') ne '__ALL__' ) {
+
+ if ( $cgi->param('cdrbatchnum') eq '' ) {
+ my $search = "( cdrbatchnum IS NULL )";
push @qsearch, $search;
push @search, $search;
- } else {
- $hashref->{cdrbatch} = $cgi->param('cdrbatch');
- push @search, 'cdrbatch = '. dbh->quote($cgi->param('cdrbatch'));
+ } elsif ( $cgi->param('cdrbatchnum') =~ /^(\d+)$/ ) {
+ $hashref->{cdrbatchnum} = $1;
+ push @search, "cdrbatchnum = $1";
}
+
}
###
diff --git a/httemplate/search/report_cdr.html b/httemplate/search/report_cdr.html
index c685198d9..744038d12 100644
--- a/httemplate/search/report_cdr.html
+++ b/httemplate/search/report_cdr.html
@@ -132,7 +132,7 @@ my @show_default = qw(
startdate answerdate enddate duration billsec
disposition amaflags accountcode userfield
rated_price upstream_price carrierid
- svcnum freesidestatus freesiderewritestatus cdrbatch
+ svcnum freesidestatus freesiderewritestatus
);
my %show_default = map { $_=>1 } @show_default;
diff --git a/httemplate/view/svc_phone.cgi b/httemplate/view/svc_phone.cgi
index 09d5be483..c5fce62d9 100644
--- a/httemplate/view/svc_phone.cgi
+++ b/httemplate/view/svc_phone.cgi
@@ -107,11 +107,11 @@ my $html_foot = sub {
# "View $_ CDRs</A>";
#} keys(%what);
my @links = map {
- qq(<A HREF="${p}search/cdr.html?cdrbatch=__ALL__;charged_party=$number;freesidestatus=$what{$_}">).
+ qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;charged_party=$number;freesidestatus=$what{$_}">).
"View $_ CDRs</A>";
} keys(%what);
- my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatch=__ALL__;dst=$number">).
+ my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
'View incoming CDRs</A>' );
###