1 %if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
3 <& /elements/xmlhttp.html,
4 'url' => $p.'misc/cust-part_pkg.cgi',
5 'subs' => [ 'get_part_pkg' ],
8 <SCRIPT TYPE="text/javascript">
10 function part_pkg_opt(what, value, text, can_discount, can_start_date) {
11 var optionName = new Option(text, value, false, false);
12 optionName.setAttribute('data-can_discount', can_discount);
13 optionName.setAttribute('data-can_start_date', can_start_date);
14 var length = what.length;
15 what.options[length] = optionName;
18 function classnum_changed(what) {
20 what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown
21 var submitButton = what.form.submitButton; // || what.form.submit;
23 submitButton.disabled = true; //disable the submit button
25 var discountnum = what.form.discountnum;
27 discountnum.disabled = true; //disable discount dropdown
30 classnum = what.options[what.selectedIndex].value;
32 function update_part_pkg(part_pkg) {
34 // blank the current packages
35 for ( var i = what.form.pkgpart.length; i>= 0; i-- )
36 what.form.pkgpart.options[i] = null;
38 // add the new packages
39 opt(what.form.pkgpart, '', 'Select package');
40 var packagesArray = eval('(' + part_pkg + ')' );
41 for ( var s = 0; s < packagesArray.length; s=s+4 ) {
42 var packagesLabel = packagesArray[s+1];
43 var can_discount = packagesArray[s+2];
44 var can_start_date = packagesArray[s+3];
46 what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date
50 what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
54 get_part_pkg( <% $cust_main->custnum %>, classnum, update_part_pkg );
61 <TH ALIGN="right"><% mt('Package Class') |h %></TH>
63 <& /elements/select-cust-pkg_class.html,
64 'curr_value' => $opt{'classnum'},
65 'pkg_class' => \@pkg_class,
66 'onchange' => 'classnum_changed',
74 <TH ALIGN="right"><% mt('Package') |h %></TH>
76 <& /elements/select-cust-part_pkg.html,
77 'curr_value' => $opt{'curr_value'}, #$pkgpart
78 'classnum' => $opt{'classnum'},
79 'cust_main' => $opt{'cust_main'}, #$cust_main
80 'onchange' => 'pkg_changed',
87 my $conf = new FS::Conf;
91 my $pre_label = $opt{'pre_label'} || '';
92 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
94 my $cust_main = $opt{'cust_main'}
95 or die "cust_main not specified";
97 #"normal" part_pkg agent virtualization (agentnum or type)
98 my @part_pkg = qsearch({
99 'select' => 'DISTINCT classnum',
100 'table' => 'part_pkg',
101 'hashref' => { 'disabled' => '' },
103 ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
104 ' AND '. FS::part_pkg->agent_pkgs_sql( $opt{'cust_main'}->agent ),
108 sort { $a->classname cmp $b->classname } #should get a sort order in config
109 map { $_->pkg_class || new FS::pkg_class { 'classnum' => '',
110 'classname' => '(none)' }