summaryrefslogtreecommitdiff
path: root/FS/FS/sales.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-05-05 18:19:41 -0700
committerIvan Kohler <ivan@freeside.biz>2014-05-05 18:19:41 -0700
commit739d18b193ef10c6a238759af994f4abd53b4f8a (patch)
tree70ba4622bda0332c40d3f05bbfc1b09a52ca9f79 /FS/FS/sales.pm
parent34a63e9fab07ff8165dea6d207e088d29c880f83 (diff)
commission reporting optimizations, RT#28964
Diffstat (limited to 'FS/FS/sales.pm')
-rw-r--r--FS/FS/sales.pm27
1 files changed, 18 insertions, 9 deletions
diff --git a/FS/FS/sales.pm b/FS/FS/sales.pm
index bdeaf1b..f1b406d 100644
--- a/FS/FS/sales.pm
+++ b/FS/FS/sales.pm
@@ -205,28 +205,37 @@ sub cust_bill_pkg {
qsearch( $self->cust_bill_pkg_search(@_) )
}
-sub cust_credit {
+sub cust_credit_search {
my( $self, $sdate, $edate, %search ) = @_;
$search{'hashref'}->{'commission_salesnum'} = $self->salesnum;
+ my @where = ();
+ push @where, "cust_credit._date >= $sdate" if $sdate;
+ push @where, "cust_credit._date < $edate" if $edate;
+
my $classnum_sql = '';
if ( exists($search{'commission_classnum'}) ) {
my $classnum = delete($search{'commission_classnum'});
- $classnum_sql = " AND part_pkg.classnum ". ( $classnum ? " = $classnum"
- : " IS NULL " );
+ push @where, 'part_pkg.classnum '. ( $classnum ? " = $classnum"
+ : " IS NULL " );
$search{'addl_from'} .=
' LEFT JOIN cust_pkg ON ( commission_pkgnum = cust_pkg.pkgnum ) '.
' LEFT JOIN part_pkg USING ( pkgpart ) ';
}
- qsearch({ 'table' => 'cust_credit',
- 'extra_sql' => " AND cust_credit._date >= $sdate ".
- " AND cust_credit._date < $edate ".
- $classnum_sql,
- %search,
- });
+ my $extra_sql = "AND ".join(' AND ', map {"( $_ )"} @where);
+
+ { 'table' => 'cust_credit',
+ 'extra_sql' => $extra_sql,
+ %search,
+ };
+}
+
+sub cust_credit {
+ my $self = shift;
+ qsearch( $self->cust_credit_search(@_) )
}
=back