new tax rating engine
[freeside.git] / httemplate / edit / part_pkg.cgi
index 82d6226..c00af19 100755 (executable)
@@ -3,6 +3,11 @@
 )) %>
 % #), ' onLoad="visualize()"'); 
 
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_iframe.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/overlibmws_draggable.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/iframecontentmws.js"></SCRIPT>
+
 <% include('/elements/error.html') %>
 
 <FORM NAME="dummy">
@@ -81,6 +86,35 @@ Tax information
 
 % } 
 
+% if ( $conf->exists('enable_taxproducts') ) { 
+
+  <TR><TD colspan="2">
+    <% ntable("#cccccc", 2) %>
+      <TR>
+        <TD align="right">Tax product</TD>
+        <TD>
+          <INPUT name="part_pkg_taxproduct_taxproductnum" id="taxproductnum" type="hidden" value="<% $hashref->{'taxproductnum'}%>">
+          <INPUT name="part_pkg_taxproduct_description" id="taxproductnum_description" type="text" value="<% $taxproduct_description %>" size="12" onclick="overlib( OLiframeContent('<% $p %>/browse/part_pkg_taxproduct.cgi?_type=select&id=taxproductnum&taxproductnum='+document.getElementById('taxproductnum').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
+        </TD>
+      </TR>
+      <TR>
+        <TD colspan="2" align="right">
+          <INPUT name="tax_override" id="tax_override" type="hidden" value="<% $tax_override %>">
+          <A href="javascript:void(0)" onclick="overlib( OLiframeContent('part_pkg_taxoverride.html?selected='+document.getElementById('tax_override').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
+            <% $tax_override ? 'Edit tax overrides' : 'Override taxes' %>
+          </A>
+        </TD>
+      </TR>
+    </TABLE>
+  </TD></TR>
+
+% } else { 
+
+  <INPUT TYPE="hidden" NAME="taxproductnum" VALUE="<% $hashref->{taxproductnum} %>">
+  <INPUT TYPE="hidden" NAME="tax_override" VALUE="<% $tax_override %>">
+
+% } 
+
 </TABLE>
 <BR>
 
@@ -234,7 +268,7 @@ Line-item revenue recognition
 %#} else {
 %#  push @fixups, 'taxclass'; #hidden
 %#}
-%my @form_elements = ( 'classnum', 'taxclass', 'agent_type' );
+%my @form_elements = ( 'classnum', 'taxclass', 'agent_type', 'tax_override' );
 %
 %my @form_radio = ( 'pkg_svc_primary' );
 %
@@ -243,6 +277,7 @@ Line-item revenue recognition
 %  delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq;
 %}
 %
