From 469c28ee964dd55c18d21fb93aa900052a1eb0c2 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Thu, 13 Nov 2025 17:37:51 +0300 Subject: [PATCH] =?utf8?q?=D0=A8=D1=82=D0=B0=D1=82=D0=BD=D0=BE=D0=B5=20?= =?utf8?q?=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?utf8?q?=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...11_100000_create_store_staffing_tables.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 erp24/migrations/m251211_100000_create_store_staffing_tables.php diff --git a/erp24/migrations/m251211_100000_create_store_staffing_tables.php b/erp24/migrations/m251211_100000_create_store_staffing_tables.php new file mode 100644 index 00000000..e3252b11 --- /dev/null +++ b/erp24/migrations/m251211_100000_create_store_staffing_tables.php @@ -0,0 +1,83 @@ +db->beginTransaction(); + try { + // Создаем таблицу store_staffing (штатное расписание) + $staffingSchema = $this->db->getTableSchema(self::TABLE_STAFFING); + if (!isset($staffingSchema)) { + $this->createTable(self::TABLE_STAFFING, [ + 'id' => $this->primaryKey(), + 'store_id' => $this->integer()->notNull()->comment('ID магазина'), + 'employee_position_id' => $this->integer()->notNull()->comment('ID должности'), + 'count' => $this->decimal(4, 2)->notNull()->comment('Количество сотрудников (может быть дробным - пол смены)'), + 'created_at' => $this->timestamp()->defaultExpression('CURRENT_TIMESTAMP'), + 'updated_at' => $this->timestamp()->defaultExpression('CURRENT_TIMESTAMP'), + ]); + } + + // Создаем таблицу store_staffing_log (логирование изменений) + $logSchema = $this->db->getTableSchema(self::TABLE_LOG); + if (!isset($logSchema)) { + $this->createTable(self::TABLE_LOG, [ + 'id' => $this->primaryKey(), + 'store_staffing_id' => $this->integer()->null()->comment('ID записи штатного расписания (NULL для удалений)'), + 'store_id' => $this->integer()->notNull()->comment('ID магазина'), + 'employee_position_id' => $this->integer()->notNull()->comment('ID должности'), + 'action' => $this->string(10)->notNull()->comment('Действие: create, update, delete'), + 'old_count' => $this->integer()->null()->comment('Старое количество'), + 'new_count' => $this->integer()->null()->comment('Новое количество'), + 'changed_by' => $this->integer()->null()->comment('ID администратора, внесшего изменение'), + 'created_at' => $this->timestamp()->defaultExpression('CURRENT_TIMESTAMP'), + ]); + } + + $transaction->commit(); + } catch (\Exception $e) { + $transaction->rollBack(); + throw $e; + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $transaction = $this->db->beginTransaction(); + try { + // Удаляем таблицу store_staffing_log + $logSchema = $this->db->getTableSchema(self::TABLE_LOG); + if (isset($logSchema)) { + $this->dropTable(self::TABLE_LOG); + } + + // Удаляем таблицу store_staffing + $staffingSchema = $this->db->getTableSchema(self::TABLE_STAFFING); + if (isset($staffingSchema)) { + $this->dropTable(self::TABLE_STAFFING); + } + + $transaction->commit(); + } catch (\Exception $e) { + $transaction->rollBack(); + throw $e; + } + } +} + -- 2.39.5