+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('One-time charge');
+
+my $conf = new FS::Conf;
+my $date_format = $conf->config('date_format') || '%m/%d/%Y';
+my $money_char = $conf->config('money_char') || '$';
+
+my ($cust_main, $cust_pkg);
+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 {
+ $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
+ $cust_main = FS::cust_main->by_key($1) or die "custnum $1 not found";
+}
+
+my $custnum = $cust_main->custnum;
+# agent-virt
+if (!exists($curuser->agentnums_href->{$cust_main->agentnum})) {
+ die "custnum $custnum not found";
+}
+
+my $format = "%m/%d/%Y %T %z (%Z)"; #false laziness w/REAL_cust_pkg.cgi?
+my $start_date = $cust_main->next_bill_date;
+$start_date = $start_date ? time2str($format, $start_date) : '';
+
+my $amount = '';
+if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
+ $amount = $1;
+}
+
+my $quantity = 1;
+if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
+ $quantity = $1;
+}
+
+$cgi->param('pkg') =~ /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]*)$/
+ or die 'illegal description';
+my $pkg = $1;
+
+my $default_terms;
+if ( $cust_main->invoice_terms ) {
+ $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
+} else {
+ $default_terms = emt("Default ([_1])",
+ ($conf->config('invoice_default_terms') || emt('Payable upon receipt'))
+ );
+}
+
+my @description;
+my %param = $cgi->Vars;
+for (my $i = 0; exists($param{"description$i"}); $i++) {
+ push @description, $param{"description$i"};
+}
+
+my $classnum;
+if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
+ $classnum = $1;
+}
+
+my $part_pkg;
+
+if ( $cust_pkg ) { # set defaults
+ $part_pkg = $cust_pkg->part_pkg;
+ $pkg ||= $part_pkg->pkg;
+ $classnum ||= $part_pkg->classnum;
+ if (!@description) {
+ for (my $i = 0; $i < ($part_pkg->option('additional_count',1) || 0); $i++)
+ {
+ push @description, $part_pkg->option("additional_info$i",1);
+ }
+ }
+}
+
+</%init>