#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2013 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------
package RPS::Import::Melodic::MelodicBase;

use strict;

use Date::Calc qw(Days_in_Month Decode_Month);

use lib '/app/tools/common/lib';
use Common::Assert;

use lib '/app/tools/rps/lib';
use RPS::Import::ServiceMap;

use base 'RPS::Import::Importer';

sub _preProcess {
    my $self = shift;
    my %args = @_;
    $self->SUPER::_preProcess( %args );

    my $sheet_count = 0;
    my $sheet_names = $args{sheet_names};

    # All we're looking for here is the date information
    # from the statement tab.
    #
    foreach my $sheet(@{$args{sheets}})
    {
        my $sheetName = $sheet_names->[$sheet_count];
        my $sheetIndex = lc $sheetName;

        next if( 'statement' ne $sheetIndex );

        $self->{sheetname} = $sheetName; # set this for _fieldMap

        # Get the dates from the line with "Month:" on it
        #
        foreach my $line(@{ $args{lines} })
        {
            $self->{line} = $line;

            my $label = $self->_getByFieldName('label');

            if( $label =~ /^Month:$/i )
            {
                my $val = $self->_getByFieldName('value');
                if( $val =~ /^(\w*) (\d{4})$/)
                {
                    ($self->{_dateBegin}, $self->{_dateEnd}) = $self->_getDates( date_begin => "$1 $2" );
                    last;
                }
            }
        }
        $sheet_count++;
    }
}

sub _processSheet {
    my $self     = shift;
    my $sheet    = shift;
    my $sheetnum = shift;
    return $self->SUPER::_processSheet( $sheet, $sheetnum ) if( $self->{sheetname} !~ /statement/i );
}

###
1;# Play nicely.
###
