I am creating an application for live event merchandise sales. I have a table of inventory_events, each inventory_event represents a change in inventory over time. Because of the nature of my application I need to track 1 master inventory (all of the items in stock) and an inventory per event.
Essentially this is what my flow looks like:
- Assuming that today is an event day
- New inventory_events are created for each inventory_item being sold at the event
- these inventory_events are called ‘check ins’, they are checking the items into the event
- this creates a negative inventory_event and these items are subsequently removed from master inventory
- after an event is complete the remaining stock is ‘checked out’ of the event
- this creates a positive inventory_event and the left over items are added to inventory
- the net qty_change on these 2 transactions becomes my net items sold at this event
Currently this is how I have it set up:
- each Event has_many :inventory_events
- when creating inventory_events I am updating this via a fields_for in an Event update form
- this works fine for checking items in
My problems begin at checking items out (out of the event but into the system)
- Set up is the same as above except I need to be able to build 1 inventory_event for each check out event associated with this particular day’s event
My question is: How can I build 1 new field_for inventory event per inventory_event previously associated with this day’s event? I know I can just count the number of events & then build 1 for each but how do I do that & also maintain some information (item_id) so I am able to know that I am building a check in event for each item i had checked out on this day?
Thanks a lot.
You could start building a form using the previously known data. Let’s say you have
Then you could prepopulate a list of checkouts, where each correspond to one of the already registered check_ins for the same event. In the end you won’t check out things that were not checked in before…
So the object will have all the checkouts, also preset with the same amount as initially checked out, you can change it afterwards form the form.