7 use FS::Record qw(qsearch qsearchs dbh);
12 $FS::UID::AutoCommit = 0;
15 "Usage: bulk_void -s start -e end
21 -s, -e: date range (required)
22 -r: void reason text (required)
23 -c, -p, -i: void credits, payments, invoices
24 -t: only void payments with this payby
29 if (!$opt{start} or !$opt{end} or !$opt{r}) {
33 print "DRY RUN--changes will not be committed.\n" unless $opt{X};
36 $search{payby} = $opt{t} if $opt{t} && $opt{p};
38 my $date = (keys %search ? ' AND ' : ' WHERE ').
39 " _date >= $opt{start} AND _date <= $opt{end}";
49 foreach my $k (keys %tables) {
51 my $table = $tables{$k};
56 my $cursor = FS::Cursor->new({
62 while (my $record = $cursor->fetch) {
63 $error = $record->void($reason);
65 $error = "$table #" . $record->get($record->primary_key) . ": $error";
76 print " $table voided: $done_count\n errors: $error_count\n";
81 print "Committed changes.\n";
84 print "Reverted changes.\n";