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

use Getopt::Std;

use lib '/app/tools/raptor/lib';
use Raptor::Tracker::Job::DumpRoyaltyReport;

use lib '/app/tools/job/lib';
use Job::Job;

use base 'Job::Job';

# Parse the command-line, then create the job!
#
my %options;
parseCommandLine( \%options );
queueJob( $options{clientID}, $options{periodID} );

sub queueJob {
    my $clientID = shift;
    my $periodID = shift;

    my $appSingleton = Common::RSApp->new( clientID => $clientID );

    # Create the new job, and put it in the queue.
    #
    my $jobArgs = Raptor::Tracker::Job::DumpRoyaltyReport->new( clientID => $clientID, periodID => $periodID );
    my $job = $jobArgs->enqueue();

    return 1;

}

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

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

    if ( !$opt{c} || !$opt{p} ) {
        usage();
        exit(1);
    }
    $settings->{clientID} = $opt{c};
    $settings->{periodID} = $opt{p};
}

sub usage {
    print STDERR "\nusage: $0 -c <client_id> -p <period_id>\n";
    print STDERR "\n";
    print STDERR "Arguments:\n";
    print STDERR "\t-c <client_id>\tThe client_id of the client to process\n";
    print STDERR "\t-p <period_id>\tThe period_id of the tracker period to generate reports for\n";
}
