🐛 Unable to use random split in open fund
This commit is contained in:
@@ -588,13 +588,22 @@ public class PaymentService(
|
|||||||
if (fund.RemainingAmount <= 0)
|
if (fund.RemainingAmount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// For open mode funds: calculate amount per split
|
// For open mode funds: use split type calculation
|
||||||
if (fund.IsOpen)
|
if (fund.IsOpen)
|
||||||
{
|
{
|
||||||
// Calculate amount per split: TotalAmount / AmountOfSplits
|
var remainingRecipients = fund.AmountOfSplits - fund.Recipients.Count(r => r.IsReceived);
|
||||||
var amountPerSplit = fund.TotalAmount / fund.AmountOfSplits;
|
if (remainingRecipients == 0)
|
||||||
return Math.Max(amountPerSplit, 0.01m); // Minimum 0.01 per claim
|
return 0;
|
||||||
|
|
||||||
|
var amount = fund.SplitType switch
|
||||||
|
{
|
||||||
|
Shared.Models.FundSplitType.Even => SplitEvenly(fund.RemainingAmount, remainingRecipients)[0],
|
||||||
|
Shared.Models.FundSplitType.Random => SplitRandomly(fund.RemainingAmount, remainingRecipients)[0],
|
||||||
|
_ => throw new ArgumentException("Invalid split type")
|
||||||
|
};
|
||||||
|
return Math.Max(amount, 0.01m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For closed mode funds: use split type calculation
|
// For closed mode funds: use split type calculation
|
||||||
|
|
||||||
var unclaimedRecipients = fund.Recipients.Count(r => !r.IsReceived);
|
var unclaimedRecipients = fund.Recipients.Count(r => !r.IsReceived);
|
||||||
@@ -652,7 +661,7 @@ public class PaymentService(
|
|||||||
};
|
};
|
||||||
db.WalletFundRecipients.Add(recipient);
|
db.WalletFundRecipients.Add(recipient);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
fund.RemainingAmount -= amount;
|
fund.RemainingAmount -= amount;
|
||||||
}
|
}
|
||||||
else if (recipient is null)
|
else if (recipient is null)
|
||||||
|
|||||||
Reference in New Issue
Block a user