fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / bin / freeside-monthly
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Std;
5 use FS::UID qw(adminsuidsetup);
6
7 &untaint_argv;  #what it sounds like  (eww)
8 #use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y);
9 use vars qw(%opt);
10 getopts("p:a:d:vsy:", \%opt);
11
12 my $user = shift or die &usage;
13 adminsuidsetup $user;
14
15 use FS::Cron::bill qw(bill);
16 bill(%opt, 'check_freq'=>'1m' );
17
18 use FS::Cron::upload qw(upload);
19 upload(%opt);
20
21 ###
22 # subroutines
23 ###
24
25 sub untaint_argv {
26   foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
27     #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
28     # Date::Parse
29     $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
30     $ARGV[$_]=$1;
31   }
32 }
33
34 sub usage {
35   die "Usage:\n\n  freeside-monthly [ -d 'date' ] user [ custnum custnum ... ]\n";
36 }
37
38 ###
39 # documentation
40 ###
41
42 =head1 NAME
43
44 freeside-monthly - Run monthly billing and invoice collection events.
45
46 =head1 SYNOPSIS
47
48   freeside-monthly [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] user [ custnum custnum ... ]
49
50 =head1 DESCRIPTION
51
52 Bills customers and runs invoice collection events, for the alternate monthly
53 event chain.  If you have defined monthly event checks, should be run from
54 crontab monthly.
55
56 Bills customers.  Searches for customers who are due for billing and calls
57 the bill and collect methods of a cust_main object.  See L<FS::cust_main>.
58
59   -d: Pretend it's 'date'.  Date is in any format Date::Parse is happy with,
60       but be careful.
61
62   -y: In addition to -d, which specifies an absolute date, the -y switch
63       specifies an offset, in days.  For example, "-y 15" would increment the
64       "pretend date" 15 days from whatever was specified by the -d switch
65       (or now, if no -d switch was given).
66
67   -p: Only process customers with the specified payby (CARD, DCRD, CHEK, DCHK, BILL, COMP, LECB)
68
69   -a: Only process customers with the specified agentnum
70
71   -s: re-charge setup fees
72
73   -v: enable debugging
74
75 user: From the mapsecrets file - see config.html from the base documentation
76
77 custnum: if one or more customer numbers are specified, only bills those
78 customers.  Otherwise, bills all customers.
79
80 =head1 NOTE
81
82 In most cases, you would use freeside-daily only and not freeside-monthly.
83 freeside-monthly would only be used in cases where you have events that can
84 only be run once each month, for example, batching invoices to a third-party
85 print/mail provider.
86
87 =head1 BUGS
88
89 =head1 SEE ALSO
90
91 L<freeside-daily>, L<FS::cust_main>, config.html from the base documentation
92
93 =cut
94