1 <& /elements/xmlhttp.html,
2 'url' => $p.'misc/cust-part_pkg.cgi',
3 'subs' => [ 'get_part_pkg' ],
6 <SCRIPT TYPE="text/javascript">
8 function part_pkg_opt(what, value, text, can_discount, can_start_date, start_date) {
9 var optionName = new Option(text, value, false, false);
10 optionName.setAttribute('data-can_discount', can_discount);
11 optionName.setAttribute('data-can_start_date', can_start_date);
12 optionName.setAttribute('data-start_date', start_date || '');
13 var length = what.length;
14 what.options[length] = optionName;
17 function classnum_changed(what) {
19 what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown
20 var submitButton = what.form.submitButton; // || what.form.submit;
21 if ( submitButton && <% $opt{'curr_value'} ? 0 : 1 %> ) {
22 submitButton.disabled = true; //disable the submit button
24 var discountnum = what.form.discountnum;
26 discountnum.disabled = true; //disable discount dropdown
29 classnum = what.value;
31 function update_part_pkg(part_pkg) {
33 // blank the current packages
34 for ( var i = what.form.pkgpart.length; i>= 0; i-- )
35 what.form.pkgpart.options[i] = null;
37 // add the new packages
38 opt(what.form.pkgpart, '', 'Select package');
39 var packagesArray = eval('(' + part_pkg + ')' );
40 for ( var s = 0; s < packagesArray.length; s=s+5 ) {
41 //surely this should be some kind of JSON structure
42 var packagesLabel = packagesArray[s+1];
43 var can_discount = packagesArray[s+2];
44 var can_start_date = packagesArray[s+3];
45 var start_date = packagesArray[s+4];
47 what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date, start_date
51 what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
52 % if ( $opt{'curr_value'} ) {
53 what.form.pkgpart.value = <% $opt{'curr_value'} %>;
58 get_part_pkg( <% $cust_main ? $cust_main->custnum : '0' %>,
59 <% $prospect_main ? $prospect_main->prospectnum : '0' %>,
65 <&| /elements/onload.js &>
66 classnum_changed(document.getElementById('classnum'));
71 % if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
73 <TH ALIGN="right"><% mt('Package Class') |h %></TH>
75 <& /elements/select-cust-pkg_class.html,
76 'curr_value' => $opt{'classnum'},
77 'pkg_class' => \@pkg_class,
78 'onchange' => 'classnum_changed',
83 % } else { # so that the rest of the page works correctly
84 <INPUT TYPE="hidden" ID="classnum" NAME="classnum" VALUE="-1`">
88 <TH ALIGN="right"><% mt('Package') |h %></TH>
90 <& /elements/select-cust-part_pkg.html,
91 'curr_value' => $opt{'curr_value'}, #$pkgpart
92 'classnum' => $opt{'classnum'},
93 'cust_main' => $opt{'cust_main'}, #$cust_main
94 'prospect_main' => $opt{'prospect_main'}, #$prospect_main
95 'onchange' => 'pkg_changed',
102 my $conf = new FS::Conf;
106 my $pre_label = $opt{'pre_label'} || '';
107 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
109 my $cust_main = $opt{'cust_main'};
110 my $prospect_main = $opt{'prospect_main'};
112 die "neither cust_main nor prospect_main specified"
113 unless $cust_main || $prospect_main;
115 my $agent = $cust_main ? $cust_main->agent : $prospect_main->agent;
117 #"normal" part_pkg agent virtualization (agentnum or type)
118 my @part_pkg = qsearch({
119 'select' => 'DISTINCT classnum',
120 'table' => 'part_pkg',
121 'hashref' => { 'disabled' => '' },
123 ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
124 ' AND '. FS::part_pkg->agent_pkgs_sql( $agent ),
128 sort { $a->classname cmp $b->classname } #should get a sort order in config
129 map { $_->pkg_class || new FS::pkg_class { 'classnum' => '',
130 'classname' => '(none)' }