summaryrefslogtreecommitdiff
path: root/httemplate/misc/change_pkg_date.html
blob: 0a23805f487b3bc8caafaf09d91d292b5386bc01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<& /elements/header-popup.html, mt($title) &>

<& /elements/error.html &>

% # only slightly different from unhold_pkg.
<FORM NAME="MyForm" ACTION="process/change_pkg_date.html" METHOD=POST>
<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
<INPUT TYPE="hidden" NAME="field" VALUE="<% $field %>">

<BR>
<% emt(($isstart ? 'Start billing' : 'Set contract end for').' [_1]', $part_pkg->pkg_comment(cust_pkg => $cust_pkg)) %>
<UL STYLE="padding-left: 3ex; list-style: none; background-color: #cccccc">
<LI>
  <& /elements/radio.html,
    field => 'when',
    id    => 'when_now',
    value => 'now',
    curr_value => $when,
  &>
  <label for="when_now"><% emt('Now') %></label>
</LI>
% if ( $next_bill_date ) {
<LI>
  <& /elements/radio.html,
    field => 'when',
    id    => 'when_next_bill_date',
    value => 'next_bill_date',
    curr_value => $when,
  &>
  <label for="when_next_bill_date">
    <% emt('On the next bill date: [_1]', 
      time2str($date_format, $next_bill_date) ) %>
  </label>
</LI>
% }
<LI>
<& /elements/radio.html,
  field => 'when',
  id    => 'when_date',
  value => 'date',
  curr_value => $when,
&>
<label for="when_date"> <% emt('On this date:') %> </label>
<& /elements/input-date-field.html,
  { name  => 'date_value',
    value => $cgi->param('date_value') || $cust_pkg->get($field),
  }
&>
</LI>
</UL>
<INPUT TYPE="submit" NAME="submit" VALUE="<% emt('Set '.($isstart ? 'start date' : 'contract end')) %>">

</FORM>
</BODY>
</HTML>

<%init>

my $field = $cgi->param('field');

my ($acl, $isstart);
if ($field eq 'start_date') {
  $acl = 'Change package start date';
  $isstart = 1;
} elsif ($field eq 'contract_end') {
  $acl = 'Change package contract end date';
} else {
  die "Unknown date field";
}

my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
  unless $curuser->access_right($acl);

my $pkgnum;
if ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
  $pkgnum = $1;
} else {
  die "illegal query ". $cgi->keywords;
}

my $conf = new FS::Conf;
my $date_format = $conf->config('date_format') || '%m/%d/%Y';

my $title = $isstart ? 'Start billing package' : 'Change contract end';

my $cust_pkg = qsearchs({
  table     => 'cust_pkg',
  addl_from => ' JOIN cust_main USING (custnum) ',
  hashref   => { 'pkgnum' => $pkgnum },
  extra_sql => ' AND '. $curuser->agentnums_sql,
}) or die "Unknown pkgnum: $pkgnum";

my $next_bill_date = $cust_pkg->cust_main->next_bill_date;

my $part_pkg = $cust_pkg->part_pkg;

# defaults:
# sticky on error, then the existing date if any, then the customer's
# next bill date, and if none of those, default to now
my $when = $cgi->param('when');

if (!$when) {
  if ($cust_pkg->get($field)) {
    $when = 'date';
  } elsif ($next_bill_date) {
    $when = 'next_bill_date';
  } else {
    $when = 'now';
  }
}
</%init>