package WebGUI::Macro::InShopCredit; 

#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com                     info@plainblack.com
#-------------------------------------------------------------------

use strict;
use WebGUI::Shop::Credit;
use WebGUI::Session;
use WebGUI::User;

=head1 NAME

Package WebGUI::Macro::InShopCredit

=head1 DESCRIPTION

This gets the in shop credit of the current logged in user, or when a userId is passed on and 
the current user is member of the admin group, the credit of the user that corresponds to the 
passed on userId.

=head2 process( $session, $userId )

The main macro class, Macro.pm, will call this subroutine and pass it

=over 4

=item *

A session variable

=item $userId

An optional parameter which when used by an admin user changes the userId from the current user 
to the user that corrsponds to the userId

=back

=cut


#-------------------------------------------------------------------
sub process {
	my $session = shift;
	my $creditUserId = shift || $session->user->userId;
	my $currentUser = WebGUI::User->new($session,$session->user->userId);
	if($currentUser->isInGroup(3) != 1) {
		$creditUserId = $session->user->userId;
	}
	my $credit = WebGUI::Shop::Credit->new($session, $creditUserId);
	my $output = $credit->getSum;
	return $output;
}

1;

#vim:ft=perl
