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
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;
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));
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;
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;
#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',
],
},
- #'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' => [
#add weights to pkg_category
'pkg_category' => [],
+ #cdrbatch fixes
+ 'cdr' => [],
+
;
\%hash;
=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
my $job = shift;
my $opt = _import_options;
- $opt->{'params'} = [ 'format', 'cdrbatch' ];
+# $opt->{'params'} = [ 'format', 'cdrbatch' ];
FS::Record::process_batch_import( $job, $opt, @_ );
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
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;
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;
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;
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;
-% 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>
-
-% 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 {
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>
}
###
-# 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";
}
+
}
###
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;
# "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>' );
###