add unapplycredits configuration option
authorivan <ivan>
Fri, 12 Mar 2004 12:39:57 +0000 (12:39 +0000)
committerivan <ivan>
Fri, 12 Mar 2004 12:39:57 +0000 (12:39 +0000)
FS/FS/Conf.pm
httemplate/misc/unapply-cust_credit.cgi [new file with mode: 0755]
httemplate/view/cust_main.cgi

index 99eee18..ecd2a97 100644 (file)
@@ -351,6 +351,13 @@ httemplate/docs/config.html
   },
 
   {
+    'key'         => 'unapplycredits',
+    'section'     => 'UI',
+    'description' => 'Enable "unapplication" of unclosed credits.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'dirhash',
     'section'     => 'shell',
     'description' => 'Optional numeric value to control directory hashing.  If positive, hashes directories for the specified number of levels from the front of the username.  If negative, hashes directories for the specified number of levels from the end of the username.  Some examples: <ul><li>1: user -> <a href="#home">/home</a>/u/user<li>2: user -> <a href="#home">/home</a>/u/s/user<li>-1: user -> <a href="#home">/home</a>/r/user<li>-2: user -> <a href="#home">home</a>/r/e/user</ul>',
diff --git a/httemplate/misc/unapply-cust_credit.cgi b/httemplate/misc/unapply-cust_credit.cgi
new file mode 100755 (executable)
index 0000000..c658d2a
--- /dev/null
@@ -0,0 +1,18 @@
+<%
+
+#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;
+
+foreach my $cust_credit_bill ( $cust_credit->cust_credit_bill ) {
+  my $error = $cust_credit_bill->delete;
+  eidiot($error) if $error;
+}
+
+print $cgi->redirect($p. "view/cust_main.cgi?". $custnum);
+
+%>
index ee5f869..c41d2d8 100755 (executable)
@@ -554,6 +554,11 @@ function cust_pay_unapply_areyousure(href) {
  == true)
         window.location.href = href;
 }
+function cust_credit_unapply_areyousure(href) {
+    if (confirm("Are you sure you want to unapply this credit?")
+ == true)
+        window.location.href = href;
+}
 function cust_credit_areyousure(href) {
     if (confirm("Are you sure you want to delete this credit?")
  == true)
@@ -637,9 +642,13 @@ if ( $conf->config('payby-default') ne 'HIDE' ) {
         $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>)!
           : '';
+      my $unapply =
+        $cust_credit->closed !~ /^Y/i && $conf->exists('unapplycredits')
+          ? qq! (<A HREF="javascript:cust_credit_unapply_areyousure('${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum. qq!')">unapply</A>)!
+          : '';
       push @history,
         "$date\tCredit #$crednum: $reason<BR>".
-        "(applied to invoice #$invnum on $app_date)$delete\t\t\t$amount\t";
+        "(applied to invoice #$invnum on $app_date)$delete$unapply\t\t\t$amount\t";
     }
   }