diff --git a/backend/config/main.php b/backend/config/main.php index 1bc988e..2459128 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -32,6 +32,9 @@ return [ 'balance' => [ 'class' => 'backend\modules\balance\Balance', ], + 'holiday' => [ + 'class' => 'backend\modules\holiday\Holiday', + ], ], 'components' => [ 'request' => [ diff --git a/backend/modules/holiday/Holiday.php b/backend/modules/holiday/Holiday.php new file mode 100644 index 0000000..f64166f --- /dev/null +++ b/backend/modules/holiday/Holiday.php @@ -0,0 +1,21 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + public function actionIndex() + { + $searchModel = new HolidaySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + public function actionView($id) + { + $model = $this->findModel($id); + + return $this->render('view', [ + 'model' => $model, + ]); + } + + public function actionCreate() + { + $model = new Holiday(); + + if ($model->load(Yii::$app->request->post())) + { + $model->dt_start = strtotime($model->dt_start); + $model->dt_end = strtotime($model->dt_end); + $model->save(); + + Yii::$app->session->addFlash('success', 'Отпуск добавлен'); + + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post())) { + $model->dt_start = strtotime($model->dt_start); + $model->dt_end = strtotime($model->dt_end); + $model->save(); + + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + protected function findModel($id) + { + if (($model = Holiday::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} \ No newline at end of file diff --git a/backend/modules/holiday/models/Holiday.php b/backend/modules/holiday/models/Holiday.php new file mode 100644 index 0000000..cc0869f --- /dev/null +++ b/backend/modules/holiday/models/Holiday.php @@ -0,0 +1,11 @@ +with('users'); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + $dt_start = strtotime($this->dt_start) ? strtotime($this->dt_start) : null; + $dt_end = strtotime($this->dt_end) ? strtotime($this->dt_end) : null; + + 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; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'card_id' => $this->card_id, + ]); + + $query->andFilterWhere(['between', 'dt_start', $dt_start, $dt_end ]) + ->orFilterWhere(['between', 'dt_end', $dt_start, $dt_end ]); + + return $dataProvider; + } +} \ No newline at end of file diff --git a/backend/modules/holiday/views/holiday/_form.php b/backend/modules/holiday/views/holiday/_form.php new file mode 100644 index 0000000..09740b7 --- /dev/null +++ b/backend/modules/holiday/views/holiday/_form.php @@ -0,0 +1,42 @@ + +
+ = Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> +
+ = \yii\grid\GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + [ + 'label' => 'ФИО', + 'value' => function($model) + { + return $model->users->fio; + }, + 'filter' => \kartik\select2\Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'card_id', + 'data' => \common\models\UserCard::getUserList(), + 'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]), + ], + [ + 'attribute' => 'dt_start', + 'filter' => DatePicker::widget([ + 'model' => $searchModel, + 'attribute' => 'dt_start', + 'language' => 'ru', + 'dateFormat' => 'dd-MM-yyyy', + 'options' => [ + 'autocomplete' => 'off', + ], + ]), + ], + [ + 'attribute' => 'dt_end', + 'filter' => DatePicker::widget([ + 'model' => $searchModel, + 'attribute' => 'dt_end', + 'language' => 'ru', + 'dateFormat' => 'dd-MM-yyyy', + 'options' => [ + 'autocomplete' => 'off', + ], + ]), + ], + ['class' => 'yii\grid\ActionColumn'], + ], + ]);?> ++ = Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?> + = Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a('Удалить', ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +
+ += DetailView::widget([ + 'model' => $model, + 'attributes' => [ + [ + 'label' => 'ФИО', + 'value' => function($model) + { + return $model->users->fio; + }, + ], + 'dt_start', + 'dt_end' + ], +]) ?> \ No newline at end of file diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php index 38f07e9..c25abb1 100755 --- a/backend/views/layouts/left.php +++ b/backend/views/layouts/left.php @@ -42,6 +42,7 @@ ], ], ['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance']], + ['label' => 'Отпуска', 'icon' => 'user-circle', 'url' => ['/holiday/holiday']], /*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']], ['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug']], diff --git a/common/models/Holiday.php b/common/models/Holiday.php new file mode 100644 index 0000000..3b47a80 --- /dev/null +++ b/common/models/Holiday.php @@ -0,0 +1,53 @@ + 'ID пользователя', + 'dt_start' => 'Дата начала отпуска', + 'dt_end' => 'Дата конца отпуска' + ]; + } + + public function afterFind() + { + parent::afterFind(); // TODO: Change the autogenerated stub + $this->dt_start = date('d-m-Y', $this->dt_start); + $this->dt_end = date('d-m-Y', $this->dt_end); + } + + public function getUsers() + { + return $this->hasOne(UserCard::className(),['id' => 'card_id']); + } +} \ No newline at end of file diff --git a/common/models/UserCard.php b/common/models/UserCard.php index 47c946f..eab2b09 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -2,6 +2,7 @@ namespace common\models; +use common\classes\Debug; use Yii; use yii\behaviors\TimestampBehavior; use yii\db\Expression; @@ -151,4 +152,9 @@ class UserCard extends \yii\db\ActiveRecord { return ArrayHelper::map(Skill::find()->all(),'id', 'name'); } + + public static function getUserList() + { + return ArrayHelper::map(self::find()->all(), 'id', 'fio'); + } } diff --git a/console/migrations/m190715_124941_create_table_holiday.php b/console/migrations/m190715_124941_create_table_holiday.php new file mode 100644 index 0000000..6f6225f --- /dev/null +++ b/console/migrations/m190715_124941_create_table_holiday.php @@ -0,0 +1,30 @@ +createTable('holiday',[ + 'id' => $this->primaryKey(), + 'card_id' => $this->integer(11)->notNull(), + 'dt_start' => $this->integer(15)->notNull(), + 'dt_end' => $this->integer(15)->notNull(), + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('holiday'); + } +}