Grouping data in applications

Hi Community!

I have got a question about grouping things in my application, hopefully any one of you could help me out!
So, i have build an application where suppliers can registrate themselve and invite their customers to place orders through the portal.
During the month a customer can ofcourse place multiple orders at a supplier.
And at the end of every month a supplier wants to send invoices to all its customers that ordered something during that month.

The invoice could be a collection of multiple orders that have been placed that month.
So now at the end of every month i have an automation flow running, which finds all the orders placed in that specific month and groups them per supplier (since multiple suppliers can use the platform).
As a result of that i have a list of PeriodInvoices (these are the collections of orders placed in that month, grouped per supplier).
But then these still need to be grouped per Customer, since customer A does not need to receive an invoice which contains orders of Customer B.

So actually what i need to do is create a Repeat action which goes through the list of PeriodInvoices, and then a Repeat action which goes through the customers.
For now it is not possible to have a Repeat action within a Repeat action, so i am kind of stuck with this problem.

In the pictures i have attached you can see the how the PeriodInvoice currently looks.
The first table shows the different OrderLines, which are the ordered product combined from different orders of that month.
And the second table shows which customers ordered the above OrderLines.

As you can see i already can create the PeriodInvoices per Supplier, but am not able to group them per Customer.
Hopefully any one of you has an idea on how to do this.

Here’s how I would do it. Note that there might be other ways to solve this as well.

I imagine there are four data items:
– Order. Order has a reference to Customer, Supplier and Invoice (one of each).
– Customer. Each Customer has a list of Orders.
– Supplier. Each Supplier has a list of Orders.
– Invoice. Each invoice has a list of Orders and a reference to Customer and probably Supplier.

Then in a flow part, I would do:

  1. Look up all orders from the month.

  2. Create a repeat action going over all orders. We can just process all orders, regardless of who they belong to.

For each order in the repeat action I would:

  • Do a look-up action that looks up an invoice. That invoice must meet certain criteria: it must have the same customer as the order, the same supplier (if you want an invoice per customer per supplier, otherwise you can leave this out), the same period as the order, etc.
  • That’s followed by a decision that checks whether 2-1’s look-up action is empty or not.
  • If it’s empty we’re going to add a new invoice. We can access any information about the customer and supplier via the order.
    If it’s not empty we’re going to update the existing invoice. Make sure to use the “Add a Order from the flow part to the already referenced Order”-option when you update the invoice’s reference field.

That’s it for this repeat action. At the end you should have created all your invoices.

  1. Add another repeat action after it because you probably want to do some other stuff for each invoice. In this repeat action you can sum the prices of each order belonging to the invoice, generated PDFs, send it to customers and that sort of things.

Will that solve you case?

Last weekend I have implemented your idea, and it works perfect.
Thanks for your answer!