Hi … i have some problem with my code. i want to get value from tbl_transaction_summary and update field ‘total’ and ‘balance’ with new value but new value in field ‘balance’ is not fit to my manual calculation. after i check it using var_dump($model->attributes), all of the return value is true except field ‘balance’. it was return 0, whereas the value in database is 150000.
Here my code :
public function updateSummary($coaId, $year, $month, $newTotal, $oldTotal, $isInitial, $debitCredit)
{
$coa = Coa::model()->findByPk($coaId);
if (!(($coa->coaType->category->debitCredit === 'Debit' && $debitCredit === 'Debit')|| ($coa->coaType->category->debitCredit === 'Credit' && $debitCredit === 'Credit')))
{
$oldTotal = -$oldTotal;
$newTotal = -$newTotal;
}
$model=TransactionSummary::model()->find('coaId=:coaId and year=:year and month=:month and isInitial=:isInitial', array(':coaId'=>intval($coaId), ':year'=>$year, ':month'=>$month, ':isInitial'=>$isInitial));
//var_dump($model->attributes);
$model->attributes = $model->attributes;
$model->total = $model->total - $oldTotal + $newTotal;
$model->balance = $model->balance - $oldTotal + $newTotal;
if ($model->save())
{
if ($isInitial === 'Yes')
{
TransactionSummary::model()->updateAll(array('balance'=>'(balance-'.$oldTotal.'+'.$newTotal.')'), 'isInitial="No"');
}
else
{
TransactionSummary::model()->updateAll(array('balance'=>'(balance-'.$oldTotal.'+'.$newTotal.')'), 'id > '.$model->id.' and isInitial="No"');
}
return true;
}
else
{
return false;
}
}
but when i set manually variable $coaId in this method, the value that return was fit with database value. i already checked the value of $coaId and it was set correctly. anyone can help me ? please