emt('Description'),
@post_desc_header,
@peritem_desc,
+ @currency_desc,
emt('Invoice'),
emt('Date'),
emt('Paid'),
#strikethrough or "N/A ($amount)" or something these when
# they're not applicable to pkg_tax search
@peritem_sub,
+ @currency_sub,
'invnum',
sub { time2str('%b %d %Y', shift->_date ) },
sub { sprintf($money_char.'%.2f', shift->get('pay_amount')) },
'',
@post_desc_null,
@peritem,
+ @currency,
'invnum',
'_date',
#'pay_amount',
'',
@post_desc_null,
@peritem_null,
+ @currency_null,
$ilink,
$ilink,
$pay_link,
'rl'.
$post_desc_align.
$peritem_align.
+ $currency_align.
'rcrr'.
FS::UI::Web::cust_aligns(),
'color' => [
'',
@post_desc_null,
@peritem_null,
+ @currency_null,
'',
'',
'',
'',
@post_desc_null,
@peritem_null,
+ @currency_null,
'',
'',
'',
- refnum: Filter on customer reference source.
+- cust_classnum: Filter on customer class.
+
- classnum: Filter on package class.
+- report_optionnum: Filter on package report class. Can be a single report
+ class number, a comma-separated list, the word "multiple", or an empty
+ string (for "no report class").
+
- use_override: Apply "classnum" and "taxclass" filtering based on the
override (bundle) pkgpart, rather than always using the true pkgpart.
my @peritem = ( 'setup', 'recur' );
my @peritem_desc = ( 'Setup charge', 'Recurring charge' );
+my @currency_desc = ();
+my @currency_sub = ();
+my @currency = ();
+if ( $conf->config('currencies') ) {
+ @currency_desc = ( 'Setup billed', 'Recurring billed' );
+ @currency_sub = (
+ map {
+ my $what = $_;
+ sub { my $currency = $_[0]->get($what.'_billed_currency') or return '';
+ $currency. ' '. currency_symbol($currency, SYM_HTML).
+ $_[0]->get($what.'_billed_amount');
+ };
+ } qw( setup recur )
+ );
+ @currency = ( 'setup_billed_amount', 'recur_billed_amount' ); #for sorting
+}
+
my @pkgnum_header = ();
my @pkgnum = ();
my @pkgnum_null;
# valid in both the tax and non-tax cases
my $join_cust =
- " LEFT JOIN cust_bill USING (invnum)
- LEFT JOIN cust_main USING (custnum)
- ";
+ " LEFT JOIN cust_bill ON (cust_bill_pkg.invnum = cust_bill.invnum)".
+ # use cust_pkg.locationnum if it exists
+ FS::UI::Web::join_cust_main('cust_bill', 'cust_pkg');
#agent virtualization
my $agentnums_sql =
push @where, "cust_main.agentnum = $1";
}
+# salesnum
+if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) {
+
+ my $salesnum = $1;
+
+ my $cmp_salesnum = $cgi->param('cust_main_sales')
+ ? ' COALESCE( cust_pkg.salesnum, cust_main.salesnum )'
+ : ' cust_pkg.salesnum ';
+
+ push @where, "$cmp_salesnum = $salesnum";
+
+ #because currently we're called from sales_pkg_class.html for a specific
+ # class (or empty class) but not for all classes
+ #will have to do something to distinguish if someone wants the sales report
+ # (report_cust_bill_pkg.html) to have a sales person dropdown
+ $cgi->param('classnum', 0) unless $cgi->param('classnum');
+}
+
# refnum
if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
push @where, "cust_main.refnum = $1";
}
+# cust_classnum (false laziness w/ elements/cust_main_dayranges.html, elements/cust_pay_or_refund.html, prepaid_income.html, cust_bill_pay.html, cust_bill_pkg_referral.html, unearned_detail.html, cust_credit.html, cust_credit_refund.html, cust_main::Search::search_sql)
+if ( grep { $_ eq 'cust_classnum' } $cgi->param ) {
+ my @classnums = grep /^\d*$/, $cgi->param('cust_classnum');
+ push @where, 'COALESCE( cust_main.classnum, 0) IN ( '.
+ join(',', map { $_ || '0' } @classnums ).
+ ' )'
+ if @classnums;
+}
+
+
# custnum
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
push @where, "cust_main.custnum = $1";
LEFT JOIN part_pkg USING (pkgpart)';
my $part_pkg = 'part_pkg';
-if ( $cgi->param('use_override') ) {
+if ( $cgi->param('use_override') ) { #"Separate sub-packages from parents"
# still need the real part_pkg for tax applicability,
# so alias this one
$join_pkg .= " LEFT JOIN part_pkg AS override ON (
- COALESCE(cust_bill_pkg.pkgpart_override, cust_pkg.pkgpart, 0) = part_pkg.pkgpart
+ COALESCE(cust_bill_pkg.pkgpart_override, cust_pkg.pkgpart, 0) = override.pkgpart
)";
$part_pkg = 'override';
}
push @where, "COALESCE($part_pkg.classnum, 0) = $1";
}
+ if ( $cgi->param('report_optionnum') =~ /^(\w+)$/ ) {
+ # code reuse FTW
+ my $num = $1;
+ push @where,
+ FS::Report::Table->with_report_option( $1, $cgi->param('use_override') )
+ ;
+ }
+
# taxclass
if ( $cgi->param('taxclassNULL') ) {
# a little different from 'taxclass' in that it applies to the
#total payments
-my $pay_sub = "SELECT SUM(cust_bill_pay_pkg.amount) AS pay_amount,
- billpkgnum
- FROM cust_bill_pay_pkg
- GROUP BY billpkgnum";
-$join_pkg .= " LEFT JOIN ($pay_sub) AS item_pay USING (billpkgnum)";
-push @select, 'item_pay.pay_amount';
+my $pay_sub = "SELECT SUM(cust_bill_pay_pkg.amount)
+ FROM cust_bill_pay_pkg
+ WHERE cust_bill_pkg.billpkgnum = cust_bill_pay_pkg.billpkgnum
+ ";
+push @select, "($pay_sub) AS pay_amount";
# credit
#still want a credit total column
- my $credit_sub = "SELECT SUM(cust_credit_bill_pkg.amount) AS credit_amount,
- billpkgnum
- FROM cust_credit_bill_pkg
- GROUP BY billpkgnum";
- $join_pkg .= " LEFT JOIN ($credit_sub) AS item_credit USING (billpkgnum)";
-
- push @select, 'item_credit.credit_amount';
+ my $credit_sub = "
+ SELECT SUM(cust_credit_bill_pkg.amount)
+ FROM cust_credit_bill_pkg
+ WHERE cust_bill_pkg.billpkgnum = cust_credit_bill_pkg.billpkgnum
+ ";
+ push @select, "($credit_sub) AS credit_amount";
}
my $query = {
'table' => 'cust_bill_pkg',
- 'addl_from' => "$join_cust $join_pkg",
+ 'addl_from' => "$join_pkg $join_cust",
'hashref' => {},
'select' => join(",\n", @select ),
'extra_sql' => $where,
my $count_query =
'SELECT ' . join(',', @total) .
- " FROM cust_bill_pkg $join_cust $join_pkg
+ " FROM cust_bill_pkg $join_pkg $join_cust
$where";
@peritem_desc = map {emt($_)} @peritem_desc;
my @peritem_null = map { '' } @peritem; # placeholders
my $peritem_align = 'r' x scalar(@peritem);
+@currency_desc = map {emt($_)} @currency_desc;
+my @currency_null = map { '' } @currency; # placeholders
+my $currency_align = 'r' x scalar(@currency);
+
my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];
my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];