1 <% include('/elements/header-popup.html', 'Order new package' ) %>
3 <% include('/elements/xmlhttp.html',
4 'url' => $p.'misc/location.cgi',
5 'subs' => [ 'get_location' ],
9 <SCRIPT TYPE="text/javascript">
11 function locationnum_changed(what) {
12 var locationnum = what.options[what.selectedIndex].value;
13 if ( locationnum == -1 ) {
15 % for (@location_fields) {
16 what.form.<%$_%>.disabled = false;
17 what.form.<%$_%>.style.backgroundColor = '#ffffff';
20 what.form.address1.value = '';
21 what.form.address2.value = '';
22 what.form.city.value = '';
23 what.form.zip.value = '';
24 changeSelect(what.form.country, <% $countrydefault |js_string %>);
25 %#shouldn't we sleep/wait here until the state dropdown is updated?
26 %#(is it even triggered???)
27 changeSelect(what.form.state, <% $statedefault |js_string %>);
28 what.form.county.selectedIndex = 0;
32 if ( locationnum == 0 ) {
33 what.form.address1.value = <% $cust_main->address1 |js_string %>;
34 what.form.address2.value = <% $cust_main->address2 |js_string %>;
35 what.form.city.value = <% $cust_main->city |js_string %>;
36 what.form.zip.value = <% $cust_main->zip |js_string %>;
37 changeSelect(what.form.country, <% $cust_main->country | js_string %> );
38 %#shouldn't we sleep/wait here until the state dropdown is updated?
39 %#(is it even triggered???)
40 changeSelect(what.form.state, <% $cust_main->state | js_string %> );
41 %#shouldn't we sleep/wait here until the county dropdown is updated?
42 %#(is it even triggered???)
43 changeSelect(what.form.county, <% $cust_main->county | js_string %> );
45 get_location( locationnum, update_location );
48 %#sleep/wait until dropdowns are updated?
49 % for (@location_fields) {
50 what.form.<%$_%>.disabled = true;
51 what.form.<%$_%>.style.backgroundColor = '#dddddd';
57 function changeSelect(what, value) {
58 for ( var i=0; i<what.length; i++) {
59 if ( what.options[i].value == value ) {
60 what.selectedIndex = i;
65 function update_location( hash ) {
69 function enable_order_pkg () {
70 if ( document.OrderPkgForm.pkgpart.selectedIndex > 0 ) {
71 document.OrderPkgForm.submit.disabled = false;
73 document.OrderPkgForm.submit.disabled = true;
79 <% include('/elements/error.html') %>
81 <FORM NAME="OrderPkgForm" ACTION="<% $p %>edit/process/quick-cust_pkg.cgi" METHOD="POST">
83 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $cust_main->custnum %>">
85 <% ntable("#cccccc", 2) %>
87 <TH ALIGN="right">Package</TH>
89 <% include('/elements/select-cust-part_pkg.html',
90 'curr_value' => $pkgpart,
91 'cust_main' => $cust_main,
92 'onchange' => 'enable_order_pkg',
98 % if ( $conf->exists('pkg_referral') ) {
99 <% include('/elements/tr-select-part_referral.html',
100 'curr_value' => scalar( $cgi->param('refnum') ), #get rid of empty_label first# || $cust_main->refnum,
101 'disable_empty' => 1,
102 'multiple' => $conf->exists('pkg_referral-multiple'),
109 <TH ALIGN="right">Service location</TH>
111 <SELECT NAME="locationnum" onChange="locationnum_changed(this);">
112 <OPTION VALUE="">(default service address)
113 % foreach my $loc ( $cust_main->cust_location ) {
114 <OPTION VALUE="<% $loc->locationnum %>"
115 <% $locationnum == $loc->locationnum ? 'SELECTED' : '' %>
119 <% $locationnum == -1 ? 'SELECTED' : '' %>
125 <% include('/elements/location.html',
126 'object' => $cust_location,
127 #'onchange' ? probably not
128 'disabled' => ( $locationnum == -1 ? '' : 'DISABLED' ),
136 <INPUT NAME="submit" TYPE="submit" VALUE="Order Package" <% $pkgpart ? '' : 'DISABLED' %>>
143 my @location_fields = qw( address1 address2 city county state zip country );
149 unless $FS::CurrentUser::CurrentUser->access_right('Order customer package');
151 my $conf = new FS::Conf;
152 my $countrydefault = $conf->config('countrydefault') || 'US';
153 my $statedefault = $conf->config('statedefault')
154 || ($countrydefault eq 'US' ? 'CA' : '');
156 $cgi->param('custnum') =~ /^(\d+)$/ or die "no custnum";
158 my $cust_main = qsearchs({
159 'table' => 'cust_main',
160 'hashref' => { 'custnum' => $custnum },
161 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
164 my $pkgpart = scalar($cgi->param('pkgpart'));
166 $cgi->param('locationnum') =~ /^(\d*)$/ or die "illegal locationnum";
167 my $locationnum = $1;
169 if ( $locationnum ) {
170 $cust_location = qsearchs('cust_location', { 'locationnum' => $locationnum } )
171 or die "unknown locationnum";
173 $cust_location = new FS::cust_location;
174 if ( $cgi->param('error') && $locationnum == -1 ) {
175 $cust_location->$_( $cgi->param($_) ) foreach @location_fields;
177 $cust_location->$_( $cust_main->$_() ) foreach @location_fields;