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

use lib '/app/tools/rps/lib';
use RPS::Catalog::ExpenseForm;
use RPS::ArtistContract::Command::Search;

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

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

sub cmd  { return 'expense'; }
sub area { return 'catalog'; }

use constant kTemplate => "/app/tools/rps/templates/catalog/index.xsl";

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

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

    my $albumContractID = $self->getParam('AlbumContractID');
    my $form;

    if ($albumContractID) {
        $form = RPS::Catalog::ExpenseForm->new( albumContractID => $albumContractID );
    } else {
        my $command = RPS::ArtistContract::Command::Search->new();
        return RSApache::Response::Redirect->new( $command->getRedirect() );
    }

    $self->{xml}{Form} = $form;

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

    return $response;
}

1;
