From fb77a703c6ae0ea7c75e035070b219e113b940c1 Mon Sep 17 00:00:00 2001 From: JoySystem_v Date: Mon, 26 Aug 2024 11:52:36 +0300 Subject: [PATCH] =?utf8?q?=D0=B7=D0=B0=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80?= =?utf8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?utf8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=20=D0=B8=20=D0=B4=D0=BE=D0=B1?= =?utf8?q?=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0?= =?utf8?q?=D1=86=D0=B8=D1=8E=20=D0=BE=D0=BA=D0=BB=D0=B0=D0=B4=D0=B0=20?= =?utf8?q?=D0=B8=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/records/EmployeePayment.php | 29 +++++++++++++++++++++ erp24/views/crud/employee-payment/_form.php | 25 +++++------------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/erp24/records/EmployeePayment.php b/erp24/records/EmployeePayment.php index 24a4e4e2..106af439 100755 --- a/erp24/records/EmployeePayment.php +++ b/erp24/records/EmployeePayment.php @@ -43,9 +43,38 @@ class EmployeePayment extends \yii\db\ActiveRecord [['admin_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => AdminGroup::class, 'targetAttribute' => ['admin_group_id' => 'id']], [['admin_id'], 'exist', 'skipOnError' => true, 'targetClass' => Admin::class, 'targetAttribute' => ['admin_id' => 'id']], [['creator_id'], 'exist', 'skipOnError' => true, 'targetClass' => Admin::class, 'targetAttribute' => ['creator_id' => 'id']], + [['daily_payment'], 'validateDailyPayment'], + [['date', 'admin_id'], 'validateUniqueDate'], ]; } + + /** + * Валидация для daily_payment, чтобы он не был больше monthly_salary + */ + public function validateDailyPayment($attribute, $params, $validator) + { + if ($this->daily_payment > $this->monthly_salary) { + $this->addError($attribute, 'Подневная оплата не может быть больше оклада.'); + } + } + + /** + * Валидация для уникальности записи по дате и admin_id при создании новой записи. + */ + public function validateUniqueDate($attribute, $params) + { + // Проверка уникальности только для новых записей + $exists = EmployeePayment::find() + ->where(['admin_id' => $this->admin_id, 'date' => $this->date]) + ->andFilterWhere(['!=', 'id', $this->id]) + ->exists(); + + if ($exists) { + $this->addError($attribute, 'Запись с этой датой уже существует.'); + } + } + public function beforeValidate() { if (get_called_class() === self::class) { diff --git a/erp24/views/crud/employee-payment/_form.php b/erp24/views/crud/employee-payment/_form.php index 72b239dc..c34a0fcd 100755 --- a/erp24/views/crud/employee-payment/_form.php +++ b/erp24/views/crud/employee-payment/_form.php @@ -12,24 +12,13 @@ use yii\widgets\ActiveForm;
- select(['name', 'id'])->orderBy(['name' => SORT_ASC])->asArray()->all(); - - $adminsList = []; - foreach ($admins as $admin) { - $adminsList[$admin['id']] = $admin['name'] . ' ( id ' . $admin['id'] . ')'; - } - ?> - field($model, 'admin_id')->widget(Select2::classname(), [ - 'data' => $adminsList, - 'options' => [ - 'placeholder' => 'Выберите сотрудника...', - 'value' => $model->admin_id, // Устанавливаем значение по умолчанию - ], - 'pluginOptions' => [ - 'allowClear' => true - ], - ]); ?> + + field($model, 'admin_id')->hiddenInput()->label(false) ?> + field($model, 'admin_name')->textInput([ + 'value' => $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]) ?> -- 2.39.5