6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
13 my $user = shift or die &usage;
19 $FS::Record::nowarn_identical = 1;
22 $opt_d =~ /^(\d+)$/ or die "invalid date";
24 die "no date specified\n";
27 my @cust_credit = qsearch('cust_credit', { otaker => $user } );
28 die "no credits found\n" unless @cust_credit;
30 my $cust_credit = new FS::cust_credit;
31 my @fields = grep { $_ !~ /^otaker|reason|reasonnum$/ } $cust_credit->fields;
33 foreach my $cust_credit ( @cust_credit ) {
34 my %hash = $cust_credit->hash;
35 foreach (qw(otaker reason reasonnum)) {
38 $hash{'history_action'} = 'replace_old';
40 qsearchs({ 'table' => 'h_cust_credit',
43 'extra_sql' => " AND history_date <= $opt_d",
44 'order_by' => 'ORDER BY history_date DESC LIMIT 1',
47 $cust_credit->otaker($h_cust_credit->otaker);
48 my $reason = $h_cust_credit->getfield('reason');
49 if ($reason =~ /^\s*$/) {
52 $cust_credit->otaker($h_cust_credit->otaker);
53 $cust_credit->reason($reason);
54 my $error = $cust_credit->replace
55 if $cust_credit->modified;
56 die "error replacing cust_credit: $error\n"
59 warn "Skipping credit.crednum ". $cust_credit->crednum;
64 die "Usage:\n\n reset-cust_credit-otaker -d epoch_date user\n";
69 reset-cust_credit-otaker - Command line tool to reset the otaker column for cust_credits to a previous value
73 reset-cust_credit-otaker -d epoch_date user
77 Sets the otaker column of the cust_credit records specified by user and
78 datespec to the value just prior to datespec.
80 The reasonnum of the cust_credit record is also set to reason record
81 which matches the reason specified in the history.
85 L<FS::cust_credit>, L<FS::h_cust_credit>;