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 'edit_callback' => $edit_callback,
26 'error_callback' => $error_callback,
29 my $curuser = $FS::CurrentUser::CurrentUser;
30 my $acl_edit = $curuser->access_right('Edit fee definitions');
31 my $acl_edit_global = $curuser->access_right('Edit global fee definitions');
33 unless $acl_edit or $acl_edit_global;
35 my $conf = FS::Conf->new;
37 if ( $conf->exists('enable_taxproducts') ) {
39 { field => 'taxproductnum', type => 'select-taxproduct' }
43 { field => 'taxable', type => 'checkbox', value => 'Y' },
46 { field => 'taxclass', type => 'select-taxclass' },
47 ) if $conf->exists('enable_taxclasses');
50 my $default_locale = $conf->config('locale') || 'en_US';
51 my @locales = grep {$_ ne $default_locale} $conf->config('available-locales');
52 # duplicates edit/part_pkg.cgi, yuck
54 my (@locale_fields, %locale_labels);
57 { field => 'feepartmsgnum'. $n, type => 'hidden' },
58 { field => 'feepartmsgnum'. $n. '_locale', type => 'hidden', value => $_ },
59 { field => 'feepartmsgnum'. $n. '_itemdesc', type => 'text', size => 40 },
61 $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
62 'Description—' . FS::Locales->description($_);
69 'percent' => { label => 'Fraction of invoice total', type => 'percentage', },
72 'percent' => { label => 'Fraction of balance', type => 'percentage', },
75 'usage' => { type => 'part_fee_usage' }
81 { field => 'itemdesc', type => 'text', size => 40, },
84 { field => 'comment', type => 'text', size => 40, },
86 { field => 'agentnum',
87 type => 'select-agent',
88 disable_empty => !$acl_edit_global,
89 empty_label => '(global)',
92 { field => 'classnum',
93 type => 'select-pkg_class',
96 { field => 'disabled',
101 { field => 'setuprecur',
103 options => [ 'setup', 'recur' ],
104 labels => { 'setup' => 'a setup fee',
105 'recur' => 'a recurring charge' },
108 { type => 'justtitle', value => 'Fee calculation' },
109 { field => 'amount', type => 'money', },
112 type => 'selectlayers',
113 options => [ 'charged', 'owed', 'usage' ],
114 labels => { 'charged' => 'amount charged',
115 'owed' => 'balance due',
116 'usage' => 'usage charges' },
117 layer_fields => \%layer_fields,
118 layer_values_callback => sub {
119 my ($cgi, $obj) = @_;
121 'charged' => { percent => $obj->percent },
122 'owed' => { percent => $obj->percent },
123 'usage' => { usage => [ $obj->part_fee_usage ] },
127 { field => 'minimum', type => 'money', },
128 { field => 'maximum', type => 'money', },
129 { field => 'limit_credit',
133 { type => 'justtitle', value => 'Taxation' },
138 my $edit_callback = sub {
139 my ($cgi, $obj, $fields, $opt) = @_;
140 my %existing_locales;
141 if ( $obj->feepart ) {
142 %existing_locales = map { $_->locale => $_ } $obj->part_fee_msgcat;
146 $obj->set('feepartmsgnum'.$n.'_locale', $_);
147 # load the existing itemdescs
148 if ( my $msgcat = $existing_locales{$_} ) {
149 $obj->set('feepartmsgnum'.$n, $msgcat->feepartmsgnum);
150 $obj->set('feepartmsgnum'.$n.'_itemdesc', $msgcat->itemdesc);
152 # then override that with the CGI param if there is one
153 if ( my $itemdesc = $cgi->param('feepartmsgnum'.$n.'_itemdesc') ) {
154 $obj->set('feepartmsgnum'.$n.'_itemdesc', $itemdesc);
160 my $error_callback = $edit_callback;