summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-10-12 18:45:46 -0700
committerMark Wells <mark@freeside.biz>2013-10-12 18:45:46 -0700
commitf9c93506a5f42b4c6dd33e402b9248c66af5b60a (patch)
tree836d46531fd9e15c6687dee5737717d07d3f7721
parent00d1a5be415015a90c17912304835307a8fc4e7e (diff)
sales person commission report fixes, #25255
-rw-r--r--FS/FS/sales.pm1
-rw-r--r--httemplate/search/sales_commission.html60
-rw-r--r--httemplate/search/sales_pkg_class.html45
3 files changed, 66 insertions, 40 deletions
diff --git a/FS/FS/sales.pm b/FS/FS/sales.pm
index c8604abce..82c875a36 100644
--- a/FS/FS/sales.pm
+++ b/FS/FS/sales.pm
@@ -146,6 +146,7 @@ sub cust_bill_pkg {
}
qsearch({ 'table' => 'cust_bill_pkg',
+ 'select' => 'cust_bill_pkg.*',
'addl_from' => ' LEFT JOIN cust_bill USING ( invnum ) '.
' LEFT JOIN cust_pkg USING ( pkgnum ) '.
' LEFT JOIN part_pkg USING ( pkgpart ) '.
diff --git a/httemplate/search/sales_commission.html b/httemplate/search/sales_commission.html
index d7b7a88ad..b4d40aeb2 100644
--- a/httemplate/search/sales_commission.html
+++ b/httemplate/search/sales_commission.html
@@ -1,17 +1,22 @@
+% if ( $salesnum ) {
+<% $cgi->redirect($sales_link->[0] . $salesnum) %>
+% } else {
<& elements/search.html,
'title' => $title,
'name_singular' => 'sales person',
-# 'redirect' => sub { #my( $sales, $cgi ) = @);
-# $saleslink;
-# },
- 'header' => [ 'Sales person', 'Sales', 'Commission', ],
- 'fields' => [ 'salesperson', $sales_sub, $commission_sub, ],
- 'links' => [ '', $sales_link, $commission_link ],
- 'align' => 'lrr',
- 'query' => { 'table' => 'sales', },
- 'count_query' => 'SELECT COUNT(*) FROM sales',
+ 'header' => [ 'Sales person', 'One-Time Sales', 'Recurring Sales', 'Commission', ],
+ 'fields' => [ 'salesperson',
+ $sales_sub_maker->('setup'),
+ $sales_sub_maker->('recur'),
+ $commission_sub,
+ ],
+ 'links' => [ '', $sales_link, $sales_link, $commission_link ],
+ 'align' => 'lrrr',
+ 'query' => \%query,
+ 'count_query' => $count_query,
'disableable' => 1,
&>
+% }
<%init>
die "access denied"
@@ -25,6 +30,14 @@ my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
my $date_format = $conf->config('date_format') || '%m/%d/%Y';
+my %query = ( 'table' => 'sales' );
+my $count_query = "SELECT COUNT(*) FROM sales";
+
+my $salesnum;
+if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) {
+ $salesnum = $1;
+}
+
my $title = 'Sales person commission';
$title .= ': '. time2str($date_format, $beginning). ' to '.
time2str($date_format, $ending)
@@ -40,19 +53,22 @@ my $sales_link = [ 'sales_pkg_class.html?'.
'salesnum'
];
-my $sales_sub = sub {
- my $sales = shift;
-
- #efficiency improvement: ask the db for a sum instead of all the records
- my $total_recur = 0;
- my @cust_bill_pkg = $sales->cust_bill_pkg(
- $beginning,
- $ending,
- 'cust_main_sales' => $cust_main_sales,
- );
- $total_recur += $_->recur foreach @cust_bill_pkg;
-
- $money_char. sprintf('%.2f', $total_recur);
+my $sales_sub_maker = sub {
+ my $field = shift;
+ sub {
+ my $sales = shift;
+
+ #efficiency improvement: ask the db for a sum instead of all the records
+ my $total = 0;
+ my @cust_bill_pkg = $sales->cust_bill_pkg(
+ $beginning,
+ $ending,
+ 'cust_main_sales' => $cust_main_sales,
+ );
+ $total += $_->get($field) foreach @cust_bill_pkg;
+
+ $money_char. sprintf('%.2f', $total);
+ };
};
my $commission_sub = sub {
diff --git a/httemplate/search/sales_pkg_class.html b/httemplate/search/sales_pkg_class.html
index c57aae66d..da5d512d5 100644
--- a/httemplate/search/sales_pkg_class.html
+++ b/httemplate/search/sales_pkg_class.html
@@ -1,10 +1,16 @@
<& elements/search.html,
'title' => $title,
'name_singular' => 'package class',
- 'header' => [ 'Package class', 'Sales', 'Commission', ],
- 'fields' => [ 'classname', $sales_sub, $commission_sub, ],
- 'links' => [ '', $sales_link, $commission_link ],
- 'align' => 'lrr',
+ 'header' => [ 'Package class',
+ 'One-Time Sales',
+ 'Recurring Sales',
+ 'Commission', ],
+ 'fields' => [ 'classname',
+ $sales_sub_maker->('setup'),
+ $sales_sub_maker->('recur'),
+ $commission_sub, ],
+ 'links' => [ '', '', '', $commission_link ],
+ 'align' => 'lrrr',
'query' => { 'table' => 'sales_pkg_class',
'hashref' => { 'salesnum' => $salesnum },
},
@@ -45,20 +51,23 @@ my $sales_link = [ 'cust_bill_pkg.cgi?'.
'classnum'
];
-my $sales_sub = sub {
- my $sales_pkg_class = shift;
-
- #efficiency improvement: ask the db for a sum instead of all the records
- my $total_recur = 0;
- my @cust_bill_pkg = $sales->cust_bill_pkg(
- $beginning,
- $ending,
- 'cust_main_sales' => $cust_main_sales,
- 'classnum' => $sales_pkg_class->classnum,
- );
- $total_recur += $_->recur foreach @cust_bill_pkg;
-
- $money_char. sprintf('%.2f', $total_recur);
+my $sales_sub_maker = sub {
+ my $field = shift;
+ sub {
+ my $sales_pkg_class = shift;
+
+ #efficiency improvement: ask the db for a sum instead of all the records
+ my $total = 0;
+ my @cust_bill_pkg = $sales->cust_bill_pkg(
+ $beginning,
+ $ending,
+ 'cust_main_sales' => $cust_main_sales,
+ 'classnum' => $sales_pkg_class->classnum,
+ );
+ $total += $_->get($field) foreach @cust_bill_pkg;
+
+ $money_char. sprintf('%.2f', $total);
+ };
};
my $commission_sub = sub {