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

use strict;
use warnings;
use Carp;

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

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

# Note that I am getting rid of the base class.
# This will be treated as a 'mix-in' class, for multiple inheritance.
# See the 'US' version of this class as an example.
#
use base 'RPS::Statement::Mechanical::BaseStatementList';

# Have to override validate to allow it to validate all the members in my list.
#
sub validate {
    my ( $self, $skipRequiredFields ) = @_;

    # A recursive validation mechanism.
    # Subclasses should override this to perform specific
    # validation, if they care too, then call the inherited
    # method (this).  This base method implements the
    # recursive descent.
    #
    my $valid = 1;

    foreach my $item ( @{ $self->{MechanicalStatement} } ) {
        if ( !$item->validate($skipRequiredFields) ) {
            $valid = 0;
        }
    }

    return $valid;
}

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

    foreach my $statement ( @{ $self->{MechanicalStatement} } ) {
        $statement->save();
    }
}

sub clearPayments {
    my ($self, %excludedStatementIDs) = @_;
    foreach my $statement ( @{ $self->{MechanicalStatement} } ) {
        if ( !$excludedStatementIDs{ $statement->MechanicalStatementID() } ) {
            $statement->clearPayments();
        }
    }
}

sub setPaymentsToMinPayment {
    my ($self) = @_;
    foreach my $statement ( @{ $self->{MechanicalStatement} } ) {
        $statement->setPaymentsToMin();
    }
}

sub setPaymentsToFullPayment {
    my ($self, %excludedStatementIDs) = @_;
    foreach my $statement ( @{ $self->{MechanicalStatement} } ) {
        if ( !$excludedStatementIDs{ $statement->MechanicalStatementID() } ) {
            $statement->setPaymentsToFull();
        }
    }
}

1;
