8 use FS::UID qw(adminsuidsetup);
9 use FS::Record qw(qsearch);
11 use FS::cust_pay_batch;
13 # Get the currennt time and date
15 my ($sec,$min,$hour,$mday,$mon,$year) =
16 (localtime($time) )[0,1,2,3,4,5];
18 timelocal($sec,$min,$hour,$mday,$mon,$year);
20 # Set the mail program
21 my $mail_program = "/usr/sbin/sendmail -t -n";
23 &untaint_argv; #what it sounds like (eww)
24 use vars qw($opt_v $opt_p $opt_e $opt_a $opt_d);
25 getopts("vpead"); #switches
27 # Login to the database
28 my $user = shift or die &usage;
31 # Get the needed configuration files
32 my $conf = new FS::Conf;
33 my $lpr = $conf->config('lpr');
34 my $email = $conf->config('email');
36 my(@batch)=qsearch('cust_pay_batch',{});
37 if (scalar(@batch) == 0)
42 # Open print and email pipes
43 # $lpr and opt_p for printing
44 # $email and opt_e for email
46 if ($lpr && $main::opt_p)
49 print LPR qq~C R E D I T C A R D P A Y M E N T S D U E $mon/$mday/$year\n\n~;
52 if ($email && $main::opt_e)
54 open (MAIL, "|$mail_program");
57 From: Account Processor
58 Subject: CREDIT CARD PAYMENTS DUE
61 C R E D I T C A R D P A Y M E N T S D U E $mon/$mday/$year
65 # Now I can start looping
66 foreach my $cust_pay_batch (@batch)
68 my $state = $cust_pay_batch->getfield('state');
69 my $zip = $cust_pay_batch->getfield('zip');
70 my $amount = $cust_pay_batch->getfield('amount');
71 my $last = $cust_pay_batch->getfield('last');
72 my $address1 = $cust_pay_batch->getfield('address1');
73 my $address2 = $cust_pay_batch->getfield('address2');
74 my $first = $cust_pay_batch->getfield('first');
75 my $city = $cust_pay_batch->getfield('city');
76 my $cardnum = $cust_pay_batch->getfield('cardnum');
77 my $payname = $cust_pay_batch->getfield('payname');
78 my $exp = $cust_pay_batch->getfield('exp');
79 my $invnum = $cust_pay_batch->getfield('invnum');
80 my $custnum = $cust_pay_batch->getfield('custnum');
82 # Need a carriage return in address before address2
83 # if it exists. Otherwise address will just be address1
84 my $address = $address1;
85 $address .= "\n$address2" if ($address2);
87 # Only print to the screen in verbose mode
90 printf("Invoice %d for %s %s\tCustomer Number: %d\n",
96 printf("\t%s\n", $address);
97 printf("\t%s, %s, %s\n\n",
102 printf("\tCard Number: %s\tExp:%s\n",
105 printf("\t\tName: %s\n", $payname);
106 printf("\t\tAmount: %.2f\n\n\n", $amount);
109 if ($lpr && $main::opt_p)
111 printf(LPR "Invoice %d for %s %s\tCustomer Number: %d\n",
117 printf(LPR "\t%s\n", $address);
118 printf(LPR "\t%s, %s, %s\n\n",
123 printf(LPR "\tCard Number: %s\tExp:%s\n",
126 printf(LPR "\t\tName: %s\n", $payname);
127 printf(LPR "\t\tAmount: %.2f\n\n\n", $amount);
130 if ($email && $main::opt_e)
132 printf(MAIL "Invoice %d for %s %s\tCustomer Number: %d\n",
138 printf(MAIL "\t%s\n", $address);
139 printf(MAIL "\t%s, %s, %s\n\n",
144 printf(MAIL "\tCard Number: %s\tExp:%s\n",
147 printf(MAIL "\t\tName: %s\n", $payname);
148 printf(MAIL "\t\tAmount: %.2f\n\n\n", $amount);
151 # Now I want to delete the records from cust_pay_batch
152 # and mark the records in cust_pay as paid today if
153 # the delete (-d) command line option is set.
156 my $payment=new FS::cust_pay {
161 'payinfo' => $cardnum,
162 'paybatch' => "AUTO",
165 my $pay_error=$payment->insert;
168 # warn might be better if you get root's mail
169 # NEED TO TEST THIS BEFORE DELETE IF WARN IS USED
170 die "Could not update cust_pay for invnum $invnum. $pay_error\n";
174 # This just deletes the records
175 # Must be last in the foreach loop
178 my $del_error = $cust_pay_batch->delete;
181 die "Could not delete cust_pay_batch for invnum $invnum. $del_error\n";
187 # Now I need to close LPR and EMAIL if they were open
188 if($lpr && $main::opt_p)
190 close LPR || die "Could not close printer: $lpr\n";
193 if($email && $main::opt_e)
195 close MAIL || die "Could not close printer: $lpr\n";
201 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
202 $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
208 die "Usage:\n\n freeside-print-batch [-v] [-p] [-e] [-a] [-d] user\n";
213 freeside-print-batch - Prints or emails cust_pay_batch. Also deletes
214 old records and adds payment to cust_pay.
215 Usually run after the bill command.
219 freeside-print-batch [-v] [-p] [-e] [-a] [-d] user
223 Prints or emails cust_pay_batch. Can enter payment and delete
224 printed records. Usually run as a cron job.
226 B<-v>: Verbose - Prints records to STDOUT.
228 B<-p>: Print to printer lpr as found in the conf directory.
230 B<-e>: Email output to user found in the Conf email file.
232 B<-a>: Automatically pays all records in cust_pay_batch. Use -d with this option usually.
234 B<-d>: Delete - Pays account and deletes record from cust_pay_batch.
236 user: From the mapsecrets file - see config.html from the base documentation
240 $Id: freeside-print-batch,v 1.3 2001-08-21 02:44:47 ivan Exp $
244 Yes..... Use at your own risk. No guarantees or warrantees of any
245 kind apply to this program. Parts of this program are hacked from
246 other GNU licensed software created mainly by Ivan Kohler.
248 This is released under the GNU Public License. See www.gnu.org
249 for more information regarding this license.
253 L<FS::cust_main>, config.html from the base documentation
257 Joel Griffiths <griff@aver-computer.com> July 99