replace FS::CGI::header function with header-popup component, related to #71249
[freeside.git] / httemplate / edit / process / quick-cust_pkg.cgi
index 6035215..da5afe4 100644 (file)
@@ -20,7 +20,7 @@
 %      "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag";
 %  }
 % 
-<% header('Package ordered') %>
+<& /elements/header-popup.html, 'Package ordered' &>
   <SCRIPT TYPE="text/javascript">
     // XXX fancy ajax rebuild table at some point, but a page reload will do for now
 
@@ -159,14 +159,38 @@ foreach my $quantity_param ( grep { $cgi->param($_) && $cgi->param($_) > 0 }
 }
 $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} };
+}
+
 if ( $quotationnum ) {
 
   $quotation_pkg = new FS::quotation_pkg \%hash;
   $quotation_pkg->quotationnum($quotationnum);
   $quotation_pkg->prospectnum($prospect_main->prospectnum) if $prospect_main;
 
+  my %opt = @{ $details->{'quotation_detail'} }
+  ? (
+    quotation_details => $details->{'quotation_detail'},
+    copy_on_order     => scalar($cgi->param('copy_on_order')) ? 'Y' : '',
+  )
+  : ();
+
   #XXX handle new location
-  $error = $quotation_pkg->insert;
+  $error = $quotation_pkg->insert(%opt);
 
 } else {
 
@@ -194,6 +218,9 @@ if ( $quotationnum ) {
     $opt{'locationnum'} = $locationnum;
   }
 
+  $opt{'invoice_details'} = $details->{'invoice_detail'} if @{ $details->{'invoice_detail'} };
+  $opt{'package_comments'} = $details->{'package_comment'} if @{ $details->{'package_comment'} };
+
   $error = $cust_main->order_pkg( \%opt );
 
 }