change one-time charge UI to a full page to avoid conflict with taxproducts, #71394
[freeside.git] / httemplate / edit / process / quick-charge.cgi
index 6de746e..d1b8e10 100644 (file)
@@ -1,13 +1,4 @@
-% if ( $error ) {
-%   $cgi->param('error', $error );
-<% $cgi->redirect($p.'quick-charge.html?'. $cgi->query_string) %>
-% } else {
-<% header(emt($message)) %>
-  <SCRIPT TYPE="text/javascript">
-    window.top.location.reload();
-  </SCRIPT>
-  </BODY></HTML>
-% }
+<% $cgi->redirect($redirect) %>
 <%init>
 
 my $curuser = $FS::CurrentUser::CurrentUser;
@@ -24,15 +15,20 @@ for ( my $row = 0; exists($param->{"description$row"}); $row++ ) {
     if ($param->{"description$row"} =~ /\S/);
 }
 
-$param->{"custnum"} =~ /^(\d+)$/
-  or $error .= "Illegal customer number " . $param->{"custnum"} . "  ";
-my $custnum = $1;
-
-my $cust_main = FS::cust_main->by_key($custnum)
-  or die "custnum $custnum not found";
-
-exists($curuser->agentnums_href->{$cust_main->agentnum})
-  or die "access denied";
+my( $cust_main, $prospect_main, $quotation ) = ( '', '', '' );
+if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
+  $quotation = FS::quotation->by_key($1) or die "quotationnum $1 not found";
+}
+if ( $param->{"custnum"} =~ /^(\d+)$/ ) {
+  $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
+  exists($curuser->agentnums_href->{$cust_main->agentnum})
+    or die "access denied";
+}
+if ( $param->{"prospectnum"} =~ /^(\d+)$/ ) {
+  $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
+  exists($curuser->agentnums_href->{$prospect_main->agentnum})
+    or die "access denied";
+}
 
 my $message;
 
@@ -62,6 +58,18 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
   my $start_date = $cgi->param('start_date')
                      ? parse_datetime($cgi->param('start_date'))
                      : time;
+   
+  $param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/
+    or $error .= "Illegal tax override " . $param->{"tax_override"} . "  ";
+  my $override = $1;
+  if ( $param->{'taxclass'} eq '(select)' ) {
+    $error .= "Must select a tax class.  "
+      unless ($conf->config('tax_data_vendor') &&
+               ( $override || $param->{taxproductnum} )
+             );
+    $cgi->param('taxclass', '');
+  }
 
   $error = $cust_pkg->modify_charge(
       'pkg'               => scalar($cgi->param('pkg')),
@@ -70,8 +78,13 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
       'adjust_commission' => ($cgi->param('adjust_commission') ? 1 : 0),
       'amount'            => $amount,
       'setup_cost'        => $setup_cost,
+      'setuptax'          => scalar($cgi->param('setuptax')),
+      'taxclass'          => scalar($cgi->param('taxclass')),
+      'taxproductnum'     => scalar($cgi->param('taxproductnum')),
+      'tax_override'      => $override,
       'quantity'          => $quantity,
       'start_date'        => $start_date,
+      'separate_bill'     => scalar($cgi->param('separate_bill')),
   );
 
 } else { # the usual case: new one-time charge
@@ -100,36 +113,49 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge
 
   if ( $param->{'taxclass'} eq '(select)' ) {
     $error .= "Must select a tax class.  "
-      unless ($conf->exists('enable_taxproducts') &&
+      unless ($conf->config('tax_data_vendor') &&
                ( $override || $param->{taxproductnum} )
              );
     $cgi->param('taxclass', '');
   }
 
-  unless ( $error ) {
-    my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
-      or $error .= "Unknown customer number $custnum.  ";
-
-    $error ||= $cust_main->charge( {
-      'amount'        => $amount,
-      'setup_cost'    => $setup_cost,
-      'quantity'      => $quantity,
-      'bill_now'      => scalar($cgi->param('bill_now')),
-      'invoice_terms' => scalar($cgi->param('invoice_terms')),
-      'start_date'    => ( scalar($cgi->param('start_date'))
-                             ? parse_datetime($cgi->param('start_date'))
-                             : ''
-                         ),
-      'no_auto'       => scalar($cgi->param('no_auto')),
-      'pkg'           => scalar($cgi->param('pkg')),
-      'setuptax'      => scalar($cgi->param('setuptax')),
-      'taxclass'      => scalar($cgi->param('taxclass')),
-      'taxproductnum' => scalar($cgi->param('taxproductnum')),
-      'tax_override'  => $override,
-      'classnum'      => scalar($cgi->param('classnum')),
-      'additional'    => \@description,
-    } );
+  my %charge = (
+    'amount'        => $amount,
+    'setup_cost'    => $setup_cost,
+    'quantity'      => $quantity,
+    'bill_now'      => scalar($cgi->param('bill_now')),
+    'invoice_terms' => scalar($cgi->param('invoice_terms')),
+    'start_date'    => ( scalar($cgi->param('start_date'))
+                           ? parse_datetime($cgi->param('start_date'))
+                           : ''
+                       ),
+    'no_auto'       => scalar($cgi->param('no_auto')),
+    'separate_bill' => scalar($cgi->param('separate_bill')),
+    'pkg'           => scalar($cgi->param('pkg')),
+    'setuptax'      => scalar($cgi->param('setuptax')),
+    'taxclass'      => scalar($cgi->param('taxclass')),
+    'taxproductnum' => scalar($cgi->param('taxproductnum')),
+    'tax_override'  => $override,
+    'classnum'      => scalar($cgi->param('classnum')),
+    'additional'    => \@description,
+  );
+
+  if ( $quotation ) {
+    $error ||= $quotation->charge( \%charge );
+  } else {
+    $error ||= $cust_main->charge( \%charge );
   }
+
+}
+
+my $redirect;
+if ( $error ) {
+  $cgi->param('error', $error );
+  $redirect = $p.'quick-charge.html?'. $cgi->query_string;
+} elsif ( $quotation ) {
+  $redirect = $fsurl.'view/quotation.html?' . $quotation->quotationnum;
+} else {
+  $redirect = $fsurl.'view/cust_main.cgi?custnum=' . $cust_main->custnum . ';show=last';
 }
 
 </%init>