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