From: Vladimir Fomichev Date: Thu, 13 Nov 2025 14:37:51 +0000 (+0300) Subject: Штатное расписание миграция X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=469c28ee964dd55c18d21fb93aa900052a1eb0c2;p=erp24_rep%2Fyii-erp24%2F.git Штатное расписание миграция --- 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; + } + } +} +