I have stat rules in model with paramater. I don,t know how to pass parameter from search to my rules in model…
Here my code…
in model
<?php
/**
* This is the model class for table "inv_stock".
*
* The followings are the available columns in table 'inv_stock':
* @property string $id
* @property string $stock_id
* @property string $stock_name
* @property integer $stock_quantity
* @property string $supplier_id
* @property string $company_price
* @property string $selling_price
* @property string $category
* @property string $date
* @property string $uom
* @property string $expire_date
*/
class Stock extends CActiveRecord
{
public $date_first;
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Stock the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'inv_stock';
}
/**
* @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(
array('stock_quantity', 'numerical', 'integerOnly'=>true),
array('stock_id, stock_name, category, uom', 'length', 'max'=>120),
array('supplier_id', 'length', 'max'=>250),
array('company_price, selling_price', 'length', 'max'=>10),
array('expire_date', 'length', 'max'=>65),
array('date, date_first', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, stock_id, stock_name, stock_quantity, supplier_id, company_price, selling_price, category, date, uom, expire_date, date_first', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'beli_kw' => array(self::STAT,'Purchase','stock_id',
'select'=>'sum(quantity)',
'condition'=>'YEAR(date)=YEAR(:tgl) AND MONTH(date)=MONTH(:tgl)',
'params'=>array(
':tgl'=>$this->date_first,
),
),
'beli_rp' => array(self::STAT,'Purchase','stock_id',
'select'=>'sum(total)',
),
'jual_kw' => array(self::STAT,'Sales','stock_id',
'select'=>'sum(quantity)',
),
'jual_rp' => array(self::STAT,'Sales','stock_id',
'select'=>'sum(amount)',
),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'stock_id' => 'Stock',
'stock_name' => 'Stock Name',
'stock_quantity' => 'Stock Quantity',
'supplier_id' => 'Supplier',
'company_price' => 'Company Price',
'selling_price' => 'Selling Price',
'category' => 'Category',
'date' => 'Date',
'uom' => 'Kemasan',
'expire_date' => 'Expire Date',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('stock_id',$this->stock_id,true);
$criteria->compare('stock_name',$this->stock_name,true);
$criteria->compare('stock_quantity',$this->stock_quantity);
$criteria->compare('supplier_id',$this->supplier_id,true);
$criteria->compare('company_price',$this->company_price,true);
$criteria->compare('selling_price',$this->selling_price,true);
$criteria->compare('category',$this->category,true);
$criteria->compare('uom',$this->uom,true);
$criteria->compare('expire_date',$this->expire_date,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
in search form
<table>
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<td>
<?php echo "Tahun-Bulan :"; ?>
<?php
echo $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'Stock[date_first]',
'language' => 'id',
'value' => $model->date_first,
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
'changeMonth' => 'true',
'changeYear'=>'true',
'constrainInput' => 'false',
),
'htmlOptions'=>array(
'style'=>'height:20px;width:70px;',
),
// DONT FORGET TO ADD TRUE this will create the datepicker return as string
),true);
?>
</td>
<td>
<?php echo CHtml::submitButton('Search'); ?>
</td>
<?php $this->endWidget(); ?>
</table><!-- search-form -->
rules beli_kw doesn’t show result… can anybody help me?