add_holidays

This commit is contained in:
SoHardKI 2019-07-16 11:58:05 +03:00
parent 3af5bcab71
commit e961c3f35f
15 changed files with 491 additions and 0 deletions

View File

@ -32,6 +32,9 @@ return [
'balance' => [
'class' => 'backend\modules\balance\Balance',
],
'holiday' => [
'class' => 'backend\modules\holiday\Holiday',
],
],
'components' => [
'request' => [

View File

@ -0,0 +1,21 @@
<?php
namespace backend\modules\holiday;
class Holiday extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'backend\modules\holiday\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace backend\modules\holiday\controllers;
use backend\modules\holiday\models\Holiday;
use backend\modules\holiday\models\HolidaySearch;
use common\classes\Debug;
use Yii;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
class HolidayController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'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.');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace backend\modules\holiday\models;
class Holiday extends \common\models\Holiday
{
public function init()
{
parent::init();
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace backend\modules\holiday\models;
use common\classes\Debug;
use yii\base\Model;
use yii\data\ActiveDataProvider;
class HolidaySearch extends Holiday
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['card_id'], 'integer'],
[['card_id', 'dt_start', 'dt_end'], 'safe'],
];
}
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function search($params)
{
$query = Holiday::find()->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;
}
}

View File

@ -0,0 +1,42 @@
<?php
use yii\helpers\Html;
use yii\jui\DatePicker;
use yii\widgets\ActiveForm; ?>
<div class="holiday-form">
<?php $form = ActiveForm::begin(); ?>
<?php
echo \kartik\select2\Select2::widget([
'model' => $model,
'attribute' => 'card_id',
'data' => \common\models\UserCard::getUserList(),
'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
<?php
echo '<label> Выберите дату начала отпуска</label>';
echo '<br>';
echo DatePicker::widget([
'model' => $model,
'attribute' => 'dt_start',
'language' => 'ru',
'dateFormat' => 'dd-MM-yyyy',
]);
echo '<br>';
echo '<label> Выберите дату конца отпуска</label>';
echo '<br>';
echo DatePicker::widget([
'model' => $model,
'attribute' => 'dt_end',
'language' => 'ru',
'dateFormat' => 'dd-MM-yyyy',
]);
?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,28 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<div class="holiday-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'card_id') ?>
<?= $form->field($model, 'dt_start') ?>
<?= $form->field($model, 'dt_end') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
use yii\web\View;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\Balance */
$this->title = 'Добавить отпуск';
$this->params['breadcrumbs'][] = ['label' => 'Список отпусков', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="holiday-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,66 @@
<?php
use yii\data\ActiveDataProvider;
use yii\helpers\Html;
use yii\jui\DatePicker;
use yii\web\View;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Список отпусков';
$this->params['breadcrumps'][] = $this->title;
?>
<div class="holiday-index">
<p>
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= \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'],
],
]);?>
</div>

View File

@ -0,0 +1,14 @@
<?php
$this->title = 'Редактировать отпуск №' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Список отпусков', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Редактировать';
?>
<div class="holiday-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,36 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
$this->title = 'Отпуск №' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Список отпусков', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="balance-view">
<p>
<?= 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',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'label' => 'ФИО',
'value' => function($model)
{
return $model->users->fio;
},
],
'dt_start',
'dt_end'
],
]) ?>

View File

@ -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']],

53
common/models/Holiday.php Normal file
View File

@ -0,0 +1,53 @@
<?php
namespace common\models;
use yii\db\ActiveRecord;
/**
*@property int $id
*@property int $card_id
* @property int $dt_start
* @property int $dt_end
*/
class Holiday extends ActiveRecord
{
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
}
public static function tableName()
{
return 'holiday'; // TODO: Change the autogenerated stub
}
public function rules()
{
return [
[['card_id', 'dt_start', 'dt_end'], 'integer'],
// [['card_id', 'dt_start', 'dt_end'], 'required'],
];
}
public function attributeLabels()
{
return [
'card_id' => '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']);
}
}

View File

@ -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');
}
}

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Migration;
/**
* Class m190715_124941_create_table_holiday
*/
class m190715_124941_create_table_holiday extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->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');
}
}