summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeff <jeff>2002-03-06 22:44:14 +0000
committerjeff <jeff>2002-03-06 22:44:14 +0000
commita6aa711eb82626bfab39902a6c4d785f3f533ef4 (patch)
treeed23b9d0334f1211c164526f1154aedf90a1d064
parent8fd504d36e02fd1ac3d0d5c9d6dc723fdb419aa1 (diff)
billing expiration alerts
-rw-r--r--FS/FS/Conf.pm15
-rw-r--r--FS/MANIFEST1
-rwxr-xr-xFS/bin/freeside-expiration-alerter209
-rw-r--r--README.1.4.0pre122
-rw-r--r--conf/alerter_template20
-rwxr-xr-xhttemplate/docs/admin.html6
6 files changed, 253 insertions, 0 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 6fbd48732..e8686b575 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -191,6 +191,13 @@ httemplate/docs/config.html
},
{
+ 'key' => 'alerter_template',
+ 'section' => 'billing',
+ 'description' => 'Template file for billing method expiration alerts. See the <a href="../docs/billing.html#invoice_template">billing documentation</a> for details.',
+ 'type' => 'textarea',
+ },
+
+ {
'key' => 'apacheroot',
'section' => 'apache',
'description' => 'The directory containing Apache virtual hosts',
@@ -491,6 +498,14 @@ httemplate/docs/config.html
# },
{
+ 'key' => 'report_template',
+ 'section' => 'required',
+ 'description' => 'Required template file for reports. See the <a href="../docs/billing.html">billing documentation</a> for details.',
+ 'type' => 'textarea',
+ },
+
+
+ {
'key' => 'maxsearchrecordsperpage',
'section' => 'UI',
'description' => 'If set, number of search records to return per page.',
diff --git a/FS/MANIFEST b/FS/MANIFEST
index 28edf59c3..c1aa5ef1a 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -15,6 +15,7 @@ bin/freeside-receivables-report
bin/freeside-tax-report
bin/freeside-cc-receipts-report
bin/freeside-credit-report
+bin/freeside-expiration-alerter
FS.pm
FS/CGI.pm
FS/Conf.pm
diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter
new file mode 100755
index 000000000..c3dc37b31
--- /dev/null
+++ b/FS/bin/freeside-expiration-alerter
@@ -0,0 +1,209 @@
+#!/usr/bin/perl -Tw
+
+use strict;
+use Date::Format;
+use Time::Local;
+use Text::Template;
+use Getopt::Std;
+use FS::Conf;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch);
+use FS::cust_main;
+
+use vars qw($smtpmachine);
+
+#hush, perl!
+$FS::alerter::_template::first = "";
+$FS::alerter::_template::last = "";
+$FS::alerter::_template::company = "";
+$FS::alerter::_template::payby = "";
+$FS::alerter::_template::expdate = "";
+
+# Set the mail program and other variables
+my $mail_program = "/usr/sbin/sendmail -t -n";
+my $mail_sender = "billing\@mydomain.tld";
+my $default_mail_recipient = "postmaster";
+my $warning_time = 30 * 24 * 60 * 60;
+my $urgent_time = 15 * 24 * 60 * 60;
+my $panic_time = 5 * 24 * 60 * 60;
+my $window_time = 24 * 60 * 60;
+
+&untaint_argv; #what it sounds like (eww)
+
+#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++;
+
+# Login to the database
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+# Get the needed configuration files
+my $conf = new FS::Conf;
+$smtpmachine = $conf->config('smtpmachine');
+
+my(@customers)=qsearch('cust_main',{});
+if (scalar(@customers) == 0)
+{
+ exit 1;
+}
+
+# Open email pipe
+
+open (MAIL, "|$mail_program");
+print MAIL <<END
+To: $default_mail_recipient
+From: Account Processor
+Subject: Unnotified Billing Arrangement Expirations
+
+
+END
+
+;
+
+my @alerter_template = $conf->config('alerter_template')
+ or die "cannot load config file alerter_template";
+
+my $alerter = new Text::Template (TYPE => 'ARRAY', SOURCE => [ map "$_\n", @alerter_template ])
+ or die "can't create new Text::Template object: Text::Template::ERROR";
+$alerter->compile() or die "can't compile template: Text::Template::ERROR";
+
+# 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 $payby = $customer->getfield('payby');
+ my $payinfo = $customer->getfield('payinfo');
+ my $paydate = $customer->getfield('paydate');
+ my $daytime = $customer->getfield('daytime');
+ my $night = $customer->getfield('night');
+
+ my ($payyear,$paymonth,$payday) = split (/-/,$paydate);
+
+ my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear);
+
+ #credit cards expire at the end of the month/year of their exp date
+ if ($payby eq 'CARD') {
+ ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++);
+ $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear);
+ $expire_time--;
+ }
+
+ if (($expire_time < $_date + $warning_time &&
+ $expire_time > $_date + $warning_time - $window_time) ||
+ ($expire_time < $_date + $urgent_time &&
+ $expire_time > $_date + $urgent_time - $window_time) ||
+ ($expire_time < $_date + $panic_time &&
+ $expire_time > $_date + $panic_time - $window_time)) {
+
+
+
+ my @packages = $customer->ncancelled_pkgs;
+ if (scalar(@packages) != 0) {
+ my @invoicing_list = $customer->invoicing_list;
+ if ( grep { $_ ne 'POST' } @invoicing_list ) {
+ $ENV{SMTPHOSTS} = $smtpmachine;
+ $ENV{MAILADDRESS} = $mail_sender;
+ my $header = new Mail::Header ( [
+ "From: $mail_sender",
+ "To: ". join(', ', grep { $_ ne 'POST' } @invoicing_list ),
+ "Sender: $mail_sender",
+ "Reply-To: $mail_sender",
+ "Date: ". time2str("%a, %d %b %Y %X %z", time),
+ "Subject: Billing Arrangement Expiration",
+ ] );
+ $FS::alerter::_template::first = $first;
+ $FS::alerter::_template::last = $last;
+ $FS::alerter::_template::company = $company;
+ if ($payby eq 'CARD') {
+ $FS::alerter::_template::payby = "credit card (" .
+ substr($payinfo, 0, 2) . "xxxxxxxxxx" .
+ substr($payinfo, -4) . ")";
+ }elsif ($payby eq 'COMP') {
+ $FS::alerter::_template::payby = "complimentary account";
+ }else{
+ $FS::alerter::_template::payby = "current method";
+ }
+ $FS::alerter::_template::expdate = $expire_time;
+
+ my $message = new Mail::Internet (
+ 'Header' => $header,
+ 'Body' => [ $alerter->fill_in( PACKAGE => 'FS::alerter::_template' ) ],
+ );
+ $message->smtpsend or die "Can't send invoice email!: $!"; #die? warn?
+
+ } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) {
+ printf(MAIL qq{%5d %-32.32s %4s %10s %12s %12s\n},
+ $custnum,
+ $first . " " . $last . " " . $company,
+ $payby,
+ $paydate,
+ $daytime,
+ $night);
+ }
+ }
+ }
+}
+
+# Now I need to close EMAIL
+close MAIL || die "Could not close printer: $default_mail_recipient\n";
+
+
+# subroutines
+sub untaint_argv {
+ foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+ $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal argument \"$ARGV[$_]\"";
+ $ARGV[$_]=$1;
+ }
+}
+
+sub usage {
+ die "Usage:\n\n freeside-expiration-alerter user\n";
+}
+
+=head1 NAME
+
+freeside-expiration-alerter - Emails notifications of credit card expirations.
+
+=head1 SYNOPSIS
+
+ freeside-expiration-alerter user
+
+=head1 DESCRIPTION
+
+Emails customers notice that their credit card or other billing arrangement
+is about to expire. Usually run as a cron job.
+
+user: From the mapsecrets file - see config.html from the base documentation
+
+=head1 VERSION
+
+$Id: freeside-expiration-alerter,v 1.1 2002-03-06 22:44:13 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 AUTHOR
+
+Jeff Finucane <jeff@cmh.net>
+
+=cut
+
+
diff --git a/README.1.4.0pre12 b/README.1.4.0pre12
index aba8b7a37..0b453a4e4 100644
--- a/README.1.4.0pre12
+++ b/README.1.4.0pre12
@@ -19,5 +19,7 @@ Run bin/create-history-tables
Run bin/dbdef-create again
+Arrange for freeside-expiration-alerter to be run daily, if desired.
+
Restart Apache and freeside-queued
diff --git a/conf/alerter_template b/conf/alerter_template
new file mode 100644
index 000000000..4d8a012ef
--- /dev/null
+++ b/conf/alerter_template
@@ -0,0 +1,20 @@
+
+
+Ivan Kohler
+1339 Hayes St.
+San Francisco, CA 94117
+
+
+{ $first; } { $last; }:
+
+ We thank you for your continuing patronage. This notice is to remind you
+that your { $payby } used to pay SISD.COM for Internet
+service will expire on { use Date::Format; time2str("%x", $expdate); }. Please provide us with new billing
+information so that we may continue your service uninterrupted.
+
+Very Truly Yours,
+
+ SISD Service Team
+
+
+
diff --git a/httemplate/docs/admin.html b/httemplate/docs/admin.html
index 16d492095..64da760f3 100755
--- a/httemplate/docs/admin.html
+++ b/httemplate/docs/admin.html
@@ -70,6 +70,12 @@
information for your locales by clicking on the <u>View/Edit locales and tax
rates</b> on the main menu.
+ <li>If you would like Freeside to notify your customers when their credit
+ cards and other billing arrangements are about to expire, arrange for
+ <b>freeside-expiration-alerter</b> to be run daily by cron or similar
+ facility. The message it sends can be configured from the
+ <u>Configuration</u> choice of the main menu as <u>alerter_template</u>.
+
</ul>
</body>
</html>