blob: 0e1846a63335d40136b92b73c1ffeca799b847e9 (
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
|
#!/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->custnum.': '. $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;
}
}
|