#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package Support::Reports::Command::RoyaltyRunStatus;
use strict;
use warnings;

use lib '/app/tools/support/lib';
use Support::Reports::RoyaltyRunStatus;

use base 'Support::Command::Submit';

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;

use lib '/app/tools/distribution/lib';
use Support::Service::DistributionServiceList;

sub cmd  { return 'royalty_run_status'; }
sub area { return 'reports'; }

sub type { die "Virtual Method" }

use constant kTemplate => "/app/tools/support/templates/reports/royalty_run_status.xsl";

sub execute {
    my ($self) = @_;

    my $response = $self->SUPER::execute();
    return $response if $response;

    my $client      = $self->getParam('client');
    my $service     = $self->getParam('service');
    my $page        = $self->getParam('page');
    my $limit       = $self->getParam('limit') || 25;
    my $query       = $self->getParam('query');
    my $run_type    = $self->getParam('run_type');
    my $no_activity = $self->getParam('no_activity');

    my $report = new Support::Reports::RoyaltyRunStatus(
        no_activity => $no_activity,
        clientID    => $client,
        limit       => $limit,
        page        => $page,
        query       => $query,
        run_type    => $self->type()
    );

    $report->run( query => $query, service_id => $service ) if ( $self->isSubmit() );

    $self->{xml}{Services}   = new Support::Service::DistributionServiceList;
    $self->{xml}{Collection} = $report;

    $response = RSApache::Response::XSLT->new( $self->{xml}, kTemplate );
    return $response;
}

1;
