Updation Of A Table

Hi…I am new to yii…I have a table named Stock(ProductId,ProductName,Quantity,Rate) and Another table Sales(BillNo,ProductId,ProductName,Quantity,Rate) .I have generated CRUD for these two tables .Now I need to subtract the quantity of the respective stock when there is a sales…Please Help Me…Give me some Ideas how to update the Stock When There Is a sale…Give meSome Ideas…Give Me full details …Where to use and which method to use …