#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DB::Item::LabelRoyaltyStatementSale;
use strict;
use warnings;
use lib '/app/tools/common/lib';
use Common::Assert;
use Common::DB::Item;
use Common::DB::ItemCollection;
use base 'Common::DB::Item';

use constant kTable => 'label_royalty_statement_sale';
use constant kDB => Common::DB::Item::kClientDB();


sub GetAllByLabelRoyaltyStatementID
{
    my ($class, $statementID) = @_;
    assert($statementID);

    my $sql = "SELECT * FROM " . kTable . " WHERE label_royalty_statement_id=$statementID";

    $sql .= ' ORDER BY label_name,service_id,territory,product_format,album_name,disc_no,track_no';

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



sub DeleteAllByLabelRoyaltyRunID
{
    my ($class, $runID) = @_;
    assert($runID);

    my $dbo = Common::RSApp::GetClientDB();

    my $sth = $dbo->DoCmd("SELECT label_royalty_statement_id FROM label_royalty_statement WHERE label_royalty_run_id=$runID");
    while (my $hr = $sth->fetchrow_hashref())
    {
        my $statementID = $hr->{label_royalty_statement_id};
        $dbo->DoCmd("DELETE FROM " . kTable . " WHERE label_royalty_statement_id=$statementID");
    }

}

1;
