From 2c7d4f461a5d42178e88d04c34a3f8ca256ee285 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 30 Oct 2009 23:29:18 +0000 Subject: [PATCH] more reporting options for failed billing events, RT#6447 --- FS/FS/cust_event.pm | 40 +++++++++------- FS/FS/cust_main_Mixin.pm | 57 ++++++++++++++++++++++- httemplate/elements/select-part_event.html | 6 +++ httemplate/elements/select-payby.html | 4 +- httemplate/elements/tr-select-part_event.html | 20 ++++++++ httemplate/search/cust_event.html | 15 +++++- httemplate/search/report_cust_event.html | 66 ++++++++++----------------- 7 files changed, 147 insertions(+), 61 deletions(-) create mode 100644 httemplate/elements/select-part_event.html create mode 100644 httemplate/elements/tr-select-part_event.html diff --git a/FS/FS/cust_event.pm b/FS/FS/cust_event.pm index 10fb0acf7..bf3a5b749 100644 --- a/FS/FS/cust_event.pm +++ b/FS/FS/cust_event.pm @@ -322,9 +322,23 @@ specified in HASHREF. Valid parameters are =over 4 -=item +=item agentnum -=item +=item custnum + +=item invnum + +=item pkgnum + +=item failed + +=item beginning + +=item ending + +=item payby + +=item =back @@ -340,12 +354,15 @@ sub search_sql { join("\n", map { " $_: ". $param->{$_} } keys %$param ). "\n"; } - my @search = (); + my @search = $class->cust_search_sql($param); - if ( $param->{'agentnum'} && $param->{'agentnum'} =~ /^(\d+)$/ ) { - push @search, "cust_main.agentnum = $1"; - #my $agent = qsearchs('agent', { 'agentnum' => $1 } ); - #die "unknown agentnum $1" unless $agent; + #eventpart + my @eventpart = ref($param->{'eventpart'}) + ? @{ $param->{'eventpart'} } + : split(',', $param->{'eventpart'}); + @eventpart = grep /^(\d+)$/, @eventpart; + if ( @eventpart ) { + push @search, 'eventpart IN ('. join(',', @eventpart). ')'; } if ( $param->{'beginning'} =~ /^(\d+)$/ ) { @@ -361,10 +378,6 @@ sub search_sql { "statustext != 'N/A'"; } - #if ( $param->{'part_event.payby'} =~ /^(\w+)$/ ) { - # push @search, "part_event.payby = '$1'"; - #} - if ( $param->{'custnum'} =~ /^(\d+)$/ ) { push @search, "cust_main.custnum = '$1'"; } @@ -379,13 +392,8 @@ sub search_sql { "tablenum = '$1'"; } - #here is the agent virtualization - push @search, - $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' ); - my $where = 'WHERE '. join(' AND ', @search ); - join(' AND ', @search ); } diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index 86751b1cb..5a29a4c22 100644 --- a/FS/FS/cust_main_Mixin.pm +++ b/FS/FS/cust_main_Mixin.pm @@ -1,11 +1,12 @@ package FS::cust_main_Mixin; use strict; -use vars qw( $DEBUG ); +use vars qw( $DEBUG $me ); use FS::UID qw(dbh); use FS::cust_main; $DEBUG = 0; +$me = '[FS::cust_main_Mixin]'; =head1 NAME @@ -273,6 +274,60 @@ foreach my $sub (qw( prospect active inactive suspended cancelled )) { die $@ if $@; } +=item cust_search_sql + +Returns a list of SQL WHERE fragments to search for parameters specified +in HASHREF. Valid parameters are: + +=over 4 + +=item agentnum + +=item status + +=item payby + +=back + +=cut + +sub cust_search_sql { + my($class, $param) = @_; + + if ( $DEBUG ) { + warn "$me cust_search_sql called with params: \n". + join("\n", map { " $_: ". $param->{$_} } keys %$param ). "\n"; + } + + my @search = (); + + if ( $param->{'agentnum'} && $param->{'agentnum'} =~ /^(\d+)$/ ) { + push @search, "cust_main.agentnum = $1"; + } + + #status (prospect active inactive suspended cancelled) + if ( grep { $param->{'status'} eq $_ } FS::cust_main->statuses() ) { + my $method = $param->{'status'}. '_sql'; + push @search, $class->$method(); + } + + #payby + my @payby = ref($param->{'payby'}) + ? @{ $param->{'payby'} } + : split(',', $param->{'payby'}); + @payby = grep /^([A-Z]{4})$/, @payby; + if ( @payby ) { + push @search, 'cust_main.payby IN ('. join(',', map "'$_'", @payby). ')'; + } + + #here is the agent virtualization + push @search, + $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' ); + + return @search; + +} + =back =head1 BUGS diff --git a/httemplate/elements/select-part_event.html b/httemplate/elements/select-part_event.html new file mode 100644 index 000000000..f510672ba --- /dev/null +++ b/httemplate/elements/select-part_event.html @@ -0,0 +1,6 @@ +<% include( '/elements/select-table.html', + 'table' => 'part_event', + 'name_col' => 'event', + @_, + ) +%> diff --git a/httemplate/elements/select-payby.html b/httemplate/elements/select-payby.html index 3f19cb952..e0fb4f07d 100644 --- a/httemplate/elements/select-payby.html +++ b/httemplate/elements/select-payby.html @@ -8,7 +8,9 @@ % } % foreach my $option ( keys %{ $opt{'paybys'} } ) { -% my $sel = ( ref($value) && $value->{$option} ) || $option eq $value; +% my $sel = $opt{'all_selected'} +% || ( ref($value) && $value->{$option} ) +% || $option eq $value;