future package unsuspend date, #14144
[freeside.git] / httemplate / edit / REAL_cust_pkg.cgi
1 <% include("/elements/header.html",'Customer package - Edit dates') %>
2
3 %#, menubar(
4 %#  "View this customer (#$custnum)" => popurl(2). "view/cust_main.cgi?$custnum",
5 %#));
6
7 <LINK REL="stylesheet" TYPE="text/css" HREF="../elements/calendar-win2k-2.css" TITLE="win2k-2">
8 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar_stripped.js"></SCRIPT>
9 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-en.js"></SCRIPT>
10 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-setup.js"></SCRIPT>
11
12 <FORM NAME="formname" ACTION="process/REAL_cust_pkg.cgi" METHOD="POST">
13 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
14
15 % # raw error from below
16 % if ( $error ) { 
17   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT>
18 % } 
19 % #or, regular error handler
20 <% include('/elements/error.html') %>
21
22 <% ntable("#cccccc",2) %>
23
24   <TR>
25     <TD ALIGN="right">Package number</TD>
26     <TD BGCOLOR="#ffffff"><% $cust_pkg->pkgnum %></TD>
27   </TR>
28
29   <TR>
30     <TD ALIGN="right">Package</TD>
31     <TD BGCOLOR="#ffffff"><% $part_pkg->pkg %></TD>
32   </TR>
33
34   <TR>
35     <TD ALIGN="right">Custom</TD>
36     <TD BGCOLOR="#ffffff"><% $part_pkg->custom %></TD>
37   </TR>
38
39   <TR>
40     <TD ALIGN="right">Comment</TD>
41     <TD BGCOLOR="#ffffff"><% $part_pkg->comment %></TD>
42   </TR>
43
44   <TR>
45     <TD ALIGN="right">Order taker</TD>
46     <TD BGCOLOR="#ffffff"><% $cust_pkg->otaker %></TD>
47   </TR>
48
49   <& .row_display, cust_pkg=>$cust_pkg, column=>'order_date',     label=>'Order' &>
50 % if ( $cust_pkg->setup && ! $cust_pkg->start_date ) {
51   <& .row_display, cust_pkg=>$cust_pkg, column=>'start_date',   label=>'Start' &>
52 % } else {
53   <& .row_edit, cust_pkg=>$cust_pkg, column=>'start_date', label=>'Start' &>
54 % }
55
56   <& .row_edit, cust_pkg=>$cust_pkg, column=>'setup',     label=>'Setup' &>
57   <& .row_edit, cust_pkg=>$cust_pkg, column=>'last_bill', label=>$last_bill_or_renewed &>
58   <& .row_edit, cust_pkg=>$cust_pkg, column=>'bill',      label=>$next_bill_or_prepaid_until &>
59 %#if ( $cust_pkg->contract_end or $part_pkg->option('contract_end_months',1) ) {
60     <& .row_edit, cust_pkg=>$cust_pkg, column=>'contract_end',label=>'Contract end' &>
61 %#}
62   <& .row_display, cust_pkg=>$cust_pkg, column=>'adjourn',  label=>'Adjournment', note=>'(will <b>suspend</b> this package when the date is reached)' &>
63   <& .row_display, cust_pkg=>$cust_pkg, column=>'susp',     label=>'Suspension' &>
64   <& .row_display, cust_pkg=>$cust_pkg, column=>'resume',   label=>'Resumption', note=> '(will <b>unsuspend</b> this package when the date is reached' &>
65
66   <& .row_display, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Expiration', note=>'(will <b>cancel</b> this package when the date is reached)' &>
67   <& .row_display, cust_pkg=>$cust_pkg, column=>'cancel',   label=>'Cancellation' &>
68
69
70 <%def .row_edit>
71 <%args>
72   $cust_pkg
73   $column
74   $label
75   $note => ''
76 </%args>
77 % my $value = $cust_pkg->get($column);
78 % $value = $value ? time2str($format, $value) : "";
79
80   <TR>
81     <TD ALIGN="right"><% $label %> date</TD>
82     <TD>
83       <INPUT TYPE  = "text"
84              NAME  = "<% $column %>"
85              SIZE  = 32
86              ID    = "<% $column %>_text"
87              VALUE = "<% $value %>"
88       >
89       <IMG SRC   = "../images/calendar.png"
90            ID    = "<% $column %>_button"
91            STYLE = "cursor: pointer"
92            TITLE = "Select date"
93       >
94 %     if ( $note ) {
95         <BR><FONT SIZE=-1><% $note %></FONT>
96 %     }
97     </TD>
98   </TR>
99
100   <SCRIPT TYPE="text/javascript">
101     Calendar.setup({
102       inputField: "<% $column %>_text",
103       ifFormat:   "<% $date_format %>",
104       button:     "<% $column %>_button",
105       align:      "BR"
106     });
107   </SCRIPT>
108
109 </%def>
110
111 <%def .row_display>
112 <%args>
113   $cust_pkg
114   $column
115   $label
116   $note => ''
117 </%args>
118 % if ( $cust_pkg->get($column) ) { 
119     <TR>
120       <TD ALIGN="right"><% $label %> date</TD>
121       <TD BGCOLOR="#ffffff"><% time2str($format,$cust_pkg->get($column)) %>
122 %       if ( $note ) {
123           <BR><FONT SIZE=-1><% $note %></FONT>
124 %       }
125       </TD>
126     </TR>
127 % } 
128 </%def>
129
130 </TABLE>
131
132 <BR>
133 <INPUT TYPE="submit" VALUE="<% mt('Apply changes') |h %>">
134 </FORM>
135
136 <% include('/elements/footer.html') %>
137 <%shared>
138
139 my $conf = new FS::Conf;
140 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
141
142 my $format = $date_format. ' %T'; # %z (%Z)';
143
144 </%shared>
145 <%init>
146
147 die "access denied"
148   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates');
149
150
151 my $error = '';
152 my( $pkgnum, $cust_pkg );
153
154 if ( $cgi->param('error') ) {
155
156   $pkgnum = $cgi->param('pkgnum');
157
158   if ( $cgi->param('error') =~ /^_/ ) {
159
160     my @errors = ();
161     my %errors = map { $_=>1 } split(',', $cgi->param('error'));
162     $cgi->param('error', '');
163
164     if ( $errors{'_bill_areyousure'} ) {
165       if ( $cgi->param('bill') =~ /^([\s\d\/\:\-\(\w\)]*)$/ ) {
166         my $bill = $1;
167         push @errors,
168           "You are attempting to set the next bill date to $bill, which is
169            in the past.  This will charge the customer for the interval
170            from $bill until now.  Are you sure you want to do this? ".
171           '<INPUT TYPE="checkbox" NAME="bill_areyousure" VALUE="1">';
172       }
173     }
174
175     if ( $errors{'_setup_areyousure'} ) {
176       push @errors,
177         "You are attempting to remove the setup date.  This will re-charge the
178          customer for the setup fee. Are you sure you want to do this? ".
179         '<INPUT TYPE="checkbox" NAME="setup_areyousure" VALUE="1">';
180     }
181
182     if ( $errors{'_start'} ) {
183       push @errors,
184         "You are attempting to add a start date to a package that has already
185          started billing.";
186     }
187
188     $error = join('<BR><BR>', @errors );
189
190   }
191
192   #get package record
193   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
194   die "No package!" unless $cust_pkg;
195
196   foreach my $col (qw( start_date setup last_bill bill )) {
197     my $value = $cgi->param($col);
198     $cust_pkg->set( $col, $value ? parse_datetime($value) : '' );
199   }
200
201 } else {
202
203   my($query) = $cgi->keywords;
204   $query =~ /^(\d+)$/ or die "no pkgnum";
205   $pkgnum = $1;
206
207   #get package record
208   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
209   die "No package!" unless $cust_pkg;
210
211 }
212
213 my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $cust_pkg->pkgpart } );
214
215 my( $last_bill_or_renewed, $next_bill_or_prepaid_until );
216 unless ( $part_pkg->is_prepaid ) {
217   #$billed_or_prepaid = 'billed';
218   $last_bill_or_renewed = 'Last bill';
219   $next_bill_or_prepaid_until = 'Next bill';
220 } else {
221   #$billed_or_prepaid = 'prepaid';
222   $last_bill_or_renewed = 'Renewed';
223   $next_bill_or_prepaid_until = 'Prepaid until';
224 }
225
226 </%init>