+my $error;
+my $now = time;
+if (defined($cgi->param('contract_end'))) {
+ $change{'contract_end'} = parse_datetime($cgi->param('contract_end'));
+}
+
+unless ($error) {
+ if ( $cgi->param('delay') ) {
+ my $date = parse_datetime($cgi->param('start_date'));
+ if (!$date) {
+ $error = "Invalid change date '".$cgi->param('start_date')."'.";
+ } elsif ( $date < $now ) {
+ $error = "Change date ".$cgi->param('start_date')." is in the past.";
+ } else {
+ # schedule the change
+ $change{'start_date'} = $date;
+ $error = $cust_pkg->change_later(\%change);
+ }
+ } else {
+
+ # for now, can't change usageprice with change_later
+ my @old_cust_pkg_usageprice = $cust_pkg->cust_pkg_usageprice;
+
+ # build new usageprice array
+ # false laziness with /edit/process/quick-cust_pkg.cgi
+ 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)),
+ };
+ }