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 'percent' => 'Percentage of invoice amount',
18 'basis' => 'Based on',
19 'setuprecur' => 'Report this fee as',
20 'minimum' => 'Minimum fee',
21 'maximum' => 'Maximum fee',
22 'limit_credit' => 'Limit to customer credit balance',
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->exists('enable_taxproducts') ) {
40 { field => 'taxproductnum', type => 'select-taxproduct' }
44 { 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' },
60 { field => 'feepartmsgnum'. $n. '_itemdesc', type => 'text', size => 40 },
62 $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
63 'Description—' . FS::Locales->description($_);
69 { field => 'itemdesc', type => 'text', size => 40, },
72 { field => 'comment', type => 'text', size => 40, },
74 { field => 'agentnum',
75 type => 'select-agent',
76 disable_empty => !$acl_edit_global,
77 empty_label => '(global)',
80 { field => 'classnum',
81 type => 'select-pkg_class',
84 { field => 'disabled',
89 { field => 'setuprecur',
91 options => [ 'setup', 'recur' ],
92 labels => { 'setup' => 'a setup fee',
93 'recur' => 'a recurring charge' },
96 { type => 'justtitle', value => 'Fee calculation' },
97 { field => 'amount', type => 'money', },
98 { field => 'percent', type => 'percentage', },
102 options => [ 'charged', 'owed' ],
103 labels => { 'charged' => 'amount charged',
104 'owed' => 'balance due', },
107 { field => 'minimum', type => 'money', },
108 { field => 'maximum', type => 'money', },
109 { field => 'limit_credit',
113 { type => 'justtitle', value => 'Taxation' },
118 my $edit_callback = sub {
119 my ($cgi, $obj, $fields, $opt) = @_;
120 my %existing_locales;
121 if ( $obj->feepart ) {
122 %existing_locales = map { $_->locale => $_ } $obj->part_fee_msgcat;
126 $obj->set('feepartmsgnum'.$n.'_locale', $_);
127 # load the existing itemdescs
128 if ( my $msgcat = $existing_locales{$_} ) {
129 $obj->set('feepartmsgnum'.$n, $msgcat->feepartmsgnum);
130 $obj->set('feepartmsgnum'.$n.'_itemdesc', $msgcat->itemdesc);
132 # then override that with the CGI param if there is one
133 if ( my $itemdesc = $cgi->param('feepartmsgnum'.$n.'_itemdesc') ) {
134 $obj->set('feepartmsgnum'.$n.'_itemdesc', $itemdesc);
140 my $error_callback = $edit_callback;