X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fcust_bill_pkg.cgi;h=440ab150cdb2a1deb7bbd565007dfea2ab3803e4;hb=cc3a43f7d4386297a8babebfdd49646f836db127;hp=f87862a3d6660c669a93d4f673e6ba3b22ac2e67;hpb=e77413eda0cd0e13d0acd9edaae9fe1451248346;p=freeside.git diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi index f87862a3d..440ab150c 100644 --- a/httemplate/search/cust_bill_pkg.cgi +++ b/httemplate/search/cust_bill_pkg.cgi @@ -20,12 +20,10 @@ 'fields' => [ @pkgnum, sub { $_[0]->pkgnum > 0 - # possibly use override.pkg but i think this correct ? $_[0]->get('pkgpart') : '' }, sub { $_[0]->pkgnum > 0 - # possibly use override.pkg but i think this correct ? $_[0]->get('pkg') : $_[0]->get('itemdesc') }, @@ -139,9 +137,9 @@ Filtering parameters: - use_override: Apply "classnum" and "taxclass" filtering based on the override (bundle) pkgpart, rather than always using the true pkgpart. -- nottax: Limit to items that are not taxes (pkgnum > 0). +- nottax: Limit to items that are not taxes (pkgnum > 0 or feepart > 0). -- istax: Limit to items that are taxes (pkgnum == 0). +- istax: Limit to items that are taxes (pkgnum == 0 and feepart = null). - taxnum: Limit to items whose tax definition matches this taxnum. With "nottax" that means items that are subject to that tax; @@ -246,7 +244,6 @@ if ( $conf->exists('enable_taxclasses') ) { push @post_desc, 'taxclass'; push @post_desc_null, ''; $post_desc_align .= 'l'; - push @select, 'part_pkg.taxclass'; # or should this use override? } # valid in both the tax and non-tax cases @@ -308,10 +305,13 @@ if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { # we want the package and its definition if available my $join_pkg = ' LEFT JOIN cust_pkg USING (pkgnum) - LEFT JOIN part_pkg USING (pkgpart)'; + LEFT JOIN part_pkg USING (pkgpart) + LEFT JOIN part_fee USING (feepart)'; my $part_pkg = 'part_pkg'; -if ( $cgi->param('use_override') ) { #"Separate sub-packages from parents" +# "Separate sub-packages from parents" +my $use_override = $cgi->param('use_override') ? 1 : 0; +if ( $use_override ) { # still need the real part_pkg for tax applicability, # so alias this one $join_pkg .= " LEFT JOIN part_pkg AS override ON ( @@ -319,12 +319,17 @@ if ( $cgi->param('use_override') ) { #"Separate sub-packages from parents" )"; $part_pkg = 'override'; } -push @select, 'part_pkg.pkgpart', 'part_pkg.pkg'; # or should this use override? +push @select, "$part_pkg.pkgpart", "$part_pkg.pkg"; +push @select, "COALESCE($part_pkg.taxclass, part_fee.taxclass) AS taxclass" + if $conf->exists('enable_taxclasses'); # the non-tax case if ( $cgi->param('nottax') ) { - push @where, 'cust_bill_pkg.pkgnum > 0'; + push @select, "part_fee.itemdesc"; + + push @where, + '(cust_bill_pkg.pkgnum > 0 OR cust_bill_pkg.feepart IS NOT NULL)'; my @tax_where; # will go into a subquery my @exempt_where; # will also go into a subquery @@ -335,21 +340,23 @@ if ( $cgi->param('nottax') ) { # N: classnum if ( grep { $_ eq 'classnum' } $cgi->param ) { my @classnums = grep /^\d*$/, $cgi->param('classnum'); - push @where, "COALESCE($part_pkg.classnum, 0) IN ( ". + push @where, "COALESCE(part_fee.classnum, $part_pkg.classnum, 0) IN ( ". join(',', @classnums ). ' )' if @classnums; } if ( grep { $_ eq 'report_optionnum' } $cgi->param ) { - my @nums = grep /^\w+$/, $cgi->param('report_optionnum'); - my $num = join(',', @nums); + my $num = join(',', grep /^[\d,]+$/, $cgi->param('report_optionnum')); + my $not_num = join(',', grep /^[\d,]+$/, $cgi->param('not_report_optionnum')); + my $all = $cgi->param('all_report_options') ? 1 : 0; push @where, # code reuse FTW - FS::Report::Table->with_report_option( $num, $cgi->param('use_override')); - } - - if ( $cgi->param('report_optionnum') =~ /^(\w+)$/ ) { - ; + FS::Report::Table->with_report_option( + report_optionnum => $num, + not_report_optionnum => $not_num, + use_override => $use_override, + all_report_options => $all, + ); } # taxclass @@ -358,7 +365,7 @@ if ( $cgi->param('nottax') ) { # effective taxclass, not the real one push @tax_where, 'cust_main_county.taxclass IS NULL' } elsif ( $cgi->param('taxclass') ) { - push @tax_where, "$part_pkg.taxclass IN (" . + push @tax_where, "COALESCE(part_fee.taxclass, $part_pkg.taxclass) IN (" . join(', ', map {dbh->quote($_)} $cgi->param('taxclass') ). ')'; } @@ -432,12 +439,12 @@ if ( $cgi->param('nottax') ) { $join_pkg .= " LEFT JOIN ($exempt_sub) AS item_exempt USING (billpkgnum)"; - } - # process tax restrictions - unshift @tax_where, - 'cust_bill_pkg_tax_location.taxable_billpkgnum = cust_bill_pkg.billpkgnum', - 'cust_main_county.tax > 0'; + # process tax restrictions + unshift @tax_where, + 'cust_bill_pkg_tax_location.taxable_billpkgnum = cust_bill_pkg.billpkgnum', + 'cust_main_county.tax > 0'; + } my $tax_sub = "SELECT 1 FROM cust_bill_pkg_tax_location @@ -679,7 +686,7 @@ if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) { 'paid' => ($cgi->param('paid') ? 1 : 0), 'classnum' => scalar($cgi->param('classnum')) ); - $join_pkg .= " JOIN sales_pkg_class ON ( COALESCE(sales_pkg_class.classnum, 0) = COALESCE( part_pkg.classnum, 0) )"; + $join_pkg .= " JOIN sales_pkg_class ON ( COALESCE(sales_pkg_class.classnum, 0) = COALESCE( part_fee.classnum, part_pkg.classnum, 0) )"; my $extra_sql = $subsearch->{extra_sql}; $extra_sql =~ s/^WHERE//;