blob: da3779c760dd087ae73787aa9b884a79f928e245 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/usr/bin/perl
use FS::UID qw( adminsuidsetup );
use FS::Record qw( qsearch qsearchs );
use FS::cust_pay_refund;
use Data::Dumper;
adminsuidsetup shift or die usage();
## get a list of all refunds in batches.
my $extrasql = " LEFT JOIN pay_batch USING ( batchnum ) WHERE cust_pay_batch.paycode = 'C' AND pay_batch.download IS NULL";
my @batch_refunds = qsearch({
'table' => 'cust_pay_batch',
'select' => 'cust_pay_batch.*',
'extra_sql' => $extrasql,
});
warn "found ".scalar @batch_refunds." batch refunds.\n";
warn "Searching for their cust refunds...\n" if (scalar @batch_refunds > 0);
## find the cust_pay_refund for all those
foreach (@batch_refunds) {
my $extra_batch_refund_sql = " WHERE custnum = '".$_->{Hash}->{custnum}."' AND refund = '".$_->{Hash}->{amount}."' ORDER BY _date DESC LIMIT 1";
my $cust_refund = qsearchs({
'table' => 'cust_refund',
'extra_sql' => $extra_batch_refund_sql,
});
warn "found cust refund number ".$cust_refund->{Hash}->{refundnum}.", now to delete it.\n" if $cust_refund;
## delete the cust_pay_refund
my $delete_cust_refund_error = $cust_refund->delete if $cust_refund;
warn "could not delete cust refund $delete_cust_refund_error\n" if $delete_cust_refund_error;
## delete the refund from the batch.
unless ($delete_cust_refund_error) {
my $delete_cust_pay_batch_error = $_->unbatch_and_delete;
warn "could not delete cust refund $delete_cust_pay_batch_error\n" if $delete_cust_pay_batch_error;
}
if ($delete_cust_refund_error || $delete_cust_pay_batch_error) { die "Could no delete cust_pay_batch refund\n"; }
else { warn "cust refund ".$cust_refund->{Hash}->{refundnum}." deleted\n"; }
}
warn "all done!\n";
sub usage {
"Usage: Call script as user freeside\n Example: cust_pay_batch_refund_delete <freeside username> ";
}
|