3 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
6 JOIN cust_bill USING ( invnum )
7 JOIN cust_main USING ( custnum )
11 LEFT JOIN cust_pkg USING ( pkgnum )
12 LEFT JOIN part_pkg USING ( pkgpart )
16 WHERE _date >= $beginning AND _date <= $ending
20 if ( $cgi->param('out') ) {
23 AND 0 = ( SELECT COUNT(*) FROM cust_main_county
24 WHERE ( cust_main_county.county = cust_main.county
25 OR cust_main_county.county IS NULL AND cust_main.county = ''
26 OR cust_main_county.county = '' AND cust_main.county IS NULL
28 AND ( cust_main_county.state = cust_main.state
29 OR cust_main_county.state IS NULL AND cust_main.state = ''
30 OR cust_main_county.state = '' AND cust_main.state IS NULL
32 AND cust_main_county.country = cust_main.country
33 AND cust_main_county.tax > 0
37 } elsif ( $cgi->param('country' ) ) {
39 my $county = dbh->quote( $cgi->param('county') );
40 my $state = dbh->quote( $cgi->param('state') );
41 my $country = dbh->quote( $cgi->param('country') );
43 AND ( county = $county OR $county = '' )
44 AND ( state = $state OR $state = '' )
45 AND country = $country
47 $where .= ' AND taxclass = '. dbh->quote( $cgi->param('taxclass') )
48 if $cgi->param('taxclass');
52 $where .= ' AND pkgnum != 0' if $cgi->param('nottax');
54 $where .= ' AND pkgnum = 0' if $cgi->param('istax');
56 $where .= " AND tax = 'Y'" if $cgi->param('cust_tax');
59 if ( $cgi->param('pkg_tax') ) {
62 "SELECT COUNT(*), SUM( ( CASE WHEN part_pkg.setuptax = 'Y'
63 THEN cust_bill_pkg.setup
66 ( CASE WHEN part_pkg.recurtax = 'Y'
67 THEN cust_bill_pkg.recur
72 ( part_pkg.setuptax = 'Y' AND cust_bill_pkg.setup > 0 )
73 OR ( part_pkg.recurtax = 'Y' AND cust_bill_pkg.recur > 0 )
79 "SELECT COUNT(*), SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)";
82 $count_query += " FROM cust_bill_pkg $join_cust $join_pkg $where";
85 'table' => 'cust_bill_pkg',
86 'addl_from' => "$join_cust $join_pkg",
88 'select' => join(', ',
93 FS::UI::Web::cust_sql_fields(),
95 'extra_sql' => $where,
98 my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];
99 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
101 my $conf = new FS::Conf;
102 my $money_char = $conf->config('money_char') || '$';
104 %><%= include( 'elements/search.html',
105 'title' => 'Line items',
106 'name' => 'line items',
108 'count_query' => $count_query,
109 'count_addl' => [ $money_char. '%.2f total', ],
117 FS::UI::Web::cust_header(),
121 sub { $_[0]->pkgnum > 0
123 : $_[0]->get('itemdesc')
125 #strikethrough or "N/A ($amount)" or something these when
126 # they're not applicable to pkg_tax search
127 sub { sprintf($money_char.'%.2f', shift->setup ) },
128 sub { sprintf($money_char.'%.2f', shift->recur ) },
130 sub { time2str('%b %d %Y', shift->_date ) },
131 \&FS::UI::Web::cust_fields,
140 ( map { $clink } FS::UI::Web::cust_header() ),