#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Statement::Mechanical::CA::StatementWithPayments;

use strict;
use warnings;
use Carp;

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

#use Common::DiskCache;

use lib '/app/tools/rps/lib';

use RPS::Publisher::CA::PublisherAccount;
use RPS::Statement::Mechanical::StatementWithPayments;
use RPS::Statement::Mechanical::CA::BaseStatement;

use base qw(RPS::Statement::Mechanical::CA::BaseStatement);

sub _initProperties {
    my ( $self, $props, $skipTransactionsList ) = @_;

    $self->SUPER::_initProperties($props);
    $self->{PublisherAccount} = RPS::Publisher::CA::PublisherAccount->new(
        publisherID             => $props->{publisher_id},
        payorID                 => $props->{payor_id},
        showPendingPaymentsOnly => 1,
        skipTransactionsList    => $skipTransactionsList || 0
    );
}

sub _getPublisherAccount {
    my ( $self, $publisherID, $payorID ) = @_;
    return RPS::Publisher::CA::PublisherAccount->new(
        publisherID             => $publisherID,
        payorID                 => $payorID,
        showPendingPaymentsOnly => 1,
    );
}

sub clearPayments {
    my ($self) = @_;
    return if $self->OnHold();

    $self->{PublisherAccount}->clearPayments();
}

sub setPaymentsToMin {
    my ($self) = @_;
    return if $self->OnHold();
    $self->{PublisherAccount}->clearPayments();
    $self->{PublisherAccount}->setFirstPayment( $self->MinimumPayment() );
}

sub setPaymentsToFull {
    my ($self) = @_;
    return if $self->OnHold();
    $self->{PublisherAccount}->clearPayments();
    my $amountDue = $self->AmountDue();
    if ( $amountDue > 0 ) {
        $self->{PublisherAccount}->setFirstPayment($amountDue);
    }
}

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

###
1;    #
###
