fix error viewing svc_broadband services, RT#23181, fallout from svc_cable, RT#22009
[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 % # raw error from below
39 % if ( $error ) { 
40   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT>
41 % } 
42 % #or, regular error handler
43 <% include('/elements/error.html') %>
44
45 <% ntable("#cccccc",2) %>
46
47   <TR>
48     <TD ALIGN="right">Package number</TD>
49     <TD BGCOLOR="#ffffff"><% $cust_pkg->pkgnum %></TD>
50   </TR>
51
52   <TR>
53     <TD ALIGN="right">Package</TD>
54     <TD BGCOLOR="#ffffff"><% $part_pkg->pkg %></TD>
55   </TR>
56
57 % if ( $cust_pkg->main_pkgnum ) {
58 %   my $main_pkg = $cust_pkg->main_pkg;
59   <TR>
60     <TD ALIGN="right">Supplemental to</TD>
61     <TD BGCOLOR="#ffffff">Package #<% $cust_pkg->main_pkgnum%>:&nbsp;\
62     <% $main_pkg->part_pkg->pkg %></TD>
63   </TR>
64
65 % }
66   <TR>
67     <TD ALIGN="right">Custom</TD>
68     <TD BGCOLOR="#ffffff"><% $part_pkg->custom %></TD>
69   </TR>
70
71   <TR>
72     <TD ALIGN="right">Comment</TD>
73     <TD BGCOLOR="#ffffff"><% $part_pkg->comment |h %></TD>
74   </TR>
75
76   <TR>
77     <TD ALIGN="right">Order taker</TD>
78     <TD BGCOLOR="#ffffff"><% $cust_pkg->otaker %></TD>
79   </TR>
80
81   <& .row_display, cust_pkg=>$cust_pkg, column=>'order_date',     label=>'Order' &>
82 % if ( $cust_pkg->setup && ! $cust_pkg->start_date ) {
83   <& .row_display, cust_pkg=>$cust_pkg, column=>'start_date',   label=>'Start' &>
84 % } else {
85   <& .row_edit, cust_pkg=>$cust_pkg, column=>'start_date', label=>'Start', if_primary=>1 &>
86 % }
87
88   <& .row_edit, cust_pkg=>$cust_pkg, column=>'setup',     label=>'Setup', if_primary=>1 &>
89   <& .row_edit, cust_pkg=>$cust_pkg, column=>'last_bill', label=>$last_bill_or_renewed &>
90   <& .row_edit, cust_pkg=>$cust_pkg, column=>'bill',      label=>$next_bill_or_prepaid_until &>
91 %#if ( $cust_pkg->contract_end or $part_pkg->option('contract_end_months',1) ) {
92     <& .row_edit, cust_pkg=>$cust_pkg, column=>'contract_end',label=>'Contract end', if_primary=>1 &>
93 %#}
94   <& .row_display, cust_pkg=>$cust_pkg, column=>'adjourn',  label=>'Adjournment', note=>'(will <b>suspend</b> this package when the date is reached)' &>
95   <& .row_display, cust_pkg=>$cust_pkg, column=>'susp',     label=>'Suspension' &>
96   <& .row_display, cust_pkg=>$cust_pkg, column=>'resume',   label=>'Resumption', note=> '(will <b>unsuspend</b> this package when the date is reached' &>
97
98   <& .row_display, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Expiration', note=>'(will <b>cancel</b> this package when the date is reached)' &>
99   <& .row_display, cust_pkg=>$cust_pkg, column=>'cancel',   label=>'Cancellation' &>
100
101
102 <%def .row_edit>
103 <%args>
104   $cust_pkg
105   $column
106   $label
107   $note => ''
108   $if_primary => 0
109 </%args>
110 % my $value = $cust_pkg->get($column);
111 % $value = $value ? time2str($format, $value) : "";
112 %
113 % # if_primary for the dates that can't be edited on supplemental packages
114 % if ($if_primary and $cust_pkg->main_pkgnum) {
115   <INPUT TYPE="hidden" ID="<%$column%>_text" VALUE="<% $cust_pkg->get($column) %>">
116   <SCRIPT>submit_fields.push('<%$column%>');</SCRIPT>
117   <& .row_display, %ARGS &>
118 % } else {
119   <TR>
120     <TD ALIGN="right"><% $label %> date</TD>
121     <TD>
122       <INPUT TYPE  = "text"
123              NAME  = "<% $column %>"
124              SIZE  = 32
125              ID    = "<% $column %>_text"
126              VALUE = "<% $value %>"
127       >
128       <IMG SRC   = "../images/calendar.png"
129            ID    = "<% $column %>_button"
130            STYLE = "cursor: pointer"
131            TITLE = "Select date"
132       >
133 %     if ( $note ) {
134         <BR><FONT SIZE=-1><% $note %></FONT>
135 %     }
136     </TD>
137   </TR>
138
139   <SCRIPT TYPE="text/javascript">
140     Calendar.setup({
141       inputField: "<% $column %>_text",
142       ifFormat:   "<% $date_format %>",
143       button:     "<% $column %>_button",
144       align:      "BR"
145     });
146
147     submit_fields.push('<%$column%>');
148
149   </SCRIPT>
150 % }
151 </%def>
152
153 <%def .row_display>
154 <%args>
155   $cust_pkg
156   $column
157   $label
158   $note => ''
159   $is_primary => 0 #ignored
160 </%args>
161 % if ( $cust_pkg->get($column) ) { 
162     <TR>
163       <TD ALIGN="right"><% $label %> date</TD>
164       <TD BGCOLOR="#ffffff"><% time2str($format,$cust_pkg->get($column)) %>
165 %       if ( $note ) {
166           <BR><FONT SIZE=-1><% $note %></FONT>
167 %       }
168       </TD>
169     </TR>
170 % } 
171 </%def>
172
173 </TABLE>
174
175 <BR>
176 <INPUT TYPE="button" VALUE="<% mt('Apply changes') |h %>" onclick="confirm_changes()">
177 </FORM>
178
179 <% include('/elements/footer.html') %>
180 <%shared>
181
182 my $conf = new FS::Conf;
183 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
184
185 my $format = $date_format. ' %T'; # %z (%Z)';
186
187 </%shared>
188 <%init>
189
190 die "access denied"
191   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates');
192
193
194 my $error = '';
195 my( $pkgnum, $cust_pkg );
196
197 if ( $cgi->param('error') ) {
198
199   $pkgnum = $cgi->param('pkgnum');
200
201   if ( $cgi->param('error') =~ /^_/ ) {
202
203     my @errors = ();
204     my %errors = map { $_=>1 } split(',', $cgi->param('error'));
205     $cgi->param('error', '');
206     $error = join('<BR><BR>', @errors );
207
208   }
209
210   #get package record
211   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
212   die "No package!" unless $cust_pkg;
213
214   foreach my $col (qw( start_date setup last_bill bill )) {
215     my $value = $cgi->param($col);
216     $cust_pkg->set( $col, $value ? parse_datetime($value) : '' );
217   }
218
219 } else {
220
221   my($query) = $cgi->keywords;
222   $query =~ /^(\d+)$/ or die "no pkgnum";
223   $pkgnum = $1;
224
225   #get package record
226   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
227   die "No package!" unless $cust_pkg;
228
229 }
230
231 my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $cust_pkg->pkgpart } );
232
233 my( $last_bill_or_renewed, $next_bill_or_prepaid_until );
234 unless ( $part_pkg->is_prepaid ) {
235   #$billed_or_prepaid = 'billed';
236   $last_bill_or_renewed = 'Last bill';
237   $next_bill_or_prepaid_until = 'Next bill';
238 } else {
239   #$billed_or_prepaid = 'prepaid';
240   $last_bill_or_renewed = 'Renewed';
241   $next_bill_or_prepaid_until = 'Prepaid until';
242 }
243
244 </%init>