#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Catalog::AdvanceForm;

use strict;
use warnings;
use Data::Dumper;
use lib '/app/tools/common/lib';
use Common::Assert;

use lib '/app/tools/rps/lib';
use RPS::Catalog::AlbumContractAdvance;
use RPS::LabelList;

use Common::FormObject;
use base 'Common::FormObject';

sub _init
{
	my ($self, %args) = @_;

	$self->SUPER::_init(%args);

	my ($albumContractID, $albumContractAdvanceID);
	$albumContractID = $args{albumContractID};
	$albumContractAdvanceID = $args{albumContractAdvanceID};

	# one or the other
	#
    # Here's the funny thing: We don't really want to _edit_ the AlbumContractAdvance object directly.
    # So, there's no good reason to make it editable.
    #
	if($albumContractID)
	{
		$self->{AlbumContractAdvance} = RPS::Catalog::AlbumContractAdvance->new(albumContractID => $albumContractID, readOnly => 1);
	}
	elsif($albumContractAdvanceID)
	{
		$self->{AlbumContractAdvance} = RPS::Catalog::AlbumContractAdvance->new(albumContractAdvanceID => $albumContractAdvanceID, readOnly=> 1);
	}
	else
	{
		# woops!
        assert(0);
	}


    # jpk - AlbumContractAdvance will not contain AlbumContract anymore.
    # Instead, I'll just instantiate one of those as a peer, here in the form.
    #
    $self->{AlbumContract} = RPS::Catalog::AlbumContract->new
    (
        albumContractID => $self->{AlbumContractAdvance}->AlbumContractID(),
        loadSubs => 0,
        readOnly => 1,
    );

	$self->{_contractID} = $self->{AlbumContract}->ContractID();

    $self->{Album} = RPS::Catalog::AlbumSimple->new
    (
        albumID => $self->{AlbumContract}->AlbumID(),
        loadSubs => 0,
        readOnly => 1,
    );


    # Put some placeholders in here for editing purposes
    #
    $self->{Advance} = Common::FormObject::Scalar::Decimal->new(value => 0);
    $self->{Memo} = Common::FormObject::Scalar::String->new(value => "");
	$self->{LabelList} = RPS::LabelList->new();

	return $self;
}



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

	$self->{AlbumContractAdvance}->addAdvance($self->Advance(), $self->Memo());
}


sub contractID
{
	my ($self) = @_;
	return $self->{_contractID};
}

###
1;#
###
