7 use FS::UID qw(adminsuidsetup driver_name dbh);
8 use FS::Record qw(qsearch qsearchs);
11 &untaint_argv; #what it sounds like (eww)
12 use vars qw($opt_d $opt_v);
14 my $user = shift or die &usage;
18 $FS::cust_main::Debug = 1 if $opt_v;
21 ? map { qsearchs('cust_main', { custnum => $_ } ) } @ARGV
22 : qsearch('cust_main', {} )
25 #we're at now now (and later).
26 my($time)= $opt_d ? str2time($opt_d) : $^T;
29 foreach $cust_main ( @cust_main ) {
33 $error = $cust_main->bill( 'time' => $time );
34 warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error;
36 $cust_main->apply_payments;
37 $cust_main->apply_credits;
39 $error=$cust_main->collect( 'invoice_time' => $time );
40 warn "Error collecting, custnum". $cust_main->custnum. ": $error" if $error;
44 if ( driver_name eq 'Pg' ) {
45 foreach my $statement ( 'vacuum', 'vacuum analyze' ) {
46 my $sth = dbh->prepare($statement) or die dbh->errstr;
47 $sth->execute or die $sth->errstr;
54 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
55 #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
57 $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
63 die "Usage:\n\n freeside-daily [ -d 'date' ] user [ custnum custnum ... ]\n";
68 freeside-daily - Run daily billing and invoice collection events.
72 freeside-daily [ -d 'date' ] user [ custnum custnum ... ]
76 Bills customers and runs invoice collection events. Should be run from
79 This script replaces freeside-bill from 1.3.1.
81 Bills customers. Searches for customers who are due for billing and calls
82 the bill and collect methods of a cust_main object. See L<FS::cust_main>.
84 -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with,
87 user: From the mapsecrets file - see config.html from the base documentation
89 custnum: if one or more customer numbers are specified, only bills those
90 customers. Otherwise, bills all customers.
96 L<FS::cust_main>, config.html from the base documentation