1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<% include( '/elements/select-table.html',
'table' => 'discount',
'name_col' => 'description',
'order_by' => 'ORDER BY discountnum', #XXX weight
'value' => $discountnum,
'empty_label' => '(none)',
'hashref' => $hashref,
'post_options' => $post_options,
'label_callback' => $label_callback,
%opt,
)
%>
<%init>
my %opt = @_;
my $discountnum = $opt{'curr_value'} || $opt{'value'};
$opt{'records'} = delete $opt{'discount'}
if $opt{'discount'};
my $curuser = $FS::CurrentUser::CurrentUser;
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;
};
</%init>
|