#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::LabelRoyalty::Command::Show;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::FormObject;
use Common::Util;

use lib '/app/tools/rps/lib';
use RPS::LabelRoyalty::LabelRoyaltyRun;
use RPS::Command;
use RPS::Payor::Payor;
use base 'RPS::Command';

use RSApache::Response::XSLT;
use RSApache::Response::XSLTDownload;

sub area { return 'label_royalty'; }
sub cmd  { return 'show'; }

use constant kTemplate => "/app/tools/rps/templates/label_royalty/index.xsl";
use constant kTextTemplate => "/app/tools/rps/templates/label_royalty/text/index.xsl";

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

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

    my $runID = $self->getParam('LabelRoyaltyRunID');
    my $payorID = $self->getParam('PayorID');
    my $filterBy = $self->getParam('filterBy');
    my $download = $self->getParam('download');

    my $payor = RPS::Payor::Payor->new(payorID => $payorID);
    $self->{xml}{Payor} = $payor;
	$self->{xml}{LabelRoyaltyRun} = RPS::LabelRoyalty::LabelRoyaltyRun->new
    (
        labelRoyaltyRunID => $runID, 
#        payorID => $payorID,
        filterBy => $filterBy,
    );


    if ($download)
    {
        my $cleanRunLabel = Common::Util::clean_name($self->{xml}{LabelRoyaltyRun}->Label());

        my $filename = "Summary_$cleanRunLabel.txt";
        $response = RSApache::Response::XSLTDownload->new($self->{xml}, kTextTemplate, $filename);
    }
    else
    {
	    $response = RSApache::Response::XSLT->new($self->{xml}, kTemplate);
    }
	return $response;
}



1;
