2 'name_singular' => 'fee definition',
5 'feepart' => 'Fee definition',
6 'itemdesc' => 'Description',
7 'comment' => 'Comment (customer-hidden)',
8 'classnum' => 'Package class',
9 'taxable' => 'This fee is taxable',
10 'disabled' => 'Disable this fee',
11 'taxclass' => 'Tax class name',
12 'taxproductnum' => 'Tax product',
13 'pay_weight' => 'Payment weight',
14 'credit_weight' => 'Credit weight',
15 'agentnum' => 'Agent',
16 'amount' => 'Flat fee amount',
17 'basis' => 'Based on',
18 'setuprecur' => 'Report this fee as',
19 'minimum' => 'Minimum fee',
20 'maximum' => 'Maximum fee',
21 'limit_credit' => 'Limit to customer credit balance',
25 'viewall_dir' => 'browse',
26 'edit_callback' => $edit_callback,
27 'error_callback' => $error_callback,
30 my $curuser = $FS::CurrentUser::CurrentUser;
31 my $acl_edit = $curuser->access_right('Edit fee definitions');
32 my $acl_edit_global = $curuser->access_right('Edit global fee definitions');
34 unless $acl_edit or $acl_edit_global;
36 my $conf = FS::Conf->new;
38 if ( $conf->config('tax_data_vendor') ) {
40 { field => 'taxproductnum', type => 'select-taxproduct' }
44 { field => 'taxable', type => 'checkbox', value => 'Y' },
48 { field => 'taxclass', type => 'select-taxclass' },
49 ) if $conf->exists('enable_taxclasses');
52 my $default_locale = $conf->config('locale') || 'en_US';
53 my @locales = grep {$_ ne $default_locale} $conf->config('available-locales');
54 # duplicates edit/part_pkg.cgi, yuck
56 my (@locale_fields, %locale_labels);
59 { field => 'feepartmsgnum'. $n, type => 'hidden' },
60 { field => 'feepartmsgnum'. $n. '_locale', type => 'hidden', value => $_ },
61 { field => 'feepartmsgnum'. $n. '_itemdesc', type => 'text', size => 40 },
63 $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
64 'Description—' . FS::Locales->description($_);
71 'charged_percent' => { label => 'Fraction of invoice total', type => 'percentage', },
74 'owed_percent' => { label => 'Fraction of balance', type => 'percentage', },
77 'usage' => { type => 'part_fee_usage' }
83 { field => 'itemdesc', type => 'text', size => 40, },
86 { field => 'comment', type => 'text', size => 40, },
88 { field => 'agentnum',
89 type => 'select-agent',
90 disable_empty => !$acl_edit_global,
91 empty_label => '(global)',
94 { field => 'classnum',
95 type => 'select-pkg_class',
98 { field => 'disabled',
103 { field => 'setuprecur',
105 options => [ 'setup', 'recur' ],
106 labels => { 'setup' => 'a setup fee',
107 'recur' => 'a recurring charge' },
110 { type => 'tablebreak-tr-title', value => 'Fee calculation' },
111 { field => 'amount', type => 'money', },
114 type => 'selectlayers',
115 options => [ 'charged', 'owed', 'usage' ],
116 labels => { 'charged' => 'amount charged',
117 'owed' => 'balance due',
118 'usage' => 'usage charges' },
119 layer_fields => \%layer_fields,
120 layer_values_callback => sub {
121 my ($cgi, $obj) = @_;
123 'charged' => { charged_percent => $obj->percent },
124 'owed' => { owed_percent => $obj->percent },
125 'usage' => { usage => [ $obj->part_fee_usage ] },
129 { field => 'minimum', type => 'money', },
130 { field => 'maximum', type => 'money', },
131 { field => 'limit_credit',
135 { type => 'tablebreak-tr-title', value => 'Taxation' },
140 my $edit_callback = sub {
141 my ($cgi, $obj, $fields, $opt) = @_;
142 my %existing_locales;
143 if ( $obj->feepart ) {
144 %existing_locales = map { $_->locale => $_ } $obj->part_fee_msgcat;
148 $obj->set('feepartmsgnum'.$n.'_locale', $_);
149 # load the existing itemdescs
150 if ( my $msgcat = $existing_locales{$_} ) {
151 $obj->set('feepartmsgnum'.$n, $msgcat->feepartmsgnum);
152 $obj->set('feepartmsgnum'.$n.'_itemdesc', $msgcat->itemdesc);
154 # then override that with the CGI param if there is one
155 if ( my $itemdesc = $cgi->param('feepartmsgnum'.$n.'_itemdesc') ) {
156 $obj->set('feepartmsgnum'.$n.'_itemdesc', $itemdesc);
162 my $error_callback = $edit_callback;