[freeside-commits] freeside/FS/FS Conf.pm, 1.176, 1.177 Schema.pm,
1.43, 1.44 cust_main.pm, 1.263, 1.264 cust_pkg.pm, 1.70,
1.71 cust_pkg_option.pm, NONE, 1.1
Jeff Finucane,420,,
jeff at wavetail.420.am
Tue Jan 23 15:43:01 PST 2007
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv714/FS/FS
Modified Files:
Conf.pm Schema.pm cust_main.pm cust_pkg.pm
Added Files:
cust_pkg_option.pm
Log Message:
notices before first charge on flat_delayed
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- Schema.pm 21 Jan 2007 21:45:28 -0000 1.43
+++ Schema.pm 23 Jan 2007 23:42:59 -0000 1.44
@@ -654,6 +654,18 @@
'index' => [ ['custnum'], ['pkgpart'] ],
},
+ 'cust_pkg_option' => {
+ 'columns' => [
+ 'optionnum', 'serial', '', '', '', '',
+ 'pkgnum', 'int', '', '', '', '',
+ 'optionname', 'varchar', '', $char_d, '', '',
+ 'optionvalue', 'text', 'NULL', '', '', '',
+ ],
+ 'primary_key' => 'optionnum',
+ 'unique' => [],
+ 'index' => [ [ 'pkgnum' ], [ 'optionname' ] ],
+ },
+
'cust_pkg_reason' => {
'columns' => [
'num', 'serial', '', '', '', '',
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- Conf.pm 15 Jan 2007 07:22:40 -0000 1.176
+++ Conf.pm 23 Jan 2007 23:42:59 -0000 1.177
@@ -2030,6 +2030,13 @@
'type' => 'textarea',
},
+ {
+ 'key' => 'impending_recur_template',
+ 'section' => 'billing',
+ 'description' => 'Template file for alerts about looming first time recurrant billing. See the <a href="../docs/billing.html#invoice_template">billing documentation</a> for details. Also see packages with a <a href="../browse/part_pkg.cgi">flat price plan</a>',
+ 'type' => 'textarea',
+ },
+
);
1;
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.263
retrieving revision 1.264
diff -u -d -r1.263 -r1.264
--- cust_main.pm 21 Jan 2007 21:45:28 -0000 1.263
+++ cust_main.pm 23 Jan 2007 23:42:59 -0000 1.264
@@ -1011,7 +1011,9 @@
my %hash = $cust_pkg->hash;
$hash{'custnum'} = $new_custnum;
my $new_cust_pkg = new FS::cust_pkg ( \%hash );
- my $error = $new_cust_pkg->replace($cust_pkg);
+ my $error = $new_cust_pkg->replace($cust_pkg,
+ options => { $cust_pkg->options },
+ );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -1978,12 +1980,14 @@
# If $cust_pkg has been modified, update it and create cust_bill_pkg records
###
- if ( $cust_pkg->modified ) {
+ if ( $cust_pkg->modified ) { # hmmm.. and if the options are modified?
warn " package ". $cust_pkg->pkgnum. " modified; updating\n"
if $DEBUG >1;
- $error=$cust_pkg->replace($old_cust_pkg);
+ $error=$cust_pkg->replace($old_cust_pkg,
+ options => { $cust_pkg->options },
+ );
if ( $error ) { #just in case
$dbh->rollback if $oldAutoCommit;
return "Error modifying pkgnum ". $cust_pkg->pkgnum. ": $error";
@@ -4677,6 +4681,94 @@
}
+=item notify CUSTOMER_OBJECT TEMPLATE_NAME OPTIONS
+
+Sends a templated email notification to the customer (see L<Text::Template).
+
+OPTIONS is a hash and may include
+
+I<from> - the email sender (default is invoice_from)
+
+I<to> - comma-separated scalar or arrayref of recipients
+ (default is invoicing_list)
+
+I<subject> - The subject line of the sent email notification
+ (default is "Notice from company_name")
+
+I<extra_fields> - a hashref of name/value pairs which will be substituted
+ into the template
+
+The following variables are vavailable in the template.
+
+I<$first> - the customer first name
+I<$last> - the customer last name
+I<$company> - the customer company
+I<$payby> - a description of the method of payment for the customer
+ # would be nice to use FS::payby::shortname
+I<$payinfo> - the account information used to collect for this customer
+I<$expdate> - the expiration of the customer payment in seconds from epoch
+
+=cut
+
+sub notify {
+ my ($customer, $template, %options) = @_;
+
+ return unless $conf->exists($template);
+
+ my $from = $conf->config('invoice_from') if $conf->exists('invoice_from');
+ $from = $options{from} if exists($options{from});
+
+ my $to = join(',', $customer->invoicing_list_emailonly);
+ $to = $options{to} if exists($options{to});
+
+ my $subject = "Notice from " . $conf->config('company_name')
+ if $conf->exists('company_name');
+ $subject = $options{subject} if exists($options{subject});
+
+ my $notify_template = new Text::Template (TYPE => 'ARRAY',
+ SOURCE => [ map "$_\n",
+ $conf->config($template)]
+ )
+ or die "can't create new Text::Template object: Text::Template::ERROR";
+ $notify_template->compile()
+ or die "can't compile template: Text::Template::ERROR";
+
+ my $paydate = $customer->paydate;
+ $FS::notify_template::_template::first = $customer->first;
+ $FS::notify_template::_template::last = $customer->last;
+ $FS::notify_template::_template::company = $customer->company;
+ $FS::notify_template::_template::payinfo = $customer->mask_payinfo;
+ my $payby = $customer->payby;
+ 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' || $payby eq 'DCRD') {
+ $FS::notify_template::_template::payby = 'credit card';
+ ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++);
+ $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear);
+ $expire_time--;
+ }elsif ($payby eq 'COMP') {
+ $FS::notify_template::_template::payby = 'complimentary account';
+ }else{
+ $FS::notify_template::_template::payby = 'current method';
+ }
+ $FS::notify_template::_template::expdate = $expire_time;
+
+ for (keys %{$options{extra_fields}}){
+ no strict "refs";
+ ${"FS::notify_template::_template::$_"} = $options{extra_fields}->{$_};
+ }
+
+ send_email(from => $from,
+ to => $to,
+ subject => $subject,
+ body => $notify_template->fill_in( PACKAGE =>
+ 'FS::notify_template::_template' ),
+ );
+
+}
+
=back
=head1 BUGS
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- cust_pkg.pm 17 Jan 2007 17:41:48 -0000 1.70
+++ cust_pkg.pm 23 Jan 2007 23:42:59 -0000 1.71
@@ -30,7 +30,7 @@
# for sending cancel emails in sub cancel
use FS::Conf;
- at ISA = qw( FS::cust_main_Mixin FS::Record );
+ at ISA = qw( FS::cust_main_Mixin FS::option_Common FS::Record );
$DEBUG = 0;
@@ -174,7 +174,7 @@
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my $error = $self->SUPER::insert;
+ my $error = $self->SUPER::insert($options{options} ? %{$options{options}} : ());
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -318,7 +318,9 @@
}
- my $error = $new->SUPER::replace($old);
+ my $error = $new->SUPER::replace($old,
+ $options{options} ? ${options{options}} : ()
+ );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -483,7 +485,7 @@
my %hash = $self->hash;
$hash{'cancel'} = time;
my $new = new FS::cust_pkg ( \%hash );
- $error = $new->replace($self);
+ $error = $new->replace( $self, options => { $self->options } );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -568,7 +570,7 @@
my %hash = $self->hash;
$hash{'susp'} = time;
my $new = new FS::cust_pkg ( \%hash );
- $error = $new->replace($self);
+ $error = $new->replace( $self, options => { $self->options } );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -649,7 +651,7 @@
$hash{'susp'} = '';
my $new = new FS::cust_pkg ( \%hash );
- $error = $new->replace($self);
+ $error = $new->replace( $self, options => { $self->options } );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
--- NEW FILE: cust_pkg_option.pm ---
package FS::cust_pkg_option;
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
@ISA = qw(FS::Record);
=head1 NAME
FS::cust_pkg_option - Object methods for cust_pkg_option records
=head1 SYNOPSIS
use FS::cust_pkg_option;
$record = new FS::cust_pkg_option \%hash;
$record = new FS::cust_pkg_option { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::cust_pkg_option object represents an option key an value for a
customer package. FS::cust_pkg_option inherits from
FS::Record. The following fields are currently supported:
=over 4
=item optionnum - primary key
=item pkgnum -
=item optionname -
=item optionvalue -
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new option. To add the option to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
sub table { 'cust_pkg_option'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
=item delete
Delete this record from the database.
=cut
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
=item check
Checks all fields to make sure this is a valid option. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
sub check {
my $self = shift;
my $error =
$self->ut_numbern('optionnum')
|| $self->ut_foreign_key('pkgnum', 'cust_pkg', 'pkgnum')
|| $self->ut_text('optionname')
|| $self->ut_textn('optionvalue')
;
return $error if $error;
$self->SUPER::check;
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::Record>, L<FS::cust_pkg>, schema.html from the base documentation.
=cut
1;
More information about the freeside-commits
mailing list