X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fsales_commission.html;h=57b6cdcd544afe3210c5506f48fdb5e210b6a35f;hb=0393defb3dee145a4bedee761de25cfd1ac503e0;hp=d7b7a88ad5eb9d3e10929291419e05b836a0e970;hpb=eedfe58ba50912dbfb490aa47930bbc0ab9e3ac9;p=freeside.git diff --git a/httemplate/search/sales_commission.html b/httemplate/search/sales_commission.html index d7b7a88ad..57b6cdcd5 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,34 +30,54 @@ 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"; + +if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { + $query{hashref}->{agentnum} = $1; + $count_query .= " WHERE agentnum = $1"; +} + +my $salesnum = ''; +if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) { + $salesnum = $1; +} else { + $cgi->delete('salesnum'); +} + my $title = 'Sales person commission'; $title .= ': '. time2str($date_format, $beginning). ' to '. time2str($date_format, $ending) if $beginning; +my $paid = $cgi->param('paid') ? 1 : 0; +$title .= ' - paid sales only' if $paid; + my $cust_main_sales = $cgi->param('cust_main_sales') eq 'Y' ? 'Y' : ''; my $sales_link = [ 'sales_pkg_class.html?'. - "begin=$beginning;". - "end=$ending;". - "cust_main_sales=$cust_main_sales;". - "salesnum=", + # pass all of our parameters along + $cgi->query_string. ';salesnum=', '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, + 'paid' => $paid, + ); + $total += $_->get($field) foreach @cust_bill_pkg; + + $money_char. sprintf('%.2f', $total); + }; }; my $commission_sub = sub {