#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package BookPub::Tracker::Command::DownloadRoyaltyReport;
use strict;
use warnings;

use IO::Handle;
use File::Temp;

use RSApache::Response::DownloadZipDirectory;

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

use lib '/app/tools/bookpub/lib';
use BookPub::Tracker::File;
use BookPub::Tracker::Command::Main;
use BookPub::Sale::Report::Royalty::Factory;
use BookPub::Tracker::Command::DownloadRoyaltyReport::Factory;

use base 'BookPub::Command';

sub cmd      { return "download_royalty_report"; }
sub area     { return "tracker"; }
sub pageName { return "Download File"; }

use constant kTemplate => '/app/tools/bookpub/templates/tracker.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 $periodID = $self->getParam('period');
    die "ERROR - no period id" unless $periodID;

    my $report = BookPub::Sale::Report::Royalty::Factory::GetRoyaltyReport($periodID);
    my $filePath = $report->filePath();

    $response = BookPub::Tracker::Command::DownloadRoyaltyReport::Factory::GetResponse($report);
    return $response;

}

1;
