stretch
[freeside.git] / bin / wipe-agent
1 #!/usr/bin/perl
2
3 use strict;
4 use vars qw( $opt_a $opt_d );
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch);
8 use FS::cust_main;
9
10 die "i cancel and delete all customers of an agent - use the -d switch first and be careful - remove this line to enable";
11
12 getopts('a:d');
13
14 my $user = shift or die "usage: wipe-agent -a agentnum [ -d ] username\n";
15 adminsuidsetup $user;
16
17 die "no agentnum specified" unless $opt_a;
18
19 foreach my $cust_main (
20
21   qsearch('cust_main', { 'agentnum' => $opt_a } )
22
23 ) {
24
25   warn "deleting ". $cust_main->custnum.': '. $cust_main->name. "\n";
26
27   unless ( $opt_d ) { #dry run
28
29     my @cerrors = $cust_main->cancel( quiet=>1, nobill=>1 );
30     if ( @cerrors ) {
31       die join(' / ', @cerrors);
32     }
33
34     my $error = $cust_main->delete( 'delete_financials' => 1);
35     die $error if $error;
36
37   }
38
39 }