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, 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 optionName.setAttribute('data-start_date', 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+5 ) {
43 //surely this should be some kind of JSON structure
44 var packagesLabel = packagesArray[s+1];
45 var can_discount = packagesArray[s+2];
46 var can_start_date = packagesArray[s+3];
47 var start_date = packagesArray[s+4];
49 what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date, start_date
53 what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
57 get_part_pkg( <% $cust_main->custnum %>, classnum, update_part_pkg );
61 window.onload = function() {
62 classnum_changed(document.getElementById('classnum'));
68 <TH ALIGN="right"><% mt('Package Class') |h %></TH>
70 <& /elements/select-cust-pkg_class.html,
71 'curr_value' => $opt{'classnum'},
72 'pkg_class' => \@pkg_class,
73 'onchange' => 'classnum_changed',
81 <TH ALIGN="right"><% mt('Package') |h %></TH>
83 <& /elements/select-cust-part_pkg.html,
84 'curr_value' => $opt{'curr_value'}, #$pkgpart
85 'classnum' => $opt{'classnum'},
86 'cust_main' => $opt{'cust_main'}, #$cust_main
87 'onchange' => 'pkg_changed',
94 my $conf = new FS::Conf;
98 my $pre_label = $opt{'pre_label'} || '';
99 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
101 my $cust_main = $opt{'cust_main'}
102 or die "cust_main not specified";
104 #"normal" part_pkg agent virtualization (agentnum or type)
105 my @part_pkg = qsearch({
106 'select' => 'DISTINCT classnum',
107 'table' => 'part_pkg',
108 'hashref' => { 'disabled' => '' },
110 ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
111 ' AND '. FS::part_pkg->agent_pkgs_sql( $opt{'cust_main'}->agent ),
115 sort { $a->classname cmp $b->classname } #should get a sort order in config
116 map { $_->pkg_class || new FS::pkg_class { 'classnum' => '',
117 'classname' => '(none)' }