Ok thank you for your help.
This is view
<?php
$this->breadcrumbs=array(
'Coin',
);?>
<?php
echo CHtml::beginForm('','post',array('id'=>'order-form'));
?>
Status: <?php echo CHtml::dropDownList('ddlStatus', $_POST['ddlStatus'] == '' ? 'AP': $_POST['ddlStatus'], Coin::model()->getStatus())?>
Bill Type: <?php echo CHtml::dropDownList('ddlBillType', $_POST['ddlBillType'] == '' ? 'CR' : $_POST['ddlBillType'], Coin::model()->getBillType())?>
Zone: <?php echo CHtml::dropDownList('ddlZone', $_POST['ddlZone'] == '' ? '01' : $_POST['ddlZone'], Coin::model()->getZone())?>
Pay Type: <?php echo CHtml::dropDownList('ddlPayType', $_POST['ddlPayType'] == '' ? '01' : $_POST['ddlPayType'], Coin::model()->getPayType())?>
วันที่:
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'date',
'value'=>$_POST['date'],
'language'=>Yii::app()->language=='et' ? 'et' : null,
'options'=>array(
'showAnim'=>'fold', // 'show' (the default), 'slideDown', 'fadeIn', 'fold'
'showOn'=>'button', // 'focus', 'button', 'both'
'buttonText'=>Yii::t('ui','Select form calendar'),
'buttonImage'=>Yii::app()->request->baseUrl.'/images/calendar.png',
'buttonImageOnly'=>true,
'dateFormat'=>'dd-mm-yy',
),
'htmlOptions'=>array(
'style'=>'width:80px;vertical-align:top'
),
));
?>
<?php $this->widget('zii.widgets.jui.CJuiButton', array(
'buttonType'=>'submit',
'name'=>'btnSubmit',
'value'=>'1',
'caption'=>'แสดงรายการ',
));?>
<p></p>
<hr>
<p></p>
<?php
// ลิงค์สำหรับเลือกด้านบน
$this->widget('ext.widgets.bmenu.XBatchMenu', array(
'formId'=>'order-form',
'checkBoxId'=>'order-id',
'ajaxUpdate'=>'order-grid', // if you want to update grid by ajax
'emptyText'=>Yii::t('ui','กรุณาเลือกรายการก่อนครับ!'),
'confirm'=>Yii::t('ui','คุณต้องการเลือกรายการดังกล่าวใช่หรือไม่?'),
'items'=>array(
array('label'=>Yii::t('ui','ยืนยันรายการที่เลือก'), 'url'=>array('updateItems', 'op'=>'selected')),
),
'htmlOptions'=>array('class'=>'actionBar'),
));
?>
<?php $pageSize=Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']);?>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'order-grid',
'dataProvider'=>$dataProvider,
'enableSorting'=>false,
//'ajaxUpdate'=>false,
'selectableRows'=>2, // multiple rows can be selected
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'id'=>'order-id',
),
array(
'name' => 'ginv_no',
'htmlOptions' => array('width'=>'150px'),
),
array(
'name' => 'Inv_Date',
'value' => 'date_format(date_create($data->Inv_Date), "d-M-Y")',
),
array(
'name' => 'Send_Date',
'value' => 'date_format(date_create($data->Send_Date), "d-M-Y")',
),
array(
'name' => 'CU_NAME',
'htmlOptions' => array('style'=>'text-align:left'),
),
array(
'name' => 'wh_name',
'htmlOptions' => array('style'=>'text-align:center'),
),
array(
'name' => 'AR_AMT',
'htmlOptions' => array('style'=>'text-align:right'),
),
),
));
Yii::app()->clientScript->registerScript('initPageSize', <<<EOD
$('.change-pagesize').live('change', function(){
$.fn.yiiGridView.update('order-grid', {data:{pagesSize: $(this).val()}})
});
EOD
,CClientScript::POS_READY);
echo CHtml::endForm();
// ลิงค์สำหรับเลือกด้านล่าง
$this->widget('ext.widgets.bmenu.XBatchMenu', array(
'formId'=>'order-form',
'checkBoxId'=>'order-id',
'ajaxUpdate'=>'order-grid', // if you want to update grid by ajax
'emptyText'=>Yii::t('ui','กรุณาเลือกรายการก่อนครับ!'),
'confirm'=>Yii::t('ui','คุณต้องการเลือกรายการดังกล่าวใช่หรือไม่?'),
'items'=>array(
array('label'=>Yii::t('ui','ยืนยันรายการที่เลือก'), 'url'=>array('updateItems', 'op'=>'selected')),
),
'htmlOptions'=>array('class'=>'actionBar'),
));
?>
Controller
<?php
class CoinController extends Controller
{
public function actionIndex()
{
if(!isset($_POST['btnSubmit']))
{
$dataProvider = Coin::model()->getData('AP', 'CR', '01', '01', $date);
$this->render('index', array('dataProvider'=>$dataProvider));
}
else
{
if(isset($_GET['pageSize']))
{
Yii::app()->user->setState('pageSize', (int)$_GET['pageSize']);
unset($_GET['pageSize']);
}
$status = $_POST['ddlStatus'];
$bill_type = $_POST['ddlBillType'];
$zone_code = $_POST['ddlZone'];
$pay_type = $_POST['ddlPayType'];
$date = $_POST['date'];
$dataProvider = Coin::model()->getData($status, $bill_type, $zone_code, $pay_type, $date);
$this->render('index', array('dataProvider'=>$dataProvider));
}
}
public function actionUpdateItems()
{
if(isset($_GET['pageSize']))
{
Yii::app()->user->setState('pageSize', (int)$_GET['pageSize']);
unset($_GET['pageSize']);
}
// allow POST request only
if(Yii::app()->request->isPostRequest)
{
$status = $_POST['ddlStatus'];
$chkPack = $_POST['chkPack'];
$currentday = date("Y-m-d"); //2012-02-08
$currenttime = date("H:i:s");
$orderid = $_POST['order-id'];
$select=!empty($_GET['op']) && $_GET['op']=='selected' ? 1 : 0;
if($status==='AP')
{
if($_POST['chkPack'])
{
Coin::model()->updateByPk($_POST['order-id'], array('PackD'=>$currentday, 'PackT'=>$currenttime,'SendD'=>$currentday, 'SendT'=>$currenttime, 'Doc_Flow'=>'S'));
}
else
{
Coin::model()->updateByPk($_POST['order-id'], array('PackD'=>$currentday, 'PackT'=>$currenttime, 'Doc_Flow'=>'P'));
}
}
elseif ($status==='P')
{
Coin::model()->updateByPk($_POST['order-id'], array('SendD'=>$currentday, 'SendT'=>$currenttime, 'Doc_Flow'=>'S'));
}
elseif ($status==='S')
{
Coin::model()->updateByPk($_POST['order-id'], array('Doc_Flow'=>'T'));
}
//Coin::model()->updateByPk($orderid, array('PackD'=>$currentday, 'PackT'=>$currenttime,'SendD'=>$currentday, 'SendT'=>$currenttime, 'Doc_Flow'=>'S'));
// if AJAX request, we should not redirect the browser
if(!isset($_GET['ajax']))
{
if(!$this->goBack())
$this->redirect(array('index'));
else
$this->goBack();
}
}
else
{
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
}
// Uncomment the following methods and override them if needed
public function filters()
{
// return the filter configuration for this controller, e.g.:
return array(
'accessControl', // perform access control
);
}
public function accessRules()
{
return array(
/*array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index'),
'users'=>array('*'),
),*/
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('index'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('updateitems'),
'users'=>array('lakhana '),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
/*
public function actions()
{
// return external action classes, e.g.:
return array(
'action1'=>'path.to.ActionClass',
'action2'=>array(
'class'=>'path.to.AnotherActionClass',
'propertyName'=>'propertyValue',
),
);
}
*/
}
Model
class Coin extends CActiveRecord
{
public function getStatus()
{
return array(
'AP' => 'พิมพ์แล้ว',
'P' => 'จัดส่งสินค้า',
'S' => 'ส่งสินค้า',
'T' => 'โอนบิล',
'B' => 'Balance',
'C' => 'Cancel'
);
}
public function getBillType()
{
$sql = "SELECT ref_code, ref_desc FROM ref_data WHERE ref_type = '05' ORDER BY ref_code";
$rows = Yii::app()->db->createCommand($sql)->queryAll();
foreach ($rows as $row)
{
$list[$row['ref_code']] = $row['ref_desc'];
}
return $list;
}
public function getZone()
{
$sql = "SELECT ref_code, ref_desc FROM ref_data WHERE ref_type = '06' ORDER BY ref_code";
$rows = Yii::app()->db->createCommand($sql)->queryAll();
foreach ($rows as $row)
{
$list[$row['ref_code']] = $row['ref_desc'];
}
return $list;
}
public function getPayType()
{
$sql = "SELECT ref_code, ref_desc FROM ref_data WHERE ref_type = 'PT' ORDER BY ref_code";
$rows = Yii::app()->db->createCommand($sql)->queryAll();
foreach ($rows as $row)
{
$list[$row['ref_code']] = $row['ref_desc'];
}
return $list;
}
public function getData($status, $bill_type, $zone_code, $pay_type, $date)
{
$criteria = new CDbCriteria;
if($status != 'S')
{
$s1 = ' warehouse.wh_name, Rec_Stat';
$s2 = ' LEFT JOIN warehouse ON t.wh_code = warehouse.wh_code';
$s3 = ', send_date DESC';
}
else
{
$s1 = ' saleman.sl_name AS sl_name';
$s2 = ' LEFT JOIN saleman ON t.Sl_Code = saleman.Sl_Code';
$s3 = '';
}
$criteria->select = "Doc_No, (Bill_Type + '-' + t.ZO_Code + '-' + PT_Code + '-' + Inv_No ) AS ginv_no, Inv_Date, Send_Date, customer.CU_NAME, $s1, AR_AMT";
$criteria->join = "LEFT JOIN Customer ON Customer.Cu_Code = t.Cu_Code" . $s2;
$criteria->compare('Bill_Type', $bill_type);
if(!empty($date))
{
$criteria->compare('Inv_Date', $date);
}
$criteria->compare('t.ZO_Code', $zone_code);
if($status === 'AP')
{
$criteria->addCondition('Bill_FD IS NOT NULL');
}
$criteria->compare('Doc_Flow', substr($status, 0, 1));
$criteria->addNotInCondition('Rec_Stat', array(C, X), 'AND');
$criteria->order = 'ginv_no, Doc_No, Send_Date ASC';
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize'=>Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize'])
),
));
}