6 use FS::part_export; # yes, they're really "imports" in this context
7 use FS::Record qw(qsearch qsearchs dbh);
8 use Date::Format 'time2str';
17 $FS::UID::AutoCommit = 0;
19 my @exports = grep { $_->can('import_cdrs') } qsearch('part_export');
21 die "There are no CDR exports configured.\n";
24 foreach my $part_export (@exports) {
25 debug $part_export->label;
28 # find the most recently downloaded batch
29 my $prefix = $part_export->exporttype . '-' . $part_export->exportnum
31 my $most_recent = qsearchs({
32 'table' => 'cdr_batch',
33 'hashref' => { 'cdrbatch' => {op=>'like', value=>$prefix}
35 'order_by' => 'ORDER BY _date DESC LIMIT 1',
38 $most_recent->cdrbatch =~ /-(\d+)$/; # extract the end timestamp
40 debug "Downloading records since most recent batch: ".
41 time2str('%Y-%m-%d', $opt{start});
43 $opt{start} = 1262332800;
44 debug "Downloading records since January 2010.";
50 my $error_or_batch = $part_export->import_cdrs( $opt{start}, $opt{end} );
51 if ( ref $error_or_batch ) {
52 debug "Created batch #".$error_or_batch->cdrbatchnum;
54 } elsif ( $error_or_batch ) {
58 debug "No CDRs found."
63 "Usage: \n freeside-cdr-import [ options ] user
64 Imports CDRs from certain svc_phone exports that are capable of it.
67 -s date: start date (defaults to the most recent batch date)