#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Raptor::SaleReport::Command::ServiceDetail;

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

use lib '/app/tools/raptor/lib';
use Raptor::SaleReport::ServiceDetailReport;

use Raptor::Command;
use base 'Raptor::Command';

sub cmd  { return "s"; }
sub area { return "reports"; }

use constant kTemplate => '/app/tools/raptor/templates/reports.xsl';

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

    # Give any inherited methods the first crack at this.
    # (This checks for login and basic access permissions).
    #
    my $response = $self->SUPER::execute();
    return $response if $response;

    my $periodType = lc( $self->getParam("period_type") || 'q' );
    my $periodParam = $self->getParam("period");

    #    my $labelID = $self->_getUser()->LabelID() || $self->getParam("label") || undef;
    my $labelID     = $self->getParam("label") || $self->_getUser()->LabelID() || undef;
    my $countryCode = $self->getParam("country");
    my $serviceID   = $self->getParam("service");

    $self->{xml}{Report} = Raptor::SaleReport::ServiceDetailReport->new(
        periodType  => $periodType,
        periodParam => $periodParam,
        labelID     => $labelID,
        countryCode => $countryCode,
        serviceID   => $serviceID,
        commandObj  => $self,
    );

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

1;
