invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / edit / part_fee.html
index b1044c9..5f6dc38 100644 (file)
     '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',
-    'nextbill'      => 'Hold until the customer\'s next invoice',
     %locale_labels
   },
   'fields'        => \@fields,
+  'viewall_dir'   => 'browse',
   'edit_callback'   => $edit_callback,
   'error_callback'  => $error_callback,
 &>
@@ -36,7 +35,7 @@ die "access denied"
 
 my $conf = FS::Conf->new;
 my @tax_fields;
-if ( $conf->exists('enable_taxproducts') ) {
+if ( $conf->config('tax_data_vendor') ) {
   @tax_fields = (
     { field => 'taxproductnum', type => 'select-taxproduct' }
   );
@@ -44,7 +43,8 @@ if ( $conf->exists('enable_taxproducts') ) {
   @tax_fields = (
     { field => 'taxable', type => 'checkbox', value => 'Y' },
   );
-  push (
+  push @tax_fields,
+  (
     { field => 'taxclass', type => 'select-taxclass' },
   ) if $conf->exists('enable_taxclasses');
 }
@@ -56,8 +56,8 @@ 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,            type => 'hidden' },
+    { field => 'feepartmsgnum'. $n. '_locale', type => 'hidden', value => $_ },
     { field => 'feepartmsgnum'. $n. '_itemdesc',  type => 'text', size => 40 },
   ;
   $locale_labels{ 'feepartmsgnum'.$n.'_itemdesc' } =
@@ -65,6 +65,19 @@ foreach (@locales) {
   $n++;
 }
 
+$n = 0;
+my %layer_fields = (
+  'charged' => [
+    'charged_percent' => { label => 'Fraction of invoice total', type    => 'percentage', },
+  ],
+  'owed' => [
+    'owed_percent' => { label => 'Fraction of balance', type    => 'percentage', },
+  ],
+  'usage' => [
+    'usage'   => { type => 'part_fee_usage' }
+  ],
+);
+
 my @fields = (
 
   { field   => 'itemdesc',  type    => 'text', size    => 40, },
@@ -87,11 +100,6 @@ my @fields = (
     value   => 'Y',
   },
 
-  { field   => 'nextbill',
-    type    => 'checkbox',
-    value   => 'Y',
-  },
-
   { field   => 'setuprecur',
     type    => 'select',
     options => [ 'setup', 'recur' ],
@@ -99,24 +107,32 @@ my @fields = (
                  'recur'  => 'a recurring charge' },
   },
 
-  { type => 'justtitle', value => 'Fee calculation' },
+  { type => 'tablebreak-tr-title', 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', },
+    type    => 'selectlayers',
+    options => [ 'charged', 'owed', 'usage' ],
+    labels  => { 'charged'  => 'amount charged',
+                 'owed'     => 'balance due',
+                 'usage'    => 'usage charges' },
+    layer_fields => \%layer_fields,
+    layer_values_callback => sub {
+      my ($cgi, $obj) = @_;
+      {
+        'charged' => { charged_percent => $obj->percent },
+        'owed'    => { owed_percent => $obj->percent },
+        'usage'   => { usage => [ $obj->part_fee_usage ] },
+      }
+    },
   },
-
   { field   => 'minimum', type    => 'money', },
   { field   => 'maximum', type    => 'money', },
   { field   => 'limit_credit',
     type    => 'checkbox',
     value   => 'Y' },
 
-  { type => 'justtitle', value => 'Taxation' },
+  { type => 'tablebreak-tr-title', value => 'Taxation' },
 
   @tax_fields,
 );