fix misfire of USPS address correction on non-new locations, RT#12183
[freeside.git] / httemplate / misc / order_pkg.html
1 <% include('/elements/header-popup.html', 'Order new package' ) %>
2
3 <LINK REL="stylesheet" TYPE="text/css" HREF="../elements/calendar-win2k-2.css" TITLE="win2k-2">
4 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar_stripped.js"></SCRIPT>
5 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-en.js"></SCRIPT>
6 <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-setup.js"></SCRIPT>
7
8 <SCRIPT TYPE="text/javascript">
9
10   function enable_order_pkg () {
11     if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
12       document.OrderPkgForm.submitButton.disabled = false;
13       if ( document.OrderPkgForm.pkgpart.options[document.OrderPkgForm.pkgpart.selectedIndex].getAttribute('data-can_discount') == 1 ) {
14         document.OrderPkgForm.discountnum.disabled = false;
15       } else {
16         document.OrderPkgForm.discountnum.disabled = true;
17       }
18     } else {
19       document.OrderPkgForm.submitButton.disabled = true;
20       document.OrderPkgForm.discountnum.disabled = true;
21     }
22   }
23
24 </SCRIPT>
25
26 <% include('/elements/error.html') %>
27
28 <FORM NAME="OrderPkgForm" ACTION="<% $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
29
30 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main->custnum %>">
31 <INPUT TYPE="hidden" NAME="qualnum" VALUE="<% scalar($cgi->param('qualnum')) |h %>">
32 % if ( $svcpart ) {
33     <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
34 % }
35
36 <% ntable("#cccccc", 2) %>
37 % if ( $part_pkg ) {
38     <INPUT TYPE="hidden" NAME="pkgpart" VALUE="<% $part_pkg->pkgpart %>">
39     <TR>
40       <TH ALIGN="right">Package</TH>
41       <TD COLSPAN=6><% $part_pkg->pkg_comment |h %></TD>
42     </TR>
43 % } else {
44     <% include('/elements/tr-select-cust-part_pkg.html',
45                  'curr_value' => $pkgpart,
46                  'classnum'   => -1,
47                  'cust_main'  => $cust_main,
48                  'onchange'   => 'enable_order_pkg',
49               )
50     %>
51 % }
52
53 <TR>
54   <TH ALIGN="right">Start date </TD>
55   <TD COLSPAN=6>
56     <% include('/elements/input-date-field.html',{
57                 'name'      => 'start_date',
58                 'format'    => $date_format,
59                 'value'     => $start_date,
60                 'noinit'    => 1,
61               }) %>
62     <FONT SIZE=-1>(leave blank to start immediately)</FONT>
63   </TD>
64 </TR>
65
66 % if ( $cust_main->payby =~ /^(CARD|CHEK)$/ ) {
67 %   my $what = lc(FS::payby->shortname($cust_main->payby));
68     <TR>
69       <TH ALIGN="right">Disable automatic <% $what %> charge </TH>
70       <TD COLSPAN=6><INPUT TYPE="checkbox" NAME="no_auto" VALUE="Y"></TD>
71     </TR>
72 % }
73
74 % if ( $curuser->access_right('Discount customer package') ) {
75   <% include('/elements/tr-select-discount.html',
76                'element_etc' => 'DISABLED',
77                'colspan'     => 7,
78                'cgi'         => $cgi,
79             )
80   %>
81 % }
82
83 % if ( $conf->exists('pkg_referral') ) {
84   <% include('/elements/tr-select-part_referral.html',
85                'curr_value'    => scalar( $cgi->param('refnum') ), #get rid of empty_label first# || $cust_main->refnum,
86                'disable_empty' => 1,
87                'multiple'      => $conf->exists('pkg_referral-multiple'),
88                'colspan'       => 7,
89             )
90   %>
91 % }
92
93 % if ( $cgi->param('lock_locationnum') ) {
94
95     <INPUT TYPE  = "hidden"
96            NAME  = "locationnum"
97            ID    = "locationnum"
98            VALUE = "<% scalar($cgi->param('lock_locationnum')) |h %>"
99     >
100
101 % } else {
102
103     <% include('/elements/tr-select-cust_location.html',
104                  'cgi'       => $cgi,
105                  'cust_main' => $cust_main,
106               )
107     %>
108
109 % }
110
111 <TR>
112   <TH ALIGN="right">Contract end date </TD>
113   <TD COLSPAN=6>
114     <% include('/elements/input-date-field.html',{
115                 'name'      => 'contract_end',
116                 'format'    => $date_format,
117                 'value'     => '',
118                 'noinit'    => 1,
119                 }) %>
120   </TD>
121 </TR>
122
123 </TABLE>
124
125 % unless ( $cgi->param('lock_locationnum') ) {
126
127   <% include( '/elements/standardize_locations.html',
128                 'form'       => "OrderPkgForm",
129                 'onlyship'   => 1,
130                 'no_company' => 1,
131                 'callback'   => 'document.OrderPkgForm.submit();',
132             )
133   %>
134
135 % }
136
137 <BR>
138 % my $onclick = $cgi->param('lock_locationnum')
139 %                 ? 'document.OrderPkgForm.submit()'
140 %                 : 'standardize_new_location()';
141 <INPUT NAME="submitButton"
142        TYPE="button"
143        VALUE="Order Package"
144        onClick = "this.disabled=true; <% $onclick %>;"
145        <% $pkgpart ? '' : 'DISABLED' %>
146 >
147
148 <SCRIPT TYPE="text/javascript">
149
150   function standardize_new_location() {
151     var form = document.OrderPkgForm;
152     var loc = form.locationnum;
153     if (loc.type = 'select-one' && loc.options[loc.selectedIndex].value == -1) {
154       standardize_locations();
155     } else {
156       form.submit();
157     }
158   }
159
160 </SCRIPT>
161
162
163 </FORM>
164 </BODY>
165 </HTML>
166 <%init>
167
168 my $curuser = $FS::CurrentUser::CurrentUser;
169
170 die "access denied"
171   unless $curuser->access_right('Order customer package');
172
173 my $conf = new FS::Conf;
174 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
175
176 $cgi->param('custnum') =~ /^(\d+)$/ or die "no custnum";
177 my $custnum = $1;
178 my $cust_main = qsearchs({
179   'table'     => 'cust_main',
180   'hashref'   => { 'custnum' => $custnum },
181   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
182 });
183
184 my $part_pkg = '';
185 if ( $cgi->param('lock_pkgpart') ) {
186   $part_pkg = qsearchs({
187     'table'     => 'part_pkg',
188     'hashref'   => { 'pkgpart' => scalar($cgi->param('lock_pkgpart')) },
189     'extra_sql' => ' AND '. FS::part_pkg->agent_pkgs_sql( $cust_main->agent ),
190   })
191     or die "unknown pkgpart ". $cgi->param('lock_pkgpart');
192 }
193
194 my $pkgpart = $part_pkg ? $part_pkg->pkgpart : scalar($cgi->param('pkgpart'));
195
196 my $format = $date_format. ' %T %z (%Z)'; #false laziness w/REAL_cust_pkg.cgi?
197 my $start_date = '';
198 if( ! $conf->exists('order_pkg-no_start_date') ) {
199   $start_date = $cust_main->next_bill_date;
200   $start_date = $start_date ? time2str($format, $start_date) : '';
201 }
202
203 my $svcpart = scalar($cgi->param('svcpart'));
204
205 </%init>