X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fquick-charge.cgi;h=839a4e911e6d074fd335c35ca5acd03036df6c4b;hb=42132c9a86d36d7fefa7ba5f058f764ba6e7ad5b;hp=024a281e021ab3771b927bb2d9d0e7e6b0083e2b;hpb=9509e5bfb7f9331303153cac24d7bfecbe2ea9f1;p=freeside.git diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi index 024a281e0..839a4e911 100644 --- a/httemplate/edit/process/quick-charge.cgi +++ b/httemplate/edit/process/quick-charge.cgi @@ -1,47 +1,67 @@ -% -% my $error = ''; -% my $param = $cgi->Vars; -% -% my @description = (); -% for ( my $row = 0; exists($param->{"description$row"}); $row++ ) { -% push @description, $param->{"description$row"} -% if ($param->{"description$row"} =~ /\S/); -% } -% -% $param->{"custnum"} =~ /^(\d+)$/ -% or $error .= "Illegal customer number " . $param->{"custnum"} . " "; -% my $custnum = $1; -% -% $param->{"amount"} =~ /^\s*(\d+(\.\d{1,2})?)\s*$/ -% or $error .= "Illegal amount " . $param->{"amount"} . " "; -% my $amount = $1; -% -% if ( $param->{'taxclass'} eq '(select)' ) { -% $error .= "Must select a tax class. "; -% } -% -% unless ( $error ) { -% my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) -% or $error .= "Unknown customer number $custnum. "; -% -% $error ||= $cust_main->charge({ 'amount' => $amount, -% 'pkg' => $cgi->param('pkg'), -% 'taxclass' => $cgi->param('taxclass'), -% 'additional' => \@description, -% } -% ); -% } -% -% if ( $error ) { -% -% $cgi->param('error', "$error" ); -% +% if ( $error ) { +% $cgi->param('error', $error ); <% $cgi->redirect($p.'quick-charge.html?'. $cgi->query_string) %> -% -% } +% } else { <% header("One-time charge added") %> +% } +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('One-time charge'); + +my $error = ''; +my $conf = new FS::conf; +my $param = $cgi->Vars; + +my @description = (); +for ( my $row = 0; exists($param->{"description$row"}); $row++ ) { + push @description, $param->{"description$row"} + if ($param->{"description$row"} =~ /\S/); +} + +$param->{"custnum"} =~ /^(\d+)$/ + or $error .= "Illegal customer number " . $param->{"custnum"} . " "; +my $custnum = $1; + +$param->{"amount"} =~ /^\s*(\d+(\.\d{1,2})?)\s*$/ + or $error .= "Illegal amount " . $param->{"amount"} . " "; +my $amount = $1; + +my $quantity = 1; +if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) { + $quantity = $1; +} + +$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->exists('enable_taxproducts') && + ( $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, + 'quantity' => $quantity, + 'pkg' => scalar($cgi->param('pkg')), + 'taxclass' => scalar($cgi->param('taxclass')), + 'taxproductnum' => scalar($cgi->param('taxproductnum')), + 'tax_override' => $override, + 'classnum' => scalar($cgi->param('classnum')), + 'additional' => \@description, + } ); +} +