5663469c252d43f2cb329155b35c92a132390ce8
[freeside.git] / httemplate / elements / part_pkg_usageprice.html
1 % unless ( $opt{'js_only'} ) {
2
3   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
4
5   <TABLE STYLE="display:inline">
6     <TR>
7
8 %     ###
9 %     # price
10 %     ###
11       <TD>
12         <TABLE STYLE="display:inline">
13           <TR>
14             <TD>Price</TD>
15             <TD><% $money_char %><INPUT
16               TYPE  = "text"
17               NAME  = "<%$name%>_price"
18               ID    = "<%$id%>_price"
19               VALUE = "<% scalar($cgi->param($name.'_price'))
20                             || $part_pkg_usageprice->price
21                        %>"
22               <% $onchange %>
23             ></TD>
24           </TR>
25
26 % #XXX lots more work for multi-currency...  maybe larger UI changes :/
27 %         foreach my $currency ( () ) {
28 %         #foreach my $currency ( sort $conf->config('currencies') ) {
29             <TR>
30               <TD><% $currency %></TD>
31               <TD><% currency_symbol($currency, SYM_HTML) %><INPUT
32                 TYPE  = "text"
33                 NAME  = "<%$name%>_price_<%$currency%>"
34                 ID    = "<%$id%>_price_<%$currency%>"
35                 VALUE = "<% scalar($cgi->param($name.'_price_'.$currency))
36                               || $part_pkg_usageprice->price #XXX
37                          %>"
38                 <% $onchange %>
39               ></TD>
40             </TR>
41 %         }
42
43         </TABLE>
44       </TD>
45
46 %     ###
47 %     # action
48 %     ###
49       <TD>
50         <SELECT NAME = "<%$name%>_action"
51                 ID   = "<%$id%>_action"
52                 <% $onchange %>
53         >
54           <OPTION VALUE="increment">Increment
55 %#no set yet          <OPTION VALUE="set" <% ($cgi->param($name.'_action') || $part_pkg_usageprice->action) eq 'set' ? 'SELECTED' : '' %>>Set
56         </SELECT>
57       </TD>
58
59 %     ###
60 %     # target
61 %     ###
62       <TD>
63         <SELECT NAME = "<%$name%>_target"
64                 ID   = "<%$id%>_target"
65                 <% $onchange %>
66         >
67 %       foreach my $target (keys %targets) {
68           <OPTION VALUE="<% $target %>"
69                   <% ($cgi->param($name.'_target') || $part_pkg_usageprice->target) eq $target ? 'SELECTED' : '' %>
70           ><% $targets{$target}->{label} %>
71 %       }
72       </TD>
73
74 %     ###
75 %     # amount
76 %     ###
77       <TD>
78         <INPUT TYPE = "text"
79                NAME = "<%$name%>_amount"
80                ID   = "<%$id%>_amount"
81                SIZE = 5
82                VALUE = "<% scalar($cgi->param($name.'_amount'))
83                              || $part_pkg_usageprice->amount
84                         %>"
85                <% $onchange %>
86         >
87       </TD>
88
89     </TR>
90   </TABLE>
91
92 % }
93 <%init>
94
95 tie my %targets, 'Tie::IxHash', # once?
96   #'svc_acct.totalbytes' => { label => 'Megabytes',
97   #                           mult  => 1048576,
98   #                         },
99   'svc_acct.totalbytes' => { label => 'Gigabytes',
100                              mult  => 1073741824,
101                            },
102   'svc_acct.seconds' => { label => 'Hours',
103                           mult  => 3600,
104                         },
105   'svc_conferencing.participants' => { label => 'Conference Participants',
106                                        mult  => 1,
107                                      },
108 #this will take more work: set action, not increment..
109 #  and then value comes from a select, not a text field
110 #  'svc_conferencing.confqualitynum' => { label => 'Conference Quality',
111 #                                        },
112 ;
113
114 my( %opt ) = @_;
115
116 my $conf = new FS::Conf;
117 my $money_char = $conf->config('money_char') || '$';
118
119 my $name = $opt{'element_name'} || $opt{'field'} || 'usagepricepart';
120 my $id = $opt{'id'} || 'usagepricepart';
121
122 my $curr_value = $opt{'curr_value'} || $opt{'value'};
123
124 my $onchange = '';
125 if ( $opt{'onchange'} ) {
126   $onchange = $opt{'onchange'};
127   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
128   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
129                                         #callbacks should act the same
130   $onchange = 'onChange="'. $onchange. '"';
131 }
132
133 my $part_pkg_usageprice = $curr_value
134   ? qsearchs('part_pkg_usageprice', { 'usagepricepart' => $curr_value } )
135   : new FS::part_pkg_usageprice {};
136
137 </%init>