consistency is nice
authorjeff <jeff>
Tue, 5 Mar 2002 23:13:24 +0000 (23:13 +0000)
committerjeff <jeff>
Tue, 5 Mar 2002 23:13:24 +0000 (23:13 +0000)
FS/bin/freeside-cc-receipts-report
FS/bin/freeside-credit-report
FS/bin/freeside-receivables-report
FS/bin/freeside-tax-report
httemplate/search/report_cc.cgi
httemplate/search/report_credit.cgi
httemplate/search/report_tax.cgi

index 2713af3..5ea8cc5 100755 (executable)
@@ -1,9 +1,11 @@
 #!/usr/bin/perl -Tw
 
+
 use strict;
 use Date::Parse;
 use Time::Local;
 use Getopt::Std;
+use Text::Template;
 use FS::Conf;
 use FS::UID qw(adminsuidsetup);
 use FS::Record qw(qsearch qsearchs);
@@ -14,24 +16,24 @@ use FS::cust_pay_batch;
 my $mail_program = "/usr/sbin/sendmail -t -n"; 
 
 &untaint_argv; #what it sounds like  (eww)
-use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s);
-getopts("vped:s:");    #switches
+use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf);
+getopts("vpmef:s:");   #switches
 
 #we're at now now (and later).
-my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T;
-my($_startdate)= $main::opt_d ? str2time($main::opt_s) : $^T;
+my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T;
+my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T;
 
 # Get the current month
 my ($ssec,$smin,$shour,$smday,$smon,$syear) =
        (localtime($_startdate) )[0,1,2,3,4,5]; 
-$syear+=1900;
 $smon++;
+$syear += 1900;
 
 # Get the current month
-my ($esec,$emin,$ehour,$emday,$emon,$eyear) =
-       (localtime($_enddate) )[0,1,2,3,4,5]; 
-$eyear+=1900;
-$emon++;
+my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) =
+       (localtime($_finishdate) )[0,1,2,3,4,5]; 
+$fmon++;
+$fyear += 1900;
 
 # Login to the database
 my $user = shift or die &usage;
@@ -41,6 +43,19 @@ adminsuidsetup $user;
 my $conf = new FS::Conf;
 my $lpr = $conf->config('lpr');
 my $email = $conf->config('email');
+my @report_template = $conf->config('report_template')
+  or die "cannot load config file report_template";
+$report_lines = 0;
+foreach ( grep /report_lines\(\d+\)/, @report_template ) { #kludgy :/
+  /report_lines\((\d+)\)/;
+  $report_lines += $1;
+}
+die "no report_lines() functions in template?" unless $report_lines;
+$report_template = new Text::Template (
+  TYPE   => 'ARRAY',
+  SOURCE => [ map "$_\n", @report_template ],
+) or die "can't create new Text::Template object: $Text::Template::ERROR";
+
 
 my(@cust_pays)=qsearch('cust_pay',{});
 if (scalar(@cust_pays) == 0)
@@ -50,15 +65,14 @@ if (scalar(@cust_pays) == 0)
 
 # Open print and email pipes
 # $lpr and opt_p for printing
-# $email and opt_e for email
+# $email and opt_m for email
 
 if ($lpr && $main::opt_p)
 {
         open(LPR, "|$lpr");
-        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~;
 }
 
-if ($email && $main::opt_e)
+if ($email && $main::opt_m)
 {
        open (MAIL, "|$mail_program");
        print MAIL <<END
@@ -67,8 +81,6 @@ From: Account Processor
 Subject: Receivables
 
 
-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
-
 END
 }
 
@@ -87,7 +99,7 @@ foreach my $cust_pay (@cust_pays)
        my $payby = $cust_pay->getfield('payby');
        
 
