#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DB::Item::CAStatRate;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::DB::ItemCollection;

use Common::DB::Item;
use base 'Common::DB::Item';

use constant kTable => 'ca_stat_rate';
use constant kDB=> Common::DB::Item::kCommonDB();



# this only returns one item
#
sub GetByDate
{
	my ($class, $date) = @_;
	return undef unless($date);

	my $dbo = Common::RSApp::GetCommonDB();
	my $sql = "SELECT * FROM " . kTable . " WHERE date_effective <= ".$dbo->DBQuote($date)." ORDER BY date_effective DESC LIMIT 1";

	my $collection = $class->SUPER::GetAll($sql);

	if(defined $collection && $collection->hasNext())
	{
		return $collection->next();
	}
	else
	{
		return undef;
	}
}

sub GetAll
{
	my ($class) = @_;

	my $order = "date_effective DESC";

	my $sql = "SELECT * FROM " . kTable . " ORDER BY $order";

    return $class->SUPER::GetAll($sql);
}

1;
