#------------------------------------------------------------
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::DB::Item::Sale::AllExceptionsReport;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Assert;
use Common::DB::Item;
use base 'BookPub::DB::Item::Sale';

use constant kTable => 'sale';
use constant kDB    => Common::DB::Item::kClientDB;

sub _GenerateClassConfig {
    my ($class) = @_;

    # Going to extend the base 'sale' schema and add in the two columns we want to join.
    #
    my $config = BookPub::DB::Item::Sale->_GenerateClassConfig();

    $config->{orig_file_name} = { _readOnly => 1 };
    $config->{service}        = { _readOnly => 1 };
    return $config;
}

sub ReportQuery {
    my ( $class, %args ) = @_;

    my $sql =
        "SELECT file.orig_file_name as orig_file_name, service.service_name as service, sale.* from file, sale, service"
      . " WHERE file.file_id=sale.file_id"
      . " AND file.service_id=service.service_id"
      . " AND file.period_id = 0"
      . " AND product_id IS NULL";

    if ( $args{fileID} ) {
        $sql .= " AND file.file_id=" . $args{fileID};
    }

    $sql .= " ORDER BY file.service_id,sale.file_id,sale.line_num";

    return $class->GetAll($sql);
}

1;