+%#this should be replaced by /elements/selectlayers.html
 %my $widget = new HTML::Widgets::SelectLayers(
 %  'selected_layer' => $part_pkg->plan,
 %  'options'        => \%options,
@@ -251,6 +286,7 @@ Line-item revenue recognition
 %  'form_elements'  => \@form_elements,
 %  'form_text'      => [ qw(pkg comment promo_code clone pkgnum pkgpart),
 %                        qw(pay_weight credit_weight), #keys(%weight),
+%                        qw(taxproductnum),
 %                        @fixups,
 %                      ],
 %  'form_checkbox'  => [ qw(setuptax recurtax disabled) ],
@@ -285,19 +321,25 @@ Line-item revenue recognition
 %
 %      my $format = sub { shift };
 %      $format = $href->{$field}{'format'} if exists($href->{$field}{'format'});
+%
 %      if ( ! exists($href->{$field}{'type'}) ) {
+%
 %        $html .= qq!<INPUT TYPE="text" NAME="$field" VALUE="!.
 %                 ( exists($plandata{$field})
 %                     ? &$format($plandata{$field})
 %                     : $href->{$field}{'default'} ).
 %                 qq!" onChange="fchanged(this)">!;
+%
 %      } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
+%
 %        $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
 %                 ( exists($plandata{$field}) && $plandata{$field}
 %                   ? ' CHECKED'
 %                   : ''
 %                 ). '>';
+%
 %      } elsif ( $href->{$field}{'type'} =~ /^select/ ) {
+%
 %        $html .= '<SELECT';
 %        $html .= ' MULTIPLE'
 %          if $href->{$field}{'type'} eq 'select_multiple';
@@ -318,13 +360,13 @@ Line-item revenue recognition
 %          }
 %        } elsif ( $href->{$field}{'select_options'} ) {
 %          foreach my $key ( keys %{ $href->{$field}{'select_options'} } ) {
-%            my $value = $href->{$field}{'select_options'}{$key};
+%            my $label = $href->{$field}{'select_options'}{$key};
 %            $html .= qq!<OPTION VALUE="$key"!.
-%                     ( $plandata{$field} =~ /(^|, *)$value *(,|$)/
+%                     ( $plandata{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix
 %                         ? ' SELECTED'
 %                         : ''
 %                     ).
-%                     '>'. $value;
+%                     '>'. $label;
 %          }
 %
 %        } else {
@@ -333,6 +375,22 @@ Line-item revenue recognition
 %                   '</font>';
 %        }
 %        $html .= '</SELECT>';
+%
+%      } elsif ( $href->{$field}{'type'} eq 'radio' ) {
+%
+%        my $radio =
+%          qq!<INPUT TYPE="radio" NAME="$field" onChange="fchanged(this)"!;
+%
+%        foreach my $key ( keys %{ $href->{$field}{'options'} } ) {
+%          my $label = $href->{$field}{'options'}{$key};
+%          $html .= qq!$radio VALUE="$key"!.
+%                   ( $plandata{$field} =~ /(^|, *)$key *(,|$)/ #XXX fix
+%                       ? ' CHECKED'
+%                       : ''
+%                   ).
+%                   "> $label<BR>";
+%        }
+%
 %      }
 %
 %      $html .= '</TD></TR>';
@@ -363,14 +421,6 @@ Line-item revenue recognition
 <% include('/elements/footer.html') %>
 <%init>
 
-#1.7
-die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
-#1.9
-#die "access denied"
-#  unless $FS::CurrentUser::CurrentUser->access_right('Edit package definitions')
-#      || $FS::CurrentUser::CurrentUser->access_right('Edit global package definitions');
-
 if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) {
   $cgi->param('clone', $1);
 } else {
@@ -382,17 +432,26 @@ if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
   $cgi->param('pkgnum', '');
 }
 
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+  unless $curuser->access_right('Edit package definitions')
+      || $curuser->access_right('Edit global package definitions')
+      || ( $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') );
+
 my ($query) = $cgi->keywords;
 
 my $conf = new FS::Conf; 
 my $part_pkg = '';
 my @agent_type = ();
+my $tax_override;
 my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
 if ( $cgi->param('error') ) {
   $part_pkg = new FS::part_pkg ( {
     map { $_, scalar($cgi->param($_)) } fields('part_pkg')
   } );
   (@agent_type) = $cgi->param('agent_type');
+  $tax_override = $cgi->param('tax_override');
 }
 
 my $action = '';
@@ -408,6 +467,16 @@ if ( $cgi->param('clone') ) {
 } elsif ( $query && $query =~ /^(\d+)$/ ) {
   (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
     unless $part_pkg;
+  unless ($part_pkg) {
+    $tax_override =
+    join (",", map {$_->taxclassnum}
+               qsearch( 'part_pkg_taxoverride', {'pkgpart' => $1} )
+         );
+#    join (",", map {$_->taxclassnum}
+#               $part_pkg->part_pkg_taxrate( 'cch', $conf->config('defaultloc')
+#         );
+#      unless $tax_override;
+  }
   $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
   $pkgpart = $part_pkg->pkgpart;
 } else {
@@ -425,5 +494,6 @@ unless ( $part_pkg->plan ) { #backwards-compat
 }
 $action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
 my $hashref = $part_pkg->hashref;
+my $taxproduct_description = $part_pkg->taxproduct_description;
 
 </%init>