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

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

sub GetByContract {
    my ( $class, $contractID ) = @_;

    my $sql = "SELECT * FROM " . kTable . " WHERE inactive = 0 AND artist_contract_id = " . $class->quote($contractID);

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

sub CopyFromPatternContractID {
    my ( $class, $patternContractID, $newContractID ) = @_;

    $patternContractID = $class->quote($patternContractID);
    $newContractID     = $class->quote($newContractID);

    my $sql = qq/
        INSERT INTO expense_type (artist_contract_id, expense_name_id, percent, inactive)
        SELECT
            $newContractID,
            expense_name_id,
            percent,
            inactive
        FROM expense_type
        WHERE inactive = 0
            AND artist_contract_id = $patternContractID
    /;

    my $dbo = Common::RSApp::GetClientDB();
    my $sth = $dbo->DoCmd($sql);

    return 1;
}

1;
