summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/MANIFEST4
-rwxr-xr-xFS/bin/freeside-cc-receipts-report231
-rwxr-xr-xFS/bin/freeside-credit-report184
-rwxr-xr-xFS/bin/freeside-receivables-report218
-rwxr-xr-xFS/bin/freeside-tax-report270
-rw-r--r--conf/report_template14
-rw-r--r--httemplate/classic.html7
-rw-r--r--httemplate/index.html7
-rwxr-xr-xhttemplate/search/report_cc.cgi94
-rwxr-xr-xhttemplate/search/report_cc.html23
-rwxr-xr-xhttemplate/search/report_credit.cgi97
-rwxr-xr-xhttemplate/search/report_credit.html23
-rwxr-xr-xhttemplate/search/report_receivables.cgi26
-rwxr-xr-xhttemplate/search/report_tax.cgi94
-rwxr-xr-xhttemplate/search/report_tax.html23
15 files changed, 1315 insertions, 0 deletions
diff --git a/FS/MANIFEST b/FS/MANIFEST
index f7a5c1248..28edf59c3 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -11,6 +11,10 @@ bin/freeside-apply-credits
bin/freeside-adduser
bin/freeside-setinvoice
bin/freeside-overdue
+bin/freeside-receivables-report
+bin/freeside-tax-report
+bin/freeside-cc-receipts-report
+bin/freeside-credit-report
FS.pm
FS/CGI.pm
FS/Conf.pm
diff --git a/FS/bin/freeside-cc-receipts-report b/FS/bin/freeside-cc-receipts-report
new file mode 100755
index 000000000..2713af397
--- /dev/null
+++ b/FS/bin/freeside-cc-receipts-report
@@ -0,0 +1,231 @@
+#!/usr/bin/perl -Tw
+
+use strict;
+use Date::Parse;
+use Time::Local;
+use Getopt::Std;
+use FS::Conf;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch qsearchs);
+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
+
+#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;
+
+# Get the current month
+my ($ssec,$smin,$shour,$smday,$smon,$syear) =
+ (localtime($_startdate) )[0,1,2,3,4,5];
+$syear+=1900;
+$smon++;
+
+# Get the current month
+my ($esec,$emin,$ehour,$emday,$emon,$eyear) =
+ (localtime($_enddate) )[0,1,2,3,4,5];
+$eyear+=1900;
+$emon++;
+
+# Login to the database
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+# Get the needed configuration files
+my $conf = new FS::Conf;
+my $lpr = $conf->config('lpr');
+my $email = $conf->config('email');
+
+my(@cust_pays)=qsearch('cust_pay',{});
+if (scalar(@cust_pays) == 0)
+{
+ exit 1;
+}
+
+# Open print and email pipes
+# $lpr and opt_p for printing
+# $email and opt_e 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)
+{
+ open (MAIL, "|$mail_program");
+ print MAIL <<END
+To: $email
+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
+}
+
+my $uninvoiced = 0;
+my $total = 0;
+my $taxed = 0;
+my $untaxed = 0;
+my $total_tax = 0;
+
+# Now I can start looping
+foreach my $cust_pay (@cust_pays)
+{
+ my $_date = $cust_pay->getfield('_date');
+ my $invnum = $cust_pay->getfield('invnum');
+ my $paid = $cust_pay->getfield('paid');
+ my $payby = $cust_pay->getfield('payby');
+
+
+ if ($_date >= $_startdate && $_date <= $_enddate && $payby =~ 'CARD') {
+ $total += $paid;
+
+ $uninvoiced += $cust_pay->unapplied;
+ my @cust_bill_pays = $cust_pay->cust_bill_pay;
+ foreach my $cust_bill_pay (@cust_bill_pays) {
+ my $invoice_amt =0;
+ my $invoice_tax =0;
+ my(@cust_bill_pkgs)= $cust_bill_pay->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) {
+ $invoice_tax += $recur;
+ $invoice_tax += $setup;
+ } else {
+ $invoice_amt += $recur;
+ $invoice_amt += $setup;
+ }
+
+ }
+
+ if ($invoice_tax > 0) {
+ if ($invoice_amt != $paid) {
+ # attempt to prorate partially paid invoices
+ $total_tax += $paid / ($invoice_amt + $invoice_tax) * $invoice_tax;
+ $taxed += $paid / ($invoice_amt + $invoice_tax) * $invoice_amt;
+ } else {
+ $total_tax += $invoice_tax;
+ $taxed += $invoice_amt;
+ }
+ } else {
+ $untaxed += $paid;
+ }
+
+ }
+
+ }
+
+}
+
+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);
+}
+
+# Now I need to close LPR and EMAIL if they were open
+if($lpr && $main::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";
+}
+if($email && $main::opt_e)
+{
+ 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";
+}
+
+
+# subroutines
+sub untaint_argv {
+ foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+ $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
+ $ARGV[$_]=$1;
+ }
+}
+
+sub usage {
+ die "Usage:\n\n freeside-tax-report [-v] [-p] [-e] user\n";
+}
+
+=head1 NAME
+
+freeside-tax-report - Prints or emails sales taxes invoiced in a given period.
+
+=head1 SYNOPSIS
+
+ freeside-tax-report [-v] [-p] [-e] user
+
+=head1 DESCRIPTION
+
+Prints or emails sales taxes invoiced 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.
+
+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 $
+
+=head1 BUGS
+
+Yes..... Use at your own risk. No guarantees or warrantees of any
+kind apply to this program. Parts of this program are hacked from
+other GNU licensed software created mainly by Ivan Kohler.
+
+This is released under the GNU Public License. See www.gnu.org
+for more information regarding this license.
+
+=head1 SEE ALSO
+
+L<FS::cust_main>, config.html from the base documentation
+
+=head1 HISTORY
+
+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/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
+
+
+=cut
+
+
diff --git a/FS/bin/freeside-credit-report b/FS/bin/freeside-credit-report
new file mode 100755
index 000000000..4307a21b0
--- /dev/null
+++ b/FS/bin/freeside-credit-report
@@ -0,0 +1,184 @@
+#!/usr/bin/perl -Tw
+
+use strict;
+use Date::Parse;
+use Time::Local;
+use Getopt::Std;
+use FS::Conf;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch);
+use FS::cust_credit;
+
+# 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
+
+#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;
+
+# Get the current month
+my ($ssec,$smin,$shour,$smday,$smon,$syear) =
+ (localtime($_startdate) )[0,1,2,3,4,5];
+$syear+=1900;
+$smon++;
+
+# Get the current month
+my ($esec,$emin,$ehour,$emday,$emon,$eyear) =
+ (localtime($_enddate) )[0,1,2,3,4,5];
+$eyear+=1900;
+$emon++;
+
+# Login to the database
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+# Get the needed configuration files
+my $conf = new FS::Conf;
+my $lpr = $conf->config('lpr');
+my $email = $conf->config('email');
+
+my(@cust_credits)=qsearch('cust_credit',{});
+if (scalar(@cust_credits) == 0)
+{
+ exit 1;
+}
+
+# Open print and email pipes
+# $lpr and opt_p for printing
+# $email and opt_e 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)
+{
+ open (MAIL, "|$mail_program");
+ print MAIL <<END
+To: $email
+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 $total = 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) {
+ $total += $amount;
+
+ my ($sec,$min,$hour,$mday,$mon,$year) =
+ (localtime($_date) )[0,1,2,3,4,5];
+ $mon++;
+
+ }
+
+}
+
+if ($main::opt_v) {
+ printf(qq{\n\n%25s%14.2f\n}, "Credits Offered", $total);
+ printf(qq{\n%39s\n%39.2f\n}, "=========", $total);
+}
+
+# Now I need to close LPR and EMAIL if they were open
+if($lpr && $main::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";
+}
+if($email && $main::opt_e)
+{
+ 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";
+}
+
+
+# subroutines
+sub untaint_argv {
+ foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+ $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
+ $ARGV[$_]=$1;
+ }
+}
+
+sub usage {
+ die "Usage:\n\n freeside-credit-report [-v] [-p] [-e] user\n";
+}
+
+=head1 NAME
+
+freeside-credit-report - Prints or emails in house credits offered in a given period.
+
+=head1 SYNOPSIS
+
+ freeside-credit-report [-v] [-p] [-e] user
+
+=head1 DESCRIPTION
+
+Prints or emails in house credits offered 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.
+
+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 $
+
+=head1 BUGS
+
+Yes..... Use at your own risk. No guarantees or warrantees of any
+kind apply to this program. Parts of this program are hacked from
+other GNU licensed software created mainly by Ivan Kohler.
+
+This is released under the GNU Public License. See www.gnu.org
+for more information regarding this license.
+
+=head1 SEE ALSO
+
+L<FS::cust_main>, config.html from the base documentation
+
+=head1 HISTORY
+
+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
+
+
+=cut
+
+
diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report
new file mode 100755
index 000000000..cef652bfe
--- /dev/null
+++ b/FS/bin/freeside-receivables-report
@@ -0,0 +1,218 @@
+#!/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_main;
+
+# 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_m $opt_e $opt_t $report_lines $report_template @buf);
+getopts("vpmet:"); #switches
+
+#we're at now now (and later).
+my($_date)= $^T;
+
+# Get the current month
+my ($sec,$min,$hour,$mday,$mon,$year) =
+ (localtime($_date) )[0,1,2,3,4,5];
+$mon++;
+$year += 1900;
+
+# Login to the database
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+# Get the needed configuration files
+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(@customers)=qsearch('cust_main',{});
+if (scalar(@customers) == 0)
+{
+ exit 1;
+}
+
+# Open print and email pipes
+# $lpr and opt_p for printing
+# $email and opt_m for email
+
+if ($lpr && $opt_p)
+{
+ open(LPR, "|$lpr");
+}
+
+if ($email && $opt_m)
+{
+ open (MAIL, "|$mail_program");
+ print MAIL <<END
+To: $email
+From: Account Processor
+Subject: Receivables
+
+
+END
+}
+
+my $total = 0;
+
+
+# Now I can start looping
+foreach my $customer (@customers)
+{
+ my $custnum = $customer->getfield('custnum');
+ my $first = $customer->getfield('first');
+ my $last = $customer->getfield('last');
+ my $company = $customer->getfield('company');
+ my $daytime = $customer->getfield('daytime');
+ my $balance = $customer->balance;
+
+
+ if ($balance != 0) {
+ $total += $balance;
+ push @buf, sprintf(qq{%5d %-32.32s %12s %9.2f},
+ $custnum,
+ $first . " " . $last . " " . $company,
+ $daytime,
+ $balance);
+
+ }
+
+}
+
+push @buf, ('', sprintf(qq{%61s}, "========="), sprintf(qq{%61.2f}, $total));
+
+sub FS::receivables_report::_template::report_lines {
+ my $lines = shift;
+ map {
+ scalar(@buf) ? shift @buf : '' ;
+ }
+ ( 1 .. $lines );
+}
+
+$FS::receivables_report::_template::title = " R E C E I V A B L E S ";
+$FS::receivables_report::_template::title = $opt_t if $opt_t;
+$FS::receivables_report::_template::page = 1;
+$FS::receivables_report::_template::date = $_date;
+$FS::receivables_report::_template::date = $_date;
+$FS::receivables_report::_template::total_pages =
+ int( scalar(@buf) / $report_lines);
+$FS::receivables_report::_template::total_pages++ if scalar(@buf) % $report_lines;
+
+my @report;
+while (@buf) {
+ push @report, split("\n",
+ $report_template->fill_in( PACKAGE => 'FS::receivables_report::_template' )
+ );
+ $FS::receivables_report::_template::page++;
+}
+
+if ($opt_v) {
+ print map "$_\n", @report;
+}
+if($lpr && $opt_p)
+{
+ print LPR map "$_\n", @report;
+ print LPR "\f" if $opt_e;
+ close LPR || die "Could not close printer: $lpr\n";
+}
+if($email && $opt_m)
+{
+ print MAIL map "$_\n", @report;
+ close MAIL || die "Could not close printer: $email\n";
+}
+
+
+# subroutines
+
+sub untaint_argv {
+ foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+ $ARGV[$_] =~ /^([\w\-\/ ]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
+ $ARGV[$_]=$1;
+ }
+}
+
+sub usage {
+ die "Usage:\n\n freeside-receivables-report [-v] [-p] [-e] user\n";
+}
+
+=head1 NAME
+
+freeside-receivables-report - Prints or emails outstanding receivables.
+
+=head1 SYNOPSIS
+
+ freeside-receivables-report [-v] [-p] [-m] [-e] [-t "title"] user
+
+=head1 DESCRIPTION
+
+Prints or emails outstanding receivables
+
+-v: Verbose - Prints records to STDOUT.
+
+-p: Print to printer lpr as found in the conf directory.
+
+-m: Mail 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.
+
+user: From the mapsecrets file - see config.html from the base documentation
+
+=head1 VERSION
+
+$Id: freeside-receivables-report,v 1.1 2002-02-22 23:18:32 jeff Exp $
+
+=head1 BUGS
+
+Yes..... Use at your own risk. No guarantees or warrantees of any
+kind apply to this program. Parts of this program are hacked from
+other GNU licensed software created mainly by Ivan Kohler.
+
+This is released under the GNU Public License. See www.gnu.org
+for more information regarding this license.
+
+=head1 SEE ALSO
+
+L<FS::cust_main>, config.html from the base documentation
+
+=head1 HISTORY
+
+griff@aver-computer.com July 99
+
+$Log: freeside-receivables-report,v $
+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
+
+
+=cut
+
+
diff --git a/FS/bin/freeside-tax-report b/FS/bin/freeside-tax-report
new file mode 100755
index 000000000..334c4107b
--- /dev/null
+++ b/FS/bin/freeside-tax-report
@@ -0,0 +1,270 @@
+#!/usr/bin/perl -Tw
+
+use strict;
+use Date::Parse;
+use Time::Local;
+use Getopt::Std;
+use FS::Conf;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch);
+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
+
+#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;
+
+# 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;
+
+# 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;
+
+# Login to the database
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+# Get the needed configuration files
+my $conf = new FS::Conf;
+my $lpr = $conf->config('lpr');
+my $email = $conf->config('email');
+
+my(@cust_bills)=qsearch('cust_bill',{});
+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
+
+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)
+{
+ open (MAIL, "|$mail_program");
+ print MAIL <<END
+To: $email
+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 $other = 0;
+my $other_tax = 0;
+my $total = 0;
+my $taxed = 0;
+my $untaxed = 0;
+my $total_tax = 0;
+
+# Now I can start looping
+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) {
+ $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;
+ }
+
+ }
+
+}
+
+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);
+}
+
+# Now I need to close LPR and EMAIL if they were open
+if($lpr && $main::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";
+}
+if($email && $main::opt_e)
+{
+ 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";
+}
+
+
+# subroutines
+sub untaint_argv {
+ foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+ $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
+ $ARGV[$_]=$1;
+ }
+}
+
+sub usage {
+ die "Usage:\n\n freeside-tax-report [-v] [-p] [-e] user\n";
+}
+
+=head1 NAME
+
+freeside-tax-report - Prints or emails sales taxes invoiced in a given period.
+
+=head1 SYNOPSIS
+
+ freeside-tax-report [-v] [-p] [-e] user
+
+=head1 DESCRIPTION
+
+Prints or emails sales taxes invoiced 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.
+
+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 $
+
+=head1 BUGS
+
+Yes..... Use at your own risk. No guarantees or warrantees of any
+kind apply to this program. Parts of this program are hacked from
+other GNU licensed software created mainly by Ivan Kohler.
+
+This is released under the GNU Public License. See www.gnu.org
+for more information regarding this license.
+
+=head1 SEE ALSO
+
+L<FS::cust_main>, config.html from the base documentation
+
+=head1 HISTORY
+
+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
+
+
+=cut
+
+
diff --git a/conf/report_template b/conf/report_template
new file mode 100644
index 000000000..9c6bb2b4a
--- /dev/null
+++ b/conf/report_template
@@ -0,0 +1,14 @@
+{ sprintf("%-19s", "Page $page of $total_pages"); } {
+ my $spacer = (40 - length($title) > 0) ? 40 - length($title) : 0;
+ $spacer = int($spacer / 2);
+ my $titlelen = 40 - $spacer;
+ sprintf("%*s%-*s", $spacer, " ", $titlelen, $title);
+ } { use Date::Format; time2str("%x %X", $date); }
+
+
+{
+ join("\n", map { $_ } report_lines(57));
+}
+
+
+
diff --git a/httemplate/classic.html b/httemplate/classic.html
index 406852adf..e56d04d8d 100644
--- a/httemplate/classic.html
+++ b/httemplate/classic.html
@@ -43,6 +43,13 @@
<LI>120 day open invoices (<A HREF="search/cust_bill.cgi?OPEN120_invnum">by invoice number</A>) (<A HREF="search/cust_bill.cgi?OPEN120_date">by date</A>) (<A HREF="search/cust_bill.cgi?OPEN120_custnum">by customer number</A>)
<LI>all invoices (<A HREF="search/cust_bill.cgi?invnum">by invoice number</A>) (<A HREF="search/cust_bill.cgi?date">by date</A>) (<A HREF="search/cust_bill.cgi?custnum">by customer number</A>)
</UL>
+ <LI>financials
+ <UL>
+ <LI><A HREF="search/report_receivables.cgi">receivables report</A>
+ <LI><A HREF="search/report_tax.html">tax reports</A>
+ <LI><A HREF="search/report_cc.html">credit card receipts</A>
+ <LI><A HREF="search/report_credit.html">in house credits</A>
+ </UL>
<LI>packages
<UL>
<LI><A HREF="search/cust_pkg.cgi?pkgnum">packages (by package number)</A>
diff --git a/httemplate/index.html b/httemplate/index.html
index 386f6ec7c..aea44ad73 100644
--- a/httemplate/index.html
+++ b/httemplate/index.html
@@ -66,6 +66,13 @@
<LI>120 day open invoices (<A HREF="search/cust_bill.cgi?OPEN120_invnum">by invoice number</A>) (<A HREF="search/cust_bill.cgi?OPEN120_date">by date</A>) (<A HREF="search/cust_bill.cgi?OPEN120_custnum">by customer number</A>)
<LI>all invoices (<A HREF="search/cust_bill.cgi?invnum">by invoice number</A>) (<A HREF="search/cust_bill.cgi?date">by date</A>) (<A HREF="search/cust_bill.cgi?custnum">by customer number</A>)
</UL>
+ <BR><BR>Financial reports
+ <UL>
+ <LI> <A HREF="search/report_receivables.cgi">current receivables</A>
+ <LI> <A HREF="search/report_tax.html">tax reports</A>
+ <LI> <A HREF="search/report_cc.html">credit card receipts</A>
+ <LI> <A HREF="search/report_credit.html">credit memos</A>
+ </UL>
<BR><CENTER><HR WIDTH="94%" NOSHADE></CENTER><BR>
<A NAME="admin">Administration</a>
<ul>
diff --git a/httemplate/search/report_cc.cgi b/httemplate/search/report_cc.cgi
new file mode 100755
index 000000000..908ad35cd
--- /dev/null
+++ b/httemplate/search/report_cc.cgi
@@ -0,0 +1,94 @@
+<%
+#!/usr/bin/perl -Tw
+#
+# $Id: report_cc.cgi,v 1.1 2002-02-22 23:18:33 jeff Exp $
+#
+# Usage: post form to:
+# http://server.name/path/svc_domain.cgi
+#
+# ivan@voicenet.com 96-mar-5
+#
+# need to look at table in results to make it more readable
+#
+# ivan@voicenet.com
+#
+# rewrite ivan@sisd.com 98-mar-15
+#
+# Changes to allow page to work at a relative position in server
+# bmccane@maxbaud.net 98-apr-3
+#
+# $Log: report_cc.cgi,v $
+# Revision 1.1 2002-02-22 23:18:33 jeff
+# add some reporting features
+#
+# Revision 1.1 2002/02/05 15:22:00 jeff
+# preserving state prior to 1.4.0pre7 upgrade
+#
+# Revision 1.2 2000/09/20 19:25:19 jeff
+# local modifications
+#
+# Revision 1.1.1.1 2000/09/18 06:26:58 jeff
+# Import of Freeside 1.2.3
+#
+# Revision 1.10 1999/07/20 06:03:36 ivan
+# s/CGI::Request/CGI/; (how'd i miss that before?)
+#
+# Revision 1.9 1999/04/09 04:22:34 ivan
+# also table()
+#
+# Revision 1.8 1999/04/09 03:52:55 ivan
+# explicit & for table/itable/ntable
+#
+# Revision 1.7 1999/02/28 00:03:56 ivan
+# removed misleading comments
+#
+# Revision 1.6 1999/02/09 09:22:58 ivan
+# visual and bugfixes
+#
+# Revision 1.5 1999/01/19 05:14:16 ivan
+# for mod_perl: no more top-level my() variables; use vars instead
+# also the last s/create/new/;
+#
+# Revision 1.4 1999/01/18 09:41:40 ivan
+# all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
+# (good idea anyway)
+#
+# Revision 1.3 1998/12/17 09:41:11 ivan
+# s/CGI::(Base|Request)/CGI.pm/;
+#
+
+use strict;
+use vars qw( $conf $cgi $beginning $ending );
+use CGI;
+use CGI::Carp qw(fatalsToBrowser);
+use FS::UID qw(cgisuidsetup);
+use FS::CGI qw(popurl idiot header table);
+use FS::Record qw(qsearch qsearchs);
+use FS::Conf;
+
+$cgi = new CGI;
+&cgisuidsetup($cgi);
+
+$conf = new FS::Conf;
+
+$cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
+$beginning = $1;
+
+$cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
+$ending = $1;
+
+ print $cgi->header( '-expires' => '-2m' ),
+ header('Credit Card Recipt Report Results');
+
+ open (REPORT, "/usr/bin/freeside-cc-receipts-report -v -s $beginning -d $ending freeside |");
+
+ print '<PRE>';
+ while(<REPORT>) {
+ print $_;
+ }
+ print '</PRE>';
+
+ print '</BODY></HTML>';
+
+%>
+
diff --git a/httemplate/search/report_cc.html b/httemplate/search/report_cc.html
new file mode 100755
index 000000000..a028a87df
--- /dev/null
+++ b/httemplate/search/report_cc.html
@@ -0,0 +1,23 @@
+<HTML>
+ <HEAD>
+ <TITLE>Credit Card Receipt Report Criteria</TITLE>
+ </HEAD>
+ <BODY>
+ <CENTER>
+ <H1>Credit Card Receipt Report Criteria</H1>
+ </CENTER>
+ <HR>
+ <FORM ACTION="report_cc.cgi" METHOD="post">
+ Return <B>credit card receipt report</B> for period:
+ from <INPUT TYPE="text" NAME="beginning">
+ to <INPUT TYPE="text" NAME="ending">
+
+ <P><INPUT TYPE="submit" VALUE="Get Report">
+
+ </FORM>
+
+ <HR>
+
+ </BODY>
+</HTML>
+
diff --git a/httemplate/search/report_credit.cgi b/httemplate/search/report_credit.cgi
new file mode 100755
index 000000000..8535e29cc
--- /dev/null
+++ b/httemplate/search/report_credit.cgi
@@ -0,0 +1,97 @@
+<%
+#!/usr/bin/perl -Tw
+#
+# $Id: report_credit.cgi,v 1.1 2002-02-22 23:18:33 jeff Exp $
+#
+# Usage: post form to:
+# http://server.name/path/svc_domain.cgi
+#
+# ivan@voicenet.com 96-mar-5
+#
+# need to look at table in results to make it more readable
+#
+# ivan@voicenet.com
+#
+# rewrite ivan@sisd.com 98-mar-15
+#
+# Changes to allow page to work at a relative position in server
+# bmccane@maxbaud.net 98-apr-3
+#
+# $Log: report_credit.cgi,v $
+# Revision 1.1 2002-02-22 23:18:33 jeff
+# add some reporting features
+#
+# Revision 1.2 2002/02/19 14:24:53 jeff
+# might be functional now
+#
+# Revision 1.1 2002/02/05 15:22:00 jeff
+# preserving state prior to 1.4.0pre7 upgrade
+#
+# Revision 1.2 2000/09/20 19:25:19 jeff
+# local modifications
+#
+# Revision 1.1.1.1 2000/09/18 06:26:58 jeff
+# Import of Freeside 1.2.3
+#
+# Revision 1.10 1999/07/20 06:03:36 ivan
+# s/CGI::Request/CGI/; (how'd i miss that before?)
+#
+# Revision 1.9 1999/04/09 04:22:34 ivan
+# also table()
+#
+# Revision 1.8 1999/04/09 03:52:55 ivan
+# explicit & for table/itable/ntable
+#
+# Revision 1.7 1999/02/28 00:03:56 ivan
+# removed misleading comments
+#
+# Revision 1.6 1999/02/09 09:22:58 ivan
+# visual and bugfixes
+#
+# Revision 1.5 1999/01/19 05:14:16 ivan
+# for mod_perl: no more top-level my() variables; use vars instead
+# also the last s/create/new/;
+#
+# Revision 1.4 1999/01/18 09:41:40 ivan
+# all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
+# (good idea anyway)
+#
+# Revision 1.3 1998/12/17 09:41:11 ivan
+# s/CGI::(Base|Request)/CGI.pm/;
+#
+
+use strict;
+use vars qw( $conf $cgi $beginning $ending );
+use CGI;
+use CGI::Carp qw(fatalsToBrowser);
+use FS::UID qw(cgisuidsetup);
+use FS::CGI qw(popurl idiot header table);
+use FS::Record qw(qsearch qsearchs);
+use FS::Conf;
+
+$cgi = new CGI;
+&cgisuidsetup($cgi);
+
+$conf = new FS::Conf;
+
+$cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
+$beginning = $1;
+
+$cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
+$ending = $1;
+
+ print $cgi->header( '-expires' => '-2m' ),
+ header('In House Credit Report Results');
+
+ open (REPORT, "/usr/bin/freeside-credit-report -v -s $beginning -d $ending freeside |");
+
+ print '<PRE>';
+ while(<REPORT>) {
+ print $_;
+ }
+ print '</PRE>';
+
+ print '</BODY></HTML>';
+
+%>
+
diff --git a/httemplate/search/report_credit.html b/httemplate/search/report_credit.html
new file mode 100755
index 000000000..bda08e31d
--- /dev/null
+++ b/httemplate/search/report_credit.html
@@ -0,0 +1,23 @@
+<HTML>
+ <HEAD>
+ <TITLE>In House Credit Report Criteria</TITLE>
+ </HEAD>
+ <BODY>
+ <CENTER>
+ <H1>In House Credit Report Criteria</H1>
+ </CENTER>
+ <HR>
+ <FORM ACTION="report_credit.cgi" METHOD="post">
+ Return <B>in house credit report</B> for period:
+ from <INPUT TYPE="text" NAME="beginning">
+ to <INPUT TYPE="text" NAME="ending">
+
+ <P><INPUT TYPE="submit" VALUE="Get Report">
+
+ </FORM>
+
+ <HR>
+
+ </BODY>
+</HTML>
+
diff --git a/httemplate/search/report_receivables.cgi b/httemplate/search/report_receivables.cgi
new file mode 100755
index 000000000..7113ad5a7
--- /dev/null
+++ b/httemplate/search/report_receivables.cgi
@@ -0,0 +1,26 @@
+<%
+
+use strict;
+use vars qw( $cgi );
+use CGI;
+use CGI::Carp qw(fatalsToBrowser);
+use FS::UID qw(cgisuidsetup);
+
+$cgi = new CGI;
+&cgisuidsetup($cgi);
+
+print $cgi->header( '-expires' => '-2m' ),
+ header('Current Receivables Report Results');
+
+open (REPORT, "/usr/bin/freeside-receivables-report -v freeside |");
+
+print '<PRE>';
+while(<REPORT>) {
+ print $_;
+}
+print '</PRE>';
+
+print '</BODY></HTML>';
+
+%>
+
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
new file mode 100755
index 000000000..8062479b5
--- /dev/null
+++ b/httemplate/search/report_tax.cgi
@@ -0,0 +1,94 @@
+<%
+#!/usr/bin/perl -Tw
+#
+# $Id: report_tax.cgi,v 1.1 2002-02-22 23:18:34 jeff Exp $
+#
+# Usage: post form to:
+# http://server.name/path/svc_domain.cgi
+#
+# ivan@voicenet.com 96-mar-5
+#
+# need to look at table in results to make it more readable
+#
+# ivan@voicenet.com
+#
+# rewrite ivan@sisd.com 98-mar-15
+#
+# Changes to allow page to work at a relative position in server
+# bmccane@maxbaud.net 98-apr-3
+#
+# $Log: report_tax.cgi,v $
+# Revision 1.1 2002-02-22 23:18:34 jeff
+# add some reporting features
+#
+# Revision 1.1 2002/02/05 15:22:00 jeff
+# preserving state prior to 1.4.0pre7 upgrade
+#
+# Revision 1.2 2000/09/20 19:25:19 jeff
+# local modifications
+#
+# Revision 1.1.1.1 2000/09/18 06:26:58 jeff
+# Import of Freeside 1.2.3
+#
+# Revision 1.10 1999/07/20 06:03:36 ivan
+# s/CGI::Request/CGI/; (how'd i miss that before?)
+#
+# Revision 1.9 1999/04/09 04:22:34 ivan
+# also table()
+#
+# Revision 1.8 1999/04/09 03:52:55 ivan
+# explicit & for table/itable/ntable
+#
+# Revision 1.7 1999/02/28 00:03:56 ivan
+# removed misleading comments
+#
+# Revision 1.6 1999/02/09 09:22:58 ivan
+# visual and bugfixes
+#
+# Revision 1.5 1999/01/19 05:14:16 ivan
+# for mod_perl: no more top-level my() variables; use vars instead
+# also the last s/create/new/;
+#
+# Revision 1.4 1999/01/18 09:41:40 ivan
+# all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
+# (good idea anyway)
+#
+# Revision 1.3 1998/12/17 09:41:11 ivan
+# s/CGI::(Base|Request)/CGI.pm/;
+#
+
+use strict;
+use vars qw( $conf $cgi $beginning $ending );
+use CGI;
+use CGI::Carp qw(fatalsToBrowser);
+use FS::UID qw(cgisuidsetup);
+use FS::CGI qw(popurl idiot header table);
+use FS::Record qw(qsearch qsearchs);
+use FS::Conf;
+
+$cgi = new CGI;
+&cgisuidsetup($cgi);
+
+$conf = new FS::Conf;
+
+$cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
+$beginning = $1;
+
+$cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
+$ending = $1;
+
+ print $cgi->header( '-expires' => '-2m' ),
+ header('Tax Report Results');
+
+ open (REPORT, "/usr/bin/freeside-tax-report -v -s $beginning -d $ending freeside |");
+
+ print '<PRE>';
+ while(<REPORT>) {
+ print $_;
+ }
+ print '</PRE>';
+
+ print '</BODY></HTML>';
+
+%>
+
diff --git a/httemplate/search/report_tax.html b/httemplate/search/report_tax.html
new file mode 100755
index 000000000..a7beb2471
--- /dev/null
+++ b/httemplate/search/report_tax.html
@@ -0,0 +1,23 @@
+<HTML>
+ <HEAD>
+ <TITLE>Tax Report Criteria</TITLE>
+ </HEAD>
+ <BODY>
+ <CENTER>
+ <H1>Tax Report Criteria</H1>
+ </CENTER>
+ <HR>
+ <FORM ACTION="report_tax.cgi" METHOD="post">
+ Return <B>tax report</B> for period:
+ from <INPUT TYPE="text" NAME="beginning">
+ to <INPUT TYPE="text" NAME="ending">
+
+ <P><INPUT TYPE="submit" VALUE="Get Report">
+
+ </FORM>
+
+ <HR>
+
+ </BODY>
+</HTML>
+