package BookPub::Import::Importer::CourseSmart::Version2;

use strict;

use Date::Calc qw(Days_in_Month);
use Data::Dumper;

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

use lib '/app/tools/data_classes/lib';

use lib '/app/tools/bookpub/lib';
use BookPub::DB::Item::Sale;
use BookPub::Import::SaleRec;
use base 'BookPub::Import::Importer';

sub _fieldMap {
    {
        countryCode => 'B',
        dateBegin   => 'D',
        isbn        => 'K',
        rRevenue    => 'F',
    };
}

sub _headerIdentifier { ( dateBegin => 'Transaction Date' ) }

sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeLoan }
sub priceType     { 'rrp' }
sub currencyCode  { 'GBP' }
sub productType   { BookPub::DB::Item::Sale::kProductTypeEBook }
sub _dateFormat   { [ 'numerical_year_first', 'iso' ] }
sub rUnits        { 1 }
sub rListPrice    { 0 }
sub rDiscount     { 0 }
sub _useIsSaleRec { 1 }

sub rRevenue {
    my $self     = shift;
    my $revenue  = $self->_getByFieldName('rRevenue');
    my $clientID = Common::RSApp::GetClientID();

    if ( $clientID != 335 ) {
        $self->fail("This importer is not valid for this client");
    }

    return $revenue * 0.70;    #applying 30% fee
}

sub _isSaleRec {
    my $self = shift;

    return $self->dateBegin;
}

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