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