Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / edit / part_fee.html
1 <& elements/edit.html,
2   'name_singular' => 'fee definition',
3   'table'         => 'part_fee',
4   'labels'        => {
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',
24     %locale_labels
25   },
26   'fields'        => \@fields,
27   'edit_callback'   => $edit_callback,
28   'error_callback'  => $error_callback,
29 &>
30 <%init>
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');
34 die "access denied"
35   unless $acl_edit or $acl_edit_global;
36
37 my $conf = FS::Conf->new;
38 my @tax_fields;
39 if ( $conf->exists('enable_taxproducts') ) {
40   @tax_fields = (
41     { field => 'taxproductnum', type => 'select-taxproduct' }
42   );
43 } else {
44   @tax_fields = (
45     { field => 'taxable', type => 'checkbox', value => 'Y' },
46   );
47   push (
48     { field => 'taxclass', type => 'select-taxclass' },
49   ) if $conf->exists('enable_taxclasses');
50 }
51
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
55 my $n = 0;
56 my (@locale_fields, %locale_labels);
57 foreach (@locales) {
58   push @locale_fields,
59     { field => 'feepartmsgnum'. $n,               type => 'hidden' },
60     { field => 'feepartmsgnum'. $n. '_locale',    type => 'hidden' },
61     { field => 'feepartmsgnum'. $n. '_itemdesc',  type => 'text', size => 40 },
62   ;
63   $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
64     'Description&mdash;' . FS::Locales->description($_);
65   $n++;
66 }
67
68 my @fields = (
69
70   { field   => 'itemdesc',  type    => 'text', size    => 40, },
71   @locale_fields,
72
73   { field   => 'comment',   type    => 'text', size    => 40, },
74
75   { field   => 'agentnum',
76     type    => 'select-agent',
77     disable_empty => !$acl_edit_global,
78     empty_label   => '(global)',
79   },
80
81   { field   => 'classnum',
82     type    => 'select-pkg_class',
83   },
84
85   { field   => 'disabled',
86     type    => 'checkbox',
87     value   => 'Y',
88   },
89
90   { field   => 'nextbill',
91     type    => 'checkbox',
92     value   => 'Y',
93   },
94
95   { field   => 'setuprecur',
96     type    => 'select',
97     options => [ 'setup', 'recur' ],
98     labels  => { 'setup'  => 'a setup fee',
99                  'recur'  => 'a recurring charge' },
100   },
101
102   { type => 'justtitle', value => 'Fee calculation' },
103   { field   => 'amount',  type    => 'money', },
104   { field   => 'percent', type    => 'percentage', },
105
106   { field   => 'basis',
107     type    => 'select',
108     options => [ 'charged', 'owed' ],
109     labels  => { 'charged' => 'amount charged',
110                  'owed'    => 'balance due', },
111   },
112
113   { field   => 'minimum', type    => 'money', },
114   { field   => 'maximum', type    => 'money', },
115   { field   => 'limit_credit',
116     type    => 'checkbox',
117     value   => 'Y' },
118
119   { type => 'justtitle', value => 'Taxation' },
120
121   @tax_fields,
122 );
123
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;
129   }
130   my $n = 0;
131   foreach (@locales) {
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);
137     } 
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);
141     }
142     $n++;
143   }
144 };
145
146 my $error_callback = $edit_callback;
147 </%init>