-       if ($_date >= $_startdate && $_date <= $_enddate && $payby =~ 'CARD') {
+       if ($_date >= $_startdate && $_date <= $_finishdate && $payby =~ 'CARD') {
                $total += $paid;
 
                $uninvoiced += $cust_pay->unapplied; 
@@ -131,31 +143,54 @@ foreach my $cust_pay (@cust_pays)
 
 }
 
-if ($main::opt_v) {
-       printf(qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced);
-       printf(qq{%25s%14.2f\n}, "Untaxed", $untaxed);
-       printf(qq{%25s%14.2f\n}, "Taxed", $taxed);
-       printf(qq{%25s%14.2f\n}, "Tax", $total_tax);
-       printf(qq{\n%39s\n%39.2f\n}, "=========", $total);
+push @buf, sprintf(qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced);
+push @buf, sprintf(qq{%25s%14.2f\n}, "Untaxed", $untaxed);
+push @buf, sprintf(qq{%25s%14.2f\n}, "Taxed", $taxed);
+push @buf, sprintf(qq{%25s%14.2f\n}, "Tax", $total_tax);
+push @buf, sprintf(qq{\n%39s\n%39.2f\n}, "=========", $total);
+
+sub FS::cc_receipts_report::_template::report_lines {
+  my $lines = shift;
+  map {
+    scalar(@buf) ? shift @buf : '' ;
+  }
+  ( 1 .. $lines );
 }
 
-# Now I need to close LPR and EMAIL if they were open
-if($lpr && $main::opt_p)
+$FS::cc_receipts_report::_template::title = qq~CREDIT CARD RECEIPTS for period $smon/$smday/$syear through $fmon/$fmday/$fyear~;
+$FS::cc_receipts_report::_template::title = $opt_t if $opt_t;
+$FS::cc_receipts_report::_template::page = 1;
+$FS::cc_receipts_report::_template::date = $^T;
+$FS::cc_receipts_report::_template::date = $^T;
+$FS::cc_receipts_report::_template::fdate = $_finishdate;
+$FS::cc_receipts_report::_template::fdate = $_finishdate;
+$FS::cc_receipts_report::_template::sdate = $_startdate;
+$FS::cc_receipts_report::_template::sdate = $_startdate;
+$FS::cc_receipts_report::_template::total_pages = 
+  int( scalar(@buf) / $report_lines);
+$FS::cc_receipts_report::_template::total_pages++ if scalar(@buf) % $report_lines;
+
+my @report;
+while (@buf) {
+  push @report, split("\n", 
+    $report_template->fill_in( PACKAGE => 'FS::cc_receipts_report::_template' )
+  );
+  $FS::cc_receipts_report::_template::page++;
+}
+
+if ($opt_v) {
+  print map "$_\n", @report;
+}
+if($lpr && $opt_p)
 {
-       printf(LPR qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced);
-       printf(LPR qq{%25s%14.2f\n}, "Untaxed", $untaxed);
-       printf(LPR qq{%25s%14.2f\n}, "Taxed", $taxed);
-       printf(LPR qq{%25s%14.2f\n}, "Tax", $total_tax);
-       printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total);
-       close LPR || die "Could not close printer: $lpr\n";
+  print LPR map "$_\n", @report;
+  print LPR "\f" if $opt_e;
+  close LPR || die "Could not close printer: $lpr\n";
 }
-if($email && $main::opt_e)
+if($email && $opt_m)
 {
-       printf(MAIL qq{\n%25s%14.2f\n}, "Untaxed", $untaxed);
-       printf(MAIL qq{%25s%14.2f\n}, "Taxed", $taxed);
-       printf(MAIL qq{%25s%14.2f\n}, "Tax", $total_tax);
-       printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total);
-       close MAIL || die "Could not close printer: $email\n";
+  print MAIL map "$_\n", @report;
+  close MAIL || die "Could not close printer: $email\n";
 }
 
 
@@ -168,16 +203,16 @@ sub untaint_argv {
 }
 
 sub usage {
-  die "Usage:\n\n  freeside-tax-report [-v] [-p] [-e] user\n";
+  die "Usage:\n\n  freeside-cc-receipts-report [-v] [-p] [-e] user\n";
 }
 
 =head1 NAME
 
-freeside-tax-report - Prints or emails sales taxes invoiced in a given period.
+freeside-cc-receipts-report - Prints or emails total credit card receipts in a given period.
 
 =head1 SYNOPSIS
 
-  freeside-tax-report [-v] [-p] [-e] user
+  freeside-cc-receipts-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user
 
 =head1 DESCRIPTION
 
@@ -187,13 +222,21 @@ Prints or emails sales taxes invoiced in a given period.
 
 -p: Print to printer lpr as found in the conf directory.
 
--e: Email output to user found in the Conf email file.
+-m: Email output to user found in the Conf email file.
+
+-e: Print a final form feed to the printer.
+
+-t: supply a title for the top of each page.
+
+-s: starting date for inclusion
+
+-f: final date for inclusion
 
 user: From the mapsecrets file - see config.html from the base documentation
 
 =head1 VERSION
 
-$Id: freeside-cc-receipts-report,v 1.1 2002-02-22 23:18:32 jeff Exp $
+$Id: freeside-cc-receipts-report,v 1.2 2002-03-05 23:13:23 jeff Exp $
 
 =head1 BUGS
 
