fix sprintf error, mostly #31273
[freeside.git] / httemplate / edit / process / quick-cust_pkg.cgi
index 0cc17d3..67cdb87 100644 (file)
@@ -70,6 +70,9 @@ my $quantity = $1 || 1;
 $cgi->param('refnum') =~ /^(\d*)$/
   or die 'illegal refnum '. $cgi->param('refnum');
 my $refnum = $1;
+$cgi->param('salesnum') =~ /^(\d*)$/
+  or die 'illegal salesnum '. $cgi->param('salesnum');
+my $salesnum = $1;
 $cgi->param('contactnum') =~ /^(\-?\d*)$/
   or die 'illegal contactnum '. $cgi->param('contactnum');
 my $contactnum = $1;
@@ -107,10 +110,7 @@ my $error = '';
 my %hash = (
     'pkgpart'              => $pkgpart,
     'quantity'             => $quantity,
-    'start_date'           => ( scalar($cgi->param('start_date'))
-                                  ? parse_datetime($cgi->param('start_date'))
-                                  : ''
-                              ),
+    'salesnum'             => $salesnum,
     'refnum'               => $refnum,
     'contactnum'           => $contactnum,
     'locationnum'          => $locationnum,
@@ -129,6 +129,14 @@ my %hash = (
 );
 $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'))
+                          : '';
+}
+
 if ( $quotationnum ) {
 
   $quotation_pkg = new FS::quotation_pkg \%hash;
@@ -136,7 +144,7 @@ if ( $quotationnum ) {
   $quotation_pkg->prospectnum($prospect_main->prospectnum) if $prospect_main;
 
   #XXX handle new location
-  $error = $quotation_pkg->insert;
+  $error = $quotation_pkg->insert || $quotation_pkg->estimate;
 
 } else {
 
@@ -155,11 +163,13 @@ if ( $quotationnum ) {
   }
 
   if ( $locationnum == -1 ) {
-    my $cust_location = FS::cust_location->new_or_existing({
+    my $cust_location = FS::cust_location->new({
       map { $_ => scalar($cgi->param($_)) }
           ('custnum', FS::cust_main->location_fields)
     });
     $opt{'cust_location'} = $cust_location;
+  } else {
+    $opt{'locationnum'} = $locationnum;
   }
 
   $error = $cust_main->order_pkg( \%opt );