#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DB::Item::MechanicalStatementPublisherTransaction;
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 => 'mechanical_statement_publisher_transaction';
use constant kDB => Common::DB::Item::kClientDB();



sub GetByMechanicalStatementID
{
    my ($class, $stmtID) = @_;
    assert($stmtID);

    my $sql = "SELECT * FROM " . kTable
            . " WHERE mechanical_statement_id=$stmtID";
    return $class->GetAll($sql);
}


sub GetByMechanicalStatementAndPublisherID
{
    my ($class, $statement_id, $publisher_id) = @_;

    my $sql = "SELECT * FROM " . kTable . " WHERE mechanical_statement_id=$statement_id AND publisher_id=$publisher_id";
    return $class->GetAll($sql);
}


sub GetCountByMechanicalStatementAndPublisherID
{
    my ($class, $statement_id, $publisher_id) = @_;

    my $sql = "SELECT count(*) FROM " . kTable . " WHERE mechanical_statement_id=$statement_id AND publisher_id=$publisher_id";
    return $class->GetAll($sql);
}

sub DeleteByMechanicalStatementID
{
    my ($class, $id) = @_;

	my $sql = "DELETE from " . kTable . " WHERE mechanical_statement_id=$id";
	my $dbo = Common::RSApp::GetClientDB();
    $dbo->DoCmd($sql);
}


sub GetSubPublisherIDs
{
    my ($class, $statementID) = @_;
    my $dbo = Common::RSApp::GetClientDB();

    my $sql = "SELECT DISTINCT publisher_id FROM " . kTable . " WHERE mechanical_statement_id = $statementID";
    
    my $sth = $dbo->DoCmd( $sql );

    my @result;
    if ($sth)
    {
        while (my $row = $sth->fetchrow_array())
        {
            push @result, $row;
        }
    }
    return @result;
}

1;
