fix dates going all wacky on errors, when you're asked to confirm a date move into...
[freeside.git] / httemplate / edit / process / REAL_cust_pkg.cgi
1 %my $pkgnum = $cgi->param('pkgnum') or die;
2 %my $old = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
3 %my %hash = $old->hash;
4 %$hash{'setup'} = $cgi->param('setup') ? str2time($cgi->param('setup')) : '';
5 %$hash{'bill'} = $cgi->param('bill') ? str2time($cgi->param('bill')) : '';
6 %$hash{'last_bill'} =
7 %  $cgi->param('last_bill') ? str2time($cgi->param('last_bill')) : '';
8 %$hash{'adjourn'} = $cgi->param('adjourn') ? str2time($cgi->param('adjourn')) : '';
9 %$hash{'expire'} = $cgi->param('expire') ? str2time($cgi->param('expire')) : '';
10 %
11 %my $new;
12 %my $error;
13 %if ( $hash{'bill'} != $old->bill        # if the next bill date was changed
14 %     && $hash{'bill'} < time            # to a date in the past
15 %     && ! $cgi->param('bill_areyousure') # and it wasn't confirmed
16 %   )
17 %{
18 %  $error = '_bill_areyousure';
19 %} else {
20 %  $new = new FS::cust_pkg \%hash;
21 %  $error = $new->replace($old);
22 %}
23 %
24 %if ( $error ) {
25 %  $cgi->param('error', $error);
26 %  print $cgi->redirect(popurl(2). "REAL_cust_pkg.cgi?". $cgi->query_string );
27 %} else { 
28 %  my $custnum = $new->custnum;
29 %  print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum".
30 %                       "#cust_pkg$pkgnum" );
31 %}