7 use FS::UID qw(adminsuidsetup);
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 $cust_main->apply_payments;
60 $error=$cust_main->apply_credits;
64 $error=$cust_main->collect('invoice_time'=>$time,
65 'batch_card' => $main::opt_i ? 'no' : 'yes',
67 warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error"
78 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
79 #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
81 $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
87 die "Usage:\n\n freeside-bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n";
92 freeside-bill - Command line (crontab, script) interface to customer billing.
96 freeside-bill [ -c [ -p ] [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ]
100 Bills customers. Searches for customers who are due for billing and calls
101 the bill and collect methods of a cust_main object. See L<FS::cust_main>.
103 -c: Turn on collecting (you probably want this).
105 -p: Apply unapplied payments and credits before collecting (you probably want
108 -a: Call collect even if there isn't a new invoice (probably a bad idea for
111 -i: real-time billing (as opposed to batch billing). only relevant
114 -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with,
117 user: From the mapsecrets file - see config.html from the base documentation
119 custnum: if one or more customer numbers are specified, only bills those
120 customers. Otherwise, bills all customers.
124 $Id: freeside-bill,v 1.8 2001-09-03 22:07:39 ivan Exp $
130 L<FS::cust_main>, config.html from the base documentation