summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorjeff <jeff>2007-01-08 17:36:53 +0000
committerjeff <jeff>2007-01-08 17:36:53 +0000
commitb89c7f126690704c8d1558dba06d5fabd7470528 (patch)
tree7a1ce8e2d5675952f4a06472897cab9d19e01037 /FS
parent704992901b980cd3d41568d7fec0842b2a64bdf7 (diff)
refund deletion
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/AccessRight.pm2
-rw-r--r--FS/FS/Conf.pm7
-rw-r--r--FS/FS/cust_credit_refund.pm19
-rw-r--r--FS/FS/cust_pay_refund.pm15
-rw-r--r--FS/FS/cust_refund.pm42
5 files changed, 75 insertions, 10 deletions
diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm
index 4a6da083a..038cb4113 100644
--- a/FS/FS/AccessRight.pm
+++ b/FS/FS/AccessRight.pm
@@ -138,6 +138,8 @@ assigned to users and/or groups.
'Delete payment', #aka. deletepayments - Enable deletion of unclosed payments. Be very careful! Only delete payments that were data-entry errors, not adjustments. Optionally specify one or more comma-separated email addresses to be notified when a payment is deleted.
+ 'Delete refund',
+
###
# customer credit rights
###
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index f2fda8016..0d680b297 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -496,6 +496,13 @@ httemplate/docs/config.html
},
{
+ 'key' => 'deleterefunds',
+ 'section' => 'billing',
+ 'description' => 'Enable deletion of unclosed refunds. Be very careful! Only delete refunds that were data-entry errors, not adjustments.',
+ 'type' => 'checkbox',
+ },
+
+ {
'key' => 'unapplypayments',
'section' => 'deprecated',
'description' => '<B>DEPRECATED</B>, now controlled by ACLs. Used to enable "unapplication" of unclosed payments.',
diff --git a/FS/FS/cust_credit_refund.pm b/FS/FS/cust_credit_refund.pm
index 36c77aa59..f237efed2 100644
--- a/FS/FS/cust_credit_refund.pm
+++ b/FS/FS/cust_credit_refund.pm
@@ -70,20 +70,27 @@ otherwise returns false.
sub insert {
my $self = shift;
- my $error = $self->SUPER::insert;
- return $error if $error;
-
- '';
+ return "Can't apply refund to closed credit"
+ if $self->cust_credit->closed =~ /^Y/i;
+ return "Can't apply credit to closed refund"
+ if $self->cust_refund->closed =~ /^Y/i;
+ $self->SUPER::insert(@_);
}
=item delete
-Currently unimplemented (accounting reasons).
+Remove this cust_credit_refund from the database. If there is an error,
+returns the error, otherwise returns false.
=cut
sub delete {
- return "Can't (yet?) delete cust_credit_refund records!";
+ my $self = shift;
+ return "Can't remove refund from closed credit"
+ if $self->cust_credit->closed =~ /^Y/i;
+ return "Can't remove credit from closed refund"
+ if $self->cust_refund->closed =~ /^Y/i;
+ $self->SUPER::delete(@_);
}
=item replace OLD_RECORD
diff --git a/FS/FS/cust_pay_refund.pm b/FS/FS/cust_pay_refund.pm
index 15e0e533a..cb9dbcef2 100644
--- a/FS/FS/cust_pay_refund.pm
+++ b/FS/FS/cust_pay_refund.pm
@@ -73,15 +73,26 @@ sub table { 'cust_pay_refund'; }
Adds this cust_pay_refund to the database. If there is an error, returns the
error, otherwise returns false.
+=cut
+
+sub insert {
+ my $self = shift;
+ return "Can't apply refund to closed payment"
+ if $self->cust_pay->closed =~ /^Y/i;
+ return "Can't apply payment to closed refund"
+ if $self->cust_refund->closed =~ /^Y/i;
+ $self->SUPER::insert(@_);
+}
+
=item delete
=cut
sub delete {
my $self = shift;
- return "Can't apply refund to closed payment"
+ return "Can't remove refund from closed payment"
if $self->cust_pay->closed =~ /^Y/i;
- return "Can't apply closed refund"
+ return "Can't remove payment from closed refund"
if $self->cust_refund->closed =~ /^Y/i;
$self->SUPER::delete(@_);
}
diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm
index 3f17f9aa2..9cd9bf845 100644
--- a/FS/FS/cust_refund.pm
+++ b/FS/FS/cust_refund.pm
@@ -166,14 +166,52 @@ sub insert {
=item delete
-Currently unimplemented (accounting reasons).
+Unless the closed flag is set, deletes this refund and all associated
+applications (see L<FS::cust_credit_refund> and L<FS::cust_pay_refund>).
=cut
sub delete {
my $self = shift;
return "Can't delete closed refund" if $self->closed =~ /^Y/i;
- $self->SUPER::delete(@_);
+
+ 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;
+
+ foreach my $cust_credit_refund ( $self->cust_credit_refund ) {
+ my $error = $cust_credit_refund->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ foreach my $cust_pay_refund ( $self->cust_pay_refund ) {
+ my $error = $cust_pay_refund->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ my $error = $self->SUPER::delete(@_);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ '';
+
}
=item replace OLD_RECORD