summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/UI/Web.pm3
-rw-r--r--FS/FS/cust_bill_event.pm69
-rw-r--r--httemplate/search/cust_bill_event.cgi28
3 files changed, 70 insertions, 30 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..c1d122ca1 100644
--- a/FS/FS/cust_bill_event.pm
+++ b/FS/FS/cust_bill_event.pm
@@ -189,6 +189,58 @@ 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 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};
+
+ 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 +282,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 ada7e4362..f45c8a59d 100644
--- a/httemplate/search/cust_bill_event.cgi
+++ b/httemplate/search/cust_bill_event.cgi
@@ -71,32 +71,24 @@ 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'";
+ $search{failed} = '1';
}
if ( $cgi->param('part_bill_event.payby') =~ /^(\w+)$/ ) {
- push @search, "part_bill_event.payby = '$1'";
+ $search{payby} = $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 ) '.
@@ -127,16 +119,14 @@ my $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!<FORM NAME="${_}form">!,
qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
- qq!<INPUT TYPE="hidden" NAME="beginning" VALUE="$beginning">!,
- qq!<INPUT TYPE="hidden" NAME="ending" VALUE="$ending">!,
- qq!<INPUT TYPE="hidden" NAME="failed" VALUE="$failed">!,
+ (map {qq!<INPUT TYPE="hidden" NAME="$_" VALUE="$search{$_}">!} keys(%search)),
qq!</FORM>!
} qw( print_ email_ fax_ ) );