From 3202b9a6f4ea21f097ba65cbf1ada6ae9d9777fc Mon Sep 17 00:00:00 2001 From: vladfo Date: Thu, 3 Oct 2024 09:55:28 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?utf8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?utf8?q?=D0=B2=D0=B8=D1=82=D1=8C=20=D1=81=D0=BE=D1=82=D1=80=D1=83=D0=B4?= =?utf8?q?=D0=BD=D0=B8=D0=BA=D0=B0=20=D0=B8=20=D1=84=D1=83=D0=BD=D0=BA?= =?utf8?q?=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../crud/EmployeePaymentController.php | 12 +++++++- erp24/views/crud/employee-payment/_form.php | 28 ++++++++++++++----- erp24/views/crud/employee-payment/create.php | 1 + erp24/views/crud/employee-payment/index.php | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/erp24/controllers/crud/EmployeePaymentController.php b/erp24/controllers/crud/EmployeePaymentController.php index c234b29c..7d64a6b8 100755 --- a/erp24/controllers/crud/EmployeePaymentController.php +++ b/erp24/controllers/crud/EmployeePaymentController.php @@ -4,6 +4,7 @@ namespace yii_app\controllers\crud; use Yii; use yii\data\ActiveDataProvider; +use yii\helpers\ArrayHelper; use yii_app\records\Admin; use yii_app\records\EmployeePayment; use yii_app\forms\EmployeePaymentSearch; @@ -95,12 +96,19 @@ class EmployeePaymentController extends Controller */ public function actionCreate($admin_id = null) { - // $model = new EmployeePayment(['scenario' => 'create']); $model = new EmployeePayment(); // Если передан admin_id, устанавливаем его в модели if ($admin_id !== null) { $model->admin_id = $admin_id; + } else { + // Если admin_id не передан, выбираем пользователей без записи в EmployeePayment + $admins = Admin::find() + ->where(['NOT IN', 'id', EmployeePayment::find()->select('admin_id')]) + ->all(); + + // Преобразуем данные пользователей для использования в Select2 + $adminList = ArrayHelper::map($admins, 'id', 'name'); } if ($this->request->isPost) { @@ -112,8 +120,10 @@ class EmployeePaymentController extends Controller $model->date = date('Y-m-d'); } + return $this->render('create', [ 'model' => $model, + 'adminList' => $adminList ?? [], ]); } diff --git a/erp24/views/crud/employee-payment/_form.php b/erp24/views/crud/employee-payment/_form.php index c34a0fcd..628707ef 100755 --- a/erp24/views/crud/employee-payment/_form.php +++ b/erp24/views/crud/employee-payment/_form.php @@ -7,18 +7,32 @@ use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model yii_app\records\EmployeePayment */ /* @var $form yii\widgets\ActiveForm */ +/* @var $adminList array */ + ?>
- field($model, 'admin_id')->hiddenInput()->label(false) ?> - field($model, 'admin_name')->textInput([ - 'value' => $model->admin->name, - 'readonly' => true, - 'disabled' => true, - ])->label('Сотрудник') ?> + + field($model, 'admin_id')->widget(Select2::classname(), [ + 'data' => $adminList, + 'options' => ['placeholder' => 'Выберите сотрудника...'], + 'pluginOptions' => [ + 'allowClear' => true, + ], + ])->label('Сотрудник') ?> + + field($model, 'admin_id')->hiddenInput()->label(false) ?> + + field($model, 'admin_name')->textInput([ + 'value' => $model->admin ? $model->admin->name : 'Неизвестный сотрудник', + 'readonly' => true, + 'disabled' => true, + ])->label('Сотрудник') ?> + + field($model, 'date')->textInput(['type' => 'date']) ?> field($model, 'monthly_salary')->textInput(['maxlength' => true]) ?> field($model, 'daily_payment')->textInput(['maxlength' => true]) ?> @@ -30,4 +44,4 @@ use yii\widgets\ActiveForm; -
+ \ No newline at end of file diff --git a/erp24/views/crud/employee-payment/create.php b/erp24/views/crud/employee-payment/create.php index f8bcc254..49fee77e 100755 --- a/erp24/views/crud/employee-payment/create.php +++ b/erp24/views/crud/employee-payment/create.php @@ -15,6 +15,7 @@ $this->params['breadcrumbs'][] = $this->title; render('_form', [ 'model' => $model, + 'adminList' => $adminList ?? [], ]) ?> diff --git a/erp24/views/crud/employee-payment/index.php b/erp24/views/crud/employee-payment/index.php index 7e7b4197..c748cb30 100755 --- a/erp24/views/crud/employee-payment/index.php +++ b/erp24/views/crud/employee-payment/index.php @@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

- + 'btn btn-success mb-4']) ?> render('_search', ['model' => $searchModel]); ?> -- 2.39.5