6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw( qsearch );
10 &untaint_argv; #what it sounds like (eww)
12 getopts("p:a:d:sy:n", \%opt);
14 my $user = shift or die &usage;
17 my (@custnums) = @ARGV;
19 my $time = $opt{d} ? str2time($opt{d}) : $^T;
20 $time += $opt{y} * 86400 if $opt{y};
21 my $invoice_time = $opt{n} ? $^T : $time;
25 'invoice_time' => $invoice_time,
26 'actual_time' => $^T, #when freeside-bill was started
27 #(not, when using -m, freeside-queued)
28 'resetup' => ( $opt{'s'} ? $opt{'s'} : 0 ),
32 my $extra_sql = ( $opt{a} || $opt{p} ) ? ' AND ' : ' WHERE ';
33 $extra_sql .= "( ". join( ' OR ', map{ "custnum = $_" } @custnums ). " )";
34 $extra_sql = '' unless scalar @custnums;
36 my @cust = qsearch( { table => 'cust_main',
37 hashref => { $opt{a} ? ( 'agentnum' => $opt{a} ) : (),
38 $opt{p} ? ( 'payby' => $opt{p} ) : (),
40 extra_sql => $extra_sql,
44 foreach my $cust ( @cust ) {
45 my $balance = $cust->balance;
46 cust_main_special::bill($cust, %args);
47 if ($balance != $cust->balance){
48 $cust->apply_payments_and_credits;
49 my $error = $cust->collect(%args);
50 warn "Error collecting, custnum ". $cust->custnum. ": $error" if $error;
60 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
61 #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
63 $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
69 die "Usage:\n\n freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] user [ custnum custnum ... ]\n";
78 freeside-daily - Run daily billing and invoice collection events.
82 freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] user [ custnum custnum ... ]
86 Bills customers and runs invoice collection events. Should be run from
89 Bills customers. Searches for customers who are due for billing and calls
90 the bill and collect methods of a cust_main object. See L<FS::cust_main>.
92 -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with,
95 -y: In addition to -d, which specifies an absolute date, the -y switch
96 specifies an offset, in days. For example, "-y 15" would increment the
97 "pretend date" 15 days from whatever was specified by the -d switch
98 (or now, if no -d switch was given).
100 -n: When used with "-d" and/or "-y", specifies that invoices should be dated
101 with today's date, irregardless of the pretend date used to pre-generate
104 -p: Only process customers with the specified payby (I<CARD>, I<DCRD>, I<CHEK>, I<DCHK>, I<BILL>, I<COMP>, I<LECB>)
106 -a: Only process customers with the specified agentnum
108 -s: re-charge setup fees
114 -m: Experimental multi-process mode uses the job queue for multi-process and/or multi-machine billing.
116 -r: Multi-process mode dry run option
118 -k: skip notify_flat_delay and vacuum
122 custnum: if one or more customer numbers are specified, only bills those
123 customers. Otherwise, bills all customers.
129 L<FS::cust_main>, config.html from the base documentation