From: JoySystem_v Date: Mon, 26 Aug 2024 08:52:36 +0000 (+0300) Subject: заблокировал изменение пользователя и добавил валидацию оклада и даты X-Git-Tag: 1.5~20^2~15 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=fb77a703c6ae0ea7c75e035070b219e113b940c1;p=erp24_rep%2Fyii-erp24%2F.git заблокировал изменение пользователя и добавил валидацию оклада и даты --- 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]) ?>