diff options
author | Mark Wells <mark@freeside.biz> | 2014-02-27 13:06:56 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-02-27 13:07:06 -0800 |
commit | e1c6b4af716fecad943bf282b50c0d459b986720 (patch) | |
tree | fee87a69aa5b34106223af038fea820f3d5b4381 /httemplate | |
parent | 6767c91fd38ea1d8e609e57f6c46c2b9da233f70 (diff) |
package fees and usage-based fees, #27687, #25899
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/edit/part_fee.html | 38 | ||||
-rw-r--r-- | httemplate/edit/process/part_fee.html | 17 | ||||
-rw-r--r-- | httemplate/elements/tr-part_fee_usage.html | 29 |
3 files changed, 71 insertions, 13 deletions
diff --git a/httemplate/edit/part_fee.html b/httemplate/edit/part_fee.html index dada23360..e057a752d 100644 --- a/httemplate/edit/part_fee.html +++ b/httemplate/edit/part_fee.html @@ -14,7 +14,6 @@ 'credit_weight' => 'Credit weight', 'agentnum' => 'Agent', 'amount' => 'Flat fee amount', - 'percent' => 'Percentage of invoice amount', 'basis' => 'Based on', 'setuprecur' => 'Report this fee as', 'minimum' => 'Minimum fee', @@ -55,8 +54,8 @@ my $n = 0; my (@locale_fields, %locale_labels); foreach (@locales) { push @locale_fields, - { field => 'feepartmsgnum'. $n, type => 'hidden' }, - { field => 'feepartmsgnum'. $n. '_locale', type => 'hidden' }, + { field => 'feepartmsgnum'. $n, type => 'hidden' }, + { field => 'feepartmsgnum'. $n. '_locale', type => 'hidden', value => $_ }, { field => 'feepartmsgnum'. $n. '_itemdesc', type => 'text', size => 40 }, ; $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } = @@ -64,6 +63,19 @@ foreach (@locales) { $n++; } +$n = 0; +my %layer_fields = ( + 'charged' => [ + 'percent' => { label => 'Fraction of invoice total', type => 'percentage', }, + ], + 'owed' => [ + 'percent' => { label => 'Fraction of balance', type => 'percentage', }, + ], + 'usage' => [ + 'usage' => { type => 'part_fee_usage' } + ], +); + my @fields = ( { field => 'itemdesc', type => 'text', size => 40, }, @@ -95,15 +107,23 @@ my @fields = ( { type => 'justtitle', value => 'Fee calculation' }, { field => 'amount', type => 'money', }, - { field => 'percent', type => 'percentage', }, { field => 'basis', - type => 'select', - options => [ 'charged', 'owed' ], - labels => { 'charged' => 'amount charged', - 'owed' => 'balance due', }, + type => 'selectlayers', + options => [ 'charged', 'owed', 'usage' ], + labels => { 'charged' => 'amount charged', + 'owed' => 'balance due', + 'usage' => 'usage charges' }, + layer_fields => \%layer_fields, + layer_values_callback => sub { + my ($cgi, $obj) = @_; + { + 'charged' => { percent => $obj->percent }, + 'owed' => { percent => $obj->percent }, + 'usage' => { usage => [ $obj->part_fee_usage ] }, + } + }, }, - { field => 'minimum', type => 'money', }, { field => 'maximum', type => 'money', }, { field => 'limit_credit', diff --git a/httemplate/edit/process/part_fee.html b/httemplate/edit/process/part_fee.html index 25656e9b0..6d1786300 100644 --- a/httemplate/edit/process/part_fee.html +++ b/httemplate/edit/process/part_fee.html @@ -4,10 +4,19 @@ 'agent_virt' => 1, 'agent_null_right' => 'Edit global fee definitions', 'viewall_dir' => 'browse', - 'process_o2m' => { - 'table' => 'part_fee_msgcat', - 'fields' => [ 'locale', 'itemdesc' ], - }, + 'process_o2m' => [ + { + 'table' => 'part_fee_msgcat', + 'fields' => [ 'locale', 'itemdesc' ], + }, + { + 'table' => 'part_fee_usage', + 'fields' => [ 'classnum', + 'amount', + 'percent' + ], + }, + ], &> <%init> diff --git a/httemplate/elements/tr-part_fee_usage.html b/httemplate/elements/tr-part_fee_usage.html new file mode 100644 index 000000000..00f4e122a --- /dev/null +++ b/httemplate/elements/tr-part_fee_usage.html @@ -0,0 +1,29 @@ +% my $n = 0; +% foreach my $class (@classes) { +% my $pre = "feepartusagenum$n"; +% my $x = $part_fee_usage{$class->classnum} || FS::part_fee_usage->new({}); +<tr> + <td align="right"> + <input type="hidden" name="<%$pre%>" value="<% $x->partfeeusagenum %>"> + <input type="hidden" name="<%$pre%>_classnum" value="<% $class->classnum %>"> + <% $class->classname %>:</td> + <td> + <%$money_char%><input size=4 name="<%$pre%>_amount" \ + value="<% sprintf("%.2f", $x->amount) %>"> + </td> + <td>per call<b> + </b></td> + <td> + <input size=4 name="<%$pre%>_percent" \ + value="<% sprintf("%.1f", $x->percent) %>">% + </td> +</tr> +% $n++; +% } +<%init> +my %opt = @_; +my $value = $opt{'curr_value'} || $opt{'value'}; +# values is an arrayref of part_fee_usage objects +my %part_fee_usage = map { $_->classnum => $_ } @$value; +my @classes = qsearch('usage_class', { disabled => '' }); +my $money_char = FS::Conf->new->config('money_char') || '$'; +</%init> |