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',
23 'nextbill' => 'Hold until the customer\'s next invoice',
27 'edit_callback' => $edit_callback,
28 'error_callback' => $error_callback,
31 my $curuser = $FS::CurrentUser::CurrentUser;
32 my $acl_edit = $curuser->access_right('Edit fee definitions');
33 my $acl_edit_global = $curuser->access_right('Edit global fee definitions');
35 unless $acl_edit or $acl_edit_global;
37 my $conf = FS::Conf->new;
39 if ( $conf->exists('enable_taxproducts') ) {
41 { field => 'taxproductnum', type => 'select-taxproduct' }
45 { 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' },
61 { field => 'feepartmsgnum'. $n. '_itemdesc', type => 'text', size => 40 },
63 $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
64 'Description—' . FS::Locales->description($_);
70 { field => 'itemdesc', type => 'text', size => 40, },
73 { field => 'comment', type => 'text', size => 40, },
75 { field => 'agentnum',
76 type => 'select-agent',
77 disable_empty => !$acl_edit_global,
78 empty_label => '(global)',
81 { field => 'classnum',
82 type => 'select-pkg_class',
85 { field => 'disabled',
90 { field => 'nextbill',
95 { field => 'setuprecur',
97 options => [ 'setup', 'recur' ],
98 labels => { 'setup' => 'a setup fee',
99 'recur' => 'a recurring charge' },
102 { type => 'justtitle', value => 'Fee calculation' },
103 { field => 'amount', type => 'money', },
104 { field => 'percent', type => 'percentage', },
108 options => [ 'charged', 'owed' ],
109 labels => { 'charged' => 'amount charged',
110 'owed' => 'balance due', },
113 { field => 'minimum', type => 'money', },
114 { field => 'maximum', type => 'money', },
115 { field => 'limit_credit',
119 { type => 'justtitle', value => 'Taxation' },
124 my $edit_callback = sub {
125 my ($cgi, $obj, $fields, $opt) = @_;
126 my %existing_locales;
127 if ( $obj->feepart ) {
128 %existing_locales = map { $_->locale => $_ } $obj->part_fee_msgcat;
132 $obj->set('feepartmsgnum'.$n.'_locale', $_);
133 # load the existing itemdescs
134 if ( my $msgcat = $existing_locales{$_} ) {
135 $obj->set('feepartmsgnum'.$n, $msgcat->feepartmsgnum);
136 $obj->set('feepartmsgnum'.$n.'_itemdesc', $msgcat->itemdesc);
138 # then override that with the CGI param if there is one
139 if ( my $itemdesc = $cgi->param('feepartmsgnum'.$n.'_itemdesc') ) {
140 $obj->set('feepartmsgnum'.$n.'_itemdesc', $itemdesc);
146 my $error_callback = $edit_callback;