I have a task where I need to iterate through a collection to determine if an amount is a credit (negative) and then, compare elements within that collection to those amongst that collection to determine if:
We get a collection of earning file details. Within these details, we have the fields:
I iterate though these records to see if there’s one with a credit (negative amount)
I label that record as a credit and now, I need to iterate through the rest of the records to see if the following is true:
I think I’m over thinking this. Realistically, we could have one or more credits. So, for every credit, I would need to loop through the details to see if I can find a non-credit match.
I am afraid that I do not understand your problem to give a clear solution. I will try, but I’m doing some assumption that might be incorrect. What I do notice is your technical approach to your solution (iteration, using ID’s).
Since you’re using a rule engine instead of a programming language, I suppose you can reduce some complexity by using the vocabulary more to its advantage.
Suppose you have two entities:
-relation: 1 to n to details
Then you could use a single rulesheet with the following scope
- Credit (Details)
- - Amount
- NonCredit (Details)
Filter for Credit: Amount < 0
Fitler for NonCredit: Amount >= 0
What is left are the PersonCompany instances with both Credit and NonCredit Details. You can apply any action you want.
I hope this will help,