9 use FS::UID qw(adminsuidsetup);
10 use FS::Record qw(qsearch);
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_m $opt_e $opt_t $report_lines $report_template @buf);
18 getopts("vpmet:"); #switches
20 #we're at now now (and later).
23 # Get the current month
24 my ($sec,$min,$hour,$mday,$mon,$year) =
25 (localtime($_date) )[0,1,2,3,4,5];
29 # Login to the database
30 my $user = shift or die &usage;
33 # Get the needed configuration files
34 my $conf = new FS::Conf;
35 my $lpr = $conf->config('lpr');
36 my $email = $conf->config('email');
37 my @report_template = $conf->config('report_template')
38 or die "cannot load config file report_template";
40 foreach ( grep /report_lines\(\d+\)/, @report_template ) { #kludgy :/
41 /report_lines\((\d+)\)/;
44 die "no report_lines() functions in template?" unless $report_lines;
45 $report_template = new Text::Template (
47 SOURCE => [ map "$_\n", @report_template ],
48 ) or die "can't create new Text::Template object: $Text::Template::ERROR";
51 my(@customers)=qsearch('cust_main',{});
52 if (scalar(@customers) == 0)
57 # Open print and email pipes
58 # $lpr and opt_p for printing
59 # $email and opt_m for email
68 open (MAIL, "|$mail_program");
71 From: Account Processor
81 # Now I can start looping
82 foreach my $customer (@customers)
84 my $custnum = $customer->getfield('custnum');
85 my $first = $customer->getfield('first');
86 my $last = $customer->getfield('last');
87 my $company = $customer->getfield('company');
88 my $daytime = $customer->getfield('daytime');
89 my $balance = $customer->balance;
94 push @buf, sprintf(qq{%8d %-32.32s %12s %9.2f},
96 $first . " " . $last . " " . $company,
104 push @buf, ('', sprintf(qq{%61s}, "========="), sprintf(qq{%61.2f}, $total));
106 sub FS::receivables_report::_template::report_lines {
109 scalar(@buf) ? shift @buf : '' ;
114 $FS::receivables_report::_template::title = " R E C E I V A B L E S ";
115 $FS::receivables_report::_template::title = $opt_t if $opt_t;
116 $FS::receivables_report::_template::page = 1;
117 $FS::receivables_report::_template::date = $_date;
118 $FS::receivables_report::_template::date = $_date;
119 $FS::receivables_report::_template::total_pages =
120 int( scalar(@buf) / $report_lines);
121 $FS::receivables_report::_template::total_pages++ if scalar(@buf) % $report_lines;
125 push @report, split("\n",
126 $report_template->fill_in( PACKAGE => 'FS::receivables_report::_template' )
128 $FS::receivables_report::_template::page++;
132 print map "$_\n", @report;
136 print LPR map "$_\n", @report;
137 print LPR "\f" if $opt_e;
138 close LPR || die "Could not close printer: $lpr\n";
142 print MAIL map "$_\n", @report;
143 close MAIL || die "Could not close printer: $email\n";
150 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
151 $ARGV[$_] =~ /^([\w\-\/ ]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
157 die "Usage:\n\n freeside-receivables-report [-v] [-p] [-e] user\n";
162 freeside-receivables-report - Prints or emails outstanding receivables.
166 freeside-receivables-report [-v] [-p] [-m] [-e] [-t "title"] user
170 Prints or emails outstanding receivables
172 -v: Verbose - Prints records to STDOUT.
174 -p: Print to printer lpr as found in the conf directory.
176 -m: Mail output to user found in the Conf email file.
178 -e: Print a final form feed to the printer.
180 -t: supply a title for the top of each page.
182 user: From the mapsecrets file - see config.html from the base documentation
186 $Id: freeside-receivables-report,v 1.2 2002-03-05 09:44:09 ivan Exp $
190 Yes..... Use at your own risk. No guarantees or warrantees of any
191 kind apply to this program. Parts of this program are hacked from
192 other GNU licensed software created mainly by Ivan Kohler.
194 This is released under the GNU Public License. See www.gnu.org
195 for more information regarding this license.
199 L<FS::cust_main>, config.html from the base documentation
203 griff@aver-computer.com July 99
205 $Log: freeside-receivables-report,v $
206 Revision 1.2 2002-03-05 09:44:09 ivan
207 yes i have crazy customers with 8-digit customer numbers
209 Revision 1.1 2002/02/22 23:18:32 jeff
210 add some reporting features
212 Revision 1.1 2000/09/20 19:25:19 jeff
215 Revision 1.1 2000/05/13 21:57:56 ivan
216 add print_batch script from Joel Griffiths