0

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
enter image description here

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

ArK
  • 20,698
  • 67
  • 109
  • 136
Bakti Wijaya
  • 447
  • 1
  • 6
  • 21

1 Answers1

0

Your template should be (assuming that your model id is empid)

'template' =>  Html::a('<i class="glyphicon glyphicon-plus"></i> Out', 
    Url::to(['your-controller/out', 'empid=> $model->empid]),['class'=>'btn btn-success']),

but there isn't code for action out

you should add a proper (update ) code for actionOut

somethings like this for update (this is just a suggestion )

public function actionOn($empid)
{
    $model = $this->findModel($empid);

    if ($model->load(Yii::$app->request->post()) && $model->save()) {
       ......
       // your redirec..
    } else {
        return $this->render('your_view', [
            ....
        ]);
    }
}
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • Then if you don't assign a prope action to you link how do you think to manage the update ? .. .. i have update the answer .. – ScaisEdge Nov 03 '16 at 06:47
  • i already made that,but it update the whole record,and In can be inputted to.and i already tried put $model->isNewRecord to the form,but it wont run – Bakti Wijaya Nov 03 '16 at 07:10
  • @BaktiWijaya your first question was for "but when i clicked "Out" Button,the record was not update,it creating a new record with Null In Time." then if the record is update with out action the problem in your questo should be solved .. seems that you are changing the term of you question and i can't understand your prolem e so i can't help you .. you should deal with a problem at a time with a question at a time – ScaisEdge Nov 03 '16 at 07:28