#------------------------------------------------------------
# Copyright (C) 2007 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DB::Item::ArtistRoyaltyRunMissedSaleLog;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Util qw(escape_mysql_regexp escape_mysql_like);
use Common::DB::ItemCollection;
use Common::Assert;
use Common::RSApp;

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

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


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

    my $sql = "SELECT * FROM " . kTable . " WHERE artist_royalty_run_id=$id ORDER BY catalog_number, album_title, track_title, reason, details, units DESC";
    return $class->SUPER::GetAll($sql);
}

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

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

sub DeleteByRunIDAndSaleID
{
    my ($class, $runID, $saleID) = @_;

    my $sql = "DELETE FROM " . kTable . " WHERE artist_royalty_run_id=$runID and sale_id=$saleID";
    
    my $dbo = Common::RSApp::GetClientDB();
    $dbo->DoCmd($sql);
}


sub DeleteByRunIDSaleIDAndReason
{
    my ($class, $runID, $saleID, $reason) = @_;

    my $sql = "DELETE FROM " . kTable . " WHERE artist_royalty_run_id=$runID and sale_id=$saleID and reason=\"$reason\"";
    
    my $dbo = Common::RSApp::GetClientDB();
    $dbo->DoCmd($sql);
}

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

    my $sql = "SELECT distinct sale_id FROM " . kTable . " WHERE artist_royalty_run_id=$id";
    return $class->SUPER::GetAll($sql);
}


1;
