fix dates going all wacky on errors, when you're asked to confirm a date move into...
[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 %#  'Main Menu' => popurl(2)
6 %#));
7
8 <LINK REL="stylesheet" TYPE="text/css" HREF="../elements/calendar-win2k-2.css" TITLE="win2k-2">
9 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar_stripped.js"></SCRIPT>
10 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-en.js"></SCRIPT>
11 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-setup.js"></SCRIPT>
12
13 <FORM NAME="formname" ACTION="process/REAL_cust_pkg.cgi" METHOD="POST">
14 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
15
16 % if ( $error ) { 
17   <FONT SIZE="+1" COLOR="#ff0000">Error: <% $error %></FONT>
18 % } 
19
20 <% ntable("#cccccc",2) %>
21
22   <TR>
23     <TD ALIGN="right">Package number</TD>
24     <TD BGCOLOR="#ffffff"><% $cust_pkg->pkgnum %></TD>
25   </TR>
26
27   <TR>
28     <TD ALIGN="right">Package</TD>
29     <TD BGCOLOR="#ffffff"><% $cust_pkg->pkg %></TD>
30   </TR>
31
32   <TR>
33     <TD ALIGN="right">Comment</TD>
34     <TD BGCOLOR="#ffffff"><% $cust_pkg->comment %></TD>
35   </TR>
36
37   <TR>
38     <TD ALIGN="right">Order taker</TD>
39     <TD BGCOLOR="#ffffff"><% $cust_pkg->otaker %></TD>
40   </TR>
41
42   <& .row_edit, cust_pkg=>$cust_pkg, column=>'setup',     label=>'Setup' &>
43   <& .row_edit, cust_pkg=>$cust_pkg, column=>'last_bill', label=>$last_bill_or_renewed &>
44   <& .row_edit, cust_pkg=>$cust_pkg, column=>'bill',      label=>$next_bill_or_prepaid_until &>
45   <& .row_edit, cust_pkg=>$cust_pkg, column=>'adjourn',   label=>'Adjournment', note=>'(will <b>suspend</b> this package when the date is reached)' &>
46   <& .row_display, cust_pkg=>$cust_pkg, column=>'susp',   label=>'Suspension' &>
47
48   <& .row_edit, cust_pkg=>$cust_pkg, column=>'expire',   label=>'Expiration', note=>'(will <b>cancel</b> this package when the date is reached)' &>
49   <& .row_display, cust_pkg=>$cust_pkg, column=>'cancel',   label=>'Cancellation' &>
50
51 <%def .row_edit>
52 <%args>
53   $cust_pkg
54   $column
55   $label
56   $note => ''
57 </%args>
58 % my $value = $cust_pkg->get($column);
59 % $value = $value ? time2str($format, $value) : "";
60
61   <TR>
62     <TD ALIGN="right"><% $label %> date</TD>
63     <TD>
64       <INPUT TYPE  = "text"
65              NAME  = "<% $column %>"
66              SIZE  = 32
67              ID    = "<% $column %>_text"
68              VALUE = "<% $value %>"
69       >
70       <IMG SRC   = "../images/calendar.png"
71            ID    = "<% $column %>_button"
72            STYLE = "cursor: pointer"
73            TITLE = "Select date"
74       >
75 %     if ( $note ) {
76         <BR><FONT SIZE=-1><% $note %></FONT>
77 %     }
78     </TD>
79   </TR>
80
81   <SCRIPT TYPE="text/javascript">
82     Calendar.setup({
83       inputField: "<% $column %>_text",
84       ifFormat:   "%m/%d/%Y",
85       button:     "<% $column %>_button",
86       align:      "BR"
87     });
88   </SCRIPT>
89
90 </%def>
91
92 <%def .row_display>
93 <%args>
94   $cust_pkg
95   $column
96   $label
97 </%args>
98 % if ( $cust_pkg->get($column) ) { 
99     <TR>
100       <TD ALIGN="right"><% $label %> date</TD>
101       <TD BGCOLOR="#ffffff"><% time2str($format,$cust_pkg->get($column)) %></TD>
102     </TR>
103 % } 
104 </%def>
105
106 </TABLE>
107
108 <BR>
109 <INPUT TYPE="submit" VALUE="Apply Changes">
110 </FORM>
111
112 <% include('/elements/footer.html') %>
113
114 <%once>
115
116 #my $format = "%c %z (%Z)";
117 my $format = "%m/%d/%Y %T %z (%Z)";
118
119 #false laziness w/view/cust_main/packages.html
120 #my( $billed_or_prepaid,
121
122 </%once>
123 <%init>
124
125 my $error = '';
126 my( $pkgnum, $cust_pkg );
127
128 if ( $cgi->param('error') ) {
129
130   $error = $cgi->param('error');
131   $pkgnum = $cgi->param('pkgnum');
132   if ( $error eq '_bill_areyousure' ) {
133     if ( $cgi->param('bill') =~ /^([\s\d\/\:\-\(\w\)]*)$/ ) {
134       my $bill = $1;
135       $error = "You are attempting to set the next bill date to $bill, which is
136                 in the past.  This will charge the customer for the interval
137                 from $bill until now.  Are you sure you want to do this? ".
138                '<INPUT TYPE="checkbox" NAME="bill_areyousure" VALUE="1">';
139     }
140   }
141
142   #get package record
143   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
144   die "No package!" unless $cust_pkg;
145
146   foreach my $col (qw( setup last_bill bill adjourn expire )) {
147     my $value = $cgi->param($col);
148     $cust_pkg->set( $col, $value ? str2time($value) : '' );
149   }
150
151 } else {
152
153   my($query) = $cgi->keywords;
154   $query =~ /^(\d+)$/ or die "no pkgnum";
155   $pkgnum = $1;
156
157   #get package record
158   $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
159   die "No package!" unless $cust_pkg;
160
161 }
162
163 my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $cust_pkg->pkgpart } );
164
165 my( $last_bill_or_renewed, $next_bill_or_prepaid_until );
166 unless ( $part_pkg->is_prepaid ) {
167   #$billed_or_prepaid = 'billed';
168   $last_bill_or_renewed = 'Last bill';
169   $next_bill_or_prepaid_until = 'Next bill';
170 } else {
171   #$billed_or_prepaid = 'prepaid';
172   $last_bill_or_renewed = 'Renewed';
173   $next_bill_or_prepaid_until = 'Prepaid until';
174 }
175
176 </%init>
177