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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
% unless ( $opt{'js_only'} ) {
<INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
<TABLE STYLE="display:inline">
<TR>
% ###
% # price
% ###
<TD>
<TABLE STYLE="display:inline">
<TR>
<TD>Price</TD>
<TD><% $money_char %><INPUT
TYPE = "text"
NAME = "<%$name%>_price"
ID = "<%$id%>_price"
VALUE = "<% scalar($cgi->param($name.'_price'))
|| $part_pkg_usageprice->price
%>"
<% $onchange %>
></TD>
</TR>
% #XXX lots more work for multi-currency... maybe larger UI changes :/
% foreach my $currency ( () ) {
% #foreach my $currency ( sort $conf->config('currencies') ) {
<TR>
<TD><% $currency %></TD>
<TD><% currency_symbol($currency, SYM_HTML) %><INPUT
TYPE = "text"
NAME = "<%$name%>_price_<%$currency%>"
ID = "<%$id%>_price_<%$currency%>"
VALUE = "<% scalar($cgi->param($name.'_price_'.$currency))
|| $part_pkg_usageprice->price #XXX
%>"
<% $onchange %>
></TD>
</TR>
% }
</TABLE>
</TD>
% ###
% # action
% ###
<TD>
<SELECT NAME = "<%$name%>_action"
ID = "<%$id%>_action"
<% $onchange %>
>
<OPTION VALUE="increment">Increment
%#no set yet <OPTION VALUE="set" <% ($cgi->param($name.'_action') || $part_pkg_usageprice->action) eq 'set' ? 'SELECTED' : '' %>>Set
</SELECT>
</TD>
% ###
% # target
% ###
<TD>
<SELECT NAME = "<%$name%>_target"
ID = "<%$id%>_target"
<% $onchange %>
>
% foreach my $target (keys %targets) {
<OPTION VALUE="<% $target %>"
<% ($cgi->param($name.'_target') || $part_pkg_usageprice->target) eq $target ? 'SELECTED' : '' %>
><% $targets{$target}->{label} %>
% }
</TD>
% ###
% # amount
% ###
<TD>
<INPUT TYPE = "text"
NAME = "<%$name%>_amount"
ID = "<%$id%>_amount"
SIZE = 5
VALUE = "<% scalar($cgi->param($name.'_amount'))
|| $part_pkg_usageprice->amount
%>"
<% $onchange %>
>
</TD>
</TR>
</TABLE>
% }
<%init>
tie my %targets, 'Tie::IxHash', # once?
#'svc_acct.totalbytes' => { label => 'Megabytes',
# mult => 1048576,
# },
'svc_acct.totalbytes' => { label => 'Gigabytes',
mult => 1073741824,
},
'svc_acct.seconds' => { label => 'Hours',
mult => 3600,
},
'svc_conferencing.participants' => { label => 'Conference Participants',
mult => 1,
},
#this will take more work: set action, not increment..
# and then value comes from a select, not a text field
# 'svc_conferencing.confqualitynum' => { label => 'Conference Quality',
# },
;
my( %opt ) = @_;
my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';
my $name = $opt{'element_name'} || $opt{'field'} || 'usagepricepart';
my $id = $opt{'id'} || 'usagepricepart';
my $curr_value = $opt{'curr_value'} || $opt{'value'};
my $onchange = '';
if ( $opt{'onchange'} ) {
$onchange = $opt{'onchange'};
$onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
$onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange
#callbacks should act the same
$onchange = 'onChange="'. $onchange. '"';
}
my $part_pkg_usageprice = $curr_value
? qsearchs('part_pkg_usageprice', { 'usagepricepart' => $curr_value } )
: new FS::part_pkg_usageprice {};
</%init>
|