7 use FS::UID qw(adminsuidsetup swapuid);
8 use FS::Record qw(qsearch qsearchs);
11 &untaint_argv; #what it sounds like (eww)
12 use vars qw($opt_a $opt_c $opt_i $opt_d);
14 my $user = shift or die &usage;
18 my %bill_only = map { $_ => 1 } (
19 @ARGV ? @ARGV : ( map $_->custnum, qsearch('cust_main', {} ) )
22 #we're at now now (and later).
23 my($time)= $main::opt_d ? str2time($main::opt_d) : $^T;
25 # find packages w/ bill < time && cancel != '', and create corresponding
31 unless ( exists $saw{ $_->custnum } && defined $saw{ $_->custnum} ) {
32 $saw{ $_->custnum } = 0; # to avoid 'use of uninitialized value' errors
35 ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) )
36 && $bill_only{ $_->custnum }
37 && !$saw{ $_->custnum }++
39 qsearchs('cust_main',{'custnum'=> $_->custnum } );
43 } ( qsearch('cust_pkg', { 'cancel' => '' }),
44 qsearch('cust_pkg', { 'cancel' => 0 }),
50 print "Billing customer #" . $cust_main->getfield('custnum') . "\n";
54 $error=$cust_main->bill('time'=>$time);
55 warn "Error billing, customer #" . $cust_main->getfield('custnum') .
56 ":" . $error if $error;
59 $error=$cust_main->collect('invoice_time'=>$time,
60 'batch_card' => $main::opt_i ? 'no' : 'yes',
62 warn "Error collecting customer #" . $cust_main->getfield('custnum') .
63 ":" . $error if $error;
74 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
75 #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
77 $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
83 die "Usage:\n\n freeside-bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n";
88 freeside-bill - Command line (crontab, script) interface to customer billing.
92 freeside-bill [ -c [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ]
96 Bills customers. Searches for customers who are due for billing and calls
97 the bill and collect methods of a cust_main object. See L<FS::cust_main>.
99 -c: Turn on collecting (you probably want this).
101 -a: Call collect even if there isn't a new invoice (probably a bad idea for
104 -i: real-time billing (as opposed to batch billing). only relevant
107 -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with,
110 user: From the mapsecrets file - see config.html from the base documentation
112 custnum: if one or more customer numbers are specified, only bills those
113 customers. Otherwise, bills all customers.
117 $Id: freeside-bill,v 1.6 2000-06-24 00:28:30 ivan Exp $
123 L<FS::cust_main>, config.html from the base documentation