future package unsuspend date, #14144
[freeside.git] / httemplate / edit / process / REAL_cust_pkg.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "REAL_cust_pkg.cgi?". $cgi->query_string ) %>
4 %} else { 
5 %  my $custnum = $new->custnum;
6 %  my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
7 %               ? ''
8 %               : ';show=packages';
9 %  my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
10 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag" ) %>
11 %}
12 <%init>
13
14 my $curuser = $FS::CurrentUser::CurrentUser;
15
16 die "access denied"
17   unless $curuser->access_right('Edit customer package dates');
18
19 my $pkgnum = $cgi->param('pkgnum') or die;
20 my $old = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
21 my %hash = $old->hash;
22 $hash{$_}= $cgi->param($_) ? parse_datetime($cgi->param($_)) : ''
23   foreach qw( start_date setup bill last_bill contract_end );
24   # adjourn, expire, resume not editable this way
25
26 my @errors = ();
27
28 push @errors, '_bill_areyousure'
29   if $hash{'bill'} != $old->bill             # if the next bill date was changed
30   && $hash{'bill'} < time                    # to a date in the past
31   && ! $cgi->param('bill_areyousure');       # and it wasn't confirmed
32
33 push @errors, '_setup_areyousure'
34   if ! $hash{'setup'} && $old->setup         # if the setup date was removed
35   && ! $cgi->param('setup_areyousure');      # and it wasn't confirmed 
36
37 push @errors, '_start'
38   if $hash{'start_date'} && !$old->start_date # if a start date was added
39   && $hash{'setup'};                          # but there's a setup date
40
41 my $new;
42 my $error;
43 if ( @errors ) {
44   $error = join(',', @errors);
45 } else {
46   $new = new FS::cust_pkg \%hash;
47   $error = $new->replace($old);
48 }
49
50 </%init>