remove
[freeside.git] / FS / FS / cust_main.pm
index 3995e65..8a7a6f8 100644 (file)
@@ -28,6 +28,7 @@ use FS::cust_credit_bill;
 use FS::cust_bill_pay;
 use FS::prepay_credit;
 use FS::queue;
+use FS::part_pkg;
 
 @ISA = qw( FS::Record );
 
@@ -346,6 +347,7 @@ sub insert {
     }
   }
 
+  #false laziness with sub replace
   my $queue = new FS::queue { 'job' => 'FS::cust_main::append_fuzzyfiles' };
   $error = $queue->insert($self->getfield('last'), $self->company);
   if ( $error ) {
@@ -361,6 +363,7 @@ sub insert {
       return "queueing job (transaction rolled back): $error";
     }
   }
+  #eslaf
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
@@ -508,6 +511,24 @@ sub replace {
     $self->invoicing_list( $invoicing_list );
   }
 
+  #false laziness with sub insert
+  my $queue = new FS::queue { 'job' => 'FS::cust_main::append_fuzzyfiles' };
+  $error = $queue->insert($self->getfield('last'), $self->company);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return "queueing job (transaction rolled back): $error";
+  }
+
+  if ( defined $self->dbdef_table->column('ship_last') && $self->ship_last ) {
+    $queue = new FS::queue { 'job' => 'FS::cust_main::append_fuzzyfiles' };
+    $error = $queue->insert($self->getfield('last'), $self->company);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "queueing job (transaction rolled back): $error";
+    }
+  }
+  #eslaf
+
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
 
@@ -810,6 +831,18 @@ sub suspend {
   grep { $_->suspend } $self->unsuspended_pkgs;
 }
 
+=item cancel
+
+Cancels all uncancelled packages (see L<FS::cust_pkg>) for this customer.
+Always returns a list: an empty list on success or a list of errors.
+
+=cut
+
+sub cancel {
+  my $self = shift;
+  grep { $_->cancel } $self->ncancelled_pkgs;
+}
+
 =item bill OPTIONS
 
 Generates invoices (see L<FS::cust_bill>) for this customer.  Usually used in
@@ -1066,6 +1099,9 @@ CyberCash is not installed.
 report_badcard - Set this true if you want bad card transactions to
 return an error.  By default, they don't.
 
+force_print - force printing even if invoice has been printed more than once
+every 30 days, and don't increment the `printed' field.
+
 =cut
 
 sub collect {
@@ -1117,7 +1153,8 @@ sub collect {
       my $since = $invoice_time - ( $cust_bill->_date || 0 );
       #warn "$invoice_time ", $cust_bill->_date, " $since";
       if ( $since >= 0 #don't print future invoices
-           && ( $cust_bill->printed * 2592000 ) <= $since
+           && ( ( $cust_bill->printed * 2592000 ) <= $since
+                || $options{'force_print'} )
       ) {
 
         #my @print_text = $cust_bill->print_text; #( date )
@@ -1147,11 +1184,13 @@ sub collect {
                          : "Exit status $? from $lpr";
         }
 
-        my %hash = $cust_bill->hash;
-        $hash{'printed'}++;
-        my $new_cust_bill = new FS::cust_bill(\%hash);
-        my $error = $new_cust_bill->replace($cust_bill);
-        warn "Error updating $cust_bill->printed: $error" if $error;
+        unless ( $options{'force_print'} ) {
+          my %hash = $cust_bill->hash;
+          $hash{'printed'}++;
+          my $new_cust_bill = new FS::cust_bill(\%hash);
+          my $error = $new_cust_bill->replace($cust_bill);
+          warn "Error updating $cust_bill->printed: $error" if $error;
+        }
 
       }
 
@@ -1695,7 +1734,7 @@ sub check_invoicing_list {
 
 =item default_invoicing_list
 
-Returns the email addresses of any 
+Sets the invoicing list to all accounts associated with this customer.
 
 =cut
 
@@ -1713,6 +1752,21 @@ sub default_invoicing_list {
   $self->invoicing_list(\@list);
 }
 
+=item invoicing_list_addpost
+
+Adds postal invoicing to this customer.  If this customer is already configured
+to receive postal invoices, does nothing.
+
+=cut
+
+sub invoicing_list_addpost {
+  my $self = shift;
+  return if grep { $_ eq 'POST' } $self->invoicing_list;
+  my @invoicing_list = $self->invoicing_list;
+  push @invoicing_list, 'POST';
+  $self->invoicing_list(\@invoicing_list);
+}
+
 =item referral_cust_main [ DEPTH [ EXCLUDE_HASHREF ] ]
 
 Returns an array of customers referred by this customer (referral_custnum set
@@ -1775,6 +1829,29 @@ sub credit {
   $cust_credit->insert;
 }
 
+=item charge AMOUNT PKG COMMENT
+
+Creates a one-time charge for this customer.  If there is an error, returns
+the error, otherwise returns false.
+
+=cut
+
+sub charge {
+  my ( $self, $amount, $pkg, $comment ) = @_;
+
+  my $part_pkg = new FS::part_pkg ( {
+    'pkg'      => $pkg || 'One-time charge',
+    'comment'  => $comment,
+    'setup'    => $amount,
+    'freq'     => 0,
+    'recur'    => '0',
+    'disabled' => 'Y',
+  } );
+
+  $part_pkg->insert;
+
+}
+
 =back
 
 =head1 SUBROUTINES
@@ -1916,7 +1993,7 @@ sub append_fuzzyfiles {
 
 =head1 VERSION
 
-$Id: cust_main.pm,v 1.51 2001-12-26 11:17:49 ivan Exp $
+$Id: cust_main.pm,v 1.55 2002-01-29 16:33:15 ivan Exp $
 
 =head1 BUGS