Reverted menu-left-example.png back to original and cleaned up menu-top-example to...
[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:m", \%opt);
11
12 my $user = shift or die &usage;
13 adminsuidsetup $user;
14
15 die "The -p option has been removed in version 4 -- customers no longer have ".
16     "a single, specific payment type"
17   if $opt{'p'};
18
19 use FS::Cron::bill qw(bill);
20 bill(%opt, 'check_freq'=>'1m' );
21
22 use FS::Cron::upload qw(upload);
23 upload(%opt);
24
25 ###
26 # subroutines
27 ###
28
29 sub untaint_argv {
30   foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
31     #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
32     # Date::Parse
33     $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
34     $ARGV[$_]=$1;
35   }
36 }
37
38 sub usage {
39   die "Usage:\n\n  freeside-monthly [ -d 'date' ] user [ custnum custnum ... ]\n";
40 }
41
42 ###
43 # documentation
44 ###
45
46 =head1 NAME
47
48 freeside-monthly - Run monthly billing and invoice collection events.
49
50 =head1 SYNOPSIS
51
52   freeside-monthly [ -d 'date' ] [ -y days ] [ -a agentnum ] [ -s ] [ -v ] user [ custnum custnum ... ]
53
54 =head1 DESCRIPTION
55
56 Bills customers and runs invoice collection events, for the alternate monthly
57 event chain.  If you have defined monthly event checks, should be run from
58 crontab monthly.
59
60 Bills customers.  Searches for customers who are due for billing and calls
61 the bill and collect methods of a cust_main object.  See L<FS::cust_main>.
62
63   -d: Pretend it's 'date'.  Date is in any format Date::Parse is happy with,
64       but be careful.
65
66   -y: In addition to -d, which specifies an absolute date, the -y switch
67       specifies an offset, in days.  For example, "-y 15" would increment the
68       "pretend date" 15 days from whatever was specified by the -d switch
69       (or now, if no -d switch was given).
70
71   -p: Deprecated, will produce a fatal error (formerly was: Only process customers with the specified payby (CARD, DCRD, CHEK, DCHK, BILL, COMP, LECB))
72
73   -a: Only process customers with the specified agentnum
74
75   -s: re-charge setup fees
76
77   -v: enable debugging
78
79   -m: Experimental multi-process mode (delay upload jobs until billing jobs complete)
80
81 user: Typically "fs_daily"
82
83 custnum: if one or more customer numbers are specified, only bills those
84 customers.  Otherwise, bills all customers.
85
86 =head1 NOTE
87
88 In most cases, you would use freeside-daily only and not freeside-monthly.
89 freeside-monthly would only be used in cases where you have events that can
90 only be run once each month, for example, batching invoices to a third-party
91 print/mail provider.
92
93 =head1 BUGS
94
95 =head1 SEE ALSO
96
97 L<freeside-daily>, L<FS::cust_main>, config.html from the base documentation
98
99 =cut
100