X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fbrowse%2Fpart_referral.html;h=27eb5454266f2d5c110a5c124f8187a7bf27dcac;hp=6a9f7003bdba8d52bf6310f4d5d6962f5ee14866;hb=ac8410cdb67639afeb84c84e975fffadf3e6cce1;hpb=9b38584b79d03f6baa9a55bc623760261305e96c diff --git a/httemplate/browse/part_referral.html b/httemplate/browse/part_referral.html index 6a9f7003b..27eb54542 100755 --- a/httemplate/browse/part_referral.html +++ b/httemplate/browse/part_referral.html @@ -1,132 +1,241 @@ -<%= include("/elements/header.html","Advertising source Listing" ) %> +<& /elements/header.html, "Advertising source Listing" &> Where a customer heard about your service. Tracked for informational purposes.

-Add a new advertising source +Add a new advertising source

-<% - my $today = timelocal(0, 0, 0, (localtime(time))[3..5] ); - my %after; - tie %after, 'Tie::IxHash', - 'Today' => 0, - 'Yesterday' => 86400, # 60sec * 60min * 24hrs - 'Past week' => 518400, # 60sec * 60min * 24hrs * 6days - 'Past 30 days' => 2505600, # 60sec * 60min * 24hrs * 29days - 'Past 60 days' => 5097600, # 60sec * 60min * 24hrs * 59days - 'Past 90 days' => 7689600, # 60sec * 60min * 24hrs * 89days - 'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days - 'Past year' => 31486000, # 60sec * 60min * 24hrs * 364days - 'Total' => $today, - ; - my %before = ( - 'Today' => 86400, # 60sec * 60min * 24hrs - 'Yesterday' => 0, - 'Past week' => 86400, # 60sec * 60min * 24hrs - 'Past 30 days' => 86400, # 60sec * 60min * 24hrs - 'Past 60 days' => 86400, # 60sec * 60min * 24hrs - 'Past 90 days' => 86400, # 60sec * 60min * 24hrs - 'Past 6 months' => 86400, # 60sec * 60min * 24hrs - 'Past year' => 86400, # 60sec * 60min * 24hrs - 'Total' => 86400, # 60sec * 60min * 24hrs - ); - - my $curuser = $FS::CurrentUser::CurrentUser; - my $extra_sql = $curuser->agentnums_sql; - $extra_sql .= ' OR agentnum IS NULL ' - if $curuser->access_right('Edit global advertising sources'); - - $extra_sql = " WHERE $extra_sql"; - - my $statement = "SELECT COUNT(*) FROM h_cust_main - WHERE history_action = 'insert' - AND refnum = ? - AND history_date >= ? - AND history_date < ? - AND ". $curuser->agentnums_sql; - my $sth = dbh->prepare($statement) - or die dbh->errstr; - - my $show_agentnums = scalar($curuser->agentnums); - +<% $cgi->param('showdisabled') + ? do { $cgi->param('showdisabled', 0); + '( hide disabled advertising sources )'; } + : do { $cgi->param('showdisabled', 1); + '( show disabled advertising sources )'; } %> -<%= include('/elements/table-grid.html') %> +% ### +% # Header +% ### -<% my $bgcolor1 = '#eeeeee'; - my $bgcolor2 = '#ffffff'; - my $bgcolor = ''; -%> +<& /elements/table-grid.html &> +% my $bgcolor1 = '#eeeeee'; +% my $bgcolor2 = '#ffffff'; +% my $bgcolor = ''; Advertising source - <% if ( $show_agentnums ) { %> + +% if ( ! $cgi->param('showdisabled') ) { + +% } + +% if ( $show_agentnums ) { Agent - <% } %> - >Customers - -<% for my $period ( keys %after ) { %> - <%= $period %> -<% } %> +% } + + >Prospects, Customers and Packages +% for my $period ( keys %after ) { -<% -foreach my $part_referral ( + <% $period %> +% } - qsearch({ - 'table' => 'part_referral', - 'extra_sql' => "$extra_sql ORDER BY refnum", - }) + -) { +% ### +% # Rows +% ### - if ( $bgcolor eq $bgcolor1 ) { - $bgcolor = $bgcolor2; - } else { - $bgcolor = $bgcolor1; - } +%foreach my $part_referral ( FS::part_referral->all_part_referral(1,!scalar($cgi->param('showdisabled'))) ) { +% +% if ( $bgcolor eq $bgcolor1 ) { +% $bgcolor = $bgcolor2; +% } else { +% $bgcolor = $bgcolor1; +% } +% +% $a = 0; -%> - - <%= $part_referral->refnum %> - - <%= $part_referral->referral %> - - <% if ( $show_agentnums ) { %> - <%= $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %> - <% } %> - - <% for my $period ( keys %after ) { - $sth->execute( $part_referral->refnum, - $today-$after{$period}, - $today+$before{$period}, - ) or die $sth->errstr; - my $number = $sth->fetchrow_arrayref->[0]; - %> - <%= $number %> - <% } %> + +% if ( $part_referral->agentnum || $curuser->access_right('Edit global advertising sources') ) { +% $a++; +% + + +% } + + <% $part_referral->refnum %><% $a ? '' : '' %> + +% if ( $a ) { + + +% } + + <% $part_referral->referral %><% $a ? '' : '' %> + +% if ( ! $cgi->param('showdisabled') ) { + + <% $part_referral->disabled + ? 'DISABLED' + : 'Active' + %> + +% } + +% if ( $show_agentnums ) { + + <% $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %> +% } +% for my $period ( keys %after ) { +% my @param = ( $part_referral->refnum, +% $today-$after{$period}, +% $today+$before{$period}, +% ); +% $prospect_sth->execute(@param) or die $prospect_sth->errstr; +% my $num_prospect = $prospect_sth->fetchrow_arrayref->[0]; +% $cust_sth->execute(@param) or die $cust_sth->errstr; +% my $num_cust = $cust_sth->fetchrow_arrayref->[0]; +% $pkg_sth->execute(@param) or die $pkg_sth->errstr; +% my $num_pkg = $pkg_sth->fetchrow_arrayref->[0]; + + + + + + + + + + + + + + + +
<% $num_prospect %> prospects 
<% $num_cust %> customers 
<% $num_pkg %> packages 
+ +% } + -<% } %> +% } + + +% ### +% # Bottom Totals +% ### + +% $prospect_statement =~ s/AND refnum = \?//; +% $prospect_sth = dbh->prepare($prospect_statement) +% or die dbh->errstr; +% +% $cust_statement =~ s/AND refnum = \?//; +% $cust_sth = dbh->prepare($cust_statement) +% or die dbh->errstr; +% +% $pkg_statement =~ s/AND h_pkg_referral\.refnum = \?//; +% $pkg_sth = dbh->prepare($pkg_statement) +% or die dbh->errstr; -<% - $statement =~ s/AND refnum = \?//; - $sth = dbh->prepare($statement) - or die dbh->errstr; -%> - Total - <% for my $period ( keys %after ) { - $sth->execute( $today-$after{$period}, - $today+$before{$period}, - ) or die $sth->errstr; - my $number = $sth->fetchrow_arrayref->[0]; - %> - <%= $number %> - <% } %> + param('showdisabled') %>Total +% for my $period ( keys %after ) { +% my @param = ( $today-$after{$period}, +% $today+$before{$period}, +% ); +% $prospect_sth->execute(@param) or die $prospect_sth->errstr; +% my $num_prospect = $prospect_sth->fetchrow_arrayref->[0]; +% $cust_sth->execute( @param ) or die $cust_sth->errstr; +% my $num_cust = $cust_sth->fetchrow_arrayref->[0]; +% $pkg_sth->execute(@param) or die $pkg_sth->errstr; +% my $num_pkg = $pkg_sth->fetchrow_arrayref->[0]; + + + + + + + + + + + + + + + +
<% $num_prospect %> prospects 
<% $num_cust %> customers 
<% $num_pkg %> packages 
+ + +% } + - - + +<& /elements/footer.html &> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Edit advertising sources') + || $FS::CurrentUser::CurrentUser->access_right('Edit global advertising sources'); + +my $today = timelocal(0, 0, 0, (localtime(time))[3..5] ); + +tie my %after, 'Tie::IxHash', + 'Today' => 0, + 'Yesterday' => 86400, # 60sec * 60min * 24hrs + 'Past week' => 518400, # 60sec * 60min * 24hrs * 6days + 'Past 30 days' => 2505600, # 60sec * 60min * 24hrs * 29days + 'Past 60 days' => 5097600, # 60sec * 60min * 24hrs * 59days + 'Past 90 days' => 7689600, # 60sec * 60min * 24hrs * 89days + 'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days + 'Past year' => 31486000, # 60sec * 60min * 24hrs * 364days + 'Total' => $today, +; +my %before = ( + 'Today' => 86400, # 60sec * 60min * 24hrs + 'Yesterday' => 0, + 'Past week' => 86400, # 60sec * 60min * 24hrs + 'Past 30 days' => 86400, # 60sec * 60min * 24hrs + 'Past 60 days' => 86400, # 60sec * 60min * 24hrs + 'Past 90 days' => 86400, # 60sec * 60min * 24hrs + 'Past 6 months' => 86400, # 60sec * 60min * 24hrs + 'Past year' => 86400, # 60sec * 60min * 24hrs + 'Total' => 86400, # 60sec * 60min * 24hrs +); + +my $curuser = $FS::CurrentUser::CurrentUser; + +my $show_agentnums = ( scalar($curuser->agentnums) > 1 ); + +my $prospect_statement = "SELECT COUNT(*) FROM h_prospect_main + WHERE history_action = 'insert' + AND refnum = ? + AND history_date >= ? + AND history_date < ? + AND ". $curuser->agentnums_sql; +my $prospect_sth = dbh->prepare($prospect_statement) + or die dbh->errstr; + +my $cust_statement = "SELECT COUNT(*) FROM h_cust_main + WHERE history_action = 'insert' + AND refnum = ? + AND history_date >= ? + AND history_date < ? + AND ". $curuser->agentnums_sql; +my $cust_sth = dbh->prepare($cust_statement) + or die dbh->errstr; + +my $pkg_statement = "SELECT COUNT(*) FROM h_pkg_referral + LEFT JOIN cust_pkg USING ( pkgnum ) + LEFT JOIN cust_main USING ( custnum ) + WHERE history_action = 'insert' + AND h_pkg_referral.refnum = ? + AND history_date >= ? + AND history_date < ? + AND ". $curuser->agentnums_sql; +my $pkg_sth = dbh->prepare($pkg_statement) + or die dbh->errstr; + +