summaryrefslogtreecommitdiff
path: root/httemplate/elements/part_pkg_usageprice.html
blob: 5482137478bccc68f94b5605050137882c56a367 (plain)
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
% 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
%     ###
%     my $amount =
%       scalar($cgi->param($name.'_amount'))
%         || ( $part_pkg_usageprice->amount
%               / ($targets->{$part_pkg_usageprice->target}{multiplier} || 1) );
%     $amount = '' unless $amount > 0;
      <TD>
        <INPUT TYPE = "text"
               NAME = "<%$name%>_amount"
               ID   = "<%$id%>_amount"
               SIZE = 5
               VALUE = "<% $amount %>"
               <% $onchange %>
        >
      </TD>

    </TR>
  </TABLE>

% }
<%init>

my $targets = FS::part_pkg_usageprice->targets;

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>