-my $ending = ( str2time($1) || 4294880896 ) + 86399;
-
-my($total, $exempt, $taxable, $tax) = ( 0, 0, 0, 0 );
+my $ending = ( $1 ? str2time($1) : 4294880896 ) + 86399;
+
+my $from_join_cust = "
+ FROM cust_bill_pkg
+ JOIN cust_bill USING ( invnum )
+ JOIN cust_main USING ( custnum )
+";
+my $join_pkg = "
+ JOIN cust_pkg USING ( pkgnum )
+ JOIN part_pkg USING ( pkgpart )
+";
+my $where = "
+ WHERE _date >= $beginning AND _date <= $ending
+ AND ( county = ? OR ? = '' )
+ AND ( state = ? OR ? = '' )
+ AND ( country = ? )
+ AND payby != 'COMP'
+";
+my @base_param = qw( county county state state country );
+
+my $gotcust = "
+ WHERE 0 < ( SELECT COUNT(*) FROM cust_main
+ WHERE ( cust_main.county = cust_main_county.county
+ OR cust_main_county.county = ''
+ OR cust_main_county.county IS NULL )
+ AND ( cust_main.state = cust_main_county.state
+ OR cust_main_county.state = ''
+ OR cust_main_county.state IS NULL )
+ AND ( cust_main.country = cust_main_county.country )
+ LIMIT 1
+ )
+";
+
+my($total, $exempt, $taxable, $owed, $tax) = ( 0, 0, 0, 0, 0 );