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