1 %if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
3 <% include('/elements/xmlhttp.html',
4 'url' => $p.'misc/cust-part_pkg.cgi',
5 'subs' => [ 'get_part_pkg' ],
9 <SCRIPT TYPE="text/javascript">
11 function part_pkg_opt(what, value, text, can_discount, can_start_date) {
12 var optionName = new Option(text, value, false, false);
13 optionName.setAttribute('data-can_discount', can_discount);
14 optionName.setAttribute('data-can_start_date', can_start_date);
15 var length = what.length;
16 what.options[length] = optionName;
19 function classnum_changed(what) {
21 what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown
22 var submitButton = what.form.submitButton; // || what.form.submit;
24 submitButton.disabled = true; //disable the submit button
26 var discountnum = what.form.discountnum;
28 discountnum.disabled = true; //disable discount dropdown
31 classnum = what.options[what.selectedIndex].value;
33 function update_part_pkg(part_pkg) {
35 // blank the current packages
36 for ( var i = what.form.pkgpart.length; i>= 0; i-- )
37 what.form.pkgpart.options[i] = null;
39 // add the new packages
40 opt(what.form.pkgpart, '', 'Select package');
41 var packagesArray = eval('(' + part_pkg + ')' );
42 for ( var s = 0; s < packagesArray.length; s=s+4 ) {
43 var packagesLabel = packagesArray[s+1];
44 var can_discount = packagesArray[s+2];
45 var can_start_date = packagesArray[s+3];
47 what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date
51 what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
55 get_part_pkg( <% $cust_main->custnum %>, classnum, update_part_pkg );
62 <TH ALIGN="right">Package Class</TH>
64 <% include('/elements/select-cust-pkg_class.html',
65 'curr_value' => $opt{'classnum'},
66 'pkg_class' => \@pkg_class,
67 'onchange' => 'classnum_changed',
76 <TH ALIGN="right">Package</TH>
78 <& /elements/select-cust-part_pkg.html,
79 'curr_value' => $opt{'curr_value'}, #$pkgpart
80 'classnum' => $opt{'classnum'},
81 'cust_main' => $opt{'cust_main'}, #$cust_main
82 'onchange' => 'pkg_changed',
89 my $conf = new FS::Conf;
93 my $pre_label = $opt{'pre_label'} || '';
94 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
96 my $cust_main = $opt{'cust_main'}
97 or die "cust_main not specified";
99 #my @pkg_class = sort { $a->classname cmp $b->classname }
100 # qsearch( 'pkg_class', { 'disabled' => '' } );
102 #"normal" part_pkg agent virtualization (agentnum or type)
103 my @part_pkg = qsearch({
104 'select' => 'DISTINCT classnum',
105 'table' => 'part_pkg',
106 'hashref' => { 'disabled' => '' },
108 ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
109 ' AND '. FS::part_pkg->agent_pkgs_sql( $opt{'cust_main'}->agent ),
113 sort { $a->classname cmp $b->classname } #should get a sort order in config
114 map { $_->pkg_class || new FS::pkg_class { 'classnum' => '',
115 'classname' => '(none)' }