#---------------------------------------------------------------
# ____                   _ _         ____  _                    
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___ 
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/                            
#
# Copyright (C) 2012 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------

package RPS::ArtistRoyalty::Fast::Final::ArtistRoyaltyTransaction;

use strict;
use Data::Dumper;
use File::Path;

use lib '/app/tools/common/lib';
use lib '/app/tools/rps/lib';
use lib '/app/tools/raptor/lib';
use Common::RSApp;
use Common::RSDB;

use Data::Dumper;
use DB_File;

use RPS::ArtistRoyalty::Fast::Mapped::Data;
use RPS::ArtistRoyalty::Fast::Final::ArtistRoyaltyAlbum;
use RPS::ArtistRoyalty::Fast::Final::ArtistRoyaltyStatement;

use Common::Log;

use base 'RPS::ArtistRoyalty::Fast::Final';

use constant kArtistRoyaltyStatementID  => 0;
use constant kAmount                    => 1;
use constant kMemo                      => 2;
use constant kCheckNumber               => 3;
use constant kPendingTransactionID      => 4;
use constant kTransactionDate           => 5;
use constant kTypeCode                  => 6;

use constant kAlbumRef                  => 7;


my @gFields =
(
'artist_royalty_statement_id',
'amount',
'memo',
'check_number',
'pending_transaction_id',
'transaction_date',
'type_code',
);



sub Fields { return \@gFields; }



sub FileName { 'artist_royalty_transaction' }

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

    return 0;
}


sub new
{
    my ($class, $data, $album) = @_;

    # We get passed the $album, since this is sort of a line-item entity.
    # But we really need the statement_id (although I find that... weird).
    #

    my $item = $class->BlankItem();

    # So, really, we don't 'accumulate' these.
    # Each line of data maps to a line in the output file.

    # Meaning, we'll do essentially everything here in the constructor.
    # process will _always_ return undef.
    #
    $item->[kArtistRoyaltyStatementID]  = $album->[RPS::ArtistRoyalty::Fast::Final::ArtistRoyaltyAlbum::kArtistRoyaltyStatementID];
    $item->[kAmount]                    = $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPendingTransactionAmount];
    $item->[kMemo]                      = $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPendingTransactionMemo];
    $item->[kCheckNumber]               = $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPendingTransactionCheckNumber];
    $item->[kPendingTransactionID]      = $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPendingTransactionID];
    $item->[kTransactionDate]           = $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPendingTransactionDate];
    $item->[kTypeCode]                  = $data->[RPS::ArtistRoyalty::Fast::Mapped::Data::kPendingTransactionTypeCode];

    push @$item, $album;

    return bless($item, $class);
}


sub process
{
    my ($self, $data) = @_;

    return undef;
}



# Override _output to send our totals up to the Album
#
sub _output
{
    my ($self, $ITEMS) = @_;
    my $album = pop @$self;

    # We really need to update the _statement_, so we'll need to get that reference
    # from our album.
    #
    my $statement = $album->statement();
    $statement->[RPS::ArtistRoyalty::Fast::Final::ArtistRoyaltyStatement::kTransactionSubtotal] += $self->[kAmount];

    $self->SUPER::_output($ITEMS);
}





1;

