summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorivan <ivan>2010-11-19 21:58:43 +0000
committerivan <ivan>2010-11-19 21:58:43 +0000
commit6c447c88737be60074a02ab4f634aeaab4cbfe13 (patch)
tree9cea5e15adceb308eae6c21fe940610edabc3305 /bin
parent14ce41081337ded937c6264f43f23923e5574018 (diff)
adding wipe-agent script, RT#10679
Diffstat (limited to 'bin')
-rw-r--r--bin/wipe-agent39
1 files changed, 39 insertions, 0 deletions
diff --git a/bin/wipe-agent b/bin/wipe-agent
new file mode 100644
index 000000000..fbe58a804
--- /dev/null
+++ b/bin/wipe-agent
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+use strict;
+use vars qw( $opt_a $opt_d );
+use Getopt::Std;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch);
+use FS::cust_main;
+
+die "i cancel and delete all customers of an agent - use the -d switch first and be careful - remove this line to enable";
+
+getopts('a:d');
+
+my $user = shift or die "usage: wipe-agent -a agentnum [ -d ] username\n";
+adminsuidsetup $user;
+
+die "no agentnum specified" unless $opt_a;
+
+foreach my $cust_main (
+
+ qsearch('cust_main', { 'agentnum' => $opt_a } )
+
+) {
+
+ warn "deleting ". $cust_main->name. "\n";
+
+ unless ( $opt_d ) { #dry run
+
+ my @cerrors = $cust_main->cancel( quiet=>1, nobill=>1 );
+ if ( @cerrors ) {
+ die join(' / ', @cerrors);
+ }
+
+ my $error = $cust_main->delete( 'delete_financials' => 1);
+ die $error if $error;
+
+ }
+
+}