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