projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
correctly alias itemdesc column, #28506
[freeside.git]
/
httemplate
/
search
/
cust_bill_pkg.cgi
diff --git
a/httemplate/search/cust_bill_pkg.cgi
b/httemplate/search/cust_bill_pkg.cgi
index
7476f4d
..
b1086e3
100644
(file)
--- a/
httemplate/search/cust_bill_pkg.cgi
+++ b/
httemplate/search/cust_bill_pkg.cgi
@@
-20,15
+20,10
@@
'fields' => [
@pkgnum,
sub { $_[0]->pkgnum > 0
'fields' => [
@pkgnum,
sub { $_[0]->pkgnum > 0
- # possibly use override.pkg but i think this correct
? $_[0]->get('pkgpart')
: ''
},
? $_[0]->get('pkgpart')
: ''
},
- sub { $_[0]->pkgnum > 0
- # possibly use override.pkg but i think this correct
- ? $_[0]->get('pkg')
- : $_[0]->get('itemdesc')
- },
+ 'itemdesc', # is part_pkg.pkg if applicable
@post_desc,
#strikethrough or "N/A ($amount)" or something these when
# they're not applicable to pkg_tax search
@post_desc,
#strikethrough or "N/A ($amount)" or something these when
# they're not applicable to pkg_tax search
@@
-139,9
+134,9
@@
Filtering parameters:
- use_override: Apply "classnum" and "taxclass" filtering based on the
override (bundle) pkgpart, rather than always using the true pkgpart.
- 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;
- taxnum: Limit to items whose tax definition matches this taxnum.
With "nottax" that means items that are subject to that tax;
@@
-246,9
+241,11
@@
if ( $conf->exists('enable_taxclasses') ) {
push @post_desc, 'taxclass';
push @post_desc_null, '';
$post_desc_align .= 'l';
push @post_desc, 'taxclass';
push @post_desc_null, '';
$post_desc_align .= 'l';
- push @select, 'part_pkg.taxclass'; # or should this use override?
}
}
+# used in several places
+my $itemdesc = 'COALESCE(part_fee.itemdesc, part_pkg.pkg, cust_bill_pkg.itemdesc)';
+
# valid in both the tax and non-tax cases
my $join_cust =
" LEFT JOIN cust_bill ON (cust_bill_pkg.invnum = cust_bill.invnum)".
# valid in both the tax and non-tax cases
my $join_cust =
" LEFT JOIN cust_bill ON (cust_bill_pkg.invnum = cust_bill.invnum)".
@@
-308,7
+305,8
@@
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
# we want the package and its definition if available
my $join_pkg =
' LEFT JOIN cust_pkg USING (pkgnum)
# 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';
# "Separate sub-packages from parents"
my $part_pkg = 'part_pkg';
# "Separate sub-packages from parents"
@@
-321,12
+319,17
@@
if ( $use_override ) {
)";
$part_pkg = 'override';
}
)";
$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') ) {
# the non-tax case
if ( $cgi->param('nottax') ) {
- push @where, 'cust_bill_pkg.pkgnum > 0';
+ push @select, "($itemdesc) AS 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
my @tax_where; # will go into a subquery
my @exempt_where; # will also go into a subquery
@@
-337,7
+340,7
@@
if ( $cgi->param('nottax') ) {
# N: classnum
if ( grep { $_ eq 'classnum' } $cgi->param ) {
my @classnums = grep /^\d*$/, $cgi->param('classnum');
# 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;
join(',', @classnums ).
' )'
if @classnums;
@@
-362,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') ) {
# 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') ).
')';
}
join(', ', map {dbh->quote($_)} $cgi->param('taxclass') ).
')';
}
@@
-506,14
+509,16
@@
if ( $cgi->param('nottax') ) {
push @where, 'cust_bill_pkg.pkgnum = 0';
# tax location when using tax_rate_location
push @where, 'cust_bill_pkg.pkgnum = 0';
# tax location when using tax_rate_location
- if (
scalar( grep( /locationtaxid/, $cgi->param )
) ) {
+ if (
$cgi->param('vendortax'
) ) {
$join_pkg .= ' LEFT JOIN cust_bill_pkg_tax_rate_location USING ( billpkgnum ) '.
' LEFT JOIN tax_rate_location USING ( taxratelocationnum )';
$join_pkg .= ' LEFT JOIN cust_bill_pkg_tax_rate_location USING ( billpkgnum ) '.
' LEFT JOIN tax_rate_location USING ( taxratelocationnum )';
- push @where, FS::tax_rate_location->location_sql(
- map { $_ => (scalar($cgi->param($_)) || '') }
- qw( district city county state locationtaxid )
- );
+ foreach (qw( state county city locationtaxid)) {
+ if ( scalar($cgi->param($_)) ) {
+ my $place = dbh->quote( $cgi->param($_) );
+ push @where, "tax_rate_location.$_ = $place";
+ }
+ }
$total[1] = 'SUM(
COALESCE(cust_bill_pkg_tax_rate_location.amount,
$total[1] = 'SUM(
COALESCE(cust_bill_pkg_tax_rate_location.amount,
@@
-572,17
+577,12
@@
if ( $cgi->param('nottax') ) {
dbh->quote($cgi->param('taxname'));
}
dbh->quote($cgi->param('taxname'));
}
- # specific taxnums
- if ( $cgi->param('taxnum') =~ /^([\d,]+)$/) {
- push @where, "cust_main_county.taxnum IN ($1)";
- }
-
- # itemdesc, for some reason
+ # itemdesc, for breakdown from the vendor tax report
if ( $cgi->param('itemdesc') ) {
if ( $cgi->param('itemdesc') eq 'Tax' ) {
if ( $cgi->param('itemdesc') ) {
if ( $cgi->param('itemdesc') eq 'Tax' ) {
- push @where, "(
itemdesc='Tax' OR
itemdesc is null)";
+ push @where, "(
$itemdesc = 'Tax' OR $
itemdesc is null)";
} else {
} else {
- push @where,
'itemdesc='
. dbh->quote($cgi->param('itemdesc'));
+ push @where,
"$itemdesc = "
. dbh->quote($cgi->param('itemdesc'));
}
}
}
}
@@
-683,7
+683,7
@@
if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) {
'paid' => ($cgi->param('paid') ? 1 : 0),
'classnum' => scalar($cgi->param('classnum'))
);
'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//;
my $extra_sql = $subsearch->{extra_sql};
$extra_sql =~ s/^WHERE//;