From 779ca0263837bebf7f0ab6f45cb8381706049658 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 13 Jul 2006 03:54:07 +0000 Subject: [PATCH] fix multiple-agent virtualization properly for these reports --- FS/FS/Report/Table/Monthly.pm | 10 +++++++++- httemplate/search/cust_credit.html | 7 ++++--- httemplate/search/cust_pay.cgi | 16 +++++++++------- httemplate/search/report_receivables.cgi | 3 +++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/FS/FS/Report/Table/Monthly.pm b/FS/FS/Report/Table/Monthly.pm index 1b7e93aba..145f2a85c 100644 --- a/FS/FS/Report/Table/Monthly.pm +++ b/FS/FS/Report/Table/Monthly.pm @@ -5,6 +5,7 @@ use vars qw( @ISA $expenses_kludge ); use Time::Local; use FS::UID qw( dbh ); use FS::Report::Table; +use FS::CurrentUser; @ISA = qw( FS::Report::Table ); @@ -215,7 +216,7 @@ sub credits { ); } -#these should be auto-generated +#these should be auto-generated or $AUTOLOADed or something sub invoiced_12mo { my( $self, $speriod, $eperiod, $agentnum ) = @_; $speriod = $self->_subtract_11mo($speriod); @@ -330,9 +331,16 @@ sub suspended { #suspended sub in_time_period_and_agent { my( $self, $speriod, $eperiod, $agentnum ) = splice(@_, 0, 4); my $table = @_ ? shift().'.' : ''; + my $sql = "${table}_date >= $speriod AND ${table}_date < $eperiod"; + + #agent selection $sql .= " AND agentnum = $agentnum" if $agentnum; + + #agent virtualization + $sql .= ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql; + $sql; } diff --git a/httemplate/search/cust_credit.html b/httemplate/search/cust_credit.html index 279d682cd..eb78db5cd 100755 --- a/httemplate/search/cust_credit.html +++ b/httemplate/search/cust_credit.html @@ -36,9 +36,10 @@ push @search, " _date < $1 "; } - my $where = scalar(@search) - ? 'WHERE '. join(' AND ', @search) - : ''; + #here is the agent virtualization + push @search, $FS::CurrentUser::CurrentUser->agentnums_sql; + + my $where = 'WHERE '. join(' AND ', @search); my $count_query = 'SELECT COUNT(*), SUM(amount) '. 'FROM cust_credit LEFT JOIN cust_main USING ( custnum ) '. diff --git a/httemplate/search/cust_pay.cgi b/httemplate/search/cust_pay.cgi index 99ffc3d20..0247b0b0d 100755 --- a/httemplate/search/cust_pay.cgi +++ b/httemplate/search/cust_pay.cgi @@ -96,10 +96,10 @@ die "unknown search magic: ". $cgi->param('magic'); } - my $search = ''; - if ( @search ) { - $search = ' WHERE '. join(' AND ', @search); - } + #here is the agent virtualization + push @search, $FS::CurrentUser::CurrentUser->agentnums_sql; + + my $search = ' WHERE '. join(' AND ', @search); $count_query = "SELECT COUNT(*), SUM(paid) ". "FROM cust_pay LEFT JOIN cust_main USING ( custnum )". @@ -125,14 +125,16 @@ $cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby"; my $payby = $1; - $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay ". - "WHERE payinfo = '$payinfo' AND payby = '$payby'"; + $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay". + " WHERE payinfo = '$payinfo' AND payby = '$payby'". + " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql; $sql_query = { 'table' => 'cust_pay', 'hashref' => { 'payinfo' => $payinfo, 'payby' => $payby }, - 'extra_sql' => "ORDER BY _date", + 'extra_sql' => $FS::CurrentUser::CurrentUser->agentnums_sql. + " ORDER BY _date", }; } diff --git a/httemplate/search/report_receivables.cgi b/httemplate/search/report_receivables.cgi index ac94e1a5c..c1a239fd2 100755 --- a/httemplate/search/report_receivables.cgi +++ b/httemplate/search/report_receivables.cgi @@ -92,6 +92,9 @@ END $where .= " AND agentnum = '$agentnum' "; } + #here is the agent virtualization + $where .= ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql; + my $count_sql = "select count(*) from cust_main $where"; my $sql_query = { -- 2.11.0