7 use FS::UID qw(adminsuidsetup swapuid);
8 use FS::Record qw(qsearch qsearchs);
11 &untaint_argv; #what it sounds like (eww)
12 use vars qw($opt_b $opt_c $opt_i $opt_d);
13 getopts("bcid:"); #switches
14 my $user = shift or die &usage;
18 #we're at now now (and later).
19 my($time)= $main::opt_d ? str2time($main::opt_d) : $^T;
21 # find packages w/ bill < time && cancel != '', and create corresponding
27 if ( ( $_->getfield('bill') || 0 ) <= $time &&
28 !$saw{ $_->getfield('custnum') }++ ) {
29 qsearchs('cust_main',{'custnum'=> $_->getfield('custnum') } );
33 } qsearch('cust_pkg',{'cancel'=>''})
38 print "Billing customer #" . $cust_main->getfield('custnum') . "\n";
42 $error=$cust_main->bill('time'=>$time);
43 warn "Error billing, customer #" . $cust_main->getfield('custnum') .
44 ":" . $error if $error;
47 $error=$cust_main->collect('invoice_time'=>$time,
48 'batch_card' => $main::opt_i ? 'no' : 'yes',
50 warn "Error collecting customer #" . $cust_main->getfield('custnum') .
51 ":" . $error if $error;
62 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
63 $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
69 die "Usage:\n\n bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n";
74 bill - Command line (crontab, script) interface to customer billing.
78 bill [ -c [ i ] ] [ -d 'date' ] user
82 Bills all customers. Searches for customers who are due for billing and calls
83 the bill and collect methods of a cust_main object. See L<FS::cust_main>.
85 -c: Turn on collecting (you probably want this).
87 -i: real-time billing (as opposed to batch billing). only relevant
90 -d: Pretent it's 'date'. Date is in any format Date::Parse is happy with,
93 user: From the mapsecrets file - see config.html from the base documentation
99 L<FS::cust_main>, config.html from the base documentation
103 ivan@voicenet.com sep/oct 96
105 separated billing and collections, cleaned up code.
106 ivan@voicenet.com 96-nov-11
109 ivan@voicenet.com 96-nov-13
111 added -v option and started to implement it, added 'd:' to getopts call
113 ivan@voicenet.com 97-jan-2
115 added more debug messages, moved some searches to fssearch.pl library (for
117 rewrote "all customer" finder to know about bill dates, for speed.
118 ivan@voicenet.com 97-jan-8
120 thought about it a while, and removed passing of the -d option to collect...?
121 ivan@voicenet.com 97-jan-14
123 make all -v stuff STDERR
124 ivan@voicenet.com 97-feb-4
126 added pkgnum as argument to program from /db/part_pkg, with kludge for the
127 "/bin/echo XX" 's already there.
128 ivan@voicenet.com 97-feb-23
131 - customers who are suspended can still be billed for the setup fee
132 - cust_pkg record is re-read after the package setup fee program is run.
134 that program can modify the record (for example, to start accounts off
136 (best to think four or five times before modifying anything else!)
137 ivan@voicenet.com 97-feb-26
139 don't bill recurring fee if its not time! (was removed)
140 ivan@voicenet.com 97-mar-6
142 added -b option, send batch when done billing.
143 ivan@voicenet.com 97-apr-4
145 insecure dependency on line 179ish below needs to be fixed before bill is
147 ivan@voicenet.com 97-jun-2
149 removed running of setup program (depriciated)
150 ivan@voicenet.com 97-jul-21
152 rewrote for new API, removed option to specify custnums (use FS::Bill
153 instead), removed -v option (?)
154 ivan@voicenet.com 97-jul-22 - 23 - 25 -28
155 (need to add back in email stuff, look in /home/ivan/old/dbin/collect)
157 s/suidsetup/adminsuidsetup/, s/FS::Search/FS::Record/, added some batch
158 exporting stuff (which still needs to be generalized) and removed &idiot
159 ivan@sisd.com 98-may-27
162 Revision 1.5 1998-11-15 02:51:21 ivan
163 adminsuidsetup needs user, pod, cleanup
165 Revision 1.4 1998/11/07 08:21:26 ivan