2 # don't take any world-facing input
9 use FS::UID qw(adminsuidsetup);
10 use FS::Record qw(qsearch qsearchs);
13 &untaint_argv; #what it sounds like (eww)
14 use vars qw($opt_a $opt_c $opt_d $opt_p);
16 my $user = shift or die &usage;
20 my %bill_only = map { $_ => 1 } (
21 @ARGV ? @ARGV : ( map $_->custnum, qsearch('cust_main', {} ) )
24 #we're at now now (and later).
25 my($time)= $opt_d ? str2time($opt_d) : $^T;
27 # find packages w/ bill < time && cancel != '', and create corresponding
33 unless ( exists $saw{ $_->custnum } && defined $saw{ $_->custnum} ) {
34 $saw{ $_->custnum } = 0; # to avoid 'use of uninitialized value' errors
37 ( $opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) )
38 && $bill_only{ $_->custnum }
39 && !$saw{ $_->custnum }++
41 qsearchs('cust_main',{'custnum'=> $_->custnum } );
45 } ( qsearch('cust_pkg', { 'cancel' => '' }),
46 qsearch('cust_pkg', { 'cancel' => 0 }),
52 print "Billing customer #" . $cust_main->getfield('custnum') . "\n";
56 $error=$cust_main->bill('time'=>$time);
57 warn "Error billing, customer #" . $cust_main->getfield('custnum') .
58 ":" . $error if $error;
61 $cust_main->apply_payments;
62 $cust_main->apply_credits;
66 $error=$cust_main->collect( 'invoice_time' => $time);
67 warn "Error collecting from customer #" . $cust_main->custnum. ":$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 [ -p ] ] [ -d 'date' ] user [ custnum custnum ... ]\n";
92 freeside-bill - Command line (crontab, script) interface to customer billing.
96 freeside-bill [ -c [ -p ] [ -a ] ] [ -d 'date' ] user [ custnum custnum ... ]
100 This script is deprecated in 1.4.0. You should use freeside-daily instead.
102 Bills customers. Searches for customers who are due for billing and calls
103 the bill and collect methods of a cust_main object. See L<FS::cust_main>.
105 -c: Turn on collecting (you probably want this).
107 -p: Apply unapplied payments and credits before collecting (you probably want
110 -a: Call collect even if there isn't a new invoice (probably a bad idea for
113 -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with,
116 user: From the mapsecrets file - see config.html from the base documentation
118 custnum: if one or more customer numbers are specified, only bills those
119 customers. Otherwise, bills all customers.
125 L<freeside-daily>, L<FS::cust_main>, config.html from the base documentation