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

use strict;
use warnings;
use Carp;
use Data::Dumper;

use lib '/app/tools/common/lib';
use Common::FormObject;

use lib '/app/tools/rps/lib';
use RPS::LabelRoyalty::LabelRoyaltyRun;
use RPS::DB::Item::LabelRoyaltyRun;

use base 'Common::FormObject';

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

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

    $self->{LabelRoyaltyRun} = [];

    my $collection = RPS::DB::Item::LabelRoyaltyRun->GetAll();

    if ($collection) {
        while ( $collection->hasNext() ) {
            my $obj = $collection->next();

            push @{ $self->{LabelRoyaltyRun} }, RPS::LabelRoyalty::LabelRoyaltyRun->new( _dbItem => $obj, loadSubs => 0 );
        }
    }

    # These should be sorted by run id.
    #
    @{ $self->{LabelRoyaltyRun} } = sort { $b->LabelRoyaltyRunID() <=> $a->LabelRoyaltyRunID() } @{ $self->{LabelRoyaltyRun} };

    return $self;
}

1;

