I have this cases if Button "In" clicked,it will create a new record for attendance.and if Button "Out" clicked,it will update the record created from the new record before.
for cases like this,it should be done on SQL using query,or on Yii itself ?
what i've tried so far,i can create new record for "In" Button.but when i clicked "Out" Button,the record was not update,it creating a new record with Null In Time.
here is the design of table
id empid date in out status desc
1 20 2016-11-01 08:00 1 In
and this is the design of the form
EDIT :
This is my controller for "In" Button
public function actionIn()
{
// $session->open();
// $
$model = new AttDetail();
$idAbsen = Att::find()->where(['empID'=>Yii::$app->user->id])->one();
$db = Yii::$app->getDb();
$command = $db->createCommand('
SELECT group_shift.In FROM group_shift JOIN att on group_shift.Id = att.IdGs WHERE att.empId = 1
');
$In = $command->queryOne();
if ( $model->load( Yii::$app->request->post() ) && $model->save() )
{
return $this->redirect(['index', 'id' => $model->Id]);
}
else
{
return $this->render('in', [
'model' => $model,
'in' => $in,
'in' => $idAtt
]);
}
}
and this is my Index
'toolbar'=> [
['content'=> Html::a('<i class="glyphicon glyphicon-plus"></i> In', ['in'],['class'=>'btn btn-success']),
],
],
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
'Id',
'IdAtt',
'Date',
'In',
'Out',
['class' => 'kartik\grid\ActionColumn',
'template' => Html::a('<i class="glyphicon glyphicon-plus"></i> Out', ['out'],['class'=>'btn btn-success']),
'dropdown'=>false,
'dropdownOptions'=>['class'=>'pull-right'],
i'm open to all suggestion about how this is could done.Thank You