#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
#!/usr/bin/perl
use strict;

use Data::Dumper;
use Getopt::Std;
use POSIX qw(ceil);
use Carp;

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

use lib '/app/tools/raptor/lib';
use Raptor::DB::Item::Sale;

use lib '/app/tools/rps/lib';
use RPS::DB::Item::ArtistRoyaltyRun;
use RPS::DB::Item::ArtistRoyaltyStatement;
use RPS::DB::Item::ArtistRoyaltyIncomeItem;
use RPS::DB::Item::ArtistRoyaltyExpenseItem;
use RPS::DB::Item::ArtistRoyaltyAlbum;
use RPS::DB::Item::SaleArtistRoyaltyRunMap;

my $gVerbosityLevel = 1;

# Get the id from the command-line
#
my %options;
_parseCommandLine( \%options );
_dumpSaleStatus( $options{clientID} );

sub _parseCommandLine {
    my ($settings) = @_;

    my %opt;
    getopts( 'c:V:', \%opt );

    if ( !$opt{c} ) {
        _usage();
        exit(1);
    }
    $settings->{clientID} = $opt{c};
    if ( $opt{V} ) {
        $gVerbosityLevel = $opt{V};
    }
}

sub _usage {
    print "\nusage: $0 -c client_id\n";
    print "\n";
    print "Arguments:\n";
    print "\t-c <client_id>\t\tThe client_id of the client to process\n";
}

sub _dumpSaleStatus {
    my ( $clientID, $runID ) = @_;
    assert($clientID);

    # Instantiate the application singleton.
    #
    my $appSingleton = Common::RSApp->new( clientID => $clientID );

    my $sales = Raptor::DB::Item::Sale->GetAll();
    while ( my $sale = $sales->next() ) {
        print $sale->sale_id . "," . $sale->artist_royalty_status . "," . $sale->mechanical_royalty_status . "\n";
    }
}

sub _report {
    my ( $string, $verbosity ) = @_;
    $verbosity = 1 unless defined $verbosity;

    if ( $gVerbosityLevel >= $verbosity ) {
        print STDERR $string . "\n";
    }
}

