#'#',
'Description',
( $unearned
- ? 'Unearned'
- : 'Setup charge'
+ ? ( 'Unearned', 'Owed', 'Payment date' )
+ : ( 'Setup charge' )
),
( $use_usage eq 'usage'
? 'Usage charge'
sprintf($money_char.'%.2f', $cust_bill_pkg->setup );
}
},
+ ( $unearned
+ ? ( $owed_sub, $payment_date_sub, )
+ : ()
+ ),
sub { my $row = shift;
my $value = 0;
if ( $use_usage eq 'recurring' ) {
sub { time2str('%b %d %Y', shift->_date ) },
\&FS::UI::Web::cust_fields,
],
+ 'sort_fields' => [
+ '',
+ 'setup', #broken in $unearned case i guess
+ ( $unearned ? ('', '') : () ),
+ ( $use_usage eq 'recurring' ? 'recur - usage' :
+ $use_usage eq 'usage' ? 'usage'
+ : 'recur'
+ ),
+ ( $unearned ? ('sdate', 'edate') : () ),
+ 'invnum',
+ '_date',
+ ],
'links' => [
#'',
'',
'',
+ ( $unearned ? ( '', '' ) : () ),
'',
( $unearned ? ( '', '' ) : () ),
$ilink,
),
],
#'align' => 'rlrrrc'.FS::UI::Web::cust_aligns(),
- 'align' => 'lrr'.
+ 'align' => 'lr'.
+ ( $unearned ? 'rc' : '' ).
+ 'r'.
( $unearned ? 'cc' : '' ).
'rc'.
FS::UI::Web::cust_aligns(),
#'',
'',
'',
+ ( $unearned ? ( '', '' ) : () ),
'',
( $unearned ? ( '', '' ) : () ),
'',
#'',
'',
'',
+ ( $unearned ? ( '', '' ) : () ),
'',
( $unearned ? ( '', '' ) : () ),
'',
push @where, "_date >= $beginning",
"_date <= $ending";
-push @where , " payby != 'COMP' "
- unless $cgi->param('include_comp_cust');
-
if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
push @where, "cust_main.agentnum = $1";
}
#
#} else {
- push @where,
- ' ( '. join(' OR ',
- map ' part_pkg.taxclass = '.dbh->quote($_),
- $cgi->param('taxclass')
- ).
- ' ) ';
+ push @where, ' part_pkg.taxclass IN ( '.
+ join(', ', map dbh->quote($_), $cgi->param('taxclass') ).
+ ' ) ';
#}
die "unknown base region for empty taxclass" unless $cust_main_county;
my $same_sql = $cust_main_county->sql_taxclass_sameregion;
+ $same_sql =~ s/taxclass/part_pkg.taxclass/g;
push @where, $same_sql if $same_sql;
}
} else {
- $count_query = "SELECT COUNT(*), ";
+ if ( $use_usage ) {
+ $count_query = "SELECT COUNT(*), ";
+ } else {
+ $count_query = "SELECT COUNT(DISTINCT billpkgnum), ";
+ }
if ( $use_usage eq 'recurring' ) {
$count_query .= "SUM(setup + recur - usage)";
$count_query .= "SUM(usage)";
} elsif ( $unearned ) {
$count_query .= "SUM(cust_bill_pkg.recur)";
+ } elsif ( scalar( grep( /locationtaxid/, $cgi->param ) ) ) {
+ $count_query .= "SUM( COALESCE(cust_bill_pkg_tax_rate_location.amount, cust_bill_pkg.setup + cust_bill_pkg.recur))";
+ } elsif ( $cgi->param('iscredit') eq 'rate') {
+ $count_query .= "SUM( cust_credit_bill_pkg.amount )";
} else {
$count_query .= "SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)";
}
} elsif ( $cgi->param('istax') ) {
#false laziness w/report_tax.cgi $taxfromwhere
- if ( $conf->exists('tax-pkg_address') ) {
+ if ( scalar( grep( /locationtaxid/, $cgi->param ) ) ||
+ $cgi->param('iscredit') eq 'rate') {
+
+ $join_pkg .=
+ ' LEFT JOIN cust_bill_pkg_tax_rate_location USING ( billpkgnum ) '.
+ ' LEFT JOIN tax_rate_location USING ( taxratelocationnum ) ';
+
+ } elsif ( $conf->exists('tax-pkg_address') ) {
+
$join_pkg .= ' LEFT JOIN cust_bill_pkg_tax_location USING ( billpkgnum )
LEFT JOIN cust_location USING ( locationnum ) ';
#quelle kludge, somewhat false laziness w/report_tax.cgi
s/cust_pkg\.locationnum/cust_bill_pkg_tax_location.locationnum/g for @where;
- } elsif ( scalar( grep( /locationtaxid/, $cgi->param ) ) ||
- $cgi->param('iscredit') eq 'rate') {
- $join_pkg .=
- ' LEFT JOIN cust_bill_pkg_tax_rate_location USING ( billpkgnum ) '.
- ' LEFT JOIN tax_rate_location USING ( taxratelocationnum ) ';
}
if ( $cgi->param('iscredit') ) {
$join_pkg .= ' JOIN cust_credit_bill_pkg USING ( billpkgnum';
- if ( $conf->exists('tax-pkg_address') ) {
+ if ( $cgi->param('iscredit') eq 'rate' ) {
+ $join_pkg .= ', billpkgtaxratelocationnum )';
+ } elsif ( $conf->exists('tax-pkg_address') ) {
$join_pkg .= ', billpkgtaxlocationnum )';
push @where, "billpkgtaxratelocationnum IS NULL";
- } elsif ( $cgi->param('iscredit') eq 'rate' ) {
- $join_pkg .= ', billpkgtaxratelocationnum )';
} else {
$join_pkg .= ' )';
push @where, "billpkgtaxratelocationnum IS NULL";
my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';
+my $owed_sub = sub {
+ $money_char. shift->owed_recur; #_recur :/
+};
+
+my $payment_date_sub = sub {
+ #my $cust_bill_pkg = shift;
+ my @cust_pay = sort { $a->_date <=> $b->_date }
+ map $_->cust_bill_pay->cust_pay,
+ shift->cust_bill_pay_pkg('recur') #recur :/
+ or return '';
+ time2str('%b %d %Y', $cust_pay[-1]->_date );
+};
+
</%init>