#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::DB::Item::Period;

use strict;
use warnings;

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

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

use constant kTable => 'period';
use constant kDB    => Common::DB::Item::kClientDB;

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

    my $dbo = Common::RSApp::GetClientDB();
    my $sql = 'SELECT MAX(period_id) as max FROM ' . kTable;

    my $sth   = $dbo->DoCmd($sql);
    my $hr    = $sth->fetchrow_hashref();
    my $maxID = $hr->{'max'};
    return undef unless defined $maxID;
    return $maxID;
}

sub GetNameByPeriodID {
    my ( $class, $periodID ) = @_;
    assert( defined($periodID) && $periodID ne '', 'ERROR - periodID is required' );

    my $dbo  = Common::RSApp::GetClientDB();
    my $sql  = "SELECT * FROM " . kTable . " WHERE period_id=" . $class->quote($periodID);
    my $sth  = $dbo->DoCmd($sql);
    my $hr   = $sth->fetchrow_hashref();
    my $name = $hr->{'name'};
    return undef unless defined $name;
    return $name;
}

1;