@@ -213,8 +256,8 @@ L<FS::cust_main>, config.html from the base documentation
 griff@aver-computer.com July 99
 
 $Log: freeside-cc-receipts-report,v $
-Revision 1.1  2002-02-22 23:18:32  jeff
-add some reporting features
+Revision 1.2  2002-03-05 23:13:23  jeff
+consistency is nice
 
 Revision 1.2  2002/02/19 14:24:53  jeff
 might be functional now
index 4307a21..92931bc 100755 (executable)
@@ -1,9 +1,11 @@
 #!/usr/bin/perl -Tw
 
+
 use strict;
 use Date::Parse;
 use Time::Local;
 use Getopt::Std;
+use Text::Template;
 use FS::Conf;
 use FS::UID qw(adminsuidsetup);
 use FS::Record qw(qsearch);
@@ -13,24 +15,24 @@ use FS::cust_credit;
 my $mail_program = "/usr/sbin/sendmail -t -n"; 
 
 &untaint_argv; #what it sounds like  (eww)
-use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s);
-getopts("vped:s:");    #switches
+use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf);
+getopts("vpmef:s:");   #switches
 
 #we're at now now (and later).
-my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T;
-my($_startdate)= $main::opt_s ? str2time($main::opt_s) : $^T;
+my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T;
+my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T;
 
 # Get the current month
 my ($ssec,$smin,$shour,$smday,$smon,$syear) =
        (localtime($_startdate) )[0,1,2,3,4,5]; 
-$syear+=1900;
 $smon++;
+$syear += 1900;
 
 # Get the current month
-my ($esec,$emin,$ehour,$emday,$emon,$eyear) =
-       (localtime($_enddate) )[0,1,2,3,4,5]; 
-$eyear+=1900;
-$emon++;
+my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) =
+       (localtime($_finishdate) )[0,1,2,3,4,5]; 
+$fmon++;
+$fyear += 1900;
 
 # Login to the database
 my $user = shift or die &usage;
@@ -40,6 +42,19 @@ adminsuidsetup $user;
 my $conf = new FS::Conf;
 my $lpr = $conf->config('lpr');
 my $email = $conf->config('email');
+my @report_template = $conf->config('report_template')
+  or die "cannot load config file report_template";
+$report_lines = 0;
+foreach ( grep /report_lines\(\d+\)/, @report_template ) { #kludgy :/
+  /report_lines\((\d+)\)/;
+  $report_lines += $1;
+}
+die "no report_lines() functions in template?" unless $report_lines;
+$report_template = new Text::Template (
+  TYPE   => 'ARRAY',
+  SOURCE => [ map "$_\n", @report_template ],
+) or die "can't create new Text::Template object: $Text::Template::ERROR";
+
 
 my(@cust_credits)=qsearch('cust_credit',{});
 if (scalar(@cust_credits) == 0)
@@ -49,15 +64,14 @@ if (scalar(@cust_credits) == 0)
 
 # Open print and email pipes
 # $lpr and opt_p for printing
-# $email and opt_e for email
+# $email and opt_m for email
 
 if ($lpr && $main::opt_p)
 {
         open(LPR, "|$lpr");
-        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~;
 }
 
-if ($email && $main::opt_e)
+if ($email && $main::opt_m)
 {
        open (MAIL, "|$mail_program");
        print MAIL <<END
@@ -66,49 +80,71 @@ From: Account Processor
 Subject: In House Credits
 
 
-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
-
 END
 }
 
+my $uninvoiced = 0;
 my $total = 0;
