d5748d6b9e42aa6c371d4cf5cb6ae972ac86e012
[freeside.git] / FS / bin / freeside-daily
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);
9 getopts("p:a:d:vsy:n", \%opt);
10
11 my $user = shift or die &usage;
12 adminsuidsetup $user;
13
14 use FS::Cron::bill qw(bill);
15 bill(%opt);
16
17 use FS::Cron::notify qw(notify_flat_delay);
18 notify_flat_delay(%opt);
19
20 use FS::Cron::vacuum qw(vacuum);
21 vacuum();
22
23 use FS::Cron::backup qw(backup_scp);
24 backup_scp();
25
26 ###
27 # subroutines
28 ###
29
30 sub untaint_argv {
31   foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
32     #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
33     # Date::Parse
34     $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
35     $ARGV[$_]=$1;
36   }
37 }
38
39 sub usage {
40   die "Usage:\n\n  freeside-daily [ -d 'date' ] user [ custnum custnum ... ]\n";
41 }
42
43 ###
44 # documentation
45 ###
46
47 =head1 NAME
48
49 freeside-daily - Run daily billing and invoice collection events.
50
51 =head1 SYNOPSIS
52
53   freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] user [ custnum custnum ... ]
54
55 =head1 DESCRIPTION
56
57 Bills customers and runs invoice collection events.  Should be run from
58 crontab daily.
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   -n: When used with "-d" and/or "-y", specifies that invoices should be dated
72       with today's date, irregardless of the pretend date used to pre-generate
73       the invoices.
74
75   -p: Only process customers with the specified payby (I<CARD>, I<DCRD>, I<CHEK>, I<DCHK>, I<BILL>, I<COMP>, I<LECB>)
76
77   -a: Only process customers with the specified agentnum
78
79   -s: re-charge setup fees
80
81   -v: enable debugging
82
83 user: From the mapsecrets file - see config.html from the base documentation
84
85 custnum: if one or more customer numbers are specified, only bills those
86 customers.  Otherwise, bills all customers.
87
88 =head1 BUGS
89
90 =head1 SEE ALSO
91
92 L<FS::cust_main>, config.html from the base documentation
93
94 =cut
95