X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=bin%2Ffreeside-migrate-events;h=4b46393eb1a46983fc8aeffd9e5f3eaee70628b2;hb=794a4505360fec404e2b9d5c6daf79f750186bfe;hp=74732b7f22822eb00435cb7840965296d9d9c9f6;hpb=eb4ff7f73c5d4bdf74a3472448b5a195598ff4cd;p=freeside.git diff --git a/bin/freeside-migrate-events b/bin/freeside-migrate-events index 74732b7f2..4b46393eb 100644 --- a/bin/freeside-migrate-events +++ b/bin/freeside-migrate-events @@ -16,20 +16,20 @@ my %plan2action = ( '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 - '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', - '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', @@ -40,7 +40,6 @@ my %plan2action = ( 'collect' => 'collect', ); -#XXX may need to fudge some plandata2option names!!! foreach my $part_bill_event ( qsearch({ @@ -62,6 +61,19 @@ foreach my $part_bill_event ( next; } + my %plandata = map { /^(\w+) (.*)$/; ($1, $2); } + split(/\n/, $part_bill_event->plandata); + + #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, 'eventtable' => 'cust_bill', @@ -71,7 +83,7 @@ foreach my $part_bill_event ( 'disabled' => $part_bill_event->disabled, }; - my $error = $part_event->insert; + my $error = $part_event->insert(\%plandata); die "error inserting part_event: $error\n" if $error; print ' '. $part_event->eventpart; @@ -82,12 +94,19 @@ foreach my $part_bill_event ( }; $error = $once->insert; die $error if $error; - + 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 { + 'eventpart' => $part_event->eventpart, + 'conditionname' => 'cust_bill_owed' + }; + $error = $cust_bill_owed->insert( 'owed' => 0 ); die $error if $error; my $payby = new FS::part_event_condition { @@ -103,10 +122,19 @@ foreach my $part_bill_event ( 'eventpart' => $part_event->eventpart, 'conditionname' => 'cust_bill_age' }; - $error = $payby->insert( 'age' => ($part_bill_event->seconds/86400 ).'d' ); + $error = $age->insert( 'age' => ($part_bill_event->seconds/86400 ).'d' ); 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; @@ -127,7 +155,8 @@ foreach my $part_bill_event ( }; my $cerror = $cust_event->insert; - die "error inserting cust_event: $cerror\n" if $cerror; + #die "error inserting cust_event: $cerror\n" if $cerror; + warn "error inserting cust_event: $cerror\n" if $cerror; #my $dcerror = $cust_bill_event->delete; #die "error removing cust_bill_event: $dcerror\n" if $dcerror;