Still not working Maurizio,
This is inside my FormHeader.php
public $customer;
public $supplier;
public $partnerName;
public $calcCharges;
public $calcPayments;
public $calcBalance;
...
/**
* @return array validation rules for model attributes.
*/
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
...
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('calcCharges, calcPayments, calcBalance, customer, supplier, partnerName, partnerFk, formType, headerNo, formDate, partnerFk, dueDate, referenceNo, truckNo, driver, memo, postingStatus', 'safe', 'on' => 'search'),
);
}
...
/**
* Add remember-filter-gridview behaviour
* @return Array of behaviors
*/
public function behaviors() {
return CMap::mergeArray(parent::behaviors(), array(
'ERememberFiltersBehavior' => array(
'class' => 'application.components.ERememberFiltersBehavior',
'defaults' => array(), /* optional line */
'defaultStickOnClear' => false /* optional line */
),
));
}
...
/**
* Retrieves a list of models based on the current search/filter conditions.
*/
public function search($accountType, $pageSize = 'FormHeader_pageSize', $page = 'FormHeader_page') {
$calcChargesSql = "(SELECT SUM(d.unitPrice * d.quantity) FROM form_detail d WHERE d.headerFk = t.id)";
$calcPaymentsSql = "(SELECT SUM(p.amount) FROM payment_detail p WHERE p.headerFk = t.id)";
$calcBalanceSql = "(SELECT (c.totChr - p.totPay) FROM "
. "(SELECT d.headerFk, SUM(d.unitPrice * d.quantity) AS totChr FROM form_detail d GROUP BY d.headerFk) c LEFT JOIN "
. "(SELECT pd.headerFk, SUM(pd.amount) AS totPay FROM payment_detail pd GROUP BY pd.headerFk) p ON p.headerFk = c.headerFk WHERE c.headerFk = t.id)";
$criteria = new CDbCriteria;
$criteria->with = array('partner');
// select
$criteria->select = array(
'*',
$calcChargesSql . " AS calcCharges",
$calcPaymentsSql . " AS calcPayments",
$calcBalanceSql . " AS calcBalance",
);
$criteria->compare($calcChargesSql, MyActiveRecord::changeFormat($this->calcCharges));
$criteria->compare($calcPaymentsSql, MyActiveRecord::changeFormat($this->calcPayments));
$criteria->compare($calcBalanceSql, MyActiveRecord::changeFormat($this->calcBalance));
...
$sort = new CSort;
$sort->defaultOrder = 'dueDate ASC';
$sort->attributes = array(
'id' => array(
'asc' => 'id ASC',
'desc' => 'id DESC',
),
...
'calcCharges' => array(
'asc' => 'calcCharges ASC',
'desc' => 'calcCharges DESC',
),
'calcPayments' => array(
'asc' => 'calcPayments ASC',
'desc' => 'calcPayments DESC',
),
'calcBalance' => array(
'asc' => 'calcBalance ASC',
'desc' => 'calcBalance DESC',
),
);
$sort->applyOrder($criteria);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort' => $sort,
'pagination' => array(
'pageSize' => Yii::app()->user->getState($pageSize, Yii::app()->params['defaultPageSize']),
'currentPage' => Yii::app()->user->getState($page, 0),
),
));
}
}
I tried with
$model->unsetAttribute($model->getSafeAttributeNames());
and also
$model->unsetAttributes(array('headerNo', 'partnerFk', 'formDate', 'dueDate', 'calcCharges', 'calcPayments', 'calcBalance'));
But still the calcCharges, calcPayments and calcBalance cannot be set to null with both.
Any idea other than directly set them to null?