namespace yii_app\controllers\crud;
+use yii\data\ActiveDataProvider;
+use yii_app\records\Admin;
use yii_app\records\EmployeePayment;
use yii_app\forms\EmployeePaymentSearch;
use yii\web\Controller;
$searchModel = new EmployeePaymentSearch();
$dataProvider = $searchModel->search($this->request->queryParams);
+ $dataProvider->query->orderBy(['admin_id' => SORT_ASC]);
+
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
*/
public function actionView($id)
{
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => EmployeePayment::find()->where(['admin_id' => $id]),
+ ]);
+
+ // Получение данных сотрудника для заголовка
+ $admin = Admin::findOne($id);
+
+ if (!$admin) {
+ throw new NotFoundHttpException("Сотрудник не найден");
+ }
+
return $this->render('view', [
- 'model' => $this->findModel($id),
+ 'admin' => $admin,
+ 'dataProvider' => $dataProvider,
]);
}
* If creation is successful, the browser will be redirected to the 'view' page.
* @return string|\yii\web\Response
*/
- public function actionCreate()
+ public function actionCreate($admin_id = null)
{
$model = new EmployeePayment();
+ // Если передан admin_id, устанавливаем его в модели
+ if ($admin_id !== null) {
+ $model->admin_id = $admin_id;
+ }
+
if ($this->request->isPost) {
if ($model->load($this->request->post()) && $model->save()) {
- return $this->redirect(['index']);
+ return $this->redirect(['view', 'id' => $model->admin_id]);
}
} else {
$model->loadDefaultValues();
$model = $this->findModel($id);
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
- return $this->redirect(['index']);
+ return $this->redirect(['view', 'id' => $model->admin_id]);
}
return $this->render('update', [
*/
public function actionDelete($id)
{
- $this->findModel($id)->delete();
+ $model = $this->findModel($id);
+ $admin_id = $model->admin_id;
+
+ $model->delete();
- return $this->redirect(['index']);
+ // Редирект на страницу просмотра сотрудника после удаления записи
+ return $this->redirect(['view', 'id' => $admin_id]);
}
/**
*/
public function search($params)
{
- $query = EmployeePayment::find();
+ $subQuery = EmployeePayment::find()
+ ->select(['MAX(id)'])
+ ->groupBy('admin_id');
+
+ $query = EmployeePayment::find()
+ ->where(['id' => $subQuery]);
// add conditions that should always apply here
+
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
?>
<?= $form->field($model, 'admin_id')->widget(Select2::classname(), [
'data' => $adminsList,
- 'options' => ['placeholder' => 'Select a state ...'],
+ 'options' => [
+ 'placeholder' => 'Выберите сотрудника...',
+ 'value' => $model->admin_id, // Устанавливаем значение по умолчанию
+ ],
'pluginOptions' => [
'allowClear' => true
],
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
+ <?= Html::a('Назад', ['view', 'id' => $model->admin_id], ['class' => 'btn btn-danger']) ?>
</div>
<?php ActiveForm::end(); ?>
],
]); ?>
<div class="row">
- <div class="col-4">
- <?= $form->field($model, 'id') ?>
- </div>
+ <!--<div class="col-4">
+ <?/*= $form->field($model, 'id') */?>
+ </div>-->
<div class="col-4">
<?php
$adminsWithGroup = \yii_app\records\Admin::find()->select(['name', 'id'])->indexBy('id')->orderBy('name' , SORT_DESC)->all();
]) ?>
</div>
</div>
- <div class="row">
+ <!--<div class="row">
<div class="col-3">
- <?= $form->field($model, 'date') ?>
+ <?/*= $form->field($model, 'date') */?>
</div>
<div class="col-3">
- <?= $form->field($model, 'monthly_salary') ?>
+ <?/*= $form->field($model, 'monthly_salary') */?>
</div>
<div class="col-3">
- <?= $form->field($model, 'daily_payment') ?>
+ <?/*= $form->field($model, 'daily_payment') */?>
</div>
<div class="col-3">
- <?= $form->field($model, 'creator_id')->dropDownList(\yii_app\records\AdminGroup::find()->select(['name', 'id'])->indexBy('id')->column(), [
+ <?/*= $form->field($model, 'creator_id')->dropDownList(\yii_app\records\AdminGroup::find()->select(['name', 'id'])->indexBy('id')->column(), [
'prompt' => '---',
- ]) ?>
+ ]) */?>
</div>
- </div>
+ </div>-->
<div class="form-group">
<?= Html::submitButton('Найти', ['class' => 'btn btn-primary']) ?>
- <?= Html::resetButton('Сбросить фильтры', ['class' => 'btn btn-outline-secondary']) ?>
+ <?/*= Html::resetButton('Сбросить фильтры', ['class' => 'btn btn-outline-secondary']) */?>
+ <?= Html::a('Сбросить фильтры', ['index'], ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
$this->params['breadcrumbs'][] = ['label' => 'Оклады', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
-<div class="employee-payment-create">
+<div class="employee-payment-create p-4">
<h1><?= Html::encode($this->title) ?></h1>
$this->title = 'Оклад и стоимость рабочего дня';
$this->params['breadcrumbs'][] = $this->title;
?>
-<div class="employee-payment-index">
+<div class="employee-payment-index p-4">
<h1><?= Html::encode($this->title) ?></h1>
'label' => 'ID',
'format' => 'raw',
'value' => function($model) {
- return Html::a($model->id, ['employee-payment/view', 'id' => $model->admin_id]);
+ return Html::a($model->admin_id, ['employee-payment/view', 'id' => $model->admin_id]);
}
],
[
'label' => 'Сотрудник',
'format' => 'raw',
'value' => function($model) {
- return $model->admin ? Html::a(Html::encode($model->admin->name), ['employee/view', 'id' => $model->admin_id]) : null;
+ return $model->admin ? Html::a(Html::encode($model->admin->name), ['employee-payment/view', 'id' => $model->admin_id]) : null;
}
],
'adminGroup.name:text:Должность',
- 'date',
- 'monthly_salary',
- 'daily_payment',
- 'creator.name:text:Создавший правило',
+ // 'date',
+ // 'monthly_salary',
+ // 'daily_payment',
+ // 'creator.name:text:Создавший правило',
[
'class' => ActionColumn::class,
'template' => '{view}', // Оставляем только кнопку "view"
<?php Pjax::end(); ?>
- <?php print_r($searchModel); ?>
+
</div>
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
-<div class="employee-payment-update">
+<div class="employee-payment-update p-4">
<h1><?= Html::encode($this->title) ?></h1>
<?php
use yii\helpers\Html;
+use yii\grid\GridView;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
-/* @var $model yii_app\records\EmployeePayment */
+/* @var $admin yii_app\records\Admin */
+/* @var $dataProvider yii\data\ActiveDataProvider */
-$this->title = $model->id;
+$this->title = $admin->name . ' - ' . $admin->adminGroup->name;
$this->params['breadcrumbs'][] = ['label' => 'Оклады', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
-\yii\web\YiiAsset::register($this);
+//var_dump($this->params['breadcrumbs']);
?>
-<div class="employee-payment-view">
+<div class="employee-payment-view p-4">
<h1><?= Html::encode($this->title) ?></h1>
<p>
- <?= Html::a('Добавить запись', ['create'], ['class' => 'btn btn-success']) ?>
- </p>
-
- <p>
- <?= Html::a('Поменять', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
- <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
- 'class' => 'btn btn-danger',
- 'data' => [
- 'confirm' => 'Вы точно хотите удалить запись?',
- 'method' => 'post',
- ],
- ]) ?>
+ <?= Html::a('Добавить запись', ['create', 'admin_id' => $admin->id], ['class' => 'btn btn-success']) ?>
+ <?= Html::a('Назад', ['index'], ['class' => 'btn btn-danger']) ?>
</p>
<?= DetailView::widget([
- 'model' => $model,
+ 'model' => $admin,
'attributes' => [
- 'id',
- 'admin.name:text:Сотрудник',
+ 'id:text:Admin ID',
+ 'name:text:Сотрудник',
'adminGroup.name:text:Должность',
+ ],
+ ]) ?>
+
+ <h2>Записи выплат</h2>
+
+ <?= GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+ 'id',
'date',
'monthly_salary',
'daily_payment',
'creator.name:text:Правило создал',
+ [
+ 'class' => 'yii\grid\ActionColumn',
+ 'template' => ' {update} {delete}', // Оставляем все действия
+ 'urlCreator' => function ($action, $model, $key, $index, $column) use ($admin) {
+ return [$action, 'id' => $model->id, 'admin_id' => $admin->id];
+ }
+ ],
],
]) ?>
</div>
+
* @var string $content rendered content
* @var \yii\web\View $this
*/
- global $_CONFIG;
+ global
+
+
+
+$_CONFIG;
app\assets\CommonAsset::register($this);
app\assets\CachemenutopAsset::register($this);
app\assets\JQueryPluginsAsset::register($this); /** @TODO удалить после переписывания основного функционала */
+
+use yii\widgets\Breadcrumbs;
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
</aside>
<div class="app-content main-content">
<?= $this->render('header.php'); ?>
+ <?= Breadcrumbs::widget([
+ 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
+ ]) ?>
<?= $content ?>
</div>
</div>