29c8ca63ffc8f67b76114d673e3ba17a0a88aba0
[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 % if ( $cust_pkg->setup && ! $cust_pkg->start_date ) {
50   <& .row_display, cust_pkg=>$cust_pkg, column=>'start_date',   label=>'Start' &>
51 % } else {
52   <& .row_edit, cust_pkg=>$cust_pkg, column=>'start_date', label=>'Start' &>
53 % }
54
55   <& .row_edit, cust_pkg=>$cust_pkg, column=>'setup',     label=>'Setup' &>
56   <& .row_edit, cust_pkg=>$cust_pkg, column=>'last_bill', label=>$last_bill_or_renewed &>
57   <& .row_edit, cust_pkg=>$cust_pkg, column=>'bill',      label=>$next_bill_or_prepaid_until &>
58   <& .row_display, cust_pkg=>$cust_pkg, column=>'adjourn',   label=>'Adjournment', note=>'(will <b>suspend</b> this package when the date is reached)' &>
59   <& .row_display, cust_pkg=>$cust_pkg, column=>'susp',   label=>'Suspension' &>
60
61   <& .row_display, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Expiration', note=>'(will <b>cancel</b> this package when the date is reached)' &>
62   <& .row_display, cust_pkg=>$cust_pkg, column=>'cancel',   label=>'Cancellation' &>
63
64 <%def .row_edit>
65 <%args>
66   $cust_pkg
67   $column
68   $label
69   $note => ''
70 </%args>
71 % my $value = $cust_pkg->get($column);
72 % $value = $value ? time2str($format, $value) : "";
73
74   <TR>
75     <TD ALIGN="right"><% $label %> date</TD>
76     <TD>
77       <INPUT TYPE  = "text"
78              NAME  = "<% $column %>"
79              SIZE  = 32
80              ID    = "<% $column %>_text"
81              VALUE = "<% $value %>"
82       >
83       <IMG SRC   = "../images/calendar.png"
84            ID    = "<% $column %>_button"
85            STYLE = "cursor: pointer"
86            TITLE = "Select date"
87       >
88 %     if ( $note ) {
89         <BR><FONT SIZE=-1><% $note %></FONT>
90 %     }
91     </TD>
92   </TR>
93
94   <SCRIPT TYPE="text/javascript">
95     Calendar.setup({
96       inputField: "<% $column %>_text",
97       ifFormat:   "<% $date_format %>",
98       button:     "<% $column %>_button",
99       align:      "BR"
100     });
101   </SCRIPT>
102
103 </%def>
104
105 <%def .row_display>
106 <%args>
107   $cust_pkg
108   $column
109   $label
110   $note => ''
111 </%args>
112 % if ( $cust_pkg->get($column) ) { 
113     <TR>
114       <TD ALIGN="right"><% $label %> date</TD>
115       <TD BGCOLOR="#ffffff"><% time2str($format,$cust_pkg->get($column)) %>
116 %       if ( $note ) {
117           <BR><FONT SIZE=-1><% $note %></FONT>
118 %       }
119       </TD>
120     </TR>
121 % } 
122 </%def>
123
124 </TABLE>
125
126 <BR>
127 <INPUT TYPE="submit" VALUE="Apply Changes">
128 </FORM>
129
130 <% include('/elements/footer.html') %>
131 <%shared>
132
133 my $conf = new FS::Conf;
134 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
135
136 my $format = $date_format. ' %T %z (%Z)';
137
138 </%shared>
139 <%init>
140
141 die "access denied"
142   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer package dates');
143
144
145 my $error = '';
146 my( $pkgnum, $cust_pkg );
147
148 if ( $cgi->param('error') ) {
149
150   $pkgnum = $cgi->param('pkgnum');
151
152   if ( $cgi->param('error') =~ /^_/ ) {
153
154     my @errors = ();
155     my %errors = map { $_=>1 } split(',', $cgi->param('error'));
156     $cgi->param('error', '');
157
158     if ( $errors{'_bill_areyousure'} ) {
159       if ( $cgi->param('bill') =~ /^([\s\d\/\:\-\(\w\)]*)$/ ) {
160         my $bill = $1;
161         push @errors,
162           "You are attempting to set the next bill date to $bill, which is
163            in the past.  This will charge the customer for the interval
164            from $bill until now.  Are you sure you want to do this? ".
165           '<INPUT TYPE="checkbox" NAME="bill_areyousure" VALUE="1">';
166       }
167     }
168
169     if ( $errors{'_setup_areyousure'} ) {
170       push @errors,
171         "You are attempting to remove the setup date.  This will re-charge the
172          customer for the setup fee. Are you sure you want to do this? ".
173         '<INPUT TYPE="checkbox" NAME="setup_areyousure" VALUE="1">';
174     }
175
176     if ( $errors{'_start'} ) {
177       push @errors,
178         "You are attempting to add a start date to a package that has already
179          started billing.";
180     }
181
182     $error = join('<BR><BR>', @errors );
183
184   }
185
186   #get package record
187   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
188   die "No package!" unless $cust_pkg;
189
190   foreach my $col (qw( setup last_bill bill adjourn expire )) {
191     my $value = $cgi->param($col);
192     $cust_pkg->set( $col, $value ? str2time($value) : '' );
193   }
194
195 } else {
196
197   my($query) = $cgi->keywords;
198   $query =~ /^(\d+)$/ or die "no pkgnum";
199   $pkgnum = $1;
200
201   #get package record
202   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
203   die "No package!" unless $cust_pkg;
204
205 }
206
207 my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $cust_pkg->pkgpart } );
208
209 my( $last_bill_or_renewed, $next_bill_or_prepaid_until );
210 unless ( $part_pkg->is_prepaid ) {
211   #$billed_or_prepaid = 'billed';
212   $last_bill_or_renewed = 'Last bill';
213   $next_bill_or_prepaid_until = 'Next bill';
214 } else {
215   #$billed_or_prepaid = 'prepaid';
216   $last_bill_or_renewed = 'Renewed';
217   $next_bill_or_prepaid_until = 'Prepaid until';
218 }
219
220 </%init>