X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fquick-charge.cgi;h=c130a550fc8964998de225b63b43fe3a63214807;hb=1553b7eca477f52824b6b352a0e87df68622411b;hp=e87be62724c2bc8c1ecd6d3f852ecfd14e411fc7;hpb=52bea6aecfcc8274fd852f626a0f751e1b5bd6a8;p=freeside.git diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi index e87be6272..c130a550f 100644 --- a/httemplate/edit/process/quick-charge.cgi +++ b/httemplate/edit/process/quick-charge.cgi @@ -24,15 +24,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; @@ -83,9 +88,11 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge my $amount = $1; my $setup_cost = ''; - $param->{"setup_cost"} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/ - or $error .= "Illegal setup_cost " . $param->{"setup_cost"} . " "; - my $setup_cost = $1; + if ( $param->{setup_cost} =~ /\S/ ) { + $param->{setup_cost} =~ /^\s*(\d*(?:\.?\d{1,2}))\s*$/ + or $error .= "Illegal setup_cost " . $param->{setup_cost} . " "; + $setup_cost = $1; + } my $quantity = 1; if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) { @@ -104,30 +111,32 @@ if ( $param->{'pkgnum'} =~ /^(\d+)$/ ) { #modifying an existing one-time charge $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')), + '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 ); } + }