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

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

use lib '/app/tools/rps/lib';
use RPS::ArtistContract::ContractRateType;
use RPS::DB::Item::ClientOptions;

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

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

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

    $self->{ContractRateType} = [];

    my $collection = RPS::DB::Item::ContractRateType->GetAll();
    while ( $collection->hasNext() ) {
        my $obj = $collection->next();

        my $contract_rate_type_id = $obj->contract_rate_type_id;
        my $gross_revenue_enabled = RPS::DB::Item::ClientOptions->Get('gross_revenue');

        # Exclude rate types:
        # - ID 3 ("% PPD")
        # - ID 4 ("% Avg")
        # - ID 10 ("% Gross Revenue") if 'gross_revenue' option is not enabled
        next if (
               $contract_rate_type_id == 3
            || $contract_rate_type_id == 4
            || ($contract_rate_type_id == 10 && !$gross_revenue_enabled)
        );

        push @{ $self->{ContractRateType} }, RPS::ArtistContract::ContractRateType->new( _dbItem => $obj );
    }

    return $self;
}

###
1;    #
###

