8 use FS::UID qw(adminsuidsetup);
9 use FS::Record qw(qsearch);
12 # Set the mail program
13 my $mail_program = "/usr/sbin/sendmail -t -n";
15 &untaint_argv; #what it sounds like (eww)
16 use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s);
17 getopts("vped:s:"); #switches
19 #we're at now now (and later).
20 my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T;
21 my($_startdate)= $main::opt_s ? str2time($main::opt_s) : $^T;
23 # Get the current month
24 my ($ssec,$smin,$shour,$smday,$smon,$syear) =
25 (localtime($_startdate) )[0,1,2,3,4,5];
29 # Get the current month
30 my ($esec,$emin,$ehour,$emday,$emon,$eyear) =
31 (localtime($_enddate) )[0,1,2,3,4,5];
35 # Login to the database
36 my $user = shift or die &usage;
39 # Get the needed configuration files
40 my $conf = new FS::Conf;
41 my $lpr = $conf->config('lpr');
42 my $email = $conf->config('email');
44 my(@cust_credits)=qsearch('cust_credit',{});
45 if (scalar(@cust_credits) == 0)
50 # Open print and email pipes
51 # $lpr and opt_p for printing
52 # $email and opt_e for email
54 if ($lpr && $main::opt_p)
57 print LPR qq~ I N H O U S E C R E D I T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~;
60 if ($email && $main::opt_e)
62 open (MAIL, "|$mail_program");
65 From: Account Processor
66 Subject: In House Credits
69 I N H O U S E C R E D I T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear
76 # Now I can start looping
77 foreach my $cust_credit (@cust_credits)
79 my $_date = $cust_credit->getfield('_date');
80 my $amount = $cust_credit->getfield('amount');
81 my $credited = $cust_credit->getfield('credited');
84 if ($_date >= $_startdate && $_date <= $_enddate) {
87 my ($sec,$min,$hour,$mday,$mon,$year) =
88 (localtime($_date) )[0,1,2,3,4,5];
96 printf(qq{\n\n%25s%14.2f\n}, "Credits Offered", $total);
97 printf(qq{\n%39s\n%39.2f\n}, "=========", $total);
100 # Now I need to close LPR and EMAIL if they were open
101 if($lpr && $main::opt_p)
103 printf(LPR qq{\n\n%25s%14.2f\n}, "Credits Offered", $total);
104 printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total);
105 close LPR || die "Could not close printer: $lpr\n";
107 if($email && $main::opt_e)
109 printf(MAIL qq{\n\n%25s%14.2f\n}, "Credits Offered", $total);
110 printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total);
111 close MAIL || die "Could not close printer: $email\n";
117 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
118 $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
124 die "Usage:\n\n freeside-credit-report [-v] [-p] [-e] user\n";
129 freeside-credit-report - Prints or emails in house credits offered in a given period.
133 freeside-credit-report [-v] [-p] [-e] user
137 Prints or emails in house credits offered in a given period.
139 -v: Verbose - Prints records to STDOUT.
141 -p: Print to printer lpr as found in the conf directory.
143 -e: Email output to user found in the Conf email file.
145 user: From the mapsecrets file - see config.html from the base documentation
149 $Id: freeside-credit-report,v 1.1 2002-02-22 23:18:32 jeff Exp $
153 Yes..... Use at your own risk. No guarantees or warrantees of any
154 kind apply to this program. Parts of this program are hacked from
155 other GNU licensed software created mainly by Ivan Kohler.
157 This is released under the GNU Public License. See www.gnu.org
158 for more information regarding this license.
162 L<FS::cust_main>, config.html from the base documentation
166 griff@aver-computer.com July 99
168 $Log: freeside-credit-report,v $
169 Revision 1.1 2002-02-22 23:18:32 jeff
170 add some reporting features
172 Revision 1.1 2002/02/19 14:24:53 jeff
173 might be functional now
175 Revision 1.1 2000/09/20 19:25:19 jeff
178 Revision 1.1 2000/05/13 21:57:56 ivan
179 add print_batch script from Joel Griffiths