diff options
Diffstat (limited to 'httemplate/elements/tr-select-cust-part_pkg.html')
| -rw-r--r-- | httemplate/elements/tr-select-cust-part_pkg.html | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/httemplate/elements/tr-select-cust-part_pkg.html b/httemplate/elements/tr-select-cust-part_pkg.html new file mode 100644 index 000000000..767d23264 --- /dev/null +++ b/httemplate/elements/tr-select-cust-part_pkg.html @@ -0,0 +1,114 @@ +%if ( scalar(@pkg_class) > 1 && ! $conf->exists('disable-cust-pkg_class') ) { + + <& /elements/xmlhttp.html, + 'url' => $p.'misc/cust-part_pkg.cgi', + 'subs' => [ 'get_part_pkg' ], + &> + + <SCRIPT TYPE="text/javascript"> + + function part_pkg_opt(what, value, text, can_discount, can_start_date) { + var optionName = new Option(text, value, false, false); + optionName.setAttribute('data-can_discount', can_discount); + optionName.setAttribute('data-can_start_date', can_start_date); + var length = what.length; + what.options[length] = optionName; + } + + function classnum_changed(what) { + + what.form.pkgpart.disabled = 'disabled'; //disable part_pkg dropdown + var submitButton = what.form.submitButton; // || what.form.submit; + if ( submitButton ) { + submitButton.disabled = true; //disable the submit button + } + var discountnum = what.form.discountnum; + if ( discountnum ) { + discountnum.disabled = true; //disable discount dropdown + } + + classnum = what.options[what.selectedIndex].value; + + function update_part_pkg(part_pkg) { + + // blank the current packages + for ( var i = what.form.pkgpart.length; i>= 0; i-- ) + what.form.pkgpart.options[i] = null; + + // add the new packages + opt(what.form.pkgpart, '', 'Select package'); + var packagesArray = eval('(' + part_pkg + ')' ); + for ( var s = 0; s < packagesArray.length; s=s+4 ) { + var packagesLabel = packagesArray[s+1]; + var can_discount = packagesArray[s+2]; + var can_start_date = packagesArray[s+3]; + part_pkg_opt( + what.form.pkgpart, packagesArray[s], packagesLabel, can_discount, can_start_date + ); + } + + what.form.pkgpart.disabled = ''; //re-enable part_pkg dropdown + + } + + get_part_pkg( <% $cust_main->custnum %>, classnum, update_part_pkg ); + + } + + </SCRIPT> + + <TR> + <TH ALIGN="right"><% mt('Package Class') |h %></TH> + <TD COLSPAN=7> + <& /elements/select-cust-pkg_class.html, + 'curr_value' => $opt{'classnum'}, + 'pkg_class' => \@pkg_class, + 'onchange' => 'classnum_changed', + &> + </TD> + </TR> + +%} + +<TR> + <TH ALIGN="right"><% mt('Package') |h %></TH> + <TD COLSPAN=7> + <& /elements/select-cust-part_pkg.html, + 'curr_value' => $opt{'curr_value'}, #$pkgpart + 'classnum' => $opt{'classnum'}, + 'cust_main' => $opt{'cust_main'}, #$cust_main + 'onchange' => 'pkg_changed', + &> + </TD> +</TR> + +<%init> + +my $conf = new FS::Conf; + +my %opt = @_; + +my $pre_label = $opt{'pre_label'} || ''; +$pre_label .= ' ' if length($pre_label) && $pre_label =~ /\S$/; + +my $cust_main = $opt{'cust_main'} + or die "cust_main not specified"; + +#"normal" part_pkg agent virtualization (agentnum or type) +my @part_pkg = qsearch({ + 'select' => 'DISTINCT classnum', + 'table' => 'part_pkg', + 'hashref' => { 'disabled' => '' }, + 'extra_sql' => + ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( 'null'=>1 ). + ' AND '. FS::part_pkg->agent_pkgs_sql( $opt{'cust_main'}->agent ), +}); + +my @pkg_class = + sort { $a->classname cmp $b->classname } #should get a sort order in config + map { $_->pkg_class || new FS::pkg_class { 'classnum' => '', + 'classname' => '(none)' } + } + @part_pkg; + +</%init> |
