diff options
author | ivan <ivan> | 2009-02-21 17:56:07 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-02-21 17:56:07 +0000 |
commit | b953866b9f57ce381a34f272926f91f7f706de24 (patch) | |
tree | 04d0fd4e60c2809707b0a07167db2ab5c88972ae /bin | |
parent | 97b377f991f6e9475e8e95c211f67e1186d33062 (diff) |
adding follow-tax-rename tool (well, quick hack), RT#4878
Diffstat (limited to 'bin')
-rw-r--r-- | bin/follow-tax-rename | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/bin/follow-tax-rename b/bin/follow-tax-rename new file mode 100644 index 000000000..b7536e815 --- /dev/null +++ b/bin/follow-tax-rename @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +use FS::UID qw( adminsuidsetup ); +use FS::Record qw( qsearch qsearchs ); +use FS::cust_bill_pkg; + +$FS::Record::nowarn_classload = 1; +$FS::Record::nowarn_classload = 1; + +adminsuidsetup shift; + +my $begin = 1231876106; + +my @old = qsearch('h_cust_main_county', { + 'history_action' => 'replace_old', + 'history_date' => { op=>'>=', value=>$begin, }, +} ); + +foreach my $old (@old) { + + my $new = qsearchs('h_cust_main_county', { + 'history_action' => 'replace_new', + 'history_date' => $old->history_date, + }); + + unless ( $new ) { + warn "huh? no corresponding new record found?"; + next; + } + + my $old_taxname = $old->taxname; + my $new_taxname = $new->taxname; + + my @cust_bill_pkg = qsearch('cust_bill_pkg', { + 'pkgnum' => 0, + 'itemdesc' => $old->taxname, + }); + + next unless @cust_bill_pkg; + + warn 'fixing '. scalar(@cust_bill_pkg). + " dangling line items for rename $old_taxname -> $new_taxname\n"; + + foreach my $cust_bill_pkg ( @cust_bill_pkg ) { + + $cust_bill_pkg->itemdesc( $new->taxname ); + my $error = $cust_bill_pkg->replace; + die $error if $error; + + } + +} |