How to map between 2 columns in different sheets unless a number in sheet 1 is completely utilized or becomes 0

Hi team, I got a use case related to Excel.

In the first sheet I have 2 columns A-Invoice number and B-Hours A[inv1, inv2, inv3] B[8,6,3] and in the second sheet I have 2 columns as well, A-Invoice number and B-Hours A[to be determined] B[6,6,5].

In the above excel I need to map invoice numbers from sheet 1 based on the hours in sheet 2 until all hours of invoice is utilized. For ex: in sheet 2 A will be [inv1 (6), inv1(2) inv2(4), inv2(2) inv3(3)]

can someone please help me to automate this use case? I tried using while loop and if condition but unable to find a solution
excel.xlsx (11.7 KB)