X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fselect-discount.html;h=4bbdc661a0a8cbf979df1a90498978389c3f98fe;hb=1e47a33fdc2c79a1417c9359d338473c23723500;hp=b7f1fa5bea89572f06dff24843161d10d770b8fe;hpb=b5c4237a34aef94976bc343c8d9e138664fc3984;p=freeside.git diff --git a/httemplate/elements/select-discount.html b/httemplate/elements/select-discount.html index b7f1fa5be..4bbdc661a 100644 --- a/httemplate/elements/select-discount.html +++ b/httemplate/elements/select-discount.html @@ -4,8 +4,9 @@ 'order_by' => 'ORDER BY discountnum', #XXX weight 'value' => $discountnum, 'empty_label' => '(none)', - 'hashref' => { 'disabled' => '' }, + 'hashref' => $hashref, 'post_options' => $post_options, + 'label_callback' => $label_callback, %opt, ) %> @@ -19,10 +20,45 @@ $opt{'records'} = delete $opt{'discount'} my $curuser = $FS::CurrentUser::CurrentUser; -#make an opt if we need to turn this off -my $post_options = $curuser->access_right('Custom discount customer package') - ? [ -1 => 'Custom discount' ] - : []; +my $hashref = $opt{hashref} || { 'disabled' => '' }; - +my $post_options = []; + +# If a 'custom' discount is applied to existing cust_pkg, +# also add that option to the selectbox +my $pkgnum = $cgi ? $cgi->param('pkgnum') : undef; +if ($pkgnum) { + + # Does pkgnum have a custom discount? + my $cust_pkg_discount = qsearchs(cust_pkg_discount => { + disabled => '', + pkgnum => $pkgnum, + }); + + if ($cust_pkg_discount) { + my $discount = qsearchs(discount => { + discountnum => $cust_pkg_discount->discountnum, + disabled => 'Y', + }); + if ($discount) { + my $descr = $opt{carry_value} eq $discount->discountnum + ? $discount->description.' [Continue existing discount]' + : $discount->description; + push @$post_options, $discount->discountnum, $descr; + } + } +} +push @$post_options, -1 => 'Custom discount' + if $curuser->access_right('Custom discount customer package') + && ! $opt{disable_custom_discount}; + +my $label_callback = sub { + my $rec = shift; + if ( $opt{carry_value} eq $rec->discountnum ) { + return $rec->description.' [Continue existing discount]'; + } + return $rec->description; +}; + +