1 - For each referrer - SUM up all 'paid' and 'status accepted' rewards (using RewardActions) without the referral paid and set that amount of tokens
(In TokenRewards for the referrer) to pendingReferralTokens
3 - Recalculate all TokenReward values for - PendingTokens - i.e. status of pending only, EarnedTokens - All accepted rewards
4 - For each TokenReward with the same type of token payment, Sum up EarnedTokens and [ReferalTokens] and output the users
UserId, PaymentToken, CryptoAddress, TotalToBePaid
5 - Set all rows of 1 to referralPaid
6 - Set all values of accepted rewards to paid if they were changed in step 3
7 - Set all rows that were used in step 4 to change from [EarnedTokens] to [PaidTokens] and [ReferalTokens] to [PaidReferalTokens]
1 - For each referrer - SUM up all 'paid' and 'status accepted' rewards (using RewardActions) without the referral paid and set that amount of tokens (In TokenRewards for the referrer) to pendingReferralTokens
3 - Recalculate all TokenReward values for - PendingTokens - i.e. status of pending only, EarnedTokens - All accepted rewards
4 - For each TokenReward with the same type of token payment, Sum up EarnedTokens and [ReferalTokens] and output the users UserId, PaymentToken, CryptoAddress, TotalToBePaid
5 - Set all rows of 1 to referralPaid
6 - Set all values of accepted rewards to paid if they were changed in step 3
7 - Set all rows that were used in step 4 to change from [EarnedTokens] to [PaidTokens] and [ReferalTokens] to [PaidReferalTokens]