1 <% include( '/elements/select-table.html',
3 'name_col' => 'description',
4 'order_by' => 'ORDER BY discountnum', #XXX weight
5 'value' => $discountnum,
6 'empty_label' => '(none)',
8 'post_options' => $post_options,
9 'label_callback' => $label_callback,
16 my $discountnum = $opt{'curr_value'} || $opt{'value'};
18 $opt{'records'} = delete $opt{'discount'}
21 my $curuser = $FS::CurrentUser::CurrentUser;
23 my $hashref = $opt{hashref} || { 'disabled' => '' };
25 my $post_options = [];
27 # If a 'custom' discount is applied to existing cust_pkg,
28 # also add that option to the selectbox
29 my $pkgnum = $cgi ? $cgi->param('pkgnum') : undef;
32 # Does pkgnum have a custom discount?
33 my $cust_pkg_discount = qsearchs(cust_pkg_discount => {
38 if ($cust_pkg_discount) {
39 my $discount = qsearchs(discount => {
40 discountnum => $cust_pkg_discount->discountnum,
44 my $descr = $opt{carry_value} eq $discount->discountnum
45 ? $discount->description.' [Continue existing discount]'
46 : $discount->description;
47 push @$post_options, $discount->discountnum, $descr;
52 push @$post_options, -1 => 'Custom discount'
53 if $curuser->access_right('Custom discount customer package')
54 && ! $opt{disable_custom_discount};
56 my $label_callback = sub {
58 if ( $opt{carry_value} eq $rec->discountnum ) {
59 return $rec->description.' [Continue existing discount]';
61 return $rec->description;