#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::DB::Item::Payor;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Util qw(escape_mysql_regexp escape_mysql_like);
use Common::DB::ItemCollection;
use Common::Assert;

use Common::DB::Item;
use base 'Common::DB::Item';

use constant kTable => 'payor';
use constant kDB => Common::DB::Item::kClientDB();

use constant kCycleQuarterly  => 1;
use constant kCycleSemiAnnual => 2;
use constant kCycleAnnual     => 3;
use constant kCycleMonthly    => 4;




sub GetDefault
{
    my ($class) = @_;
    return RPS::DB::Item::Payor->Lookup(is_default => 1);
}


sub GetFromIDList
{
    my ($class, $listRef) = @_;

    my $sql = "SELECT * FROM ".kTable. " WHERE payor_id IN (" . join(',', @$listRef) . ")";
    return $class->SUPER::GetAll($sql);
}

sub GetAll
{
    my ($class) = @_;
    assert($class);
	my $sql = "SELECT * FROM ".kTable." ORDER BY name";
    return $class->SUPER::GetAll($sql);
}


sub Search
{
    my ($class, $searchTerm) = @_;

	my $dbo = Common::RSApp::GetClientDB();

	my $sql = "SELECT * FROM ".kTable
		. " WHERE " . $class->SearchSyntax(field => "name", value => $searchTerm)
		. " OR " . $class->SearchSyntax(field => "client_payor_id", value => $searchTerm)
		. " ORDER BY name";

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


sub Match
{
    my ($class, $lookupValue) = @_;

	my $dbo = Common::RSApp::GetClientDB();

	my $sql = "SELECT * FROM ".kTable
		. " WHERE client_payor_id=".$dbo->DBQuote($lookupValue)
		. " OR name=".$dbo->DBQuote($lookupValue);

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



1;


