working one-time charges
authorivan <ivan>
Wed, 26 Jun 2002 01:35:08 +0000 (01:35 +0000)
committerivan <ivan>
Wed, 26 Jun 2002 01:35:08 +0000 (01:35 +0000)
FS/FS/cust_main.pm
httemplate/edit/process/quick-charge.cgi [new file with mode: 0644]
httemplate/edit/process/quick-cust_pkg.cgi
httemplate/view/cust_main.cgi

index b39a77f..b68bf9e 100644 (file)
@@ -1743,16 +1743,45 @@ the error, otherwise returns false.
 sub charge {
   my ( $self, $amount, $pkg, $comment ) = @_;
 
 sub charge {
   my ( $self, $amount, $pkg, $comment ) = @_;
 
+  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 $part_pkg = new FS::part_pkg ( {
     'pkg'      => $pkg || 'One-time charge',
   my $part_pkg = new FS::part_pkg ( {
     'pkg'      => $pkg || 'One-time charge',
-    'comment'  => $comment || '$'. sprintf("%.2f".$amount),
+    'comment'  => $comment || '$'. sprintf("%.2f",$amount),
     'setup'    => $amount,
     'freq'     => 0,
     'recur'    => '0',
     'disabled' => 'Y',
   } );
 
     'setup'    => $amount,
     'freq'     => 0,
     'recur'    => '0',
     'disabled' => 'Y',
   } );
 
-  $part_pkg->insert;
+  my $error = $part_pkg->insert;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  my $cust_pkg = new FS::cust_pkg ( {
+    'custnum' => $self->custnum,
+    'pkgpart' => $part_pkg->pkgpart,
+  } );
+
+  $error = $cust_pkg->insert;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
 
 }
 
 
 }
 
diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi
new file mode 100644 (file)
index 0000000..49175d8
--- /dev/null
@@ -0,0 +1,27 @@
+<%
+
+#untaint custnum
+$cgi->param('custnum') =~ /^(\d+)$/
+  or die 'illegal custnum '. $cgi->param('custnum');
+my $custnum = $1;
+
+$cgi->param('amount') =~ /^\s*(\d+(\.\d{1,2})?)\s*$/
+  or die 'illegal amount '. $cgi->param('amount');
+my $amount = $1;
+
+my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+  or die "unknown custnum $custnum";
+
+my $error = $cust_main->charge( $amount, $cgi->param('pkg') );
+
+if ($error) {
+%>
+<!-- mason kludge -->
+<%
+  eidiot($error);
+} else {
+  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum" );
+}
+
+%>
+
index c663dce..a8f5b14 100644 (file)
@@ -2,10 +2,10 @@
 
 #untaint custnum
 $cgi->param('custnum') =~ /^(\d+)$/
 
 #untaint custnum
 $cgi->param('custnum') =~ /^(\d+)$/
-  or eidiot 'illegal custnum '. $cgi->param('custnum');
+  or die 'illegal custnum '. $cgi->param('custnum');
 my $custnum = $1;
 $cgi->param('pkgpart') =~ /^(\d+)$/
 my $custnum = $1;
 $cgi->param('pkgpart') =~ /^(\d+)$/
-  or eidiot 'illegal pkgpart '. $cgi->param('pkgpart');
+  or die 'illegal pkgpart '. $cgi->param('pkgpart');
 my $pkgpart = $1;
 
 my @cust_pkg = ();
 my $pkgpart = $1;
 
 my @cust_pkg = ();
index c5a8c82..8e76619 100755 (executable)
@@ -268,6 +268,13 @@ foreach my $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
 
 print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"><BR>';
 
 
 print '</SELECT><INPUT TYPE="submit" VALUE="Order Package"><BR>';
 
+print '<BR>'.
+  qq!<FORM ACTION="${p}edit/process/quick-charge.cgi" METHOD="POST">!.
+  qq!<INPUT TYPE="hidden" NAME="custnum" VALUE="$custnum">!.
+  qq!Description:<INPUT TYPE="text" NAME="pkg">!.
+  qq! Amount:<INPUT TYPE="text" NAME="amount" SIZE=6>!.
+  qq!&nbsp;<INPUT TYPE="submit" VALUE="One-time charge"><BR>!;
+
 print <<END;
 <SCRIPT>
 function cust_pkg_areyousure(href) {
 print <<END;
 <SCRIPT>
 function cust_pkg_areyousure(href) {