<%INIT>
use Algorithm::Accounting;
use List::Util qw(sum);
</%INIT>
<%PERL>
 my $AccAlgo = Algorithm::Accounting->new
   (fields => [qw(queueid tickets creator owner status)],
    field_groups => [
      [qw(creator status)],
      [qw(owner status)],
      [qw(queueid tickets)],
    ]
   );

 my $QueueAcc = Algorithm::Accounting->new
   (fields => [qw(queue user users)],
    field_groups => [ [qw(queue users)], ] );

 my $Queues = RT::Queues->new( $session{'CurrentUser'});
 $Queues->Limit( FIELD => 'Id', OPERATOR => '!=', VALUE => 0 );
 $Queues->OrderBy( FIELD => 'Id' );
 my $TotalProjects;
 while(my $QueueObj = $Queues->Next) {
   $TotalProjects++;
   my $Members = $QueueObj->AdminCc->MembersObj;
   while (my $watcher = $Members->Next) {
     $QueueAcc->append_data([[ $QueueObj->Name, $watcher->MemberObj->Object->Name ,'users']]);
   }
   $Members = $QueueObj->Cc->MembersObj;
   while (my $watcher = $Members->Next) {
     $QueueAcc->append_data([[ $QueueObj->Name, $watcher->MemberObj->Object->Name ,'users']]);
   }
 }

 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
 $Tickets->LimitStatus( OPERATOR => '!=', VALUE => '__NO_SUCH_VALUE__' );
 $Tickets->OrderBy( FIELD => 'Id' );
 # Is this the way to select only project-issue tickets ?
 $Tickets->Limit( FIELD => 'Creator', OPERATOR => '!=', VALUE => '12');
 $Tickets->Limit( FIELD => 'Owner',   OPERATOR => '!=', VALUE => '10');

 my $queue = RT::Queue->new($session{'CurrentUser'});
 my $QueueName;
 if($QueueId) {
   $Tickets->Limit( FIELD => 'Queue', OPERATOR => '=', VALUE => $QueueId );
   $queue->Load($QueueId);
   $QueueName = $queue->Name;
 }

 while (my $Ticket = $Tickets->Next) {
   my $creator = RT::User->new($session{'CurrentUser'});
   $creator->Load($Ticket->Creator);
   my $owner = RT::User->new($session{'CurrentUser'});
   $owner->Load($Ticket->Owner);
   $queue->Load($Ticket->Queue);
   $AccAlgo->append_data([[$queue->Name,'tickets',$creator->Name , $owner->Name, $Ticket->Status ]]);
 }

 my $queue_result = $QueueAcc->result;

 my $result   = $AccAlgo->result;
 my $queue_tickets = $result->[0]; 
 my $tickets  = $result->[1]->{'tickets'};
 my $creators = $result->[2];
</%PERL>
Total Projects: <% $TotalProjects %><br/>
Total Members: <% $queue_result->[2]->{users} %><br/>
Number of Tickets <% $QueueName? "of \"$QueueName\"" : ''%> :<% $tickets %><br/>
<hr>

<& Result, Title => 'Project-Members', List => $queue_result->[0] &>

% unless ($QueueId) {
<& Result, Title => 'Project-Ticket', List => $queue_tickets &>
% }

<& Result, Title => 'Developer-Ticket', List => $creators &>
<hr>
<%ARGS>
$QueueId => 0
</%ARGS>

