I have a table with cost_price and selling_price. I also have a persistent calculated column (I’m using Mariadb) which shows the margin percentage using the formula (selling_price - cost_price) / cost_price * 100.
That already works fine but my customer wants to be able to change the selling price and see what the margin would be before updating the product record.
My plan is to have a calculated field on the form that uses the same calculation as the table column to show the margin %. The field would be updated when either the cost_price or selling_price are changed. As the calculation would be the same then, when the record in updated, I will not update the calculated table field (actually I don’t think I can anyway) as the calculated field will have the same value as the form anyway.
I did look at a solution which involved updating the record and refreshing the form at each change of selling_price or cost_price… I couldn’t see an easy way to do this and I think the extra overhead is poor design.
The best solution appears to be Ajax using the changed events to update a calculated field on the form but couldn’t find a good example and javascript is not my strong point…
Can anyone point me at a solution? I cannot believe this problem is a new one but I didn’t find one on the forum.
David Goadby, North Wales