RT# 79284 Updated discounts UI for Change Package screen
[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'   => 'document.OrderPkgForm.submit()',
123 &>
124
125 <INPUT NAME    = "submitButton"
126        TYPE    = "button"
127        VALUE   = "<% mt("Change package") |h %>"
128        onClick = "this.disabled=true; standardize_new_location();"
129        <% #scalar($cgi->param('pkgpart')) ? '' : 'DISABLED' %>
130 >
131
132 </FORM>
133 </BODY>
134 </HTML>
135
136 <%init>
137
138 my $conf = new FS::Conf;
139
140 my $curuser = $FS::CurrentUser::CurrentUser;
141
142 die "access denied"
143   unless $curuser->access_right('Change customer package');
144
145 my $pkgnum = scalar($cgi->param('pkgnum'));
146 $pkgnum =~ /^(\d+)$/ or die "illegal pkgnum $pkgnum";
147 $pkgnum = $1;
148
149 my $cust_pkg =
150   qsearchs({
151     'table'     => 'cust_pkg',
152     'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
153     'hashref'   => { 'pkgnum' => $pkgnum },
154     'extra_sql' => ' AND '. $curuser->agentnums_sql,
155   }) or die "unknown pkgnum $pkgnum";
156
157 my $cust_main = $cust_pkg->cust_main
158   or die "can't get cust_main record for custnum ". $cust_pkg->custnum.
159          " ( pkgnum ". cust_pkg->pkgnum. ")";
160
161 my $part_pkg = $cust_pkg->part_pkg;
162
163 my $title = "Change Package";
164
165 my $use_contract_end = $cust_pkg->get('contract_end') ? 1 : 0;
166
167 # if there's already a package change ordered, preload it
168 if ( $cust_pkg->change_to_pkgnum ) {
169   my $change_to = FS::cust_pkg->by_key($cust_pkg->change_to_pkgnum);
170   $cgi->param('delay', 1);
171   foreach(qw( start_date pkgpart locationnum quantity )) {
172     $cgi->param($_, $change_to->get($_));
173   }
174   if ($use_contract_end) {
175     $cgi->param('contract_end', $change_to->get('contract_end'));
176   }
177   $title = "Edit Scheduled Package Change";
178 }
179
180 # Get current values of discounts for selectboxes
181 my %discount = (setup => undef, recur => undef);
182 $discount{$_->setuprecur} = $_->discountnum
183   for qsearch('cust_pkg_discount', {
184     pkgnum   => $cust_pkg->pkgnum,
185     disabled => '',
186   });
187 $discount{setup} = '-2' if $cust_pkg->waive_setup;
188
189 </%init>