How To Use Calculated _Post Value In A Model To Calculate Another Field In The Same Model Before Actioncreate Save It To Db

hello everyone,

i got problem while getting calculated _post value and use it to calculate a new field value, i need to use the calculated first _post Value before it being saved to the db, and use it to calculate another field value and finally save both of them to a table.

here’s my code :

my controller code :

public function actionCreate()


		$model=new Stuff;

		$tot = Stuff::model()->getAttributes(array('stuff_total_price'), array('qty'), array('price_per_unit'),array('discount_unit'), array ('price_after_discount'));



		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);








			$model['stuff_total_price'] = ($model['qty'] ) * ($model['price_per_unit'] )


			$model['price_after_discount'] = (($model('stuff_total_price') -(($model['discount_unit']) * ($model['stuff_total_price'])))))







here is the condition, i need to calculate

stuff_total_price = qty*price_per_unit

price_after_discount = stuff_total_price - (discount_unit * stuff_total_price)

i know it sounds stupid while i can get price_after_discount using a formula :

price_after_discount = ((qtyprice_per_unit) - (discount_unit (qty*price_per_unit)))

in my case i won’t do that, cause i need to use stuff_total_price and price_after_discount separately in another table to calculate another value in the other table, something like monthly report - sum up the stuff_total_price and sum_up the price_after_discount to get a monthly report…

my question is, while i use the code there was no error, but, it comes with the result like this :

stuff_id 46

stuff_name drill

Qty 12

price_per_unit 12

discount_unit 0.10 (in percentge = 10%)

stuff_total_price 0 ---->> the result = 0

price_after_discount 0 ---->> the result = 0

i really need to fix this up as soon as possible, can anyone find out what should i do this things?

thanks in advance>>


Can you solve it?