Setup barcode scan for inventory check

Hello guys, Thanks for checking on my issue

I deliver goods to my customers in reusable boxes which (mostly) return to me. The quest is to know which customers owe me which amount of boxes automatically. This is the level design:

:white_check_mark:1. Every box got its own barcode (A). Every order got its order ID, printed as a second barcode (B1).

:white_check_mark:2. When a box is ready to ship, both barcodes get scanned. This way it’s recorded where the boxes went (the customers adress is tracable via the order ID (B1). Later this database has to link with the order database - but first things first)

:white_check_mark:3. When a box returns to the warehouse, barcode (A) gets scanned again.

:interrobang:4. Now Airtable is recognizing the previous entry already existing. It marks the box as returned. (The database entry could get archived this way.)

:interrobang:5. Next time a returned box is used for shipping it gets scanned again (A) in combination with a different order ID (B2). Now Airtable has to create another database entry and know the old one is obsolet.

I get stucked at Level 4. Do you have any idea how to solve this? How will Airtable recogize a barcode belongs to an existing entry already and will act in a different way then it would with an unknown barcode?
I appreciate all solutions.