ac8aa40cb6d0c9b565c3af8bc0bdf9eae46e9dca
[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 % if ( $cust_pkg->change_to_pkgnum ) {
99 %   my $change_to_pkg = FS::cust_pkg->by_key($cust_pkg->change_to_pkgnum);
100 %   my $desc;
101 %   if ( $change_to_pkg->pkgpart != $cust_pkg->pkgpart ) {
102 %     $desc = '<b>change package</b> to '.$change_to_pkg->part_pkg->pkg;
103 %   }
104 %   if ( $change_to_pkg->locationnum != $cust_pkg->locationnum ) {
105 %     $desc .= ' and ' if $desc;
106 %     $desc .= '<b>change location</b> to "'.
107 %                 $change_to_pkg->cust_location->line . '"';
108 %   }
109   <& .row_display, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Change package', note=>"(will $desc when the date is reached)" &>
110 % } else {
111   <& .row_display, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Expiration', note=>'(will <b>cancel</b> this package when the date is reached)' &>
112 % }
113   <& .row_display, cust_pkg=>$cust_pkg, column=>'cancel',   label=>'Cancellation' &>
114
115
116 <%def .row_edit>
117 <%args>
118   $cust_pkg
119   $column
120   $label
121   $note => ''
122   $if_primary => 0
123 </%args>
124 % my $value = $cust_pkg->get($column);
125 % $value = $value ? time2str($format, $value) : "";
126 %
127 % # if_primary for the dates that can't be edited on supplemental packages
128 % if ($if_primary and $cust_pkg->main_pkgnum) {
129   <INPUT TYPE="hidden" ID="<%$column%>_text" VALUE="<% $cust_pkg->get($column) %>">
130   <SCRIPT>submit_fields.push('<%$column%>');</SCRIPT>
131   <& .row_display, %ARGS &>
132 % } else {
133   <TR>
134     <TD ALIGN="right"><% $label %> date</TD>
135     <TD>
136       <INPUT TYPE  = "text"
137              NAME  = "<% $column %>"
138              SIZE  = 32
139              ID    = "<% $column %>_text"
140              VALUE = "<% $value %>"
141       >
142       <IMG SRC   = "../images/calendar.png"
143            ID    = "<% $column %>_button"
144            STYLE = "cursor: pointer"
145            TITLE = "Select date"
146       >
147 %     if ( $note ) {
148         <BR><FONT SIZE=-1><% $note %></FONT>
149 %     }
150     </TD>
151   </TR>
152
153   <SCRIPT TYPE="text/javascript">
154     Calendar.setup({
155       inputField: "<% $column %>_text",
156       ifFormat:   "<% $date_format %>",
157       button:     "<% $column %>_button",
158       align:      "BR"
159     });
160
161     submit_fields.push('<%$column%>');
162
163   </SCRIPT>
164 % }
165 </%def>
166
167 <%def .row_display>
168 <%args>
169   $cust_pkg
170   $column
171   $label
172   $note => ''
173   $is_primary => 0 #ignored
174 </%args>
175 % if ( $cust_pkg->get($column) ) { 
176     <TR>
177       <TD ALIGN="right"><% $label %> date</TD>
178       <TD BGCOLOR="#ffffff"><% time2str($format,$cust_pkg->get($column)) %>
179 %       if ( $note ) {
180           <BR><FONT SIZE=-1><% $note %></FONT>
181 %       }
182       </TD>
183     </TR>
184 % } 
185 </%def>
186
187 </TABLE>
188
189 <BR>
190 <INPUT TYPE="button" VALUE="<% mt('Apply changes') |h %>" onclick="confirm_changes()">
191 </FORM>
192
193 <% include('/elements/footer.html') %>
194 <%shared>
195
196 my $conf = new FS::Conf;
197 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
198
199 my $format = $date_format. ' %T'; # %z (%Z)';
200
201 </%shared>
202 <%init>
203
204 die "access denied"
205   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates');
206
207
208 my $error = '';
209 my( $pkgnum, $cust_pkg );
210
211 if ( $cgi->param('error') ) {
212
213   $pkgnum = $cgi->param('pkgnum');
214
215   if ( $cgi->param('error') =~ /^_/ ) {
216
217     my @errors = ();
218     my %errors = map { $_=>1 } split(',', $cgi->param('error'));
219     $cgi->param('error', '');
220     $error = join('<BR><BR>', @errors );
221
222   }
223
224   #get package record
225   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
226   die "No package!" unless $cust_pkg;
227
228   foreach my $col (qw( start_date setup last_bill bill )) {
229     my $value = $cgi->param($col);
230     $cust_pkg->set( $col, $value ? parse_datetime($value) : '' );
231   }
232
233 } else {
234
235   my($query) = $cgi->keywords;
236   $query =~ /^(\d+)$/ or die "no pkgnum";
237   $pkgnum = $1;
238
239   #get package record
240   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
241   die "No package!" unless $cust_pkg;
242
243 }
244
245 my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $cust_pkg->pkgpart } );
246
247 my( $last_bill_or_renewed, $next_bill_or_prepaid_until );
248 unless ( $part_pkg->is_prepaid ) {
249   #$billed_or_prepaid = 'billed';
250   $last_bill_or_renewed = 'Last bill';
251   $next_bill_or_prepaid_until = 'Next bill';
252 } else {
253   #$billed_or_prepaid = 'prepaid';
254   $last_bill_or_renewed = 'Renewed';
255   $next_bill_or_prepaid_until = 'Prepaid until';
256 }
257
258 </%init>