public function findTimesheet($_user_id, $_date) { $list = Timesheet::findAll(['user_id' => $_user_id]); foreach ($list as $ts) { if ($ts->date == $_date) { return $ts; } } return null; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Timesheet::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'user_id', 'point', 'date']]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'point' => $this->point, 'date' => $this->date, 'status' => $this->status]); return $dataProvider; }
/** * Finds the Timesheet model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Timesheet the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Timesheet::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use kartik\editable\Editable; use common\models\User; use frontend\models\Process; use frontend\models\Timesheet; use frontend\models\Team; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\WorkSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Chấm điểm timesheet'; $this->params['breadcrumbs'][] = $this->title; $formatter = Yii::$app->formatter; ?> <div class="work-index container-fluid"> <h1 style="text-align: center;"><?php echo Html::encode($this->title); ?> </h1> <?php $gridColumns = [['attribute' => 'timesheet.date', 'format' => 'date', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'width' => '13em', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['pluginOptions' => ['autoClose' => true, 'format' => 'yyyy-mm-dd'], 'removeButton' => false], 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'User', 'attribute' => 'user.full_name', 'width' => '15em', 'group' => true, 'subGroupOf' => 0, 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(User::find()->orderBy('full_name')->asArray()->all(), 'full_name', 'full_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Full name']]], ['attribute' => 'work_time', 'value' => function ($data) { return $data->work_time . ' hour(s)'; }, 'width' => '2em', 'mergeHeader' => true, 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'Team', 'attribute' => 'team.team_name', 'width' => '5em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Team::find()->orderBy('team_name')->asArray()->all(), 'team_name', 'team_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Team']]], ['label' => 'Process', 'attribute' => 'process.process_name', 'width' => '9em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Process::find()->orderBy('process_name')->asArray()->all(), 'process_name', 'process_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Process']]], ['label' => 'Work Details', 'attribute' => 'work_name', 'mergeHeader' => true], ['label' => 'Comment', 'attribute' => 'comment', 'mergeHeader' => true], ['class' => 'kartik\\grid\\EditableColumn', 'label' => 'Point', 'attribute' => 'timesheet.point', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'width' => '2.2em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Timesheet::find()->orderBy('point')->asArray()->all(), 'point', 'point'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Point']], 'hAlign' => GridView::ALIGN_CENTER, 'editableOptions' => ['header' => 'điểm', 'inputType' => \kartik\editable\Editable::INPUT_TEXT, 'format' => Editable::FORMAT_BUTTON, 'valueIfNull' => '<em style="color:red">Chưa chấm !</em>', 'preHeader' => '<i class="glyphicon glyphicon-edit"></i> Chấm ', 'type' => 'danger', 'placement' => 'left', 'options' => ['placeholder' => 'Chấm điểm ở đây']]], ['class' => 'kartik\\grid\\EditableColumn', 'label' => 'Director Comment', 'attribute' => 'timesheet.director_comment', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'mergeHeader' => true, 'editableOptions' => ['header' => 'comment', 'inputType' => \kartik\editable\Editable::INPUT_TEXTAREA, 'valueIfNull' => '<em style="color:red">Chưa comment !</em>', 'preHeader' => '<i class="glyphicon glyphicon-edit"></i> Viết ', 'editableValueOptions' => ['style' => 'color: blue'], 'type' => 'warning', 'size' => 'lg', 'placement' => 'left', 'options' => ['placeholder' => 'Viết comment vào đây']]]]; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'hover' => TRUE, 'striped' => FALSE]); ?> </div>
use kartik\grid\ExpandRowColumn; use common\models\User; use frontend\models\Process; use frontend\models\Timesheet; use frontend\models\Team; /* @var $this yii\web\View */ /* @var $searchModel frontend\models\WorkSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'HBLab Timesheets'; $this->params['breadcrumbs'][] = $this->title; $formatter = Yii::$app->formatter; ?> <div class="work-index container-fluid"> <h1 style="text-align: center; margin-bottom: 40px;"><?php echo Html::encode($this->title); ?> </h1> <?php $gridColumns = [['attribute' => 'timesheet.date', 'format' => 'date', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'width' => '13em', 'filterType' => GridView::FILTER_DATE, 'filterWidgetOptions' => ['pluginOptions' => ['autoClose' => true, 'format' => 'yyyy-mm-dd'], 'removeButton' => false], 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'User', 'attribute' => 'user.full_name', 'width' => '15em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(User::find()->orderBy('full_name')->asArray()->all(), 'full_name', 'full_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Full name']], 'group' => true, 'subGroupOf' => 0], ['attribute' => 'work_time', 'value' => function ($data) { return $data->work_time . ' hour(s)'; }, 'width' => '2em', 'mergeHeader' => true, 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'Team', 'attribute' => 'team.team_name', 'width' => '5em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Team::find()->orderBy('team_name')->asArray()->all(), 'team_name', 'team_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Team']]], ['label' => 'Process', 'attribute' => 'process.process_name', 'width' => '9em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Process::find()->orderBy('process_name')->asArray()->all(), 'process_name', 'process_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Process']]], ['label' => 'Work Details', 'attribute' => 'work_name', 'mergeHeader' => true], ['label' => 'Comment', 'attribute' => 'comment', 'mergeHeader' => true], ['label' => 'Point', 'attribute' => 'timesheet.point', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'width' => '2.2em', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Timesheet::find()->orderBy('point')->asArray()->all(), 'point', 'point'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'options' => ['placeholder' => 'Point']], 'hAlign' => GridView::ALIGN_CENTER], ['label' => 'Director Comment', 'attribute' => 'timesheet.director_comment', 'group' => true, 'groupOddCssClass' => false, 'groupEvenCssClass' => false, 'subGroupOf' => 1, 'mergeHeader' => true]]; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'hover' => TRUE, 'striped' => FALSE, 'rowOptions' => function ($model, $key, $index, $grid) { return ['id' => $model['timesheet_id'], 'onclick' => 'window.location.href = "index.php?r=timesheet/view&id="+this.id;']; }, 'panel' => ['heading' => '<span class="glyphicon glyphicon-list-alt"></span>', 'type' => GridView::TYPE_DEFAULT], 'toolbar' => [['content' => Html::a('<i class="glyphicon glyphicon-plus"></i> Create', ['work/create2', 'id' => Yii::$app->user->identity->id], ['class' => 'btn btn-success'])], '{toggleData}', '{export}'], 'export' => ['fontAwesome' => false, 'label' => 'Export']]); ?> </div>
public function actionCreate2() { $formatter = Yii::$app->formatter; $work = new Work(); $timesheet = new Timesheet(); $isUpdated = false; $isCreated = false; if (Yii::$app->request->post()) { $formAttributes = Yii::$app->request->post('createForm'); $date = $formAttributes['date']; $availTimesheet = Timesheet::find()->where(['date' => $date, 'user_id' => Yii::$app->user->identity->id])->one(); if ($availTimesheet) { // timesheet is available if ($availTimesheet->status) { Yii::$app->session->setFlash('CreateTimesheetFailed'); return $this->render('create'); } $work->timesheet_id = $availTimesheet->id; $availTimesheet->updated_at = time(); if ($availTimesheet->update()) { $isUpdated = true; } } else { $timesheet->created_at = time(); $timesheet->updated_at = time(); $timesheet->date = $date; $timesheet->user_id = Yii::$app->user->identity->id; $timesheet->point = 0; $timesheet->director_comment = ''; $timesheet->status = 0; if ($timesheet->save()) { $isCreated = true; } } if ($isUpdated || $isCreated && ($work->timesheet_id = $timesheet->id)) { $process = Process::find()->where(['process_name' => $formAttributes['process_name']])->one(); $team = Team::find()->where(['team_name' => $formAttributes['team_name']])->one(); $work->process_id = $process->id; $work->team_id = $team->id; $work->work_time = $formAttributes['work_time']; $work->work_name = $formAttributes['work_name']; $work->comment = $formAttributes['comment']; $work->created_at = time(); $work->updated_at = time(); if ($work->save()) { return $this->goBack(); } else { return $this->render('create'); } } } return $this->render('create'); }
/** * @return \yii\db\ActiveQuery */ public function getTimesheet() { return $this->hasOne(Timesheet::className(), ['id' => 'timesheet_id']); }