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

package RPS::Report::Dynamic::Sales::DigitalAndPhysical;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use lib '/app/tools/report/lib';
use lib '/app/tools/rps/lib';
use lib '/app/tools/appuser/lib';

use Common::Log;
use Common::Assert;
use File::Path;
use AppUser::DB::Item::AccessLevel;
use Text::CSV::Encoded;
use Report::Dynamic::Parameters;

use RPS::DB::Item::DynamicReport::Sales::Base;

use base 'RPS::Report::Dynamic::Sales::Base';


sub Type    { 'Digital And Physical'; }
sub FilenameType { 'Sales_DigitalAndPhysical' }

# defined at the end of this file
#
sub _ParamClass { 'RPS::Report::Dynamic::Sales::DigitalAndPhysical::Parameters'; }
 

sub _getPrice
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};

    if( $rowItem->product_type eq 'T' || $rowItem->product_type eq 'A' ) {
        return $rowItem->price();
    }
    else {
        return undef;
    }
}

sub _getUnits
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};

    if( $rowItem->product_type eq 'T' || $rowItem->product_type eq 'A' ) {
        return $rowItem->units();
    }
    else {
        return $rowItem->sales() - $rowItem->returns();
    }
}

sub _getExtPrice
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};

    if( $rowItem->product_type eq 'T' || $rowItem->product_type eq 'A' ) {
        return $rowItem->units() * $rowItem->price();
    }
    else {
        return $rowItem->total_revenue();
    }
}

sub _getNativePrice
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};

    if( $rowItem->product_type eq 'T' || $rowItem->product_type eq 'A' ) {
        return $rowItem->price() * $rowItem->conversion_rate();
    }
    else {
        return undef;
    }
}

sub _getNativeExtPrice
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};

    if( $rowItem->product_type eq 'T' || $rowItem->product_type eq 'A' ) {
        return $rowItem->conversion_rate() * $rowItem->units() * $rowItem->price();
    }
    else {
        return $rowItem->conversion_rate() * $rowItem->total_revenue();
    }
}

sub _getNativeNetPrice
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};

    if( $rowItem->product_type eq 'T' || $rowItem->product_type eq 'A' ) {
        return $rowItem->conversion_rate() * $rowItem->units() * $rowItem->price() * (1 - $rowItem->dist_fee());
    }
    else {
        return $rowItem->total_revenue() * $rowItem->conversion_rate() * (1 - $rowItem->dist_fee());
    }
}



1;

package RPS::Report::Dynamic::Sales::DigitalAndPhysical::Parameters;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use lib '/app/tools/report/lib';
use lib '/app/tools/rps/lib';
use base 'RPS::Report::Dynamic::Sales::Parameters';


1;
