diff options
| -rw-r--r-- | FS/FS/cust_bill_pay.pm | 6 | ||||
| -rw-r--r-- | FS/FS/cust_credit_refund.pm | 6 | ||||
| -rw-r--r-- | FS/FS/cust_pay.pm | 57 | ||||
| -rw-r--r-- | FS/FS/cust_refund.pm | 55 | ||||
| -rwxr-xr-x | bin/fs-migrate-payref | 30 | 
5 files changed, 144 insertions, 10 deletions
| diff --git a/FS/FS/cust_bill_pay.pm b/FS/FS/cust_bill_pay.pm index fea6aee02..ac82c542d 100644 --- a/FS/FS/cust_bill_pay.pm +++ b/FS/FS/cust_bill_pay.pm @@ -1,4 +1,4 @@ -package cust_bill_pay; +package FS::cust_bill_pay;  use strict;  use vars qw( @ISA ); @@ -156,7 +156,7 @@ sub check {    my $error =       $self->ut_numbern('billpaynum')      || $self->ut_number('invnum') -    || $self->ut_numner('paynum') +    || $self->ut_number('paynum')      || $self->ut_money('amount')      || $self->ut_numbern('_date')    ; @@ -194,7 +194,7 @@ sub cust_bill {  =head1 VERSION -$Id: cust_bill_pay.pm,v 1.5 2001-09-02 04:25:55 ivan Exp $ +$Id: cust_bill_pay.pm,v 1.6 2001-09-02 05:38:13 ivan Exp $  =head1 BUGS diff --git a/FS/FS/cust_credit_refund.pm b/FS/FS/cust_credit_refund.pm index 200e34e55..4c5195717 100644 --- a/FS/FS/cust_credit_refund.pm +++ b/FS/FS/cust_credit_refund.pm @@ -1,4 +1,4 @@ -package cust_credit_refund; +package FS::cust_credit_refund;  use strict;  use vars qw( @ISA ); @@ -141,7 +141,7 @@ sub check {    my $error =       $self->ut_numbern('creditrefundnum')      || $self->ut_number('crednum') -    || $self->ut_numner('refundnum') +    || $self->ut_number('refundnum')      || $self->ut_money('amount')      || $self->ut_numbern('_date')    ; @@ -170,7 +170,7 @@ sub cust_refund {  =head1 VERSION -$Id: cust_credit_refund.pm,v 1.2 2001-09-02 01:27:11 ivan Exp $ +$Id: cust_credit_refund.pm,v 1.3 2001-09-02 05:38:13 ivan Exp $  =head1 BUGS diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index a70b7cb37..70d1b7314 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -105,6 +105,9 @@ sub insert {        $dbh->rollback if $oldAutoCommit;        return $error;      } +    warn $cust_bill_pay; +    warn $cust_bill_pay->cust_bill; +    warn $cust_bill_pay->cust_bill->custnum;      $self->custnum($cust_bill_pay->cust_bill->custnum);    } @@ -120,6 +123,56 @@ sub insert {  } +sub upgrade_replace { #1.3.x->1.4.x +  my $self = shift; + +  local $SIG{HUP} = 'IGNORE'; +  local $SIG{INT} = 'IGNORE'; +  local $SIG{QUIT} = 'IGNORE'; +  local $SIG{TERM} = 'IGNORE'; +  local $SIG{TSTP} = 'IGNORE'; +  local $SIG{PIPE} = 'IGNORE'; + +  my $oldAutoCommit = $FS::UID::AutoCommit; +  local $FS::UID::AutoCommit = 0; +  my $dbh = dbh; + +  my $error = $self->check; +  return $error if $error; + +  my %new = $self->hash; +  my $new = FS::cust_pay->new(\%new); + +  if ( $self->invnum ) { +    my $cust_bill_pay = new FS::cust_bill_pay { +      'invnum' => $self->invnum, +      'paynum' => $self->paynum, +      'amount' => $self->paid, +      '_date'  => $self->_date, +    }; +    $error = $cust_bill_pay->insert; +    if ( $error ) { +      $dbh->rollback if $oldAutoCommit; +      return $error; +    } +    $new->custnum($cust_bill_pay->cust_bill->custnum); +  } else { +    die; +  } + +  $error = $new->SUPER::replace($self); +  if ( $error ) { +    $dbh->rollback if $oldAutoCommit; +    return $error; +  } + +  $dbh->commit or die $dbh->errstr if $oldAutoCommit; + +  ''; + + +} +  =item delete  Currently unimplemented (accounting reasons). @@ -152,7 +205,7 @@ sub check {    my $error =      $self->ut_numbern('paynum') -    || $self->ut_number('custnum') +    || $self->ut_numbern('custnum')      || $self->ut_money('paid')      || $self->ut_numbern('_date')      || $self->ut_textn('paybatch') @@ -223,7 +276,7 @@ sub unapplied {  =head1 VERSION -$Id: cust_pay.pm,v 1.5 2001-09-02 02:46:55 ivan Exp $ +$Id: cust_pay.pm,v 1.6 2001-09-02 05:38:13 ivan Exp $  =head1 BUGS diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 89f8f68c5..77bacdffb 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -96,9 +96,11 @@ sub insert {    my $error = $self->check;    return $error if $error; +  die; +    if ( $self->crednum ) {      my $cust_credit_refund = new FS::cust_credit_refund { -      'cred'      => $self->cred, +      'crednum'   => $self->crednum,        'refundnum' => $self->refundnum,        'amount'    => $self->refund,        '_date'     => $self->_date, @@ -123,6 +125,55 @@ sub insert {  } +sub upgrade_replace { +  my $self = shift; + +  local $SIG{HUP} = 'IGNORE'; +  local $SIG{INT} = 'IGNORE'; +  local $SIG{QUIT} = 'IGNORE'; +  local $SIG{TERM} = 'IGNORE'; +  local $SIG{TSTP} = 'IGNORE'; +  local $SIG{PIPE} = 'IGNORE'; + +  my $oldAutoCommit = $FS::UID::AutoCommit; +  local $FS::UID::AutoCommit = 0; +  my $dbh = dbh; + +  my $error = $self->check; +  return $error if $error; + +  my %new = $self->hash; +  my $new = FS::cust_refund->new(\%new); + +  if ( $self->crednum ) { +    my $cust_credit_refund = new FS::cust_credit_refund { +      'crednum'   => $self->crednum, +      'refundnum' => $self->refundnum, +      'amount'    => $self->refund, +      '_date'     => $self->_date, +    }; +    $error = $cust_credit_refund->insert; +    if ( $error ) { +      $dbh->rollback if $oldAutoCommit; +      return $error; +    } +    $new->custnum($cust_credit_refund->cust_credit->custnum); +  } else { +    die; +  } + +  $error = $new->SUPER::insert($self); +  if ( $error ) { +    $dbh->rollback if $oldAutoCommit; +    return $error; +  } + +  $dbh->commit or die $dbh->errstr if $oldAutoCommit; + +  ''; + +} +  =item delete  Currently unimplemented (accounting reasons). @@ -198,7 +249,7 @@ sub check {  =head1 VERSION -$Id: cust_refund.pm,v 1.7 2001-09-02 04:25:55 ivan Exp $ +$Id: cust_refund.pm,v 1.8 2001-09-02 05:38:13 ivan Exp $  =head1 BUGS diff --git a/bin/fs-migrate-payref b/bin/fs-migrate-payref new file mode 100755 index 000000000..f1513112b --- /dev/null +++ b/bin/fs-migrate-payref @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +use strict; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_pay; +use FS::cust_refund; + +my $user = shift or die &usage; +my $dbh = adminsuidsetup $user; + +#local $FS::UID::AutoCommit = 0; #quelle hack, in this case +# $FS::UID::AutoCommit = 0; #quelle hack, in this case + +# apply payments to invoices + +foreach my $cust_pay ( qsearch('cust_pay', {} ) ) { +  my $error = $cust_pay->upgrade_replace; +  warn $error if $error; +} + +# apply refunds to credits + +foreach my $cust_refund ( qsearch('cust_refund') ) { +  my $error = $cust_refund->upgrade_replace; +  warn $error if $error; +} + +# ? apply credits to invoices + | 