+my $taxed = 0;
+my $untaxed = 0;
+my $total_tax = 0;
 
 # Now I can start looping
 foreach my $cust_credit (@cust_credits)
 {
        my $_date = $cust_credit->getfield('_date');
        my $amount = $cust_credit->getfield('amount');
-       my $credited = $cust_credit->getfield('credited');
-       
 
-       if ($_date >= $_startdate && $_date <= $_enddate) {
+       if ($_date >= $_startdate && $_date <= $_finishdate) {
                $total += $amount;
-
-               my ($sec,$min,$hour,$mday,$mon,$year) =
-                       (localtime($_date) )[0,1,2,3,4,5]; 
-               $mon++;
-
        }
+}
 
+push @buf, sprintf(qq{\n%25s%14.2f\n}, "Credits Offered", $total);
+push @buf, sprintf(qq{\n%39s\n%39.2f\n}, "=========", $total);
+
+sub FS::credit_report::_template::report_lines {
+  my $lines = shift;
+  map {
+    scalar(@buf) ? shift @buf : '' ;
+  }
+  ( 1 .. $lines );
 }
 
-if ($main::opt_v) {
-       printf(qq{\n\n%25s%14.2f\n}, "Credits Offered", $total);
-       printf(qq{\n%39s\n%39.2f\n}, "=========", $total);
+$FS::credit_report::_template::title = qq~IN HOUSE CREDITS for $smon/$smday/$syear through $fmon/$fmday/$fyear~;
+$FS::credit_report::_template::title = $opt_t if $opt_t;
+$FS::credit_report::_template::page = 1;
+$FS::credit_report::_template::date = $^T;
+$FS::credit_report::_template::date = $^T;
+$FS::credit_report::_template::fdate = $_finishdate;
+$FS::credit_report::_template::fdate = $_finishdate;
+$FS::credit_report::_template::sdate = $_startdate;
+$FS::credit_report::_template::sdate = $_startdate;
+$FS::credit_report::_template::total_pages = 
+  int( scalar(@buf) / $report_lines);
+$FS::credit_report::_template::total_pages++ if scalar(@buf) % $report_lines;
+
+my @report;
+while (@buf) {
+  push @report, split("\n", 
+    $report_template->fill_in( PACKAGE => 'FS::credit_report::_template' )
+  );
+  $FS::credit_report::_template::page++;
 }
 
-# Now I need to close LPR and EMAIL if they were open
-if($lpr && $main::opt_p)
+if ($opt_v) {
+  print map "$_\n", @report;
+}
+if($lpr && $opt_p)
 {
-       printf(LPR qq{\n\n%25s%14.2f\n}, "Credits Offered", $total);
-       printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total);
-       close LPR || die "Could not close printer: $lpr\n";
+  print LPR map "$_\n", @report;
+  print LPR "\f" if $opt_e;
+  close LPR || die "Could not close printer: $lpr\n";
 }
-if($email && $main::opt_e)
+if($email && $opt_m)
 {
-       printf(MAIL qq{\n\n%25s%14.2f\n}, "Credits Offered", $total);
-       printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total);
-       close MAIL || die "Could not close printer: $email\n";
+  print MAIL map "$_\n", @report;
+  close MAIL || die "Could not close printer: $email\n";
 }
 
 
@@ -126,27 +162,35 @@ sub usage {
 
 =head1 NAME
 
-freeside-credit-report - Prints or emails in house credits offered in a given period.
+freeside-credit-report - Prints or emails total credit memos in a given period.
 
 =head1 SYNOPSIS
 
-  freeside-credit-report [-v] [-p] [-e] user
+  freeside-credit-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user
 
 =head1 DESCRIPTION
 
-Prints or emails in house credits offered in a given period.
+Prints or emails total credit memos in a given period.
 
 -v: Verbose - Prints records to STDOUT.
 
 -p: Print to printer lpr as found in the conf directory.
 
--e: Email output to user found in the Conf email file.
+-m: Email output to user found in the Conf email file.
+
+-e: Print a final form feed to the printer.
+
+-t: supply a title for the top of each page.
+
+-s: starting date for inclusion
+
+-f: final date for inclusion
 
 user: From the mapsecrets file - see config.html from the base documentation
 
 =head1 VERSION
 
-$Id: freeside-credit-report,v 1.1 2002-02-22 23:18:32 jeff Exp $
+$Id: freeside-credit-report,v 1.2 2002-03-05 23:13:23 jeff Exp $
 
 =head1 BUGS
 
@@ -166,17 +210,8 @@ L<FS::cust_main>, config.html from the base documentation
 griff@aver-computer.com July 99
 
 $Log: freeside-credit-report,v $
-Revision 1.1  2002-02-22 23:18:32  jeff
-add some reporting features
-
-Revision 1.1  2002/02/19 14:24:53  jeff
-might be functional now
-
-Revision 1.1  2000/09/20 19:25:19  jeff
-local modifications
-
-Revision 1.1  2000/05/13 21:57:56  ivan
-add print_batch script from Joel Griffiths
+Revision 1.2  2002-03-05 23:13:23  jeff
+consistency is nice
 
 
 =cut
index c4d188c..6d04ba9 100755 (executable)
@@ -183,7 +183,7 @@ user: From the mapsecrets file - see config.html from the base documentation
 
 =head1 VERSION
 
-$Id: freeside-receivables-report,v 1.2 2002-03-05 09:44:09 ivan Exp $
+$Id: freeside-receivables-report,v 1.3 2002-03-05 23:13:23 jeff Exp $
 
 =head1 BUGS
 
@@ -203,17 +203,8 @@ L<FS::cust_main>, config.html from the base documentation
 griff@aver-computer.com July 99
 
 $Log: freeside-receivables-report,v $
-Revision 1.2  2002-03-05 09:44:09  ivan
-yes i have crazy customers with 8-digit customer numbers
-
-Revision 1.1  2002/02/22 23:18:32  jeff
-add some reporting features
-
-Revision 1.1  2000/09/20 19:25:19  jeff
-local modifications
-
-Revision 1.1  2000/05/13 21:57:56  ivan
-add print_batch script from Joel Griffiths
+Revision 1.3  2002-03-05 23:13:23  jeff
+consistency is nice
 
 
 =cut
index 334c410..080b4df 100755 (executable)
@@ -1,39 +1,40 @@
 #!/usr/bin/perl -Tw
 
+
 use strict;
 use Date::Parse;
 use Time::Local;
 use Getopt::Std;
+use Text::Template;
 use FS::Conf;
 use FS::UID qw(adminsuidsetup);
 use FS::Record qw(qsearch);
+use FS::cust_bill;
+use FS::cust_bill_pay;
 use FS::cust_pay;
-use FS::cust_pay_batch;
 
 # Set the mail program
 my $mail_program = "/usr/sbin/sendmail -t -n"; 
 
 &untaint_argv; #what it sounds like  (eww)
-use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s);
-getopts("vped:s:");    #switches
+use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf);
+getopts("vpmef:s:");   #switches
 
 #we're at now now (and later).
