summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2004-01-09 22:11:54 +0000
committerivan <ivan>2004-01-09 22:11:54 +0000
commitf3212b82d6d54500bbe31c02c8ffa456f018a067 (patch)
tree71af32913a105b30f105a0eeb2bab4caa668ff38
parente68e85f88922d6678a9c6fc1a7624065e38b7361 (diff)
add deletecredits config value to enable deletion of credits
-rw-r--r--FS/FS/Conf.pm9
-rw-r--r--FS/FS/cust_credit.pm59
-rw-r--r--FS/FS/cust_credit_bill.pm5
-rwxr-xr-xhttemplate/misc/delete-cust_credit.cgi16
-rwxr-xr-xhttemplate/view/cust_main.cgi11
5 files changed, 96 insertions, 4 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 2404e59..11243a9 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -332,7 +332,14 @@ httemplate/docs/config.html
{
'key' => 'deletepayments',
'section' => 'UI',
- 'description' => '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.',
+ 'description' => '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.',
+ 'type' => [qw( checkbox text )],
+ },
+
+ {
+ 'key' => 'deletecredits',
+ 'section' => 'UI',
+ 'description' => 'Enable deletion of unclosed credits. Be very careful! Only delete credits that were data-entry errors, not adjustments. Optionally specify one or more comma-separated email addresses to be notified when a credit is deleted.',
'type' => [qw( checkbox text )],
},
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 18ab1c3..90f9b59 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -130,7 +130,64 @@ Currently unimplemented.
sub delete {
my $self = shift;
return "Can't delete closed credit" 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_bill ( $self->cust_credit_bill ) {
+ my $error = $cust_credit_bill->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ my $error = $self->SUPER::delete(@_);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ if ( $conf->config('deletecredits') ne '' ) {
+
+ my $cust_main = qsearchs('cust_main',{ 'custnum' => $self->custnum });
+
+ my $error = send_email(
+ 'from' => $conf->config('invoice_from'), #??? well as good as any
+ 'to' => $conf->config('deletecredits'),
+ 'subject' => 'FREESIDE NOTIFICATION: Credit deleted',
+ 'body' => [
+ "This is an automatic message from your Freeside installation\n",
+ "informing you that the following credit has been deleted:\n",
+ "\n",
+ 'crednum: '. $self->crednum. "\n",
+ 'custnum: '. $self->custnum.
+ " (". $cust_main->last. ", ". $cust_main->first. ")\n",
+ 'amount: $'. sprintf("%.2f", $self->amount). "\n",
+ 'date: '. time2str("%a %b %e %T %Y", $self->_date). "\n",
+ 'reason: '. $self->reason. "\n",
+ ],
+ );
+
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't send credit deletion notification: $error";
+ }
+
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ '';
+
}
=item replace OLD_RECORD
diff --git a/FS/FS/cust_credit_bill.pm b/FS/FS/cust_credit_bill.pm
index 88a732b..bd76c2e 100644
--- a/FS/FS/cust_credit_bill.pm
+++ b/FS/FS/cust_credit_bill.pm
@@ -96,7 +96,10 @@ Currently unimplemented.
=cut
sub delete {
- return "Can't unapply credit!"
+ my $self = shift;
+ return "Can't delete application for closed credit"
+ if $self->cust_credit->closed =~ /^Y/i;
+ $self->SUPER::delete(@_);
}
=item replace OLD_RECORD
diff --git a/httemplate/misc/delete-cust_credit.cgi b/httemplate/misc/delete-cust_credit.cgi
new file mode 100755
index 0000000..30de04d
--- /dev/null
+++ b/httemplate/misc/delete-cust_credit.cgi
@@ -0,0 +1,16 @@
+<%
+
+#untaint crednum
+my($query) = $cgi->keywords;
+$query =~ /^(\d+)$/ || die "Illegal crednum";
+my $crednum = $1;
+
+my $cust_credit = qsearchs('cust_credit',{'crednum'=>$crednum});
+my $custnum = $cust_credit->custnum;
+
+my $error = $cust_credit->delete;
+eidiot($error) if $error;
+
+print $cgi->redirect($p. "view/cust_main.cgi?". $custnum);
+
+%>
diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi
index fb01567..8123b2f 100755
--- a/httemplate/view/cust_main.cgi
+++ b/httemplate/view/cust_main.cgi
@@ -554,6 +554,11 @@ function cust_pay_unapply_areyousure(href) {
== true)
window.location.href = href;
}
+function cust_credit_areyousure(href) {
+ if (confirm("Are you sure you want to delete this credit?")
+ == true)
+ window.location.href = href;
+}
</SCRIPT>
END
@@ -628,9 +633,13 @@ if ( $conf->config('payby-default') ne 'HIDE' ) {
$cust_credit->reason,
time2str("%D", $cust_credit_bill->_date),
);
+ my $delete =
+ $cust_credit->closed !~ /^Y/i && $conf->exists('deletecredits')
+ ? qq! (<A HREF="javascript:cust_credit_areyousure('${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum. qq!')">delete</A>)!
+ : '';
push @history,
"$date\tCredit #$crednum: $reason<BR>".
- "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t";
+ "(applied to invoice #$invnum on $app_date)$delete\t\t\t$amount\t";
}
}