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

use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Assert;
use Common::Util;

use lib '/app/tools/rps/lib';
use RPS::Payor::Payor;
use RPS::RoyaltyRun::RoyaltyRunStatusList;

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

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

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

	my $publisherID = $args{publisherID};
	my $payorID = $args{payorID};

	unless ($publisherID && $payorID)
    {
        assert(0, 'publisher and payor are required');
    }
    
    # There may not be an account yet, so we need to do this.
    #
    my $currentAccount = $self->_publisherAccount()->new(payorID => $payorID, publisherID => $publisherID);

    # Putting this in a list to make it consistent with the indirect form.
    # This will allow me to re-use a lot of the same xsl and javascript.
    #
    $self->{AccountList} = $self->_accountList()->new(payorID => $payorID, publisherID => $publisherID, currentAccountID => $currentAccount->FinanceAccountID());
    
    # Add the current account to the list.
    #
    push @{$self->{AccountList}{Account}}, $currentAccount;
  
    
    $self->{Publisher} = $self->_publisherObj()->new(
        publisherID => $publisherID,
        loadSubs => 0,
        readOnly => 1,
    );

    $self->{Payor} = RPS::Payor::Payor->new(
        payorID => $payorID,
        loadSubs => 0,
        readOnly => 1,
    );   
    
    my $directLicenses = $self->_trackLicense()->GetDirectByPublisherIDPayorID($publisherID, $payorID);
    $self->{Payor}->{PublisherDirectLicenseCount} = $directLicenses->size();

    my $totalLicenses = $self->_trackLicense()->GetByPublisherIDPayorID($publisherID, $payorID);
    $self->{Payor}->{PublisherTotalLicenseCount} = $totalLicenses->size();   

    $self->{RoyaltyRunStatus} = $self->_royaltyRunStatusList();
	return $self;
}


sub save
{
	my ($self) = @_;
	
    $self->{AccountList}->save(); 
}


sub publisherID
{
	my ($self) = @_;
	return $self->{Publisher}->PublisherID();
}

###
1;#
###
