RT#40215: OFM - Separate permissions for edit dates and contract dates [v3 only]
[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 <SCRIPT TYPE="text/javascript">
13 var submit_fields = [];
14 function confirm_changes() {
15   var i;
16   var querystring = 'pkgnum=<%$pkgnum%>';
17   var f = document.forms.formname;
18   for(i = 0; i < submit_fields.length; i++) {
19     querystring += ';'
20                 + submit_fields[i]
21                 + '='
22                 + encodeURIComponent(f.elements[submit_fields[i] + '_text'].value);
23   }
24   overlib(
25     OLiframeContent(
26       '<%$p%>/misc/confirm-cust_pkg-edit_dates.html?' + querystring,
27       576, 576, 'confirm_popup'
28     ),
29     CAPTION, 'Package date changes', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', 
30     MIDX, 0, MIDY, 0, DRAGGABLE, BGCOLOR, '#333399', CGCOLOR, '#333399', 
31     TEXTSIZE, 3
32   );
33 }
34 </SCRIPT>
35 <FORM NAME="formname" ACTION="process/REAL_cust_pkg.cgi" METHOD="POST">
36 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
37
38 % if ($contract_only) {
39   <INPUT TYPE="hidden" ID="contract_only_text" NAME="contract_only" VALUE="1">
40   <SCRIPT>submit_fields.push('contract_only');</SCRIPT>
41 % }
42
43 % # raw error from below
44 % if ( $error ) { 
45   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT>
46 % } 
47 % #or, regular error handler
48 <% include('/elements/error.html') %>
49
50 <% ntable("#cccccc",2) %>
51
52   <TR>
53     <TD ALIGN="right">Package number</TD>
54     <TD BGCOLOR="#ffffff"><% $cust_pkg->pkgnum %></TD>
55   </TR>
56
57   <TR>
58     <TD ALIGN="right">Package</TD>
59     <TD BGCOLOR="#ffffff"><% $part_pkg->pkg %></TD>
60   </TR>
61
62 % if ( $cust_pkg->main_pkgnum ) {
63 %   my $main_pkg = $cust_pkg->main_pkg;
64   <TR>
65     <TD ALIGN="right">Supplemental to</TD>
66     <TD BGCOLOR="#ffffff">Package #<% $cust_pkg->main_pkgnum%>:&nbsp;\
67     <% $main_pkg->part_pkg->pkg %></TD>
68   </TR>
69
70 % }
71   <TR>
72     <TD ALIGN="right">Custom</TD>
73     <TD BGCOLOR="#ffffff"><% $part_pkg->custom %></TD>
74   </TR>
75
76   <TR>
77     <TD ALIGN="right">Comment</TD>
78     <TD BGCOLOR="#ffffff"><% $part_pkg->comment |h %></TD>
79   </TR>
80
81   <TR>
82     <TD ALIGN="right">Order taker</TD>
83     <TD BGCOLOR="#ffffff"><% $cust_pkg->otaker %></TD>
84   </TR>
85
86   <& .row_display, cust_pkg=>$cust_pkg, column=>'order_date',     label=>'Order' &>
87 % if ( $cust_pkg->setup && ! $cust_pkg->start_date ) {
88   <& .row_display, cust_pkg=>$cust_pkg, column=>'start_date',   label=>'Start' &>
89 % } else {
90   <& .row_edit, cust_pkg=>$cust_pkg, column=>'start_date', label=>'Start', if_primary=>1 &>
91 % }
92
93   <& .row_edit, cust_pkg=>$cust_pkg, column=>'setup',     label=>'Setup', if_primary=>1 &>
94   <& .row_edit, cust_pkg=>$cust_pkg, column=>'last_bill', label=>$last_bill_or_renewed &>
95   <& .row_edit, cust_pkg=>$cust_pkg, column=>'bill',      label=>$next_bill_or_prepaid_until &>
96 %#if ( $cust_pkg->contract_end or $part_pkg->option('contract_end_months',1) ) {
97     <& .row_edit, cust_pkg=>$cust_pkg, column=>'contract_end',label=>'Contract end', if_primary=>1 &>
98 %#}
99   <& .row_display, cust_pkg=>$cust_pkg, column=>'adjourn',  label=>'Adjournment', note=>'(will <b>suspend</b> this package when the date is reached)' &>
100   <& .row_display, cust_pkg=>$cust_pkg, column=>'susp',     label=>'Suspension' &>
101   <& .row_display, cust_pkg=>$cust_pkg, column=>'resume',   label=>'Resumption', note=> '(will <b>unsuspend</b> this package when the date is reached' &>
102
103 % if ( $cust_pkg->change_to_pkgnum ) {
104 %   my $change_to_pkg = FS::cust_pkg->by_key($cust_pkg->change_to_pkgnum);
105 %   my $desc;
106 %   if ( $change_to_pkg->pkgpart != $cust_pkg->pkgpart ) {
107 %     $desc = '<b>change package</b> to '.$change_to_pkg->part_pkg->pkg;
108 %   }
109 %   if ( $change_to_pkg->locationnum != $cust_pkg->locationnum ) {
110 %     $desc .= ' and ' if $desc;
111 %     $desc .= '<b>change location</b> to "'.
112 %                 $change_to_pkg->cust_location->line . '"';
113 %   }
114   <& .row_display, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Change package', note=>"(will $desc when the date is reached)" &>
115 % } else {
116   <& .row_display, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Expiration', note=>'(will <b>cancel</b> this package when the date is reached)' &>
117 % }
118   <& .row_display, cust_pkg=>$cust_pkg, column=>'cancel',   label=>'Cancellation' &>
119
120
121 <%def .row_edit>
122 <%args>
123   $cust_pkg
124   $column
125   $label
126   $note => ''
127   $if_primary => 0
128 </%args>
129 % my $value = $cust_pkg->get($column);
130 % $value = $value ? time2str($format, $value) : "";
131 %
132 % if ($contract_only and $column ne 'contract_end') {
133   <& .row_display, %ARGS &>
134 % # if_primary for the dates that can't be edited on supplemental packages
135 % } elsif ($if_primary and $cust_pkg->main_pkgnum) {
136   <INPUT TYPE="hidden" ID="<%$column%>_text" VALUE="<% $cust_pkg->get($column) %>">
137   <SCRIPT>submit_fields.push('<%$column%>');</SCRIPT>
138   <& .row_display, %ARGS &>
139 % } else {
140   <TR>
141     <TD ALIGN="right"><% $label %> date</TD>
142     <TD>
143       <INPUT TYPE  = "text"
144              NAME  = "<% $column %>"
145              SIZE  = 32
146              ID    = "<% $column %>_text"
147              VALUE = "<% $value %>"
148       >
149       <IMG SRC   = "../images/calendar.png"
150            ID    = "<% $column %>_button"
151            STYLE = "cursor: pointer"
152            TITLE = "Select date"
153       >
154 %     if ( $note ) {
155         <BR><FONT SIZE=-1><% $note %></FONT>
156 %     }
157     </TD>
158   </TR>
159
160   <SCRIPT TYPE="text/javascript">
161     Calendar.setup({
162       inputField: "<% $column %>_text",
163       ifFormat:   "<% $date_format %>",
164       button:     "<% $column %>_button",
165       align:      "BR"
166     });
167
168     submit_fields.push('<%$column%>');
169
170   </SCRIPT>
171 % }
172 </%def>
173
174 <%def .row_display>
175 <%args>
176   $cust_pkg
177   $column
178   $label
179   $note => ''
180   $is_primary => 0 #ignored
181 </%args>
182 % if ( $cust_pkg->get($column) ) { 
183     <TR>
184       <TD ALIGN="right"><% $label %> date</TD>
185       <TD BGCOLOR="#ffffff"><% time2str($format,$cust_pkg->get($column)) %>
186 %       if ( $note ) {
187           <BR><FONT SIZE=-1><% $note %></FONT>
188 %       }
189       </TD>
190     </TR>
191 % } 
192 </%def>
193
194 </TABLE>
195
196 <BR>
197 <INPUT TYPE="button" VALUE="<% mt('Apply changes') |h %>" onclick="confirm_changes()">
198 </FORM>
199
200 <% include('/elements/footer.html') %>
201 <%shared>
202
203 my $conf = new FS::Conf;
204 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
205
206 my $format = $date_format. ' %T'; # %z (%Z)';
207
208 my $contract_only = $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates') ? 0 : 1;
209
210 </%shared>
211 <%init>
212
213 # see $contract_only in shared block above
214 die "access denied"
215   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates')
216       or $FS::CurrentUser::CurrentUser->access_right('Change package contract end date');
217
218 my $error = '';
219 my( $pkgnum, $cust_pkg );
220
221 if ( $cgi->param('error') ) {
222
223   $pkgnum = $cgi->param('pkgnum');
224
225   if ( $cgi->param('error') =~ /^_/ ) {
226
227     my @errors = ();
228     my %errors = map { $_=>1 } split(',', $cgi->param('error'));
229     $cgi->param('error', '');
230     $error = join('<BR><BR>', @errors );
231
232   }
233
234   #get package record
235   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
236   die "No package!" unless $cust_pkg;
237
238   foreach my $col (qw( start_date setup last_bill bill )) {
239     my $value = $cgi->param($col);
240     $cust_pkg->set( $col, $value ? parse_datetime($value) : '' );
241   }
242
243 } else {
244
245   my($query) = $cgi->keywords;
246   $query =~ /^(\d+)$/ or die "no pkgnum";
247   $pkgnum = $1;
248
249   #get package record
250   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
251   die "No package!" unless $cust_pkg;
252
253 }
254
255 my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $cust_pkg->pkgpart } );
256
257 my( $last_bill_or_renewed, $next_bill_or_prepaid_until );
258 unless ( $part_pkg->is_prepaid ) {
259   #$billed_or_prepaid = 'billed';
260   $last_bill_or_renewed = 'Last bill';
261   $next_bill_or_prepaid_until = 'Next bill';
262 } else {
263   #$billed_or_prepaid = 'prepaid';
264   $last_bill_or_renewed = 'Renewed';
265   $next_bill_or_prepaid_until = 'Prepaid until';
266 }
267
268 </%init>