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, start_on_hold, 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-start_on_hold', start_on_hold);
12 optionName.setAttribute('data-can_start_date', can_start_date);
13 optionName.setAttribute('data-start_date', 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;
22 if ( submitButton && <% $opt{'curr_value'} ? 0 : 1 %> ) {
23 submitButton.disabled = true; //disable the submit button
25 var discountnum = what.form.discountnum;
27 discountnum.disabled = true; //disable discount dropdown
30 classnum = what.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 while (packagesArray.length > 0) {
42 //surely this should be some kind of JSON structure
43 var pkgpart = packagesArray.shift();
44 var label = packagesArray.shift();
45 var can_discount = packagesArray.shift();
46 var start_on_hold = packagesArray.shift();
47 var can_start_date = packagesArray.shift();
48 var start_date = packagesArray.shift();
50 what.form.pkgpart, pkgpart, label, can_discount, start_on_hold, can_start_date, start_date
54 what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown
55 % if ( $opt{'curr_value'} ) {
56 what.form.pkgpart.value = <% $opt{'curr_value'} %>;
63 get_part_pkg( <% $cust_main ? $cust_main->custnum : '0' %>,
64 <% $prospect_main ? $prospect_main->prospectnum : '0' %>,
70 <&| /elements/onload.js &>
71 classnum_changed(document.getElementById('classnum'));
76 % if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) {
78 <TH ALIGN="right"><% mt('Package Class') |h %></TH>
80 <& /elements/select-cust-pkg_class.html,
81 'curr_value' => $opt{'classnum'},
82 'pkg_class' => \@pkg_class,
83 'onchange' => 'classnum_changed',
88 % } else { # so that the rest of the page works correctly
89 <INPUT TYPE="hidden" ID="classnum" NAME="classnum" VALUE="-1`">
93 <TH ALIGN="right"><% mt('Package') |h %></TH>
95 <& /elements/select-cust-part_pkg.html,
96 'curr_value' => $opt{'curr_value'}, #$pkgpart
97 'classnum' => $opt{'classnum'},
98 'cust_main' => $opt{'cust_main'}, #$cust_main
99 'prospect_main' => $opt{'prospect_main'}, #$prospect_main
100 'onchange' => 'pkg_changed',
101 'label_callback' => sub { shift->pkg_comment },
108 my $conf = new FS::Conf;
112 my $pre_label = $opt{'pre_label'} || '';
113 $pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/;
115 my $cust_main = $opt{'cust_main'};
116 my $prospect_main = $opt{'prospect_main'};
118 die "neither cust_main nor prospect_main specified"
119 unless $cust_main || $prospect_main;
121 my $agent = $cust_main ? $cust_main->agent : $prospect_main->agent;
123 #"normal" part_pkg agent virtualization (agentnum or type)
124 my @part_pkg = qsearch({
125 'select' => 'DISTINCT classnum',
126 'table' => 'part_pkg',
127 'hashref' => { 'disabled' => '' },
129 ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ).
130 ' AND '. FS::part_pkg->agent_pkgs_sql( $agent ),
134 sort { $a->classname cmp $b->classname } #should get a sort order in config
135 map { $_->pkg_class || new FS::pkg_class { 'classnum' => '',
136 'classname' => '(none)' }