diff options
| author | Ivan Kohler <ivan@freeside.biz> | 2013-10-19 22:31:58 -0700 |
|---|---|---|
| committer | Ivan Kohler <ivan@freeside.biz> | 2013-10-19 22:31:58 -0700 |
| commit | ecc15d03711690d2b2aeeda2bd8ff1119956c583 (patch) | |
| tree | 39803c33eda9afbbd7dd85fc59939ffddff92bc2 /httemplate/search | |
| parent | 6bcf9060e47a38b1e209b2be09f70dcce4b0e8c0 (diff) | |
| parent | 0af30a9f44dc538f8696e20d02e32183b8ccf82b (diff) | |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/search')
| -rw-r--r-- | httemplate/search/cust_bill_pkg.cgi | 41 | ||||
| -rwxr-xr-x | httemplate/search/cust_pkg.cgi | 4 | ||||
| -rwxr-xr-x | httemplate/search/report_cust_pkg.html | 60 | ||||
| -rw-r--r-- | httemplate/search/report_sales_commission.html | 16 | ||||
| -rw-r--r-- | httemplate/search/sales_commission.html | 72 | ||||
| -rw-r--r-- | httemplate/search/sales_pkg_class.html | 56 |
6 files changed, 152 insertions, 97 deletions
diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi index 4c5e90f6a..fc74b542e 100644 --- a/httemplate/search/cust_bill_pkg.cgi +++ b/httemplate/search/cust_bill_pkg.cgi @@ -283,24 +283,7 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { push @where, "cust_main.agentnum = $1"; } -# salesnum -if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) { - - my $salesnum = $1; - - my $cmp_salesnum = $cgi->param('cust_main_sales') - ? ' COALESCE( cust_pkg.salesnum, cust_main.salesnum )' - : ' cust_pkg.salesnum '; - - push @where, "$cmp_salesnum = $salesnum"; - - #because currently we're called from sales_pkg_class.html for a specific - # class (or empty class) but not for all classes - #will have to do something to distinguish if someone wants the sales report - # (report_cust_bill_pkg.html) to have a sales person dropdown - $cgi->param('classnum', 0) unless $cgi->param('classnum'); -} - +# salesnum--see below # refnum if ( $cgi->param('refnum') =~ /^(\d+)$/ ) { push @where, "cust_main.refnum = $1"; @@ -704,6 +687,28 @@ if ( $cgi->param('credit') ) { push @select, 'cust_main.custnum', FS::UI::Web::cust_sql_fields(); +#salesnum +if ( $cgi->param('salesnum') =~ /^(\d+)$/ ) { + + my $salesnum = $1; + my $sales = FS::sales->by_key($salesnum) + or die "salesnum $salesnum not found"; + + my $subsearch = $sales->cust_bill_pkg_search('', '', + 'cust_main_sales' => ($cgi->param('cust_main_sales') ? 1 : 0), + 'paid' => ($cgi->param('paid') ? 1 : 0), + 'classnum' => scalar($cgi->param('classnum')) + ); + $join_pkg .= " JOIN sales_pkg_class ON ( COALESCE(sales_pkg_class.classnum, 0) = COALESCE( part_pkg.classnum, 0) )"; + + my $extra_sql = $subsearch->{extra_sql}; + $extra_sql =~ s/^WHERE//; + push @where, $extra_sql; + + $cgi->param('classnum', 0) unless $cgi->param('classnum'); +} + + my $where = join(' AND ', @where); $where &&= "WHERE $where"; diff --git a/httemplate/search/cust_pkg.cgi b/httemplate/search/cust_pkg.cgi index 995779a46..54bfa00bf 100755 --- a/httemplate/search/cust_pkg.cgi +++ b/httemplate/search/cust_pkg.cgi @@ -175,6 +175,10 @@ for my $param (qw( censustract censustract2 )) { if grep { $_ eq $param } $cgi->param; } +#location flags (checkboxes) +my @loc = grep /^\w+$/, $cgi->param('loc'); +$search_hash{"location_$_"} = 1 foreach @loc; + my $report_option = $cgi->param('report_option'); $search_hash{report_option} = $report_option if $report_option; diff --git a/httemplate/search/report_cust_pkg.html b/httemplate/search/report_cust_pkg.html index f9aabfc7a..b3f2004b8 100755 --- a/httemplate/search/report_cust_pkg.html +++ b/httemplate/search/report_cust_pkg.html @@ -8,11 +8,7 @@ <TABLE BGCOLOR="#cccccc" CELLSPACING=0> - <TR> - <TH CLASS="background" COLSPAN=2 ALIGN="left"> - <FONT SIZE="+1">Customer search options</FONT> - </TH> - </TR> + <& /elements/tr-title.html, value => mt('Customer search options') &> <& /elements/tr-select-agent.html, 'curr_value' => scalar( $cgi->param('agentnum') ), @@ -56,11 +52,7 @@ <TABLE BGCOLOR="#cccccc" CELLSPACING=0> - <TR> - <TH CLASS="background" COLSPAN=2 ALIGN="left"> - <FONT SIZE="+1">Package search options</FONT> - </TH> - </TR> + <& /elements/tr-title.html, value => mt('Package search options') &> <& /elements/tr-select-sales.html, 'label' => 'Package sales person', @@ -70,11 +62,10 @@ 'disable_empty' => 1, &> - <% include( '/elements/tr-select-cust_pkg-status.html', + <& /elements/tr-select-cust_pkg-status.html, 'label' => 'Package status', 'onchange' => 'status_changed(this);', - ) - %> + &> <SCRIPT TYPE="text/javascript"> @@ -120,23 +111,21 @@ </SCRIPT> - <% include( '/elements/tr-select-pkg_class.html', + <& /elements/tr-select-pkg_class.html, 'pre_options' => [ '0' => 'all' ], 'empty_label' => '(empty class)', - ) - %> + &> % if ( scalar( qsearch( 'part_pkg_report_option', { 'disabled' => '' } ) ) ) { - <% include( '/elements/tr-select-table.html', + <& /elements/tr-select-table.html, 'label' => 'Report classes', 'table' => 'part_pkg_report_option', 'name_col' => 'name', 'hashref' => { 'disabled' => '' }, 'element_name' => 'report_option', 'multiple' => 'multiple', - ) - %> + &> % } <TR> @@ -189,24 +178,33 @@ </SCRIPT> - <% include( '/elements/tr-checkbox.html', + <& /elements/tr-checkbox.html, 'label' => 'Custom packages', 'field' => 'custom', 'value' => 1, 'onchange' => 'custom_changed(this);', - ) - %> - - <% include( '/elements/tr-selectmultiple-part_pkg.html' ) %> + &> + + <& /elements/tr-selectmultiple-part_pkg.html &> + + <& /elements/tr-title.html, value => mt('Location search options') &> + +% my @location_options = qw(cust nocust census nocensus); + <& /elements/tr-checkbox-multiple.html, + 'label' => 'Where package location:', + 'field' => 'loc', + 'options' => \@location_options, + 'labels' => { 'cust' => "is the customer's default location", + 'nocust' => "is not the customer's default location", + 'census' => "has a census tract", + 'nocensus' => "does not have a census tract", + }, + 'value' => { map { $_ => 1 } @location_options }, + &> - <TR> - <TH CLASS="background" COLSPAN=2> </TH> - </TR> + <& /elements/tr-title.html, value => mt('Display options') &> - <TR> - <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH> - </TR> - <% include( '/elements/tr-select-cust-fields.html' ) %> + <& /elements/tr-select-cust-fields.html &> </TABLE> diff --git a/httemplate/search/report_sales_commission.html b/httemplate/search/report_sales_commission.html index cc17e6bed..792c3353e 100644 --- a/httemplate/search/report_sales_commission.html +++ b/httemplate/search/report_sales_commission.html @@ -20,14 +20,22 @@ </SCRIPT> -<& /elements/tr-select-sales.html &> +<& /elements/tr-select-sales.html, + 'empty_label' => 'all', +&> <& /elements/tr-checkbox.html, - 'label' => 'Customer sales person if there is no package sales person', - 'field' => 'cust_main_sales', - 'value' => 'Y', + 'label' => 'Customer sales person if there is no package sales person', + 'field' => 'cust_main_sales', + 'value' => 'Y', &> +<& /elements/tr-checkbox.html, + 'label' => 'Show paid sales only', + 'field' => 'paid', + 'value' => 'Y', +&> + <& /elements/tr-input-beginning_ending.html &> </TABLE> diff --git a/httemplate/search/sales_commission.html b/httemplate/search/sales_commission.html index d7b7a88ad..e74f3792e 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,49 @@ 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; +} 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 { diff --git a/httemplate/search/sales_pkg_class.html b/httemplate/search/sales_pkg_class.html index c57aae66d..8bb6bde4c 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' => [ '', $sales_link, $sales_link, $commission_link ], + 'align' => 'lrrr', 'query' => { 'table' => 'sales_pkg_class', 'hashref' => { 'salesnum' => $salesnum }, }, @@ -34,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;". @@ -45,20 +54,22 @@ 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; + # 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, + ); + $search->{'select'} = "SUM(cust_bill_pkg.$field) AS total"; + my $result = qsearchs($search); + $money_char. sprintf('%.2f', $result ? $result->get('total') : 0); + }; }; my $commission_sub = sub { @@ -76,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;". |