-my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T;
-my($_startdate)= $main::opt_s ? str2time($main::opt_s) : $^T;
+my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T;
+my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T;
 
 # Get the current month
 my ($ssec,$smin,$shour,$smday,$smon,$syear) =
        (localtime($_startdate) )[0,1,2,3,4,5]; 
 $smon++;
-$syear -= 100 if $syear >= 100;
-$syear = "0" . $syear if $syear < 10;
+$syear += 1900;
 
 # Get the current month
-my ($esec,$emin,$ehour,$emday,$emon,$eyear) =
-       (localtime($_enddate) )[0,1,2,3,4,5]; 
-$emon++;
-$eyear -= 100 if $eyear >= 100;
-$eyear = "0" . $eyear if $eyear < 10;
+my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) =
+       (localtime($_finishdate) )[0,1,2,3,4,5]; 
+$fmon++;
+$fyear += 1900;
 
 # Login to the database
 my $user = shift or die &usage;
@@ -43,6 +44,19 @@ adminsuidsetup $user;
 my $conf = new FS::Conf;
 my $lpr = $conf->config('lpr');
 my $email = $conf->config('email');
+my @report_template = $conf->config('report_template')
+  or die "cannot load config file report_template";
+$report_lines = 0;
+foreach ( grep /report_lines\(\d+\)/, @report_template ) { #kludgy :/
+  /report_lines\((\d+)\)/;
+  $report_lines += $1;
+}
+die "no report_lines() functions in template?" unless $report_lines;
+$report_template = new Text::Template (
+  TYPE   => 'ARRAY',
+  SOURCE => [ map "$_\n", @report_template ],
+) or die "can't create new Text::Template object: $Text::Template::ERROR";
+
 
 my(@cust_bills)=qsearch('cust_bill',{});
 if (scalar(@cust_bills) == 0)
@@ -50,22 +64,16 @@ if (scalar(@cust_bills) == 0)
        exit 1;
 }
 
-if ($main::opt_v)
-{
-        print qq~ S A L E S  T A X E S  I N V O I C E D  for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~;
-}
-
 # Open print and email pipes
 # $lpr and opt_p for printing
-# $email and opt_e for email
+# $email and opt_m for email
 
 if ($lpr && $main::opt_p)
 {
         open(LPR, "|$lpr");
-        print LPR qq~ S A L E S  T A X E S  I N V O I C E D  for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~;
 }
 
-if ($email && $main::opt_e)
+if ($email && $main::opt_m)
 {
        open (MAIL, "|$mail_program");
        print MAIL <<END
@@ -74,13 +82,11 @@ From: Account Processor
 Subject: Sales Taxes Invoiced
 
 
-S A L E S  T A X E S  I N V O I C E D  for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear
-
 END
 }
 
