From af81319b032830fdec2ba0bc51313a469c254aab Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 2 Oct 2007 15:31:35 +0000 Subject: [PATCH] fix up re-email these events --- FS/FS/UI/Web.pm | 3 +- FS/FS/cust_bill_event.pm | 73 ++++++++++++++++++++++++++++++----- httemplate/search/cust_bill_event.cgi | 30 +++++--------- 3 files changed, 75 insertions(+), 31 deletions(-) diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index 7699a7d54..29e06bcc6 100644 --- a/FS/FS/UI/Web.pm +++ b/FS/FS/UI/Web.pm @@ -410,7 +410,7 @@ use Carp; use Storable qw(nfreeze); use MIME::Base64; use JSON; -use FS::UID; +use FS::UID qw(getotaker); use FS::Record qw(qsearchs); use FS::queue; @@ -483,6 +483,7 @@ sub start_job { push @{$param{$field}}, $value; } } + $param{CurrentUser} = getotaker(); warn "FS::UI::Web::start_job\n". join('', map { if ( ref($param{$_}) ) { diff --git a/FS/FS/cust_bill_event.pm b/FS/FS/cust_bill_event.pm index 82e22f7f9..ff383ff99 100644 --- a/FS/FS/cust_bill_event.pm +++ b/FS/FS/cust_bill_event.pm @@ -189,6 +189,62 @@ sub retriable { $self->replace($old); } +=item search_sql HREF + +Class method which returns an SQL WHERE fragment to search for parameters +specified in HREF. Valid parameters are + +=over 4 +=item agentnum +=item beginning - an epoch date setting a lower bound for _date values +=item ending - an epoch date setting a upper bound for _date values +=item failed - limits the search to failed events if true +=item payby - requires that the search be JOIN'd to part_bill_event # Bug? +=item invnum +=item currentuser - specifies the user for agent virtualization +=back + +=cut + +sub search_sql { + my ($class, $params) = @_; + my @search = (); + + push @search, "agentnum = ". $params->{agentnum} if $params->{agentnum}; + + push @search, "cust_bill_event._date >= ". $params->{beginning} + if $params->{beginning}; + push @search, "cust_bill_event._date <= ". $params->{ending} + if $params->{ending}; + + push @search, "statustext != ''", + "statustext IS NOT NULL", + "statustext != 'N/A'" + if $params->{failed}; + + push @search, "part_bill_event.payby = '". $params->{payby}. "'" + if $params->{payby}; + + push @search, "cust_bill_event.invnum = '". $params->{invnum}. "'" + if $params->{invnum}; + + if ($params->{CurrentUser}) { + my $access_user = qsearchs('access_user', + {username => $params->{CurrentUser} } + ); + if ($access_user) { + push @search, $access_user->agentnums_sql; + }else{ + push @search, "1=0"; + } + }else{ + push @search, $FS::CurrentUser::CurrentUser->agentnums_sql; + } + + join(' AND ', @search ); + +} + =back =head1 SUBROUTINES @@ -230,24 +286,21 @@ sub process_re_X { re_X( $method, - $param->{'beginning'}, - $param->{'ending'}, - $param->{'failed'}, + $param, $job, ); } sub re_X { - my($method, $beginning, $ending, $failed, $job) = @_; + my($method, $param, $job) = @_; - my $where = " WHERE plan LIKE 'send%'". - " AND cust_bill_event._date >= $beginning". - " AND cust_bill_event._date <= $ending"; - $where .= " AND statustext != '' AND statustext IS NOT NULL" - if $failed; + my $where = FS::cust_bill_event->search_sql($param); + $where = " WHERE plan LIKE 'send%'". ( $where ? " AND $where" : "" ); - my $from = 'LEFT JOIN part_bill_event USING ( eventpart )'; + my $from = 'LEFT JOIN part_bill_event USING ( eventpart )'. + 'LEFT JOIN cust_bill USING ( invnum )'. + 'LEFT JOIN cust_main USING ( custnum )'; my @cust_bill_event = qsearch( 'cust_bill_event', {}, '', $where, '', $from ); diff --git a/httemplate/search/cust_bill_event.cgi b/httemplate/search/cust_bill_event.cgi index ffd95e976..51f9f8863 100644 --- a/httemplate/search/cust_bill_event.cgi +++ b/httemplate/search/cust_bill_event.cgi @@ -75,36 +75,28 @@ my $title = $cgi->param('failed') ? 'Failed invoice events' : 'Invoice events'; -my @search = (); +my %search = (); if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) { - push @search, "agentnum = $1"; - #my $agent = qsearchs('agent', { 'agentnum' => $1 } ); - #die "unknown agentnum $1" unless $agent; + $search{agentnum} = $1; } -my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi); -push @search, "cust_bill_event._date >= $beginning", - "cust_bill_event._date <= $ending"; +($search{beginning}, $search{ending}) + = FS::UI::Web::parse_beginning_ending($cgi); if ( $cgi->param('failed') ) { - push @search, "statustext != ''", - "statustext IS NOT NULL", - "statustext != 'N/A'"; + push $search{failed} = '1'; } if ( $cgi->param('part_bill_event.payby') =~ /^(\w+)$/ ) { - push @search, "part_bill_event.payby = '$1'"; + $search{payby} = $1; } if ( $cgi->param('invnum') =~ /^(\d+)$/ ) { - push @search, "cust_bill_event.invnum = '$1'"; + $search{invnum} = $1; } -#here is the agent virtualization -push @search, $FS::CurrentUser::CurrentUser->agentnums_sql; - -my $where = 'WHERE '. join(' AND ', @search ); +my $where = 'WHERE '. FS::cust_bill_event->search_sql( \%search ); my $join = 'LEFT JOIN part_bill_event USING ( eventpart ) '. 'LEFT JOIN cust_bill USING ( invnum ) '. @@ -139,16 +131,14 @@ $html_init .= join("\n", map { ( my $action = $_ ) =~ s/_$//; include('/elements/progress-init.html', $_.'form', - [ 'action', 'beginning', 'ending', 'failed' ], + [ keys(%search) ], "../misc/${_}invoice_events.cgi", { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but... $_, #key ), qq!
!, qq!!, #not used though - qq!!, - qq!!, - qq!!, + (map {qq!!} keys(%search)), qq!
! } qw( print_ email_ fax_ ) ); -- 2.11.0