8 use FS::UID qw(adminsuidsetup);
9 use FS::Record qw(qsearch qsearchs);
11 use FS::cust_pay_batch;
13 # Set the mail program
14 my $mail_program = "/usr/sbin/sendmail -t -n";
16 &untaint_argv; #what it sounds like (eww)
17 use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s);
18 getopts("vped:s:"); #switches
20 #we're at now now (and later).
21 my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T;
22 my($_startdate)= $main::opt_d ? str2time($main::opt_s) : $^T;
24 # Get the current month
25 my ($ssec,$smin,$shour,$smday,$smon,$syear) =
26 (localtime($_startdate) )[0,1,2,3,4,5];
30 # Get the current month
31 my ($esec,$emin,$ehour,$emday,$emon,$eyear) =
32 (localtime($_enddate) )[0,1,2,3,4,5];
36 # Login to the database
37 my $user = shift or die &usage;
40 # Get the needed configuration files
41 my $conf = new FS::Conf;
42 my $lpr = $conf->config('lpr');
43 my $email = $conf->config('email');
45 my(@cust_pays)=qsearch('cust_pay',{});
46 if (scalar(@cust_pays) == 0)
51 # Open print and email pipes
52 # $lpr and opt_p for printing
53 # $email and opt_e for email
55 if ($lpr && $main::opt_p)
58 print LPR qq~ C R E D I T C A R D R E C E I P T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~;
61 if ($email && $main::opt_e)
63 open (MAIL, "|$mail_program");
66 From: Account Processor
70 C R E D I T C A R D R E C E I P T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear
81 # Now I can start looping
82 foreach my $cust_pay (@cust_pays)
84 my $_date = $cust_pay->getfield('_date');
85 my $invnum = $cust_pay->getfield('invnum');
86 my $paid = $cust_pay->getfield('paid');
87 my $payby = $cust_pay->getfield('payby');
90 if ($_date >= $_startdate && $_date <= $_enddate && $payby =~ 'CARD') {
93 $uninvoiced += $cust_pay->unapplied;
94 my @cust_bill_pays = $cust_pay->cust_bill_pay;
95 foreach my $cust_bill_pay (@cust_bill_pays) {
98 my(@cust_bill_pkgs)= $cust_bill_pay->cust_bill->cust_bill_pkg;
99 foreach my $cust_bill_pkg (@cust_bill_pkgs) {
101 my $recur = $cust_bill_pkg->getfield('recur');
102 my $setup = $cust_bill_pkg->getfield('setup');
103 my $pkgnum = $cust_bill_pkg->getfield('pkgnum');
106 $invoice_tax += $recur;
107 $invoice_tax += $setup;
109 $invoice_amt += $recur;
110 $invoice_amt += $setup;
115 if ($invoice_tax > 0) {
116 if ($invoice_amt != $paid) {
117 # attempt to prorate partially paid invoices
118 $total_tax += $paid / ($invoice_amt + $invoice_tax) * $invoice_tax;
119 $taxed += $paid / ($invoice_amt + $invoice_tax) * $invoice_amt;
121 $total_tax += $invoice_tax;
122 $taxed += $invoice_amt;
135 printf(qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced);
136 printf(qq{%25s%14.2f\n}, "Untaxed", $untaxed);
137 printf(qq{%25s%14.2f\n}, "Taxed", $taxed);
138 printf(qq{%25s%14.2f\n}, "Tax", $total_tax);
139 printf(qq{\n%39s\n%39.2f\n}, "=========", $total);
142 # Now I need to close LPR and EMAIL if they were open
143 if($lpr && $main::opt_p)
145 printf(LPR qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced);
146 printf(LPR qq{%25s%14.2f\n}, "Untaxed", $untaxed);
147 printf(LPR qq{%25s%14.2f\n}, "Taxed", $taxed);
148 printf(LPR qq{%25s%14.2f\n}, "Tax", $total_tax);
149 printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total);
150 close LPR || die "Could not close printer: $lpr\n";
152 if($email && $main::opt_e)
154 printf(MAIL qq{\n%25s%14.2f\n}, "Untaxed", $untaxed);
155 printf(MAIL qq{%25s%14.2f\n}, "Taxed", $taxed);
156 printf(MAIL qq{%25s%14.2f\n}, "Tax", $total_tax);
157 printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total);
158 close MAIL || die "Could not close printer: $email\n";
164 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
165 $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
171 die "Usage:\n\n freeside-tax-report [-v] [-p] [-e] user\n";
176 freeside-tax-report - Prints or emails sales taxes invoiced in a given period.
180 freeside-tax-report [-v] [-p] [-e] user
184 Prints or emails sales taxes invoiced in a given period.
186 -v: Verbose - Prints records to STDOUT.
188 -p: Print to printer lpr as found in the conf directory.
190 -e: Email output to user found in the Conf email file.
192 user: From the mapsecrets file - see config.html from the base documentation
196 $Id: freeside-cc-receipts-report,v 1.1 2002-02-22 23:18:32 jeff Exp $
200 Yes..... Use at your own risk. No guarantees or warrantees of any
201 kind apply to this program. Parts of this program are hacked from
202 other GNU licensed software created mainly by Ivan Kohler.
204 This is released under the GNU Public License. See www.gnu.org
205 for more information regarding this license.
209 L<FS::cust_main>, config.html from the base documentation
213 griff@aver-computer.com July 99
215 $Log: freeside-cc-receipts-report,v $
216 Revision 1.1 2002-02-22 23:18:32 jeff
217 add some reporting features
219 Revision 1.2 2002/02/19 14:24:53 jeff
220 might be functional now
222 Revision 1.1 2000/09/20 19:25:19 jeff
225 Revision 1.1 2000/05/13 21:57:56 ivan
226 add print_batch script from Joel Griffiths