delete payments
authorivan <ivan>
Thu, 7 Feb 2002 22:29:35 +0000 (22:29 +0000)
committerivan <ivan>
Thu, 7 Feb 2002 22:29:35 +0000 (22:29 +0000)
FS/FS/Conf.pm
FS/FS/cust_bill_pay.pm
FS/FS/cust_pay.pm
Makefile
httemplate/browse/agent_type.cgi
httemplate/browse/nas.cgi
httemplate/misc/delete-cust_pay.cgi [new file with mode: 0755]
httemplate/view/cust_main.cgi

index cc91e82..873ee75 100644 (file)
@@ -267,6 +267,13 @@ httemplate/docs/config.html
     'type'        => 'checkbox',
   },
 
+  {
+    'key'         => 'deletepayments',
+    'section'     => 'UI',
+    'description' => 'Enable deletion of unclosed payments.  Be very careful!  Only delete payments that were data-entry errors, not adjustments.',
+    'type'        => 'checkbox',
+  },
+
   {
     'key'         => 'dirhash',
     'section'     => 'shell',
index 1c838b9..913704b 100644 (file)
@@ -125,12 +125,16 @@ sub insert {
 
 =item delete
 
-Currently unimplemented (accounting reasons).
+Deletes this payment application, unless the closed flag for the parent payment
+(see L<FS::cust_pay>) is set.
 
 =cut
 
 sub delete {
-  return "Can't (yet?) delete cust_bill_pay records!";
+  my $self = shift;
+  return "Can't delete application for closed payment"
+    if $self->cust_pay->closed =~ /^Y/i;
+  $self->SUPER::delete(@_);
 }
 
 =item replace OLD_RECORD
@@ -195,7 +199,7 @@ sub cust_bill {
 
 =head1 VERSION
 
-$Id: cust_bill_pay.pm,v 1.11 2002-01-24 16:58:47 ivan Exp $
+$Id: cust_bill_pay.pm,v 1.12 2002-02-07 22:29:34 ivan Exp $
 
 =head1 BUGS
 
index 51c7b29..839571a 100644 (file)
@@ -211,14 +211,44 @@ sub upgrade_replace { #1.3.x->1.4.x
 
 =item delete
 
-Currently unimplemented (accounting reasons).
+Deletes this payment and all associated applications (see L<FS::cust_bill_pay>),
+unless the closed flag is set.
 
 =cut
 
 sub delete {
   my $self = shift;
   return "Can't delete closed payment" 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_bill_pay ( $self->cust_bill_pay ) {
+    my $error = $cust_bill_pay->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
@@ -318,7 +348,7 @@ sub unapplied {
 
 =head1 VERSION
 
-$Id: cust_pay.pm,v 1.15 2002-01-29 16:33:15 ivan Exp $
+$Id: cust_pay.pm,v 1.16 2002-02-07 22:29:34 ivan Exp $
 
 =head1 BUGS
 
index 0f86b49..e5b6ad1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,8 @@ aspdocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/*
        cp -pr httemplate aspdocs
        touch aspdocs
 
-masondocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
+#masondocs: htmlman httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
+masondocs: httemplate/* httemplate/*/* httemplate/*/*/* httemplate/*/*/*/* httemplate/*/*/*/*/*
        rm -rf masondocs
        cp -pr httemplate masondocs
        ( cd masondocs; \
index 8321048..d75c450 100755 (executable)
@@ -1,4 +1,4 @@
-<!-- $Id: agent_type.cgi,v 1.7 2002-01-30 14:18:08 ivan Exp $ -->
+<!-- $Id: agent_type.cgi,v 1.8 2002-02-07 22:29:34 ivan Exp $ -->
 <%
 
 print header("Agent Type Listing", menubar(
@@ -7,7 +7,7 @@ print header("Agent Type Listing", menubar(
     " particular agents.<BR><BR>", &table(), <<END;
       <TR>
         <TH COLSPAN=2>Agent Type</TH>
-        <TH COLSPAN="2">Packages</TH>
+        <TH COLSPAN=2>Packages</TH>
       </TR>
 END
 
@@ -47,7 +47,7 @@ END
 }
 
 print <<END;
-  <TR><TD COLSPAN=2><I><A HREF="${p}edit/agent_type.cgi">Add a new agent type</A></I></TD></TR>
+  <TR><TD COLSPAN=4><I><A HREF="${p}edit/agent_type.cgi">Add a new agent type</A></I></TD></TR>
     </TABLE>
   </BODY>
 </HTML>
index b392dc0..2bac990 100755 (executable)
@@ -45,6 +45,7 @@ foreach my $nas ( sort { $a->nasnum <=> $b->nasnum } qsearch( 'nas', {} ) ) {
   print "</TABLE><BR>";
 }
 
+#Time::Duration??
 sub pretty_interval {
   my $interval = shift;
   my %howlong = (
diff --git a/httemplate/misc/delete-cust_pay.cgi b/httemplate/misc/delete-cust_pay.cgi
new file mode 100755 (executable)
index 0000000..3fb786d
--- /dev/null
@@ -0,0 +1,17 @@
+<!-- $Id: delete-cust_pay.cgi,v 1.1 2002-02-07 22:29:35 ivan Exp $ -->
+<%
+
+#untaint paynum
+my($query) = $cgi->keywords;
+$query =~ /^(\d+)$/ || die "Illegal paynum";
+my $paynum = $1;
+
+my $cust_pay = qsearchs('cust_pay',{'paynum'=>$paynum});
+my $custnum = $cust_pay->custnum;
+
+my $error = $cust_pay->delete;
+eidiot($error) if $error;
+
+print $cgi->redirect($p. "view/cust_main.cgi?". $custnum);
+
+%>
index 9595a07..dc4760d 100755 (executable)
@@ -1,4 +1,4 @@
-<!-- $Id: cust_main.cgi,v 1.19 2002-01-30 14:18:09 ivan Exp $ -->
+<!-- $Id: cust_main.cgi,v 1.20 2002-02-07 22:29:35 ivan Exp $ -->
 <%
 
 my $conf = new FS::Conf;
@@ -324,6 +324,16 @@ print "</TR>";
 #formatting
 print "</TABLE>";
 
+print <<END;
+<SCRIPT>
+function areyousure(href) {
+    if (confirm("Are you sure you want to delete this payment?")
+ == true)
+        window.location.href = href;
+}
+</SCRIPT>
+END
+
 #formatting
 print qq!<BR><BR><A NAME="history">Payment History!.
       qq!</A> ( !.
@@ -371,8 +381,11 @@ foreach my $bill (@bills) {
     my $target = "$payby$payinfo";
     $payby =~ s/^BILL$/Check #/ if $payinfo;
     $payby =~ s/^(CARD|COMP)$/$1 /;
+    my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
+                   ? qq! (<A HREF="javascript:areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
+                   : '';
     push @history,
-      "$date\tPayment, Invoice #$invnum ($payby$payinfo)\t\t$paid\t\t\t$target";
+      "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete\t\t$paid\t\t\t$target";
   }
 
   my(@cust_credit_bill)=
@@ -430,11 +443,15 @@ foreach my $payment (@unapplied_payments) {
   my $target = "$payby$payinfo";
   $payby =~ s/^BILL$/Check #/ if $payinfo;
   $payby =~ s/^(CARD|COMP)$/$1 /;
+  my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments')
+                 ? qq! (<A HREF="javascript:areyousure('${p}misc/delete-cust_pay.cgi?!. $payment->paynum. qq!')">delete</A>)!
+                 : '';
   push @history,
     $payment->_date. "\t".
-    '<A HREF="'. popurl(2). 'edit/cust_bill_pay.cgi?'. $payment->paynum. '">'.
     '<b><font size="+1" color="#ff0000">Unapplied payment #' .
-    $payment->paynum . " ($payby$payinfo)</font></b></A>".
+    $payment->paynum . " ($payby$payinfo)</font></b> ".
+    '(<A HREF="'. popurl(2). 'edit/cust_bill_pay.cgi?'. $payment->paynum. '">'.
+    "apply</A>)$delete".
     "\t\t" . $payment->unapplied . "\t\t\t$target";
 }