From 62a808f08c065aa5a29fb9cbf6b7108fe4cb8d15 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 13 May 2000 21:57:56 +0000 Subject: [PATCH] add print_batch script from Joel Griffiths --- FS/bin/freeside-print-batch | 266 ++++++++++++++++++++++++++++++++++++++++++++ TODO | 68 ++++++++++- htdocs/docs/billing.html | 12 +- 3 files changed, 340 insertions(+), 6 deletions(-) create mode 100755 FS/bin/freeside-print-batch diff --git a/FS/bin/freeside-print-batch b/FS/bin/freeside-print-batch new file mode 100755 index 000000000..c1a25edb2 --- /dev/null +++ b/FS/bin/freeside-print-batch @@ -0,0 +1,266 @@ +#!/usr/bin/perl -Tw + +use strict; +#use Date::Format; +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; + +# Get the currennt time and date +my $time = time; +my ($sec,$min,$hour,$mday,$mon,$year) = + (localtime($time) )[0,1,2,3,4,5]; +my $_date = + timelocal($sec,$min,$hour,$mday,$mon,$year); + +# 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_a $opt_d); +getopts("vpead"); #switches + +# 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(@batch)=qsearch('cust_pay_batch',{}); +if (scalar(@batch) == 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 P A Y M E N T S D U E $mon/$mday/$year\n\n~; +} + +if ($email && $main::opt_e) +{ + open (MAIL, "|$mail_program"); + print MAIL <getfield('state'); + my $zip = $cust_pay_batch->getfield('zip'); + my $amount = $cust_pay_batch->getfield('amount'); + my $last = $cust_pay_batch->getfield('last'); + my $address1 = $cust_pay_batch->getfield('address1'); + my $address2 = $cust_pay_batch->getfield('address2'); + my $first = $cust_pay_batch->getfield('first'); + my $city = $cust_pay_batch->getfield('city'); + my $cardnum = $cust_pay_batch->getfield('cardnum'); + my $payname = $cust_pay_batch->getfield('payname'); + my $exp = $cust_pay_batch->getfield('exp'); + my $invnum = $cust_pay_batch->getfield('invnum'); + my $custnum = $cust_pay_batch->getfield('custnum'); + + # Need a carriage return in address before address2 + # if it exists. Otherwise address will just be address1 + my $address = $address1; + $address .= "\n$address2" if ($address2); + + # Only print to the screen in verbose mode + if ($main::opt_v) + { + printf("Invoice %d for %s %s\tCustomer Number: %d\n", + $invnum, + $first, + $last, + $custnum); + + printf("\t%s\n", $address); + printf("\t%s, %s, %s\n\n", + $city, + $state, + $zip); + + printf("\tCard Number: %s\tExp:%s\n", + $cardnum, + $exp); + printf("\t\tName: %s\n", $payname); + printf("\t\tAmount: %.2f\n\n\n", $amount); + } + + if ($lpr && $main::opt_p) + { + printf(LPR "Invoice %d for %s %s\tCustomer Number: %d\n", + $invnum, + $first, + $last, + $custnum); + + printf(LPR "\t%s\n", $address); + printf(LPR "\t%s, %s, %s\n\n", + $city, + $state, + $zip); + + printf(LPR "\tCard Number: %s\tExp:%s\n", + $cardnum, + $exp); + printf(LPR "\t\tName: %s\n", $payname); + printf(LPR "\t\tAmount: %.2f\n\n\n", $amount); + } + + if ($email && $main::opt_e) + { + printf(MAIL "Invoice %d for %s %s\tCustomer Number: %d\n", + $invnum, + $first, + $last, + $custnum); + + printf(MAIL "\t%s\n", $address); + printf(MAIL "\t%s, %s, %s\n\n", + $city, + $state, + $zip); + + printf(MAIL "\tCard Number: %s\tExp:%s\n", + $cardnum, + $exp); + printf(MAIL "\t\tName: %s\n", $payname); + printf(MAIL "\t\tAmount: %.2f\n\n\n", $amount); + } + + # Now I want to delete the records from cust_pay_batch + # and mark the records in cust_pay as paid today if + # the delete (-d) command line option is set. + if($main::opt_a) + { + my $payment=new FS::cust_pay { + 'invnum' => $invnum, + 'paid' => $amount, + '_date' => $_date, + 'payby' => "CARD", + 'payinfo' => $cardnum, + 'paybatch' => "AUTO", + }; + + my $pay_error=$payment->insert; + if ($pay_error) + { + # warn might be better if you get root's mail + # NEED TO TEST THIS BEFORE DELETE IF WARN IS USED + die "Could not update cust_pay for invnum $invnum. $pay_error\n"; + } + } + + # This just deletes the records + # Must be last in the foreach loop + if($main::opt_d) + { + my $del_error = $cust_pay_batch->delete; + if ($del_error) + { + die "Could not delete cust_pay_batch for invnum $invnum. $del_error\n"; + } + } + +} + +# Now I need to close LPR and EMAIL if they were open +if($lpr && $main::opt_p) +{ + close LPR || die "Could not close printer: $lpr\n"; +} + +if($email && $main::opt_e) +{ + close MAIL || die "Could not close printer: $lpr\n"; +} + + +# subroutines +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-print-batch [-v] [-p] [-e] [-a] [-d] user\n"; +} + +=head1 NAME + +freeside-print-batch - Prints or emails cust_pay_batch. Also deletes + old records and adds payment to cust_pay. + Usually run after the bill command. + +=head1 SYNOPSIS + + freeside-print-batch [-v] [-p] [-e] [-a] [-d] user + +=head1 DESCRIPTION + +Prints or emails cust_pay_batch. Can enter payment and delete +printed records. Usually run as a cron job. + +-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. + +-a: Automatically pays all records in cust_pay_batch. Use -d with this option usually. + +-d: Delete - Pays account and deletes record from cust_pay_batch. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: freeside-print-batch,v 1.1 2000-05-13 21:57:56 ivan 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, config.html from the base documentation + +=head1 HISTORY + +griff@aver-computer.com July 99 + +$Log: freeside-print-batch,v $ +Revision 1.1 2000-05-13 21:57:56 ivan +add print_batch script from Joel Griffiths + + +=cut + + diff --git a/TODO b/TODO index 19baa7228..f3fc919ea 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.42 2000-03-06 14:12:56 ivan Exp $ +$Id: TODO,v 1.43 2000-05-13 21:57:56 ivan Exp $ If you are interested in helping with any of these, please join the mailing list (send a blank message to ivan-freeside-subscribe@sisd.com) to avoid @@ -6,6 +6,67 @@ duplication of effort. --- +pro-rating, fiddling dates + +It looks like svc_acct.import doesn't deal well with comments and +multi-attribute lines. + +ivan@rootwood:~/freeside_current$ rgrep -r domuid * | cut -d: -f1 | sort | +uniq +CVS/Base/TODO +TODO +bin/fs-setup +bin/svc_acct_sm.export +bin/svc_acct_sm.import +htdocs/docs/man/svc_acct_sm.txt +htdocs/docs/schema.html +htdocs/edit/CVS/Base/part_svc.cgi +htdocs/edit/part_svc.cgi +htdocs/edit/process/svc_acct_sm.cgi +htdocs/edit/svc_acct_sm.cgi +htdocs/search/svc_acct_sm.cgi +htdocs/view/svc_acct_sm.cgi +site_perl/svc_acct_sm.pm + +rootwood:COMPLETEHOST/TODO + +Currently, you set a value in the %FS::UID::callback hash with a coderef +of the code you want to execute, but this was bad design and will shortly +be changed to a subroutine to which you pass your coderef to register it. + +This is not a bug, it is how the system is currently designed. After +defining a new package, you need to specifically allow agent types to +purchase packages. You can do this from the edit screen of the new agent +type. +. +It wouldn't be a bad idea to add a configuration value that makes new +packages available for all currently existing agent types automatically. +. +On Fri, Apr 07, 2000 at 10:50:35AM -0500, David Morton wrote: +> For some reason, the type_pkgs table didn't get updated when I tried to +> create a domain service and package... insert into type_pkgs values +> (4,1); fixed it up so that I could actually order the package. + + +From: Chuck Cochems +. +1) automated generating of late notices. So far the only way I know to +generate one is to re-invoice manually. +. +2) smart credit card rejection handling. It should e-mail a note at +least, explainig that it did't go through, and why. +. +3)coment field in the main customer record. +. +4) streamlined payment entry feature. the current scheme has it fairly +buried. +. +5) queries to show al customers who owe money,and such stuff as that. + + +credits aren't counted against past invoices? hmm. something needs to be +done to "apply payment" genericly. and zero out invoices etc. + more email which should make it into a more organized TODO list: . I would also love to see Freeside support bandwidth billing by reading the @@ -176,10 +237,9 @@ in real-time instead of exporting periodically. See . these go in docs: -, and - + (was 546), and -and http://www.sisd.com/freeside/list-archive/msg00423.html +and http://www.sisd.com/freeside/list-archive/msg00421.html (was 423) > > 5: Is there anyway to get freeside to send a sysadmin a warning when a > > credit card has expired? diff --git a/htdocs/docs/billing.html b/htdocs/docs/billing.html index c0354f1ca..659049d06 100644 --- a/htdocs/docs/billing.html +++ b/htdocs/docs/billing.html @@ -3,7 +3,7 @@

Billing

- The freeside-bill script can be run daily to bill all customers. Usage: bill [ -c [ i ] ] [ -d date ] [ -b ] + The freeside-bill script can be run daily to bill all customers. Usage: bill [ -c [ i ] ] [ -d date ] [ -b ] user
  • -c: Turn on collecting (you probably want this).
  • -i: Real-time billing (as opposed to bacth billing). Only relevant for credit cards. Not available without modifying site_perl/Bill.pm @@ -35,6 +35,14 @@ if ( $error ) { # end loop -All fields except paybatch are contained in the cust_pay_batch table. You can use paybatch field to track particular batches and/or particular transactions within a batch. +All fields except paybatch are contained in the cust_pay_batch table. You can use paybatch field to track particular batches and/or particular transactions within a batch.

    +
  • The freeside-print-batch script can print or email pending credit card batches for manual entry. Usage: freeside-print-batch [-v] [-p] [-e] [-a] [-d] user +
      +
    • -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. +
    • -a: Automatically pays all records in cust_pay_batch. Use -d with this option usually. +
    • -d: Delete - Pays account and deletes record from cust_pay_batch. +
-- 2.11.0