-my $compped = 0;
-my $compped_tax = 0;
+my $comped = 0;
+my $comped_tax = 0;
 my $other = 0;
 my $other_tax = 0;
 my $total = 0;
@@ -94,104 +100,119 @@ foreach my $cust_bill (@cust_bills)
        my $_date = $cust_bill->getfield('_date');
        my $invnum = $cust_bill->getfield('invnum');
        my $charged = $cust_bill->getfield('charged');
-       
 
-       if ($_date >= $_startdate && $_date <= $_enddate) {
+       if ($_date >= $_startdate && $_date <= $_finishdate) {
                $total += $charged;
 
-               # The following lines were used to produce rather verbose reports
-               #my ($sec,$min,$hour,$mday,$mon,$year) =
-               #       (localtime($_date) )[0,1,2,3,4,5]; 
-               #$mon++;
-               #$year -= 100 if $year >= 100;
-               #$year = "0" . $year if $year < 10;
-
-               my $invoice_amt =0;
-               my $invoice_tax =0;
-               my $invoice_compped =0;
-               my(@cust_bill_pkgs)= $cust_bill->cust_bill_pkg;
-               foreach my $cust_bill_pkg (@cust_bill_pkgs) {
-
-                       my $recur = $cust_bill_pkg->getfield('recur');
-                       my $setup = $cust_bill_pkg->getfield('setup');
-                       my $pkgnum = $cust_bill_pkg->getfield('pkgnum');
-                       
-                       if ($pkgnum == 0) {
-                               # The following line was used to produce rather verbose reports
-                               # printf(MAIL qq{\n%10s%15s%14.2f}, "$mon/$mday/$year", "Tax $invnum", $recur+$setup);
-                               $invoice_tax += $recur;
-                               $invoice_tax += $setup;
-                       } else {
-                               # The following line was used to produce rather verbose reports
-                               # printf(MAIL qq{\n%10s%15s%14.2f}, "$mon/$mday/$year", "Inv $invnum", $recur+$setup);
-                               $invoice_amt += $recur;
-                               $invoice_amt += $setup;
-                       }
-
-               }
-
-               my(@cust_bill_pays)= $cust_bill->cust_bill_pay;
-               foreach my $cust_bill_pay (@cust_bill_pays) {
-                       my $payby = $cust_bill_pay->cust_pay->payby;
-                       my $paid = $cust_bill_pay->getfield('amount');
-                       if ($payby =~ 'COMP') {
-                               $invoice_compped += $paid;
-                       }
-               }
-
-               if (abs($invoice_compped - ($invoice_amt + $invoice_tax)) < 0.0001){
-                       $compped += $invoice_amt;
-                       $compped_tax += $invoice_tax;
-               } elsif ($invoice_compped > 0) {
-                       printf(qq{\nInvoice %10d has inexpliciable complimentary payments of %14.9f\n}, $invnum, $invoice_compped);
-                       $other += $invoice_amt;
-                       $other_tax += $invoice_tax;
-               } elsif ($invoice_tax > 0) {
-                       $total_tax += $invoice_tax;
-                       $taxed += $invoice_amt;
-               } else {
-                       $untaxed += $invoice_amt;
-               }
-
-       }
+                # The following lines were used to produce rather verbose reports
+                #my ($sec,$min,$hour,$mday,$mon,$year) =
+                #       (localtime($_date) )[0,1,2,3,4,5]; 
+                #$mon++;
+                #$year -= 100 if $year >= 100;
+                #$year = "0" . $year if $year < 10;
+
+                my $invoice_amt =0;
+                my $invoice_tax =0;
+                my $invoice_comped =0;
+                my(@cust_bill_pkgs)= $cust_bill->cust_bill_pkg;
+                foreach my $cust_bill_pkg (@cust_bill_pkgs) {
+
+                        my $recur = $cust_bill_pkg->getfield('recur');
+                        my $setup = $cust_bill_pkg->getfield('setup');
+                        my $pkgnum = $cust_bill_pkg->getfield('pkgnum');
+                        
+                        if ($pkgnum == 0) {
+                                # The following line was used to produce rather verbose reports
+                                # push @buf, ('', sprintf(qq{%10s%15s%14.2f}, "$mon/$mday/$year", "Tax $invnum", $recur+$setup));
+                                $invoice_tax += $recur;
+                                $invoice_tax += $setup;
+                        } else {
+                                # The following line was used to produce rather verbose reports
+                                # push @buf, ('', sprintf(qq{%10s%15s%14.2f}, "$mon/$mday/$year", "Inv $invnum", $recur+$setup));
+                                $invoice_amt += $recur;
+                                $invoice_amt += $setup;
+                        }
+
+                }
+
+                my(@cust_bill_pays)= $cust_bill->cust_bill_pay;
+                foreach my $cust_bill_pay (@cust_bill_pays) {
+                        my $payby = $cust_bill_pay->cust_pay->payby;
+                        my $paid = $cust_bill_pay->getfield('amount');
+                        if ($payby =~ 'COMP') {
+                                $invoice_comped += $paid;
+                        }
+                }
+
+                if (abs($invoice_comped - ($invoice_amt + $invoice_tax)) < 0.0001){
+                        $comped += $invoice_amt;
+                        $comped_tax += $invoice_tax;
+                } elsif ($invoice_comped > 0) {
+                        push @buf, sprintf(qq{\nInvoice %10d has inexpliciable complimentary payments of %14.9f\n}, $invnum, $invoice_comped);
+                        $other += $invoice_amt;
+                        $other_tax += $invoice_tax;
+                } elsif ($invoice_tax > 0) {
+                        $total_tax += $invoice_tax;
+                        $taxed += $invoice_amt;
+                } else {
+                        $untaxed += $invoice_amt;
+                }
+
+        }
 
 }
 
