X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fpart_pkg.cgi;h=ccce8308cc30c4f0dc2ec29fd46fe34c043d1b9e;hb=eef578f09ac0198a48287a0c85d367fcd5f17459;hp=d9dcaa87f236398e3e6107109bfdb31e4826bc89;hpb=f6251ae7cea086ef67e09cf9144f663b3842c0a1;p=freeside.git diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index d9dcaa87f..ccce8308c 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -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,26 @@ {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, + layers_only => !$taxproducts, + cell_style => ( !$taxproducts + ? 'display:none' + : '' + ), + }, { type => 'tablebreak-tr-title', value => 'Promotions', #better name? @@ -152,6 +172,9 @@ die "access denied" || $curuser->access_right('Edit global package definitions') || ( $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') ); +my $conf = new FS::Conf; +my $taxproducts = $conf->exists('enable_taxproducts'); + #XXX # - tr-part_pkg_freq: month_increments_only (from price plans) # - test cloning @@ -164,16 +187,41 @@ die "access denied" #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') } ); @@ -210,6 +258,8 @@ my $new_object_callback = sub { $part_pkg = $clone_part_pkg->clone; $part_pkg->disabled('Y'); %options = $clone_part_pkg->options; + $part_pkg->set($_ => $options{$_}) + foreach (qw( setup_fee recur_fee )); } else { $part_pkg = FS::part_pkg->new( $hashref ); $part_pkg->set($_ => '0') @@ -221,15 +271,19 @@ my $new_object_callback = sub { }; 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') @@ -430,8 +484,57 @@ my $html_bottom = sub { include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ). ''; }; +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 }); + +}; +