summaryrefslogtreecommitdiff
path: root/FS/FS/cust_bill
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2015-07-03 11:38:23 -0700
committerMark Wells <mark@freeside.biz>2015-07-03 15:31:10 -0700
commit32365ef65ca6a40b5262cf166543b1d84c6aa57d (patch)
treea052352c992beafb27d09a3cdb94533451335089 /FS/FS/cust_bill
parent53b6529e6a9c3eb3a314d87e4a405b17af4daf45 (diff)
make new gross sales calculation optional, #25943
Diffstat (limited to 'FS/FS/cust_bill')
-rw-r--r--FS/FS/cust_bill/Search.pm47
1 files changed, 30 insertions, 17 deletions
diff --git a/FS/FS/cust_bill/Search.pm b/FS/FS/cust_bill/Search.pm
index 62c55d6..38f11d1 100644
--- a/FS/FS/cust_bill/Search.pm
+++ b/FS/FS/cust_bill/Search.pm
@@ -7,6 +7,7 @@ use FS::Record qw( qsearchs dbh );
use FS::cust_main;
use FS::access_user;
use FS::Conf;
+use charnames ':full';
=item search HASHREF
@@ -18,7 +19,9 @@ following additional parameters valid:
=over 4
-=item newest_percust
+=item newest_percust - only show the most recent invoice for each customer
+
+=item invoiced - show the invoiced amount (excluding discounts) instead of gross sales
=back
@@ -27,7 +30,8 @@ following additional parameters valid:
sub search {
my( $class, $params ) = @_;
- my( $count_query, $count_addl ) = ( '', '' );
+ my $count_query = '';
+ my @count_addl;
#some false laziness w/cust_bill::re_X
@@ -77,21 +81,30 @@ sub search {
my $money = (FS::Conf->new->config('money_char') || '$') . '%.2f';
- $count_query = 'SELECT COUNT(*), '. join(', ',
- map "SUM($_)",
- ( 'charged + discounted',
- 'discounted',
- 'credited',
- 'charged - credited',
- 'charged - credited - paid',
- )
- );
- $count_addl = [ "$money sales (gross)",
- "&minus; $money discounted",
- "&minus; $money credited",
- "= $money sales (net)",
+ my @sums = ( 'credited', # credits
+ 'charged - credited', # net sales
+ 'charged - credited - paid', # balance due
+ );
+
+ @count_addl = ( "\N{MINUS SIGN} $money credited",
+ "= $money net sales",
"$money outstanding balance",
- ];
+ );
+
+ if ( $params->{'invoiced'} ) {
+
+ unshift @sums, 'charged';
+ unshift @count_addl, "$money invoiced";
+
+ } else {
+
+ unshift @sums, 'charged + discounted', 'discounted';
+ unshift @count_addl, "$money gross sales",
+ "\N{MINUS SIGN} $money discounted";
+
+ }
+
+ $count_query = 'SELECT COUNT(*), '. join(', ', map "SUM($_)", @sums);
}
$count_query .= " FROM cust_bill $join $extra_sql";
@@ -115,7 +128,7 @@ sub search {
'order_by' => 'ORDER BY '. ( $params->{'order_by'} || 'cust_bill._date' ),
'count_query' => $count_query,
- 'count_addl' => $count_addl,
+ 'count_addl' => \@count_addl,
};
}