migrate send_email, suspend_if_balance and credit events, RT#3905
authorivan <ivan>
Sat, 11 Apr 2009 21:42:52 +0000 (21:42 +0000)
committerivan <ivan>
Sat, 11 Apr 2009 21:42:52 +0000 (21:42 +0000)
FS/FS/part_event/Action/writeoff.pm [new file with mode: 0644]
bin/freeside-migrate-events

diff --git a/FS/FS/part_event/Action/writeoff.pm b/FS/FS/part_event/Action/writeoff.pm
new file mode 100644 (file)
index 0000000..fdea897
--- /dev/null
@@ -0,0 +1,33 @@
+package FS::part_event::Action::writeoff;
+
+use strict;
+use base qw( FS::part_event::Action );
+
+sub description { 'Write off bad debt with a credit entry.'; }
+
+sub option_fields {
+  ( 
+    #'charge' => { label=>'Amount', type=>'money', }, # size=>7, },
+    'reasonnum' => { 'label'        => 'Reason',
+                     'type'         => 'select-reason',
+                     'reason_class' => 'R',
+                   },
+  );
+}
+
+sub default_weight { 65; }
+
+sub do_action {
+  my( $self, $cust_object ) = @_;
+
+  my $cust_main = $self->cust_main($cust_object);
+
+  my $error = $cust_main->credit( $cust_main->balance,
+                                  $self->option('reasonnum'),
+                                );
+  die $error if $error;
+
+  '';
+}
+
+1;
index 76643b8..4b46393 100644 (file)
@@ -16,20 +16,20 @@ my %plan2action = (
   'fee'                    => 'fee',
   'fee_percent'            => 'NOTYET', #XXX need fee_percent action
   'suspend'                => 'suspend',
   'fee'                    => 'fee',
   'fee_percent'            => 'NOTYET', #XXX need fee_percent action
   'suspend'                => 'suspend',
-  'suspend-if-balance'     => 'NOTYET', #XXX "if balance" becomes a balance condition
+  'suspend-if-balance'     => 'suspend', #"if balance" becomes the balance cond
   'suspend-if-pkgpart'     => 'suspend_if_pkgpart',
   'suspend-unless-pkgpart' => 'suspend_unless_pkgpart',
   'cancel'                 => 'cancel',
   'addpost'                => 'addpost',
   'comp'                   => 'NOTYET', #XXX or N/A or something
   'suspend-if-pkgpart'     => 'suspend_if_pkgpart',
   'suspend-unless-pkgpart' => 'suspend_unless_pkgpart',
   'cancel'                 => 'cancel',
   'addpost'                => 'addpost',
   'comp'                   => 'NOTYET', #XXX or N/A or something
-  'credit'                 => 'NOTYET',
+  'credit'                 => 'writeoff',
   'realtime-card'          => 'cust_bill_realtime_card',
   'realtime-check'         => 'cust_bill_realtime_check',
   'realtime-lec'           => 'cust_bill_realtime_lec',
   'batch-card'             => 'cust_bill_batch',
   #?'retriable'             =>
   'send'                   => 'cust_bill_send',
   'realtime-card'          => 'cust_bill_realtime_card',
   'realtime-check'         => 'cust_bill_realtime_check',
   'realtime-lec'           => 'cust_bill_realtime_lec',
   'batch-card'             => 'cust_bill_batch',
   #?'retriable'             =>
   'send'                   => 'cust_bill_send',
-  'send_email'             => 'NOTYET', 
+  'send_email'             => 'cust_bill_email',
   'send_alternate'         => 'cust_bill_send_alternate',
   'send_if_newest'         => 'cust_bill_send_if_newest',
   'send_agent'             => 'cust_bill_send_agent',
   'send_alternate'         => 'cust_bill_send_alternate',
   'send_if_newest'         => 'cust_bill_send_if_newest',
   'send_agent'             => 'cust_bill_send_agent',
@@ -64,7 +64,15 @@ foreach my $part_bill_event (
   my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
                      split(/\n/, $part_bill_event->plandata);
 
   my %plandata = map { /^(\w+) (.*)$/; ($1, $2); }
                      split(/\n/, $part_bill_event->plandata);
 
-  #XXX may need to fudge some plandata2option names!!!
+  #XXX may need to fudge some other plandata2option names
+
+  my $balanceover = 0;
+  my $honor_dundate = 0;
+
+  if ( $part_bill_event->plan eq 'suspend-if-balance' ) {
+    $balanceover = delete $plandata{'balanceover'};
+    $honor_dundate = ( (delete $plandata{'balance_honor_dundate'}) =~ /1/ );
+  }
 
   my $part_event = new FS::part_event {
     'event'      => $part_bill_event->event,
 
   my $part_event = new FS::part_event {
     'event'      => $part_bill_event->event,
@@ -86,12 +94,12 @@ foreach my $part_bill_event (
   };
   $error = $once->insert;
   die $error if $error;
   };
   $error = $once->insert;
   die $error if $error;
-  
+
   my $balance = new FS::part_event_condition {
     'eventpart'     => $part_event->eventpart,
     'conditionname' => 'balance'
   };
   my $balance = new FS::part_event_condition {
     'eventpart'     => $part_event->eventpart,
     'conditionname' => 'balance'
   };
-  $error = $balance->insert( 'balance' => 0 );
+  $error = $balance->insert( 'balance' => $balanceover );
   die $error if $error;
 
   my $cust_bill_owed = new FS::part_event_condition {
   die $error if $error;
 
   my $cust_bill_owed = new FS::part_event_condition {
@@ -118,6 +126,15 @@ foreach my $part_bill_event (
     die $error if $error;
 
   }
     die $error if $error;
 
   }
+
+  if ( $honor_dundate ) { 
+    my $dundate = new FS::part_event_condition {
+      'eventpart'     => $part_event->eventpart,
+      'conditionname' => 'dundate'
+    };
+    $error = $dundate->insert();
+    die $error if $error;
+  }
   
   #my $derror = $part_bill_event->delete;
   #die "error removing part_bill_event: $derror\n" if $derror;
   
   #my $derror = $part_bill_event->delete;
   #die "error removing part_bill_event: $derror\n" if $derror;