From aa93dea296182537ef58322ab26687dc01b3ed35 Mon Sep 17 00:00:00 2001 From: marina Date: Wed, 5 Jun 2024 08:08:49 +0300 Subject: [PATCH] =?utf8?q?ERP-5=20=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?utf8?q?=D1=82=D0=B0=D1=82=D1=8C=20=D1=84=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?utf8?q?=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D0=BF=D0=BB=D0=B0=D0=BD=20?= =?utf8?q?=D0=BF=D0=BE=20=D1=81=D0=BE=D1=82=D1=80=D1=83=D0=B4=D0=BD=D0=B8?= =?utf8?q?=D0=BA=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../timetable/StartShiftStepTwoAction.php | 10 +- ...0603_082541_create_new_fact_plan_table.php | 63 +++++++++ erp24/records/TimetableFactModel.php | 120 ++++++++++++++++++ 3 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 erp24/migrations/m240603_082541_create_new_fact_plan_table.php create mode 100644 erp24/records/TimetableFactModel.php diff --git a/erp24/actions/timetable/StartShiftStepTwoAction.php b/erp24/actions/timetable/StartShiftStepTwoAction.php index 83090d75..0a7d91eb 100755 --- a/erp24/actions/timetable/StartShiftStepTwoAction.php +++ b/erp24/actions/timetable/StartShiftStepTwoAction.php @@ -3,6 +3,7 @@ declare(strict_types = 1); namespace yii_app\actions\timetable; +use app\records\TimetableFactModel; use Yii; use yii\base\Action; use yii\helpers\ArrayHelper; @@ -77,11 +78,7 @@ class StartShiftStepTwoAction extends Action /** @var TimetablePlan[] $planSlots */ $planSlots = TimetablePlan::find() - ->andWhere( - ($device->isFixedStore() && !$userModel->adminGroup->isRoaming()) ? - ['store_id' => $model->store_id] : - ['admin_id' => $model->admin_id] - ) + ->andFilterWhere(['store_id' => $model->store_id]) ->andWhere(['OR', ['BETWEEN', 'datetime_start', date('Y-m-d H:i:s'), date('Y-m-d H:i:s', strtotime('+6 hour'))], ['BETWEEN', 'datetime_end', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s')], @@ -112,6 +109,9 @@ class StartShiftStepTwoAction extends Action } } + $timetableFact = new TimetableFactModel(); + $timetableFact->setValues($model, $planSlots); + if (!$model->date) { \Yii::warning('Не указана дата явки. Скорее всего отсутствуент связанный план. admin_id:' . $model->admin_id . ', plan_id:' . $model->plan_id . ', store_id:' . $model->store_id); $model->date = date('Y-m-d'); diff --git a/erp24/migrations/m240603_082541_create_new_fact_plan_table.php b/erp24/migrations/m240603_082541_create_new_fact_plan_table.php new file mode 100644 index 00000000..0437c271 --- /dev/null +++ b/erp24/migrations/m240603_082541_create_new_fact_plan_table.php @@ -0,0 +1,63 @@ +createTable('{{%timetable_fact}}', [ + 'id' => $this->primaryKey(), + 'admin_id' => $this->integer()->comment('ID сотрудника'), + 'store_id' => $this->integer()->comment('ID магазина'), + 'admin_group_id' => $this->integer()->comment('ID должности'), + 'd_id' => $this->integer()->comment('в какой должности работал на смене'), + 'date_shift' => $this->date()->comment('дата смены'), + 'date_start' => $this->date()->comment('дата время открытия смены'), + 'date_end' => $this->date()->comment('дата время закрытия смены'), + 'is_opening' => $this->boolean()->comment('на открытие смены'), + 'is_close' => $this->boolean()->comment('на закрытие смены'), + 'tabel' => $this->integer()->comment('табель'), + 'plan_id' => $this->integer()->comment('ID табеля если смена поставлена'), + 'shift_id' => $this->integer()->comment('тип смены'), + 'admin_id_add' => $this->integer()->comment('ID поставившего смену'), + 'time_start' => $this->integer()->comment('время начала работы по графику'), + 'time_end' => $this->time()->comment('время окончания работы по графику'), + 'work_time' => $this->float()->comment('рабочее время'), + 'price_hour' => $this->float()->comment('часовая ставка'), + 'salary_shift' => $this->integer()->comment('оплата за смену'), + 'slot_type_id' => $this->integer()->comment('тип занятности'), + 'comment' => $this->text()->comment('комментарий'), + 'date_add' => $this->timestamp()->comment('дата постановки смены'), + 'status' => $this->integer()->comment('статус смены'), + ]); + + $this->addForeignKey('fk_timetable_fact_to_admin', 'timetable_fact', 'admin_id', 'admin', 'id'); + $this->addForeignKey('fk_timetable_fact_to_store', 'timetable_fact', 'store_id', 'store', 'id'); + $this->addForeignKey('fk_timetable_fact_to_admin_group', 'timetable_fact', 'admin_group_id', 'admin_group', 'id'); + $this->addForeignKey('fk_timetable_fact_to_admin_group_as_d', 'timetable_fact', 'd_id', 'admin_group', 'id'); + $this->addForeignKey('fk_timetable_fact_to_plan', 'timetable_fact', 'plan_id', 'timetable', 'id'); + $this->addForeignKey('fk_timetable_fact_to_admin_as_admin_id_add', 'timetable_fact', 'admin_id_add', 'admin', 'id'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('fk_timetable_fact_to_admin', 'timetable_fact'); + $this->dropForeignKey('fk_timetable_fact_to_store', 'timetable_fact'); + $this->dropForeignKey('fk_timetable_fact_to_admin_group', 'timetable_fact'); + $this->dropForeignKey('fk_timetable_fact_to_admin_group_as_d', 'timetable_fact'); + $this->dropForeignKey('fk_timetable_fact_to_plan', 'timetable_fact'); + $this->dropForeignKey('fk_timetable_fact_to_admin_as_admin_id_add', 'timetable_fact'); + + $this->dropTable('{{%timetable_fact}}'); + } +} diff --git a/erp24/records/TimetableFactModel.php b/erp24/records/TimetableFactModel.php new file mode 100644 index 00000000..f58a603d --- /dev/null +++ b/erp24/records/TimetableFactModel.php @@ -0,0 +1,120 @@ + AdminGroup::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], + [['admin_id', 'admin_id_add'], 'exist', 'targetClass' => Admin::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], + [['store_id'], 'exist', 'targetClass' => CityStore::class, 'targetAttribute' => 'id', 'skipOnEmpty' => true], + [['shift_id'], 'in', 'range' => array_keys(Shift::all()), 'skipOnEmpty' => false], + [['time_start', 'time_end'], 'date', 'format' => 'HH:mm:ss'], + [['work_time'], 'number', 'min' => 0, 'max' => 24], + [['comment'], 'string'], + [['comment'], 'default', 'value' => null], + ['slot_type_id', 'in', 'range' => array_keys(Timetable::slotTypeName())], + [['date_shift'], 'date', 'format' => 'yyyy-M-d'], + [['salary_shift'], 'in', 'range' => \yii_app\records\Timetable::getSalariesDay(), 'skipOnEmpty' => true], + [['datetime_start', 'datetime_end'], 'required'], + [['tabel', 'plan_id', 'status'], 'safe', 'skipOnEmpty' => false,], + ['price_hour', 'float'], + [['date_add'], 'datetime', 'format' => "yyyy-MM-dd H:m:s"], + ]; + } + + public function setValues($adminCheckin, $timetable) + { + $this->admin_id = $adminCheckin->admin_id; + $this->admin_group_id = $adminCheckin->admin->shift; + $this->d_id = $adminCheckin->d_id; + $this->store_id = $adminCheckin->store_id; + $this->date_shift = $adminCheckin->date; + $this->shift_id = $timetable->shift_id; + $this->comment = $timetable->comment; + $this->work_time = $timetable->work_time < 12 ? $timetable->work_time : 12; + $this->salary_shift = $timetable->salary_shift; + $this->admin_id_add = $timetable->admin_id_add; + $this->tabel = $timetable->tabel; + $this->slot_type_id = $timetable->slot_type_id; + $this->plan_id = $adminCheckin->plan_id; + $this->time_start = $timetable->time_start; + $this->time_end = $timetable->time_end; + $this->date_end = $timetable->datetime_end; + $this->save(); + } + + public function getAdmin() + { + return $this->hasOne(Admin::class, ['id' => 'admin_id']); + } + + public function getAdminAdd() + { + return $this->hasOne(Admin::class, ['id' => 'admin_id_add']); + } + + public function getStore() + { + return $this->hasOne(CityStore::class, ['id' => 'store_id']); + } + + public function getPlan() + { + return $this->hasOne(TimetablePlan::class, ['id' => 'plan_id']); + } + + public function getD() + { + return $this->hasOne(AdminGroup::class, ['id' => 'd_id']); + } + + public function getAdminGroup() + { + return $this->hasOne(AdminGroup::class, ['id' => 'admin_group_id']); + } +} \ No newline at end of file -- 2.39.5