#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package BookPub::Matcher::Command::Sale::Revenue;
use strict;
use warnings;
use Data::Dumper;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;
use Common::Assert;
use Common::Log;

use lib '/app/tools/bookpub/lib';
use BookPub::DB::Item::Sale;
use BookPub::Matcher::Sale::Revenue;
use BookPub::Matcher::Product;
use BookPub::Tracker::File;
use BookPub::Tracker::File::Display;
use BookPub::Sale::Match;

use base 'BookPub::Matcher::Command::Sale';

sub cmd      { return "sale"; }
sub area     { return "matcher"; }
sub pageName { return "Resolve Catalog Exceptions"; }
use constant kTemplate => '/app/tools/bookpub/templates/matcher/main.xsl';

# JPK - Want to make this abstract, so we can re-use this logic for the POS sales as well.
# Going to be a very similar interface.
#
# So, what needs abstraction?
# - Instantiation of the correct Matcher::Sale class
#   -- two different constructions.  One takes a sale id, the other takes fileID and linenum
#
# - Instantiation of the correct Tracker::File class.
#
# - GetFirstException($file), returns the id of the first sale with an exception.
#
# - The redirection URL (c=sale or c=pos_sale, etc).
#
# - The matching loop should probably be moved into its own method.
#
# - !!! Not clear what level of abstraction exists already with Sale::Match. Bill is using _something_ today...
# - --> May need to abstract the Search command.  May need to abstract the entire class?

sub _getSaleFromSaleID {
    my ( $self, $saleID ) = @_;

    return BookPub::Matcher::Sale::Revenue->new( saleID => $saleID );
}

sub _getSaleFromFileIDLineNum {
    my ( $self, $fileID, $lineNum ) = @_;

    return BookPub::Matcher::Sale::Revenue->new( fileID => $fileID, lineNum => $lineNum );
}

sub _getFirstExceptionSaleIDFromFileID {
    my ( $self, $fileID ) = @_;
    return BookPub::DB::Item::Sale->GetFirstException($fileID);
}

sub _getFileFromFileID {
    my ( $self, $fileID ) = @_;
    return BookPub::Tracker::File::Display->new( fileID => $fileID );
}

sub _previousPage {
    my ($self) = @_;
    return "/bookpub/tracker";
}

1;

