summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2014-02-18 22:04:12 -0800
committerMark Wells <mark@freeside.biz>2014-02-18 22:04:24 -0800
commit30e2dfd524a3f52445cbca6bc2cd1962dce7eb04 (patch)
tree2f54d7d1e316d4e0ab3137848e46ea8dfceb4a37 /httemplate
parent3c7fd3e7d40f2c946b2fcf63c63d595c82fcae22 (diff)
non-package fees, phase 1, #25899
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/browse/part_fee.html67
-rw-r--r--httemplate/edit/part_fee.html141
-rwxr-xr-xhttemplate/edit/process/part_fee.html20
-rw-r--r--httemplate/elements/menu.html4
4 files changed, 232 insertions, 0 deletions
diff --git a/httemplate/browse/part_fee.html b/httemplate/browse/part_fee.html
new file mode 100644
index 000000000..0370fe06d
--- /dev/null
+++ b/httemplate/browse/part_fee.html
@@ -0,0 +1,67 @@
+<& elements/browse.html,
+ 'title' => 'Fee definitions',
+ 'name_singular' => 'fee definition',
+ 'query' => $query,
+ 'count_query' => $count_query,
+ 'header' => [ '#',
+ 'Description',
+ 'Comment',
+ 'Class',
+ 'Amount',
+ 'Tax status',
+ ],
+ 'fields' => [ 'feepart',
+ 'itemdesc',
+ 'comment',
+ 'classname',
+ $sub_amount,
+ $sub_tax,
+ ],
+ disableable => 1,
+ disabled_statuspos => 3,
+ agent_pos => 6,
+ agent_virt => 1,
+ agent_null_right=> 'Edit global fee definitions',
+ links => [ '',
+ $link,
+ $link,
+ ],
+ align => 'cllccc',
+&>
+<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $acl_edit = $curuser->access_right('Edit fee definitions');
+my $acl_edit_global = $curuser->access_right('Edit global fee definitions');
+die "access denied"
+ unless $acl_edit or $acl_edit_global;
+
+my $query = {
+ 'select' => 'part_fee.*,'.
+ '(select classname from pkg_class '.
+ 'where pkg_class.classnum = part_fee.classnum) AS classname',
+ 'table' => 'part_fee',
+};
+my $count_query = "SELECT COUNT(*) FROM part_fee";
+
+my $sub_amount = sub {
+ my $obj = shift;
+ my $string = $obj->explanation;
+ $string =~ s/\n/<br>/sg;
+ $string;
+};
+
+my $sub_tax = sub {
+ my $obj = shift;
+ if ( $obj->taxable ) {
+ return $obj->taxclass || 'taxable';
+ } elsif ( $obj->taxproductnum ) {
+ return join('<br>',
+ split(/\s*:\s*/, $obj->part_pkg_taxproduct->description)
+ );
+ } else {
+ return 'exempt';
+ }
+};
+
+my $link = [ $p.'edit/part_fee.html?', 'feepart' ];
+</%init>
diff --git a/httemplate/edit/part_fee.html b/httemplate/edit/part_fee.html
new file mode 100644
index 000000000..dada23360
--- /dev/null
+++ b/httemplate/edit/part_fee.html
@@ -0,0 +1,141 @@
+<& elements/edit.html,
+ 'name_singular' => 'fee definition',
+ 'table' => 'part_fee',
+ 'labels' => {
+ 'feepart' => 'Fee definition',
+ 'itemdesc' => 'Description',
+ 'comment' => 'Comment (customer-hidden)',
+ 'classnum' => 'Package class',
+ 'taxable' => 'This fee is taxable',
+ 'disabled' => 'Disable this fee',
+ 'taxclass' => 'Tax class name',
+ 'taxproductnum' => 'Tax product',
+ 'pay_weight' => 'Payment weight',
+ 'credit_weight' => 'Credit weight',
+ 'agentnum' => 'Agent',
+ 'amount' => 'Flat fee amount',
+ 'percent' => 'Percentage of invoice amount',
+ 'basis' => 'Based on',
+ 'setuprecur' => 'Report this fee as',
+ 'minimum' => 'Minimum fee',
+ 'maximum' => 'Maximum fee',
+ 'limit_credit' => 'Limit to customer credit balance',
+ %locale_labels
+ },
+ 'fields' => \@fields,
+ 'edit_callback' => $edit_callback,
+ 'error_callback' => $error_callback,
+&>
+<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $acl_edit = $curuser->access_right('Edit fee definitions');
+my $acl_edit_global = $curuser->access_right('Edit global fee definitions');
+die "access denied"
+ unless $acl_edit or $acl_edit_global;
+
+my $conf = FS::Conf->new;
+my @tax_fields;
+if ( $conf->exists('enable_taxproducts') ) {
+ @tax_fields = (
+ { field => 'taxproductnum', type => 'select-taxproduct' }
+ );
+} else {
+ @tax_fields = (
+ { field => 'taxable', type => 'checkbox', value => 'Y' },
+ );
+ push (
+ { field => 'taxclass', type => 'select-taxclass' },
+ ) if $conf->exists('enable_taxclasses');
+}
+
+my $default_locale = $conf->config('locale') || 'en_US';
+my @locales = grep {$_ ne $default_locale} $conf->config('available-locales');
+# duplicates edit/part_pkg.cgi, yuck
+my $n = 0;
+my (@locale_fields, %locale_labels);
+foreach (@locales) {
+ push @locale_fields,
+ { field => 'feepartmsgnum'. $n, type => 'hidden' },
+ { field => 'feepartmsgnum'. $n. '_locale', type => 'hidden' },
+ { field => 'feepartmsgnum'. $n. '_itemdesc', type => 'text', size => 40 },
+ ;
+ $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
+ 'Description&mdash;' . FS::Locales->description($_);
+ $n++;
+}
+
+my @fields = (
+
+ { field => 'itemdesc', type => 'text', size => 40, },
+ @locale_fields,
+
+ { field => 'comment', type => 'text', size => 40, },
+
+ { field => 'agentnum',
+ type => 'select-agent',
+ disable_empty => !$acl_edit_global,
+ empty_label => '(global)',
+ },
+
+ { field => 'classnum',
+ type => 'select-pkg_class',
+ },
+
+ { field => 'disabled',
+ type => 'checkbox',
+ value => 'Y',
+ },
+
+ { field => 'setuprecur',
+ type => 'select',
+ options => [ 'setup', 'recur' ],
+ labels => { 'setup' => 'a setup fee',
+ 'recur' => 'a recurring charge' },
+ },
+
+ { type => 'justtitle', value => 'Fee calculation' },
+ { field => 'amount', type => 'money', },
+ { field => 'percent', type => 'percentage', },
+
+ { field => 'basis',
+ type => 'select',
+ options => [ 'charged', 'owed' ],
+ labels => { 'charged' => 'amount charged',
+ 'owed' => 'balance due', },
+ },
+
+ { field => 'minimum', type => 'money', },
+ { field => 'maximum', type => 'money', },
+ { field => 'limit_credit',
+ type => 'checkbox',
+ value => 'Y' },
+
+ { type => 'justtitle', value => 'Taxation' },
+
+ @tax_fields,
+);
+
+my $edit_callback = sub {
+ my ($cgi, $obj, $fields, $opt) = @_;
+ my %existing_locales;
+ if ( $obj->feepart ) {
+ %existing_locales = map { $_->locale => $_ } $obj->part_fee_msgcat;
+ }
+ my $n = 0;
+ foreach (@locales) {
+ $obj->set('feepartmsgnum'.$n.'_locale', $_);
+ # load the existing itemdescs
+ if ( my $msgcat = $existing_locales{$_} ) {
+ $obj->set('feepartmsgnum'.$n, $msgcat->feepartmsgnum);
+ $obj->set('feepartmsgnum'.$n.'_itemdesc', $msgcat->itemdesc);
+ }
+ # then override that with the CGI param if there is one
+ if ( my $itemdesc = $cgi->param('feepartmsgnum'.$n.'_itemdesc') ) {
+ $obj->set('feepartmsgnum'.$n.'_itemdesc', $itemdesc);
+ }
+ $n++;
+ }
+};
+
+my $error_callback = $edit_callback;
+</%init>
diff --git a/httemplate/edit/process/part_fee.html b/httemplate/edit/process/part_fee.html
new file mode 100755
index 000000000..25656e9b0
--- /dev/null
+++ b/httemplate/edit/process/part_fee.html
@@ -0,0 +1,20 @@
+<& elements/process.html,
+ 'debug' => 1,
+ 'table' => 'part_fee',
+ 'agent_virt' => 1,
+ 'agent_null_right' => 'Edit global fee definitions',
+ 'viewall_dir' => 'browse',
+ 'process_o2m' => {
+ 'table' => 'part_fee_msgcat',
+ 'fields' => [ 'locale', 'itemdesc' ],
+ },
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $acl_edit = $curuser->access_right('Edit fee definitions');
+my $acl_edit_global = $curuser->access_right('Edit global fee definitions');
+die "access denied"
+ unless $acl_edit or $acl_edit_global;
+
+</%init>
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index fb84e7501..cd4fb39ec 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -584,6 +584,10 @@ if ( $curuser->access_right('Configuration') ) {
$config_pkg{'Package report classes'} = [ $fsurl.'browse/part_pkg_report_option.html', 'Package classes define optional groups of packages for reporting only.' ];
#eo package grouping sub-menu
+ if ( $curuser->access_right([ 'Edit fee definitions',
+ 'Edit global fee definitions' ]) ) {
+ $config_pkg{'Fees'} = [ $fsurl.'browse/part_fee.html', '' ];
+ }
$config_pkg{'Discounts'} = [ $fsurl.'browse/discount.html', '' ];
$config_pkg{'Discount classes'} = [ $fsurl.'browse/discount_class.html', '' ];
$config_pkg{'Cancel/Suspend Reasons'} = [ \%config_pkg_reason, '' ];