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