add last_bill field to manpage
[freeside.git] / FS / FS / cust_pkg.pm
index c15e2fe..9f20603 100644 (file)
@@ -2,8 +2,10 @@ package FS::cust_pkg;
 
 use strict;
 use vars qw(@ISA $disable_agentcheck);
+use vars qw( $quiet );
 use FS::UID qw( getotaker dbh );
 use FS::Record qw( qsearch qsearchs );
+use FS::Misc qw( send_email );
 use FS::cust_svc;
 use FS::part_pkg;
 use FS::cust_main;
@@ -19,6 +21,9 @@ use FS::svc_domain;
 use FS::svc_www;
 use FS::svc_forward;
 
+# for sending cancel emails in sub cancel
+use FS::Conf;
+
 @ISA = qw( FS::Record );
 
 $disable_agentcheck = 0;
@@ -95,6 +100,8 @@ inherits from FS::Record.  The following fields are currently supported:
 
 =item bill - date (next bill date)
 
+=item last_bill - last bill date
+
 =item susp - date
 
 =item expire - date
@@ -295,7 +302,21 @@ sub cancel {
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
+  my $conf = new FS::Conf;
+  my @invoicing_list = grep { $_ ne 'POST' } $self->cust_main->invoicing_list;
+  if ( !$quiet && $conf->exists('emailcancel') && @invoicing_list ) {
+    my $conf = new FS::Conf;
+    my $error = send_email(
+      'from'    => $conf->config('invoice_from'),
+      'to'      => \@invoicing_list,
+      'subject' => $conf->config('cancelsubject'),
+      'body'    => [ map "$_\n", $conf->config('cancelmessage') ],
+    );
+    #should this do something on errors?
+  }
+
   ''; #no errors
+
 }
 
 =item suspend
@@ -433,6 +454,10 @@ Useful for billing metered services.
 
 sub last_bill {
   my $self = shift;
+  if ( $self->dbdef_table->column('last_bill') ) {
+    return $self->setfield('last_bill', $_[0]) if @_;
+    return $self->getfield('last_bill') if $self->getfield('last_bill');
+  }    
   my $cust_bill_pkg = qsearchs('cust_bill_pkg', { 'pkgnum' => $self->pkgnum,
                                                   'edate'  => $self->bill,  } );
   $cust_bill_pkg ? $cust_bill_pkg->sdate : $self->setup || 0;