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

use lib '/app/tools/rps/lib';
use RPS::Track::TrackContract;
use RPS::ArtistContract::Command::Show;
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 'prtc'; }
sub area { return 'track'; }

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

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

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

    my $contractID = $self->getParam('ContractID');
	my $id = $self->getParam('TrackContractID');
    my $count = $self->getParam('ProrateTrackCount');
	my $form;

    my $command;
	if(! $id)
	{
		$command = RPS::ArtistContract::Command::Search->new();
	}
    else
    {
        # Get the contract object, set it's proration value.
        #
        my $trackContract = RPS::Track::TrackContract->new(trackContractID => $id);
        $trackContract->ProrateTrackCount( $count );
        $trackContract->save();

        my $successMessage = RPS::Message->new(type => "success", code => Common::FormObject::kSuccessFormSubmit);
        $command = RPS::ArtistContract::Command::Show->new(ArtistContractID => $contractID, msg => $successMessage->toString);
    }
    return RSApache::Response::Redirect->new($command->getRedirect());
}


1;

