Automatically Distributing Lot Number in S/O Invoice Data Entry through Visual Integrator

Hello All,

I've been trying for the last two months to figure out a way to automatically distribute lot numbers by FIFO in S/O invoice data entry using visual integrator. We don't create a sales order before creating the invoice. Each of our inventory items have two lots and are set to a valuation of "Lot". It's currently being distributed by next lot serial number which is a manual field in item maintenance. The issue with doing it this way is if the QTY exceeds the specified lot it doesn't create an invoice for information uploaded that's exceeded the lot QTY.

I've tried writing a syntax but I don't think the fields are able to be inner joined in a table. I was thinking it could be based on the earliest receipt date of the lot number?

ANY suggestions are greatly appreciated! Even if you could give me some resources on the calculated expressions in visual integrator

Here's what I'm working with: