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
32 ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) )
33 && $bill_only{ $_->custnum }
34 && !$saw{ $_->custnum }++
36 qsearchs('cust_main',{'custnum'=> $_->custnum } );
40 } ( qsearch('cust_pkg', { 'cancel' => '' }),
41 qsearch('cust_pkg', { 'cancel' => 0 }),
47 print "Billing customer #" . $cust_main->getfield('custnum') . "\n";
52 $error=$cust_main->bill('time'=>$time);
53 warn "Error billing, customer #" . $cust_main->getfield('custnum') .
54 ":" . $error if $error;
57 $error=$cust_main->collect('invoice_time'=>$time,
58 'batch_card' => $main::opt_i ? 'no' : 'yes',
60 warn "Error collecting customer #" . $cust_main->getfield('custnum') .
61 ":" . $error if $error;
72 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
73 $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
79 die "Usage:\n\n bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n";
84 freeside-bill - Command line (crontab, script) interface to customer billing.
88 freeside-bill [ -c [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ]
92 Bills customers. Searches for customers who are due for billing and calls
93 the bill and collect methods of a cust_main object. See L<FS::cust_main>.
95 -c: Turn on collecting (you probably want this).
97 -a: Call collect even if there isn't a new invoice (probably a bad idea for
100 -i: real-time billing (as opposed to batch billing). only relevant
103 -d: Pretent it's 'date'. Date is in any format Date::Parse is happy with,
106 user: From the mapsecrets file - see config.html from the base documentation
108 custnum: if one or more customer numbers are specified, only bills those
109 customers. Otherwise, bills all customers.
113 $Id: freeside-bill,v 1.1 1999-08-11 20:41:27 ivan Exp $
119 L<FS::cust_main>, config.html from the base documentation