when unholding a package, optionally set it to start on the next bill date, #38921
[freeside.git] / httemplate / misc / process / unhold_pkg.html
1 <& /elements/header-popup.html &>
2   <SCRIPT TYPE="text/javascript">
3     window.top.location.reload();
4   </SCRIPT>
5   </BODY>
6 </HTML>
7 <%init>
8
9 warn Dumper +{$cgi->Vars}; # XXX
10
11 my $curuser = $FS::CurrentUser::CurrentUser;
12 die "access denied"
13   unless $curuser->access_right('Unsuspend customer package');
14
15 $cgi->param('pkgnum') =~ /^(\d+)$/
16   or die "illegal pkgnum";
17 my $pkgnum = $1;
18
19 my $cust_pkg = qsearchs({
20   table     => 'cust_pkg',
21   addl_from => ' JOIN cust_main USING (custnum) ',
22   hashref   => { 'pkgnum' => $pkgnum },
23   extra_sql => ' AND '. $curuser->agentnums_sql,
24 }) or die "Unknown pkgnum: $pkgnum";
25
26 my $cust_main = $cust_pkg->cust_main;
27
28 my $error;
29 my $start_date;
30 if ( $cgi->param('when') eq 'now' ) {
31   # start it the next time billing runs
32   $start_date = '';
33 } elsif ( $cgi->param('when') eq 'next_bill_date' ) {
34   $start_date = $cust_main->next_bill_date;
35 } elsif ( $cgi->param('when') eq 'date' ) {
36   $start_date = parse_datetime($cgi->param('start_date'));
37 }
38
39 # In this process, always unsuspend the package _now_ but with a future start
40 # date, rather than set a resume date. (There is some semantic overlap between
41 # them, yes.)
42
43 if ( $cust_pkg->setup or !$cust_pkg->susp ) {
44   $error = 'This package is '. $cust_pkg->status . ', not on hold.';
45 } else {
46   $cust_pkg->set('start_date', $start_date);
47   $error = $cust_pkg->unsuspend;
48 }
49
50 if ( $error ) {
51   $cgi->param('error', $error);
52   print $cgi->redirect($fsurl.'misc/unhold_pkg.html?', $cgi->query_string);
53 }
54 </%init>