X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fsales_pkg_class.html;fp=httemplate%2Fsearch%2Fsales_pkg_class.html;h=8bb6bde4c3791d0fac8cad134eca0a904825ed0a;hb=511df0f6b2b42849d3174fa6c8267a9e36191baf;hp=da5d512d5bf3532e4afbad3956d86af66bbba40c;hpb=0b52519a5a11bb839b1ef5abe79b97a442bc1909;p=freeside.git diff --git a/httemplate/search/sales_pkg_class.html b/httemplate/search/sales_pkg_class.html index da5d512d5..8bb6bde4c 100644 --- a/httemplate/search/sales_pkg_class.html +++ b/httemplate/search/sales_pkg_class.html @@ -9,7 +9,7 @@ $sales_sub_maker->('setup'), $sales_sub_maker->('recur'), $commission_sub, ], - 'links' => [ '', '', '', $commission_link ], + 'links' => [ '', $sales_link, $sales_link, $commission_link ], 'align' => 'lrrr', 'query' => { 'table' => 'sales_pkg_class', 'hashref' => { 'salesnum' => $salesnum }, @@ -40,6 +40,9 @@ $title .= ': '. time2str($date_format, $beginning). ' to '. if $beginning; my $cust_main_sales = $cgi->param('cust_main_sales') eq 'Y' ? 'Y' : ''; +my $paid = $cgi->param('paid') ? 1 : 0; + +$title .= " - paid sales only" if $paid; my $sales_link = [ 'cust_bill_pkg.cgi?'. "begin=$beginning;". @@ -55,18 +58,17 @@ 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( + # could be even more efficient but this is pretty good + my $search = $sales->cust_bill_pkg_search( $beginning, $ending, 'cust_main_sales' => $cust_main_sales, 'classnum' => $sales_pkg_class->classnum, + 'paid' => $paid, ); - $total += $_->get($field) foreach @cust_bill_pkg; - - $money_char. sprintf('%.2f', $total); + $search->{'select'} = "SUM(cust_bill_pkg.$field) AS total"; + my $result = qsearchs($search); + $money_char. sprintf('%.2f', $result ? $result->get('total') : 0); }; }; @@ -85,6 +87,15 @@ my $commission_sub = sub { $money_char. sprintf('%.2f', $total_credit); }; +my $sales_link = [ 'cust_bill_pkg.cgi?'. + "begin=$beginning;". + "end=$ending;". + "cust_main_sales=$cust_main_sales;". + "salesnum=$salesnum;". + "classnum=", + 'classnum' + ]; + my $commission_link = [ 'cust_credit.html?'. "begin=$beginning;". "end=$ending;".