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

package RPS::Import::Sony::v16;

use strict;

use Date::Calc qw(Days_in_Month);

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

use lib '/app/tools/rps/lib';
use base 'RPS::Import::Sony::v11';

sub _fieldMap {
    {
        # header
        #
        labelName        => 'A6',
        dateBegin        => 'E3',
        dateEnd          => 'G3',

        # detail
        #
        artistName       => 'C',
        productType      => 'D',  # Configuration
        formatType       => 'J',  # Distribio Manner
        countryCode      => 'I',
        units            => 'M',
        price            => 'R',

        albumName        => 'B',
        trackName        => 'G',

        upc              => 'F',
        isrc             => 'E',
    }
}

sub _unverifiedFieldMap {
    {
        altDateBegin       => 'K8',
        altDateEnd         => 'L8',
    }
};

 
sub _headerIdentifier {
    ( 'upc' => 'Barcode (UPC)' )
}


# Normally these are defined in RPS::Import::Importer, but our parent class (v11)
# overrides those in a way that we don't want...
#
sub albumName { shift->RPS::Import::Importer::albumName(); }
sub trackName { shift->RPS::Import::Importer::trackName(); }
sub upc       { shift->RPS::Import::Importer::upc(); }
sub isrc      { shift->RPS::Import::Importer::isrc(); }


# _processSheet is used to process a tab from the spreadsheet.
# Here, we're extracting the sale date and label information
# from the cells called out in the template.
#
sub _processSheet {
    my $self     = shift;
    my $sheet    = shift;
    my $sheetnum = shift;

    if( $self->{sheetname} !~ /^ISRC-Barcode Data$/i && $self->{sheetname} !~ /^Label Copy$/i )
    {
        # Get the date and label information from the header
        #
        foreach my $line(@$sheet)
        {
            $self->{line} = $line;


            my $labelName = $self->_getByFieldName('labelName');
            $self->{_labelName} = $labelName;

            my $startDate = $self->_getByFieldName('dateBegin');
            my $endDate   = $self->_getByFieldName('dateEnd');

            if( !$startDate && !$endDate )
            {
                $startDate = $self->_getByFieldName('altDateBegin');
                $endDate   = $self->_getByFieldName('altDateEnd');
            }
            my($dateBegin, $dateEnd) = $self->_getDates( date_begin => $startDate, date_end => $endDate );

            $self->{_startDate} = $dateBegin;
            $self->{_endDate}   = $dateEnd;

             
            last;
        }

        # Now process the detail lines
        #
        return $self->RPS::Import::Importer::_processSheet( $sheet, $sheetnum );
    }
}

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