package BookPub::Import::Importer::BakerAndTaylor::Version3;

use strict;
use Date::Calc qw(Add_Delta_Days);

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

use lib '/app/tools/bookpub/lib';
use base 'BookPub::Import::Importer::BISG::Version1';

sub _dateFormat { [ 'excel', 'iso' ] }

sub dateBegin {
    my $self = shift;
    my $dateBegin = $self->SUPER::dateBegin() || return;

    if ( $dateBegin =~ m/(\d{4})-(\d{2})-(\d{2})/ ) {

        # The dates are importing as two days ahead of what is displayed in the sales file.
        my $offset = -2;

        my ( $y, $m, $d ) = Add_Delta_Days( $1, $2, $3, $offset );
        $dateBegin = $y . "-" . $m . "-" . $d;
        $dateBegin = Common::Util::normalize_date($dateBegin);
    }

    return $dateBegin;
}

sub _isValidSaleRecord {
    my $self = shift;
    if ( $self->_getByFieldName('rRevenue') eq '-' ) {
        return undef;
    }

    return $self->SUPER::_isValidSaleRecord();
}

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