[freeside-commits] freeside/httemplate/edit part_pkg.cgi, 1.94, 1.95 part_pkg_taxoverride.html, 1.2, 1.3

Jeff Finucane,420,, jeff at wavetail.420.am
Thu Aug 28 00:38:42 PDT 2008


Update of /home/cvs/cvsroot/freeside/httemplate/edit
In directory wavetail.420.am:/tmp/cvs-serv24869/httemplate/edit

Modified Files:
	part_pkg.cgi part_pkg_taxoverride.html 
Log Message:
multiple usage classes checkpoint

Index: part_pkg.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/part_pkg.cgi,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- part_pkg.cgi	18 Jun 2008 19:24:50 -0000	1.94
+++ part_pkg.cgi	28 Aug 2008 07:38:39 -0000	1.95
@@ -23,6 +23,7 @@
                             'setuptax'         => 'Setup fee tax exempt',
                             'recurtax'         => 'Recurring fee tax exempt',
                             'taxclass'         => 'Tax class',
+                            'taxproduct_select'=> 'Tax products',
                             'plan'             => 'Price plan',
                             'disabled'         => 'Disable new orders',
                             'pay_weight'       => 'Payment weight',
@@ -82,7 +83,21 @@
                               {field=>'setuptax', type=>'checkbox', value=>'Y'},
                               {field=>'recurtax', type=>'checkbox', value=>'Y'},
                               {field=>'taxclass', type=>'select-taxclass' },
-                              {field=>'taxproductnum', type=>'select-taxproduct' },
+                              { field => 'taxproductnums',
+                                type  => 'hidden',
+                                value => join(',', @taxproductnums),
+                              },
+                              { field => 'taxproduct_select',
+                                type  => 'selectlayers',
+                                options => [ '(default)', @taxproductnums ],
+                                curr_value => '(default)',
+                                labels  => { ( '(default)' => '(default)' ),
+                                             map {($_=>$usage_class{$_})}
+                                             @taxproductnums
+                                           },
+                                layer_fields => \%taxproduct_fields,
+                                layer_values_callback => $taxproduct_values,
+                              },
 
                               { type  => 'tablebreak-tr-title',
                                 value => 'Promotions', #better name?
@@ -164,16 +179,41 @@
 #my $part_pkg = '';
 
 my @agent_type = ();
-my $tax_override;
+my %tax_override = ();
 
 my $clone_part_pkg = '';
 
+my %taxproductnums = map { ($_->classnum => 1) }
+                     qsearch('usage_class', { 'disabled' => '' });
+
+if ( $cgi->param('error') ) {  # oh well
+  foreach ($cgi->param) {
+    /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
+  }
+} elsif ( my $pkgpart = $cgi->keywords || $cgi->param('pkgpart') ) {
+  $pkgpart =~ /^(\d+)$/ or die "illegal pkgpart";
+  my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $pkgpart } );
+  die "no part_pkg for pkgpart $pkgpart" unless $pkgpart;
+  foreach ($part_pkg->options) {
+    /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
+  }
+  foreach ($part_pkg->part_pkg_taxoverride) {
+    $taxproductnums{$_->usage_class} = 1
+      if $_->usage_class;
+  }
+} else {
+  # do nothing
+}
+my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
+
 my %options = ();
 my $recur_disabled = 1;
 my $error_callback = sub {
   my($cgi, $object, $fields, $opt ) = @_;
   (@agent_type) = $cgi->param('agent_type');
-  $tax_override = $cgi->param('tax_override');
+  $tax_override{''} = $cgi->param('tax_override');
+  $tax_override{$_} = $cgi->param('tax_override_$_')
+    foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
   $opt->{action} = 'Custom' if $cgi->param('clone');
   $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
 
@@ -223,15 +263,19 @@
 };
 
 my $edit_callback = sub {
-  my( $cgi, $object, $fields ) = @_;
+  my( $cgi, $object, $fields, $opt ) = @_;
 
   $recur_disabled = $object->freq ? 0 : 1;
 
   (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1});
-  $tax_override =
+  $tax_override{$_} =
     join (",", map {$_->taxclassnum}
-               qsearch( 'part_pkg_taxoverride', {'pkgpart' => $1} )
-         );
+               qsearch( 'part_pkg_taxoverride', { 'pkgpart' => $object->pkgpart,
+                                                  'usage_class' => $_,
+                                                }
+                      )
+         )
+    foreach ( '', @taxproductnums );
 
 #    join (",", map {$_->taxclassnum}
 #               $part_pkg->part_pkg_taxrate( 'cch', $conf->config('defaultloc')
@@ -432,8 +476,57 @@
   include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
   '<SCRIPT TYPE="text/javascript">'.
     include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 ).
+    "taxproduct_selectchanged(document.getElementById('taxproduct_select'));".
   '</SCRIPT>';
 
 };
 
+my %usage_class = map { ($_->classnum => $_->classname) }
+                  qsearch('usage_class', {});
+$usage_class{setup} = 'Setup';
+$usage_class{recur} = 'Recurring';
+
+my %taxproduct_fields = map { $_ => [ "taxproductnum_$_", 
+                                      { type  => 'select-taxproduct',
+                                        #label => "$usage_class{$_} tax product",
+                                      },
+                                      "tax_override_$_", 
+                                      { type  => 'select-taxoverride' }
+                                    ]
+                            }
+                         @taxproductnums;
+$taxproduct_fields{'(default)'} =
+  [ 'taxproductnum', { type => 'select-taxproduct',
+                       #label => 'Default tax product',
+                     },
+    'tax_override',  { type => 'select-taxoverride' },
+  ];
+
+my $taxproduct_values = sub {
+  my ($cgi, $object, $flags) = @_;
+  my $routine =
+    sub { my $layer = shift;
+          my @fields = @{$taxproduct_fields{$layer}};
+          my @values = ();
+          while( @fields ) {
+            my $field = shift @fields;
+            shift @fields;
+            $field =~ /^taxproductnum_\w+$/ &&
+              push @values, ( $field => $options{"usage_$field"} );
+            $field =~ /^tax_override_(\w+)$/ &&
+              push @values, ( $field => $tax_override{$1} );
+            $field =~ /^taxproductnum$/ &&
+              push @values, ( $field => $object->taxproductnum );
+            $field =~ /^tax_override$/ &&
+              push @values, ( $field => $tax_override{''} );
+          }
+          { (@values) };
+        };
+  
+  my @result = 
+    map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
+  return({ @result });
+  
+};
+
 </%init>

Index: part_pkg_taxoverride.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/part_pkg_taxoverride.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- part_pkg_taxoverride.html	2 Apr 2008 20:42:44 -0000	1.2
+++ part_pkg_taxoverride.html	28 Aug 2008 07:38:40 -0000	1.3
@@ -10,7 +10,7 @@
   <TR><TD>
 <FORM="dummy">
   <CENTER>
-    <INPUT type="submit" value="Finish" onclick="s=fetchSelected(); s.shift(); parent.document.getElementById('tax_override').value=s.toString(); parent.cClick();">
+    <INPUT type="submit" value="Finish" onclick="s=fetchSelected(); s.shift(); parent.document.getElementById('<% $element_name || "tax_override" %>').value=s.toString(); parent.cClick();">
     <INPUT type="reset" value="Cancel" onclick="parent.cClick();">
   </CENTER>
 </FORM>
@@ -121,4 +121,7 @@
 my $selected = $1
   if $cgi->param('selected') =~/^([,\d]+)$/;
 
+my $element_name = $1
+  if $cgi->param('element_name') =~/^(\w+)$/;
+
 </%init>



More information about the freeside-commits mailing list