I'm doing an inventory program for a project with RFID. The problem is having the inputs and outputs controlled.
When something comes out of the store, it does not necessarily come out permanently so it can re-enter, the problem is that the outputs and inputs are detected by the sensors, the table of this part I have it in the following way.
Numero_Caja | Date_Entry | Departure date | Existence
In which the box number is the primary key and existence is Boolean when a new box is entered the number plus date of entry is added and when this same box enters the date of departure is added and the existence changes to false, as the box can re-enter I want the table to delete the date of departure and the state of existence change to true if this re-enters, and to remove from the table the boxes that did not re-enter a button was added that will eliminate all that in existence are in false.
Once the context has been defined, I have been trying for some time to re-enter the state of existence and if it comes out again it will change again I have a small approach with the following:
UPDATE market
SET exitdate = CASE WHEN existence = true AND boxnumm = caja que lee el sensor then now() else null END,
existence = CASE WHEN exitdate <> now() AND boxnumm = caja que lee el sensor then false else true END
;
but similarly it works halfway since it has to be executed twice to work and works badly since it changes the status and date of the current box but those of the others return it to true and with the date in null.
If you happen to another way how to pass the data of existence to a variable in the program would also help me.
Thanks in advance