-if ($main::opt_v) {
-       printf(qq{\n\n%25s%14.2f\n}, "Complimentary", $compped);
-       printf(qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax);
-       printf(qq{%25s%14.2f\n}, "Other", $other);
-       printf(qq{%25s%14.2f\n}, "Other Tax", $other_tax);
-       printf(qq{%25s%14.2f\n}, "Untaxed", $untaxed);
-       printf(qq{%25s%14.2f\n}, "Taxed", $taxed);
-       printf(qq{%25s%14.2f\n}, "Tax", $total_tax);
-       printf(qq{\n%39s\n%39.2f\n}, "=========", $total);
+push @buf, ('', sprintf(qq{%25s%14.2f}, "Complimentary", $comped));
+push @buf, sprintf(qq{%25s%14.2f}, "Complimentary Tax", $comped_tax);
+push @buf, sprintf(qq{%25s%14.2f}, "Other", $other);
+push @buf, sprintf(qq{%25s%14.2f}, "Other Tax", $other_tax);
+push @buf, sprintf(qq{%25s%14.2f}, "Untaxed", $untaxed);
+push @buf, sprintf(qq{%25s%14.2f}, "Taxed", $taxed);
+push @buf, sprintf(qq{%25s%14.2f}, "Tax", $total_tax);
+push @buf, ('', sprintf(qq{%39s}, "========="), sprintf(qq{%39.2f}, $total));
+
+sub FS::tax_report::_template::report_lines {
+  my $lines = shift;
+  map {
+    scalar(@buf) ? shift @buf : '' ;
+  }
+  ( 1 .. $lines );
+}
+
+$FS::tax_report::_template::title = qq~SALES TAXES INVOICED for $smon/$smday/$syear through $fmon/$fmday/$fyear~;
+$FS::tax_report::_template::title = $opt_t if $opt_t;
+$FS::tax_report::_template::page = 1;
+$FS::tax_report::_template::date = $^T;
+$FS::tax_report::_template::date = $^T;
+$FS::tax_report::_template::fdate = $_finishdate;
+$FS::tax_report::_template::fdate = $_finishdate;
+$FS::tax_report::_template::sdate = $_startdate;
+$FS::tax_report::_template::sdate = $_startdate;
+$FS::tax_report::_template::total_pages = 
+  int( scalar(@buf) / $report_lines);
+$FS::tax_report::_template::total_pages++ if scalar(@buf) % $report_lines;
+
+my @report;
+while (@buf) {
+  push @report, split("\n", 
+    $report_template->fill_in( PACKAGE => 'FS::tax_report::_template' )
+  );
+  $FS::tax_report::_template::page++;
 }
 
-# Now I need to close LPR and EMAIL if they were open
-if($lpr && $main::opt_p)
+if ($opt_v) {
+  print map "$_\n", @report;
+}
+if($lpr && $opt_p)
 {
-       printf(LPR qq{\n\n%25s%14.2f\n}, "Complimentary", $compped);
-       printf(LPR qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax);
-       printf(LPR qq{%25s%14.2f\n}, "Other", $other);
-       printf(LPR qq{%25s%14.2f\n}, "Other Tax", $other_tax);
-       printf(LPR qq{%25s%14.2f\n}, "Untaxed", $untaxed);
-       printf(LPR qq{%25s%14.2f\n}, "Taxed", $taxed);
-       printf(LPR qq{%25s%14.2f\n}, "Tax", $total_tax);
-       printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total);
-       close LPR || die "Could not close printer: $lpr\n";
+  print LPR map "$_\n", @report;
+  print LPR "\f" if $opt_e;
+  close LPR || die "Could not close printer: $lpr\n";
 }
