default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / misc / change_pkg.cgi
1 <& /elements/header-popup.html, mt($title) &>
2
3 <SCRIPT TYPE="text/javascript" SRC="../elements/order_pkg.js"></SCRIPT>
4 <& /elements/error.html &>
5
6 <FORM NAME="OrderPkgForm" ACTION="<% $p %>edit/process/change-cust_pkg.html" METHOD=POST>
7 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
8
9
10 <FONT CLASS="fsinnerbox-title"><% mt('Package') |h %></FONT>
11 <TABLE CLASS="fsinnerbox">
12
13   <TR>
14     <TH ALIGN="right"><% mt('Current package') |h %></TH>
15     <TD COLSPAN=7>
16       <FONT STYLE="background-color:#e8e8e8"><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B> - <% $part_pkg->comment |h %></FONT>
17     </TD>
18   </TR>
19
20   <& /elements/tr-select-cust-part_pkg.html,
21                'pre_label'  => emt('New'),
22                'curr_value' => scalar($cgi->param('pkgpart')) || $cust_pkg->pkgpart,
23                'classnum'   => $part_pkg->classnum,
24                'cust_main'  => $cust_main,
25   &>
26
27   <& /elements/tr-input-pkg-quantity.html,
28                'curr_value' => scalar($cgi->param('quantity')) || $cust_pkg->quantity
29   &>
30
31 % if ($use_contract_end) {
32   <& /elements/tr-input-date-field.html, {
33       'name'  => 'contract_end',
34       'value' => ($cgi->param('contract_end') || $cust_pkg->get('contract_end')),
35       'label' => '<B>Contract End</B>',
36     } &>
37 % }
38
39 </TABLE>
40 <BR>
41
42 <& /elements/table-cust_pkg_usageprice.html,
43      'pkgpart' => (scalar($cgi->param('pkgpart')) || $cust_pkg->pkgpart),
44      'pkgnum'  => ($cust_pkg->change_to_pkgnum || $pkgnum),
45 &>
46
47 <FONT CLASS="fsinnerbox-title"><% mt('Change') |h %></FONT>
48 <TABLE CLASS="fsinnerbox">
49
50   <SCRIPT TYPE="text/javascript">
51     function delay_changed() {
52       var enable = document.OrderPkgForm.delay[1].checked;
53       document.getElementById('start_date_text').disabled = !enable;
54       document.getElementById('start_date_button').style.display = 
55         (enable ? '' : 'none');
56       if (document.getElementById('start_date_button_disabled')) { // does this ever exist anymore?
57         document.getElementById('start_date_button_disabled').style.display =
58           (enable ? 'none' : '');
59       }
60       if (enable) {
61         usageprice_disable(1);
62       } else {
63         var form = document.OrderPkgForm;
64         usageprice_disable(0,form.pkgpart.options[form.pkgpart.selectedIndex].value);
65       }
66     }
67     <&| /elements/onload.js &>
68       delay_changed();
69     </&>
70   </SCRIPT>
71   <TR>
72     <TD> <INPUT TYPE="radio" NAME="delay" VALUE="0" \
73           <% !$cgi->param('delay') ? 'CHECKED' : '' %> \
74           onclick="delay_changed()"> Now </TD>
75     <TD> <INPUT TYPE="radio" NAME="delay" VALUE="1" \
76           <% $cgi->param('delay')  ? 'CHECKED' : '' %> \
77           onclick="delay_changed()"> In the future
78       <& /elements/input-date-field.html, {
79           'name'  => 'start_date',
80           'value' => ($cgi->param('start_date') || $cust_main->next_bill_date),
81       } &>
82     </TD>
83   </TR>
84 </TABLE>
85 </BR>
86
87 % my $discount_cust_pkg = $curuser->access_right('Discount customer package');
88 % my $waive_setup_fee   = $curuser->access_right('Waive setup fee');
89 %
90 % if ( $discount_cust_pkg || $waive_setup_fee ) {
91   <FONT CLASS="fsinnerbox-title"><% mt('Discounting') |h %></FONT>
92   <TABLE CLASS="fsinnerbox">
93     <& /elements/tr-select-pkg-discount.html,
94       # curr_value_setup    => $discount{setup},
95       # curr_value_recur    => $discount{recur},
96       disable_setup       => 0,
97       disable_recur       => 0,
98       disable_waive_setup => 0,
99       carry_value_setup   => $discount{setup},
100       carry_value_recur   => $discount{recur},
101     &>
102   </TABLE><BR>
103
104 % }
105
106 <FONT CLASS="fsinnerbox-title"><% mt('Location') |h %></FONT>
107 <TABLE CLASS="fsinnerbox">
108
109   <& /elements/tr-select-cust_location.html,
110                'cgi'       => $cgi,
111                'cust_main' => $cust_main,
112   &>
113
114 </TABLE>
115 <BR>
116
117
118 <& /elements/standardize_locations.html,
119             'form'        => "OrderPkgForm",
120             'with_census' => 1,
121             'with_census_functions' => 1,
122             'callback'    => $conf->exists('tax_district_method')
123                               ? 'wa_state_tax_district()'
124                               : 'submit_continue()',
125 &>
126
127 <script>
128   <& /elements/wa_state_tax_district.js &>
129
130   // wa_sate_tax_district() will call submit_continue() upon success,
131   //   or submit_abort() upon error
132   function submit_continue() {
133     document.OrderPkgForm.submit();
134   }
135 </script>
136
137 <INPUT NAME    = "submitButton"
138        TYPE    = "button"
139        VALUE   = "<% mt("Change package") |h %>"
140        onClick = "this.disabled=true; standardize_new_location();"
141        <% #scalar($cgi->param('pkgpart')) ? '' : 'DISABLED' %>
142 >
143
144 </FORM>
145 </BODY>
146 </HTML>
147
148 <%init>
149
150 my $conf = new FS::Conf;
151
152 my $curuser = $FS::CurrentUser::CurrentUser;
153
154 die "access denied"
155   unless $curuser->access_right('Change customer package');
156
157 my $pkgnum = scalar($cgi->param('pkgnum'));
158 $pkgnum =~ /^(\d+)$/ or die "illegal pkgnum $pkgnum";
159 $pkgnum = $1;
160
161 my $cust_pkg =
162   qsearchs({
163     'table'     => 'cust_pkg',
164     'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
165     'hashref'   => { 'pkgnum' => $pkgnum },
166     'extra_sql' => ' AND '. $curuser->agentnums_sql,
167   }) or die "unknown pkgnum $pkgnum";
168
169 my $cust_main = $cust_pkg->cust_main
170   or die "can't get cust_main record for custnum ". $cust_pkg->custnum.
171          " ( pkgnum ". cust_pkg->pkgnum. ")";
172
173 my $part_pkg = $cust_pkg->part_pkg;
174
175 my $title = "Change Package";
176
177 my $use_contract_end = $cust_pkg->get('contract_end') ? 1 : 0;
178
179 # if there's already a package change ordered, preload it
180 if ( $cust_pkg->change_to_pkgnum ) {
181   my $change_to = FS::cust_pkg->by_key($cust_pkg->change_to_pkgnum);
182   $cgi->param('delay', 1);
183   foreach(qw( start_date pkgpart locationnum quantity )) {
184     $cgi->param($_, $change_to->get($_));
185   }
186   if ($use_contract_end) {
187     $cgi->param('contract_end', $change_to->get('contract_end'));
188   }
189   $title = "Edit Scheduled Package Change";
190 }
191
192 # Get current values of discounts for selectboxes
193 my %discount = (setup => undef, recur => undef);
194 $discount{$_->setuprecur} = $_->discountnum
195   for qsearch('cust_pkg_discount', {
196     pkgnum   => $cust_pkg->pkgnum,
197     disabled => '',
198   });
199 $discount{setup} = '-2' if $cust_pkg->waive_setup;
200
201 </%init>