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,
'',
'',
'',
- 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_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');
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
-if ( $cgi->param('cust_classnum') ) {
- my @classnums = grep /^\d+$/, $cgi->param('cust_classnum');
- push @where, 'cust_main.classnum IN('.join(',',@classnums).')'
+# 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";
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
#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 @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' ];