#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DistributorPayee::Command::List;
use strict;
use warnings;

use lib '/app/tools/common/lib';

use lib '/app/tools/rps/lib';
use RPS::Command;
use RPS::AlphabeticalPagination;
use RPS::DistributorPayee::DistributorPayeeSimple;
use RPS::DB::Item::DistributorPayee;

use base 'RPS::Command';

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

sub cmd  { return 'list'; }
sub area { return 'distributor_payee'; }

use constant kTemplate => "/app/tools/rps/templates/distributor_payee/index.xsl";

sub execute
{
	my ($self) = @_;

	my $response = $self->SUPER::execute();
	return $response if $response;

    my %getArgs;

    # Get the pagination parameters
    #
    # jpk - note that I'm 'uc-ing' the parameter at the very end.
    # If you pass 'undef' to uc(), it returns '', which was screwing
    # things up.
    #
    my $page = $self->getParam("page");
    $page = 'A' if (! defined $page);
    $page = uc($page);

    if ('ALL' ne $page)
    {
        $getArgs{alpha} = $page;
    }




	my $searchCollection = RPS::DB::Item::DistributorPayee->Get(%getArgs);

    my $pagination = RPS::AlphabeticalPagination->new(currentPage => $page);

	while ($searchCollection->hasNext())
	{
		my $obj= $searchCollection->next();
        push @{$self->{xml}{DistributorPayee}}, RPS::DistributorPayee::DistributorPayeeSimple->new(_dbItem => $obj, loadSubs => 0);
	}

	$self->{xml}{Pagination} = $pagination if $pagination;

	$response = RSApache::Response::XSLT->new($self->{xml}, kTemplate);
	return $response;
}



1;
