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