+my( $cust_main, $cust_pkg, $prospect_main, $quotationnum ) = ( '', '', '', '' );
+if ( $cgi->param('change_pkgnum') ) {
+ # change an existing one-time charge
+ die "access denied"
+ unless $curuser->access_right('Modify one-time charge');
+
+ $cgi->param('change_pkgnum') =~ /^(\d+)$/ or die "illegal pkgnum";
+ $cust_pkg = FS::cust_pkg->by_key($1) or die "pkgnum $1 not found";
+ $cust_main = $cust_pkg->cust_main;
+} else {
+ if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
+ $quotationnum = $1;
+ }
+ if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
+ $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
+ }
+ if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
+ $prospect_main = FS::prospect_main->by_key($1) or die "prospectnum $1 not found";
+ }
+ die "custnum or prospectnum must be specified"
+ unless $cust_main || $prospect_main;
+}
+
+my $cust_or_prospect = $cust_main || $prospect_main;
+
+if ( $cust_main ) {
+ my $custnum = $cust_main->custnum;
+ # agent-virt
+ if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
+ die "custnum $custnum not found";
+ }
+} elsif ( $prospect_main ) {
+ my $prospectnum = $prospect_main->prospectnum;
+ # agent-virt
+ if (!exists($curuser->agentnums_href->{$prospect_main->agentnum})) {
+ die "prospectnum $prospectnum not found";
+ }
+}