Universe.Modules.Currency.BaseCurrencyConnector.GroupCurrencyTransfer C# (CSharp) Method

GroupCurrencyTransfer() public method

public GroupCurrencyTransfer ( UUID groupID, UUID userId, bool payUser, string toObjectName, UUID fromObjectID, string fromObjectName, int amount, string description, TransactionType type, UUID transactionID ) : bool
groupID UUID
userId UUID
payUser bool
toObjectName string
fromObjectID UUID
fromObjectName string
amount int
description string
type TransactionType
transactionID UUID
return bool
        public bool GroupCurrencyTransfer(UUID groupID, UUID userId, bool payUser, string toObjectName, UUID fromObjectID,
            string fromObjectName, int amount, string description, TransactionType type, UUID transactionID)
        {
            GroupBalance gb = new GroupBalance {
                StartingDate = DateTime.UtcNow
            };

            // Not sure if a group will receive a system payment but..
            UserCurrency fromCurrency = userId == UUID.Zero ? null : GetUserCurrency(userId);

            // Groups (legacy) should not receive stipends
            if (type == TransactionType.StipendPayment) 
                return false;

            if (fromCurrency != null)
            {
                // Normal users cannot have a credit balance.. check to see whether they have enough money
                if ((int)fromCurrency.Amount - amount < 0)
                    return false; // Not enough money
            }

            // is thiis a payment to the group or to the user?
            if (payUser)
                amount = -1 * amount;

            uint fromBalance = 0;
            if (fromCurrency != null) {
                // user payment
                fromCurrency.Amount -= (uint)amount;
                UserCurrencyUpdate (fromCurrency, true);
                fromBalance = fromCurrency.Amount;
            }

            // track specific group fees
            switch (type)
            {
            case TransactionType.GroupJoin:
                gb.GroupFee += amount;
                break;
            case TransactionType.LandAuction:
                gb.LandFee += amount;
                break;
            case TransactionType.ParcelDirFee:
                gb.ParcelDirectoryFee += amount;
                break;
            }

            if (payUser)
                gb.TotalTierDebit -= amount;          // not sure if this the correct place yet? Are these currency or land credits?
            else
                gb.TotalTierCredits += amount;        // .. or this?

            // update the group balance
            gb.Balance += amount;                
            GroupCurrencyUpdate(groupID, gb, true);

            //Must send out notifications to the users involved so that they get the updates
            if (m_userInfoService == null)
            {
                m_userInfoService = m_registry.RequestModuleInterface<IAgentInfoService>();
                m_userAccountService = m_registry.RequestModuleInterface<IUserAccountService> ();
            }
            if (m_userInfoService != null)
            {
                UserInfo agentInfo = userId == UUID.Zero ? null : m_userInfoService.GetUserInfo(userId.ToString());
                UserAccount agentAccount = m_userAccountService.GetUserAccount(null, userId);
                var groupService = Framework.Utilities.DataManager.RequestPlugin<IGroupsServiceConnector> ();
                var groupInfo = groupService.GetGroupRecord (userId, groupID, null);
                var groupName = "Unknown";

                if (groupInfo != null)
                    groupName = groupInfo.GroupName;

                if (m_config.SaveTransactionLogs)
                    AddGroupTransactionRecord(
                        (transactionID == UUID.Zero ? UUID.Random() : transactionID), 
                        description,
                        groupID,
                        groupName, 
                        userId,
                        (agentAccount == null ? "System" : agentAccount.Name),
                        amount,
                        type,
                        gb.TotalTierCredits,        // assume this it the 'total credit for the group but it may be land tier credit??
                        (int) fromBalance,          // this will be zero if this isa system <> group transaction
                        toObjectName,
                        fromObjectName,
                        (agentInfo == null ? UUID.Zero : agentInfo.CurrentRegionID)
                    );

                if (agentInfo != null && agentInfo.IsOnline)
                {
                    SendUpdateMoneyBalanceToClient(userId, transactionID, agentInfo.CurrentRegionURI, fromBalance,
                    "You paid " + groupName + " " +InWorldCurrency + amount);
                }
            }
            return true;
        }

Usage Example

 public bool GroupCurrencyTransfer(UUID groupID, UUID userID, bool payUser, string toObjectName, UUID fromObjectID,
                                   string fromObjectName, int amount, string description, TransactionType type, UUID transactionID)
 {
     return(m_connector.GroupCurrencyTransfer(groupID, userID, payUser, toObjectName, fromObjectID,
                                              fromObjectName, amount, description, type, transactionID));
 }