Increase and decrease value if value changed to another doctype

I have master doctype, I named it Sekat and that doctype has field max_capacity and allocated_doc with type float.

And I have another doctype I named it Check In Order as Parent and Check In Order Line as child …

In Check In Order Line I have field link to Sekat, and if user choose that like SEKAT 1 so Allocated_doc in doctype sekat name SEKAT 1 will Increment 1, I already done with this, but if user Changes into another Sekat like SEKAT 2 so allocated_doc in SEKAT 1 will decrease -1 and SEKAT 2 will increment 1, the problem is how can I Track the changes for decrease value ?

Thank for advice