Hi!
I would like to ask for your help with the following process. In the attached simulation, I am generating a certain number of daily routes, and for each route, I need to prepare a number of products according to their category, which are shown in the table "CantPorRuta".
Each of these routes has 8 orders. As I have it planned, they are registered order by order according to the category, this is the case of Butter
And the orders are listed in the table "CantMantequillaPorPedido".
For the first route, for example, every 8 iterations (orders) I must complete 40 boxes of butter (as shown in the first image). However, as I have it set up now, I would have to go through each product 8 times and check if the sum is 0, 40, or 80 (which are the probable values).
I want to check in each iteration if the order is already completed, or if not:
1. If it is the last iteration, that is, the 8th order, truncate the current value to match the sum shown in "CantPorRuta", or generate a random number such that when added to the accumulated sum of the product, it matches the required amount.
2. If it is not the last order but has already completed the product sum, the remaining should be filled with zeros.
How can I do it? Is there a single pass for all the products, perhaps using global variables?