a6c75e715499e974ee38d80299f8e2243400ce7a
[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, 'freq'=>'1m' );
17
18 ###
19 # subroutines
20 ###
21
22 sub untaint_argv {
23   foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
24     #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
25     # Date::Parse
26     $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
27     $ARGV[$_]=$1;
28   }
29 }
30
31 sub usage {
32   die "Usage:\n\n  freeside-monthly [ -d 'date' ] user [ custnum custnum ... ]\n";
33 }
34
35 ###
36 # documentation
37 ###
38
39 =head1 NAME
40
41 freeside-monthly - Run monthly billing and invoice collection events.
42
43 =head1 SYNOPSIS
44
45   freeside-monthly [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] user [ custnum custnum ... ]
46
47 =head1 DESCRIPTION
48
49 Bills customers and runs invoice collection events, for the alternate monthly
50 event chain.  If you have defined monthly event checks, should be run from
51 crontab monthly.
52
53 Bills customers.  Searches for customers who are due for billing and calls
54 the bill and collect methods of a cust_main object.  See L<FS::cust_main>.
55
56   -d: Pretend it's 'date'.  Date is in any format Date::Parse is happy with,
57       but be careful.
58
59   -y: In addition to -d, which specifies an absolute date, the -y switch
60       specifies an offset, in days.  For example, "-y 15" would increment the
61       "pretend date" 15 days from whatever was specified by the -d switch
62       (or now, if no -d switch was given).
63
64   -p: Only process customers with the specified payby (I<CARD>, I<DCRD>, I<CHEK>, I<DCHK>, I<BILL>, I<COMP>, I<LECB>)
65
66   -a: Only process customers with the specified agentnum
67
68   -s: re-charge setup fees
69
70   -v: enable debugging
71
72 user: From the mapsecrets file - see config.html from the base documentation
73
74 custnum: if one or more customer numbers are specified, only bills those
75 customers.  Otherwise, bills all customers.
76
77 =head1 NOTE
78
79 In most cases, you would use freeside-daily only and not freeside-monthly.
80 freeside-monthly would only be used in cases where you have events that can
81 only be run once each month, for example, batching invoices to a third-party
82 print/mail provider.
83
84 =head1 BUGS
85
86 =head1 SEE ALSO
87
88 L<freeside-daily>, L<FS::cust_main>, config.html from the base documentation
89
90 =cut
91