-if($email && $main::opt_e)
+if($email && $opt_m)
 {
-       printf(MAIL qq{\n\n%25s%14.2f\n}, "Complimentary", $compped);
-       printf(MAIL qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax);
-       printf(MAIL qq{%25s%14.2f\n}, "Other", $other);
-       printf(MAIL qq{%25s%14.2f\n}, "Other Tax", $other_tax);
-       printf(MAIL qq{%25s%14.2f\n}, "Untaxed", $untaxed);
-       printf(MAIL qq{%25s%14.2f\n}, "Taxed", $taxed);
-       printf(MAIL qq{%25s%14.2f\n}, "Tax", $total_tax);
-       printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total);
-       close MAIL || die "Could not close printer: $email\n";
+  print MAIL map "$_\n", @report;
+  close MAIL || die "Could not close printer: $email\n";
 }
 
 
@@ -213,7 +234,7 @@ freeside-tax-report - Prints or emails sales taxes invoiced in a given period.
 
 =head1 SYNOPSIS
 
-  freeside-tax-report [-v] [-p] [-e] user
+  freeside-tax-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user
 
 =head1 DESCRIPTION
 
@@ -223,13 +244,21 @@ Prints or emails sales taxes invoiced in a given period.
 
 -p: Print to printer lpr as found in the conf directory.
 
--e: Email output to user found in the Conf email file.
+-m: Email output to user found in the Conf email file.
+
+-e: Print a final form feed to the printer.
+
+-t: supply a title for the top of each page.
+
+-s: starting date for inclusion
+
+-f: final date for inclusion
 
 user: From the mapsecrets file - see config.html from the base documentation
 
 =head1 VERSION
 
-$Id: freeside-tax-report,v 1.1 2002-02-22 23:18:32 jeff Exp $
+$Id: freeside-tax-report,v 1.2 2002-03-05 23:13:23 jeff Exp $
 
 =head1 BUGS
 
@@ -249,20 +278,8 @@ L<FS::cust_main>, config.html from the base documentation
 griff@aver-computer.com July 99
 
 $Log: freeside-tax-report,v $
-Revision 1.1  2002-02-22 23:18:32  jeff
-add some reporting features
-
-Revision 1.3  2002/02/19 14:24:53  jeff
-might be functional now
-
-Revision 1.2  2001/08/20 18:31:49  jeff
-before-merge-to-freeside_1_4_0-pre1
-
-Revision 1.1  2000/09/20 19:25:19  jeff
-local modifications
-
-Revision 1.1  2000/05/13 21:57:56  ivan
-add print_batch script from Joel Griffiths
+Revision 1.2  2002-03-05 23:13:23  jeff
+consistency is nice
 
 
 =cut
index 128565f..c2ab726 100755 (executable)
@@ -11,7 +11,7 @@ my $ending = $1;
 
 print header('Credit Card Recipt Report Results');
 
-open (REPORT, "freeside-cc-receipts-report -v -s $beginning -d $ending $user |");
+open (REPORT, "freeside-cc-receipts-report -v -s $beginning -f $ending $user |");
 
 print '<PRE>';
 while(<REPORT>) {
index fac6c8d..2adafc0 100755 (executable)
@@ -11,7 +11,7 @@ my $ending = $1;
 
 print header('In House Credit Report Results');
 
-open (REPORT, "freeside-credit-report -v -s $beginning -d $ending $user |");
+open (REPORT, "freeside-credit-report -v -s $beginning -f $ending $user |");
 
 print '<PRE>';
 while(<REPORT>) {
index 79aa65c..ac76fad 100755 (executable)
@@ -11,7 +11,7 @@ my $ending = $1;
 
 print header('Tax Report Results');
 
-open (REPORT, "freeside-tax-report -v -s $beginning -d $ending $user |");
+open (REPORT, "freeside-tax-report -v -s $beginning -f $ending $user |");
 
 print '<PRE>';
 while(<REPORT>) {