time/data/etc. unit pricing add-ons, RT#24392
[freeside.git] / httemplate / elements / cust_pkg_usageprice.html
1 % unless ( $opt{'js_only'} ) {
2
3   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
4
5   <INPUT TYPE  = "hidden"
6          NAME  = "<%$name%>_usagepricepart"
7          ID    = "<%$id%>_usagepricepart"
8          VALUE = "<% $part_pkg_usageprice->usagepricepart %>"
9   >
10
11   <TABLE STYLE="display:inline">
12     <TR>
13
14 %     ###
15 %     # action
16 %     ###
17       <TD>
18 %       # maybe we should be a quantity entry instead of a select?  even more
19 %       #  javascript auto-calculation need to display a subtotal & total
20         <SELECT NAME = "<%$name%>_quantity"
21                 ID   = "<%$id%>_quantity"
22                 <% $onchange %>
23         >
24 %         my $info = $part_pkg_usageprice->target_info;
25 %         my $amount = $part_pkg_usageprice->amount / ($info->{multiplier}||1);
26           <OPTION VALUE="">Additional <% $info->{label} %>
27 %         for (1..100) { #100?  arbitrary.
28             <OPTION VALUE="<% $_ %>"><%
29               $money_char. sprintf('%.2f', $_ * $part_pkg_usageprice->price ).
30               ' '.
31               'for'. #( $part_pkg_usageprice->action eq 'increment' ? 'per' : 'for' ).
32               ' '.
33               ( $_ * $amount ). ' '. $info->{label}
34             %>
35 %         }
36         </SELECT>
37       </TD>
38
39     </TR>
40   </TABLE>
41
42 % }
43 <%init>
44
45 #my $targets = FS::part_pkg_usageprice->targets;
46
47 my( %opt ) = @_;
48
49 my $conf = new FS::Conf;
50 my $money_char = $conf->config('money_char') || '$';
51
52 my $name = $opt{'element_name'} || $opt{'field'} || 'usagepricenum';
53 my $id = $opt{'id'} || $opt{'field'} || 'usagepricenum';
54
55 my $curr_value = $opt{'curr_value'} || $opt{'value'};
56
57 my $onchange = '';
58 if ( $opt{'onchange'} ) {
59   $onchange = $opt{'onchange'};
60   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
61   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
62                                         #callbacks should act the same
63   $onchange = 'onChange="'. $onchange. '"';
64 }
65
66 my $cust_pkg_usageprice = $curr_value
67   ? qsearchs('cust_pkg_usageprice', { 'usagepricenum' => $curr_value } )
68   : new FS::cust_pkg_usageprice { 'usagepricepart' => $opt{usagepricepart} };
69
70 my $part_pkg_usageprice = $cust_pkg_usageprice->part_pkg_usageprice;
71
72 </%init>