agent commission schedules for consecutive invoices, #71217
[freeside.git] / httemplate / elements / commission_rate.html
1 % unless ( $opt{'js_only'} ) {
2
3   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
4
5       <& select.html,
6         field         => "${name}_cycle",
7         options       => [ '', 1 .. 12 ],
8         option_labels => {
9           ''  => '',
10           1   => '1st',
11           2   => '2nd',
12           3   => '3rd',
13           map { $_ => $_.'th' } 4 .. 12
14         },
15         onchange      => $onchange,
16         curr_value    => $commission_rate->get("cycle"),
17       &>
18       <B><% $money_char %></B>
19       <& input-text.html,
20         field         => "${name}_amount",
21         size          => 8,
22         curr_value    => $commission_rate->get("amount")
23                          || '0.00',
24         'text-align'  => 'right'
25       &>
26       <B> + </B>
27       <& input-text.html,
28         field         => "${name}_percent",
29         size          => 8,
30         curr_value    => $commission_rate->get("percent")
31                          || '0',
32         'text-align'  => 'right'
33       &><B>%</B>
34 % }
35 <%init>
36
37 my( %opt ) = @_;
38
39 my $conf = new FS::Conf;
40 my $money_char = $conf->config('money_char') || '$';
41
42 my $name = $opt{'field'} || 'commissionratenum';
43 my $id = $opt{'id'} || 'commissionratenum';
44
45 my $curr_value = $opt{'curr_value'} || $opt{'value'};
46
47 my $onchange = '';
48 if ( $opt{'onchange'} ) {
49   $onchange = $opt{'onchange'};
50   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
51   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
52                                         #callbacks should act the same
53   $onchange = 'onChange="'. $onchange. '"';
54 }
55
56 my $commission_rate;
57 if ( $curr_value ) {
58   $commission_rate = qsearchs('commission_rate', { 'commissionratenum' => $curr_value } );
59 } else {
60   $commission_rate = new FS::commission_rate {};
61 }
62
63 foreach my $field (qw( amount percent cycle)) {
64   my $value = $cgi->param("${name}_${field}");
65   $commission_rate->set($field, $value) if $value;
66 }
67
68 </%init>