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

use lib '/app/tools/rps/lib';
use RPS::Statement::FastRender::Mechanical::US::Full;
use RPS::DB::Item::MechanicalStatement;

use lib '/app/tools/common/lib';
use Common::FormObject;
use Common::WriteXML;
use RSApache::Response::XSLT;
use RSApache::Response::XSLTDownload;

use RPS::Command;
use RPS::CommandLog;
use base 'RPS::Command';

sub cmd  { return 'show_mechanical_page'; }
sub area { return 'statement'; }

use constant kTemplate    => "/app/tools/rps/templates/statement/show_mechanical_paginated.xsl";
use constant kHFATemplate => "/app/tools/rps/templates/statement/hfa.xsl";

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

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

    my $id          = $self->getParam('MechanicalStatementID');
    my $commandName = 'ShowMechanical';

    my $page = $self->getParam('page');
    my $row  = $self->getParam('row');

    my $statement = RPS::Statement::FastRender::Mechanical::US::Full->new(
        mechanicalStatementID => $id,
        page                  => $page,
        row                   => $row,
    );

    $self->{xml}{Statement} = $statement;

    my $statementDB = RPS::DB::Item::MechanicalStatement->Lookup( mechanical_statement_id => $id );
    my $runID       = $statementDB->mechanical_run_id;
    my $payorID     = $statementDB->payor_id;

    $self->{xml}{Run}{MechanicalRunID} = $runID;
    $self->{xml}{Run}{PayorID}         = $payorID;

    my $template = kTemplate;
    RPS::CommandLog::Log( $self, $id );
    $response = RSApache::Response::XSLT->new( $self->{xml}, kTemplate );

    return $response;
}

1;
