Update lastprice(customized field) from inventory transactions form


I am added one new field(LastPice) in purchparmline in account payable and my requirement is after post the invoice and data flow to inventory transaction . in inventory transaction form already have costprice  and date physical and batchnumber.so i want to update the lastprice based on datephysical and batch number. plz tell me how to update lastprice using classes