+my $qualnum = '';
+if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
+ $qualnum = $1;
+}
+my $quotationnum = '';
+if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
+ $quotationnum = $1;
+}
+# verify this quotation is visible to this user
+
+my $cust_pkg = '';
+my $quotation_pkg = '';
+my $error = '';
+
+my %hash = (
+ 'pkgpart' => $pkgpart,
+ 'quantity' => $quantity,
+ 'salesnum' => $salesnum,
+ 'refnum' => $refnum,
+ 'contactnum' => $contactnum,
+ 'locationnum' => $locationnum,
+ 'contract_end' => ( scalar($cgi->param('contract_end'))
+ ? parse_datetime($cgi->param('contract_end'))
+ : ''
+ ),
+);
+
+if ( $cgi->param('setup_discountnum') =~ /^(-?\d+)$/ ) {
+ if ( $1 == -2 ) {
+ $hash{waive_setup} = 'Y';
+ } else {
+ $hash{setup_discountnum} = $1;
+ $hash{setup_discountnum_amount} = $cgi->param('setup_discountnum_amount');
+ $hash{setup_discountnum_percent} = $cgi->param('setup_discountnum_percent');
+ }
+}
+
+if ( $cgi->param('recur_discountnum') =~ /^(-?\d+)$/ ) {
+ $hash{recur_discountnum} = $1;
+ $hash{recur_discountnum_amount} = $cgi->param('recur_discountnum_amount');
+ $hash{recur_discountnum_percent} = $cgi->param('recur_discountnum_percent');
+ $hash{recur_discountnum_months} = $cgi->param('recur_discountnum_months');
+}
+
+$hash{'custnum'} = $cust_main->custnum if $cust_main;
+
+if ( $cgi->param('start') eq 'on_hold' ) {
+ $hash{'susp'} = 'now';
+} elsif ( $cgi->param('start') eq 'on_date' ) {
+ $hash{'start_date'} = scalar($cgi->param('start_date'))
+ ? parse_datetime($cgi->param('start_date'))
+ : '';
+}
+
+my @cust_pkg_usageprice = ();
+foreach my $quantity_param ( grep { $cgi->param($_) && $cgi->param($_) > 0 }
+ grep /^usagepricenum(\d+)_quantity$/,
+ $cgi->param
+ )
+{
+ $quantity_param =~ /^usagepricenum(\d+)_quantity$/ or die 'unpossible';
+ my $num = $1;
+ push @cust_pkg_usageprice, new FS::cust_pkg_usageprice {
+ usagepricepart => scalar($cgi->param("usagepricenum${num}_usagepricepart")),
+ quantity => scalar($cgi->param($quantity_param)),
+ };
+}
+$hash{cust_pkg_usageprice} = \@cust_pkg_usageprice;
+
+# extract details (false laziness with /misc/order_pkg.html)
+my $details = {
+ 'invoice_detail' => [],
+ 'package_comment' => [],
+ 'quotation_detail' => [],
+};
+foreach my $field ( $cgi->param ) {
+ foreach my $detailtype ( keys %$details ) {
+ if ($field =~ /^$detailtype(\d+)$/) {
+ $details->{$detailtype}->[$1] = $cgi->param($field);
+ }
+ }
+}
+foreach my $detailtype ( keys %$details ) {
+ @{ $details->{$detailtype} } = grep { length($_) } @{ $details->{$detailtype} };