7 use FS::Record qw(qsearch qsearchs dbh);
8 use Date::Format 'time2str';
17 $FS::UID::AutoCommit = 0;
19 my @exports = qsearch('part_export', { exporttype => 'voip_ms' });
21 die "There are no voip.ms exports configured.\n";
24 foreach my $part_export (@exports) {
25 debug "Account #".$part_export->option('account');
28 # find the most recently downloaded batch
29 my $exportnum = $part_export->exportnum;
30 my $most_recent = qsearchs({
31 'table' => 'cdr_batch',
32 'hashref' => { 'cdrbatch' => {op=>'like',
33 value=>'voip_ms-' . $exportnum . '-%'}
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 cdr-voip_ms.import [ options ] user
66 -s date: start date (defaults to the most recent batch date)