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' },
47 { field => 'taxclass', type => 'select-taxclass' },
48 ) if $conf->exists('enable_taxclasses');
51 my $default_locale = $conf->config('locale') || 'en_US';
52 my @locales = grep {$_ ne $default_locale} $conf->config('available-locales');
53 # duplicates edit/part_pkg.cgi, yuck
55 my (@locale_fields, %locale_labels);
58 { field => 'feepartmsgnum'. $n, type => 'hidden' },
59 { field => 'feepartmsgnum'. $n. '_locale', type => 'hidden', value => $_ },
60 { field => 'feepartmsgnum'. $n. '_itemdesc', type => 'text', size => 40 },
62 $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
63 'Description—' . FS::Locales->description($_);
70 'percent' => { label => 'Fraction of invoice total', type => 'percentage', },
73 'percent' => { label => 'Fraction of balance', type => 'percentage', },
76 'usage' => { type => 'part_fee_usage' }
82 { field => 'itemdesc', type => 'text', size => 40, },
85 { field => 'comment', type => 'text', size => 40, },
87 { field => 'agentnum',
88 type => 'select-agent',
89 disable_empty => !$acl_edit_global,
90 empty_label => '(global)',
93 { field => 'classnum',
94 type => 'select-pkg_class',
97 { field => 'disabled',
102 { field => 'setuprecur',
104 options => [ 'setup', 'recur' ],
105 labels => { 'setup' => 'a setup fee',
106 'recur' => 'a recurring charge' },
109 { type => 'justtitle', value => 'Fee calculation' },
110 { field => 'amount', type => 'money', },
113 type => 'selectlayers',
114 options => [ 'charged', 'owed', 'usage' ],
115 labels => { 'charged' => 'amount charged',
116 'owed' => 'balance due',
117 'usage' => 'usage charges' },
118 layer_fields => \%layer_fields,
119 layer_values_callback => sub {
120 my ($cgi, $obj) = @_;
122 'charged' => { percent => $obj->percent },
123 'owed' => { percent => $obj->percent },
124 'usage' => { usage => [ $obj->part_fee_usage ] },
128 { field => 'minimum', type => 'money', },
129 { field => 'maximum', type => 'money', },
130 { field => 'limit_credit',
134 { type => 'justtitle', value => 'Taxation' },
139 my $edit_callback = sub {
140 my ($cgi, $obj, $fields, $opt) = @_;
141 my %existing_locales;
142 if ( $obj->feepart ) {
143 %existing_locales = map { $_->locale => $_ } $obj->part_fee_msgcat;
147 $obj->set('feepartmsgnum'.$n.'_locale', $_);
148 # load the existing itemdescs
149 if ( my $msgcat = $existing_locales{$_} ) {
150 $obj->set('feepartmsgnum'.$n, $msgcat->feepartmsgnum);
151 $obj->set('feepartmsgnum'.$n.'_itemdesc', $msgcat->itemdesc);
153 # then override that with the CGI param if there is one
154 if ( my $itemdesc = $cgi->param('feepartmsgnum'.$n.'_itemdesc') ) {
155 $obj->set('feepartmsgnum'.$n.'_itemdesc', $itemdesc);
161 my $error_callback = $edit_callback;