Server Script issue

Hi,
I have written a server script to calculate a deduction component(PT) in salary slip and set doctype event as before save. When i save the salary slip the value is correct and when i submit the same salary slip the value gets changed.
How to resolve this?