From c016d6a31988e57a8ace3d9ad430bb8b8df0f441 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 12 Mar 2026 11:30:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=91=D0=94=20=D0=B8=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/auditor.rb | 3 + app/models/document_type.rb | 5 ++ app/models/financial_statement.rb | 6 ++ app/models/organization.rb | 6 ++ app/models/yearly_file.rb | 10 ++++ .../20260312000001_create_organizations.rb | 18 ++++++ db/migrate/20260312000002_create_auditors.rb | 13 +++++ .../20260312000003_create_document_types.rb | 9 +++ .../20260312000004_create_yearly_files.rb | 11 ++++ ...60312000005_create_financial_statements.rb | 12 ++++ db/schema.rb | 56 ++++++++++++++++++- 11 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 app/models/auditor.rb create mode 100644 app/models/document_type.rb create mode 100644 app/models/financial_statement.rb create mode 100644 app/models/organization.rb create mode 100644 app/models/yearly_file.rb create mode 100644 db/migrate/20260312000001_create_organizations.rb create mode 100644 db/migrate/20260312000002_create_auditors.rb create mode 100644 db/migrate/20260312000003_create_document_types.rb create mode 100644 db/migrate/20260312000004_create_yearly_files.rb create mode 100644 db/migrate/20260312000005_create_financial_statements.rb diff --git a/app/models/auditor.rb b/app/models/auditor.rb new file mode 100644 index 0000000..e3056b6 --- /dev/null +++ b/app/models/auditor.rb @@ -0,0 +1,3 @@ +class Auditor < ApplicationRecord + has_many :yearly_files, dependent: :nullify +end diff --git a/app/models/document_type.rb b/app/models/document_type.rb new file mode 100644 index 0000000..17db798 --- /dev/null +++ b/app/models/document_type.rb @@ -0,0 +1,5 @@ +class DocumentType < ApplicationRecord + has_many :financial_statements, dependent: :restrict_with_error + + validates :name, presence: true +end diff --git a/app/models/financial_statement.rb b/app/models/financial_statement.rb new file mode 100644 index 0000000..427ad08 --- /dev/null +++ b/app/models/financial_statement.rb @@ -0,0 +1,6 @@ +class FinancialStatement < ApplicationRecord + belongs_to :yearly_file + belongs_to :document_type + + validates :data, presence: true +end diff --git a/app/models/organization.rb b/app/models/organization.rb new file mode 100644 index 0000000..4cedcd4 --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,6 @@ +class Organization < ApplicationRecord + has_many :yearly_files, dependent: :destroy + has_many :financial_statements, through: :yearly_files + + validates :inn, presence: true +end diff --git a/app/models/yearly_file.rb b/app/models/yearly_file.rb new file mode 100644 index 0000000..d094f8a --- /dev/null +++ b/app/models/yearly_file.rb @@ -0,0 +1,10 @@ +class YearlyFile < ApplicationRecord + belongs_to :organization + belongs_to :auditor, optional: true + + has_many :financial_statements, dependent: :destroy + + has_one_attached :file + + validates :year, presence: true +end diff --git a/db/migrate/20260312000001_create_organizations.rb b/db/migrate/20260312000001_create_organizations.rb new file mode 100644 index 0000000..a2a2b19 --- /dev/null +++ b/db/migrate/20260312000001_create_organizations.rb @@ -0,0 +1,18 @@ +class CreateOrganizations < ActiveRecord::Migration[7.1] + def change + create_table :organizations do |t| + t.string :inn, null: false + t.string :full_name + t.string :kpp + t.string :okpo + t.string :okfs + t.string :okopf + t.string :okved2 + t.string :address + + t.timestamps + end + + add_index :organizations, :inn + end +end diff --git a/db/migrate/20260312000002_create_auditors.rb b/db/migrate/20260312000002_create_auditors.rb new file mode 100644 index 0000000..5edfe27 --- /dev/null +++ b/db/migrate/20260312000002_create_auditors.rb @@ -0,0 +1,13 @@ +class CreateAuditors < ActiveRecord::Migration[7.1] + def change + create_table :auditors do |t| + t.string :name + t.string :inn + t.string :ogrn + + t.timestamps + end + + add_index :auditors, :inn + end +end diff --git a/db/migrate/20260312000003_create_document_types.rb b/db/migrate/20260312000003_create_document_types.rb new file mode 100644 index 0000000..9b64f1c --- /dev/null +++ b/db/migrate/20260312000003_create_document_types.rb @@ -0,0 +1,9 @@ +class CreateDocumentTypes < ActiveRecord::Migration[7.1] + def change + create_table :document_types do |t| + t.string :name, null: false + + t.timestamps + end + end +end diff --git a/db/migrate/20260312000004_create_yearly_files.rb b/db/migrate/20260312000004_create_yearly_files.rb new file mode 100644 index 0000000..2604aba --- /dev/null +++ b/db/migrate/20260312000004_create_yearly_files.rb @@ -0,0 +1,11 @@ +class CreateYearlyFiles < ActiveRecord::Migration[7.1] + def change + create_table :yearly_files do |t| + t.references :organization, null: false, foreign_key: true + t.integer :year, null: false + t.references :auditor, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20260312000005_create_financial_statements.rb b/db/migrate/20260312000005_create_financial_statements.rb new file mode 100644 index 0000000..6aeaf71 --- /dev/null +++ b/db/migrate/20260312000005_create_financial_statements.rb @@ -0,0 +1,12 @@ +class CreateFinancialStatements < ActiveRecord::Migration[7.1] + def change + create_table :financial_statements do |t| + t.references :yearly_file, null: false, foreign_key: true + t.references :document_type, null: false, foreign_key: true + t.integer :sheet_number + t.jsonb :data, default: {} + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6967052..7cab919 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2025_12_09_142642) do +ActiveRecord::Schema[7.1].define(version: 2026_03_12_000005) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -42,6 +42,46 @@ ActiveRecord::Schema[7.1].define(version: 2025_12_09_142642) do t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end + create_table "auditors", force: :cascade do |t| + t.string "name" + t.string "inn" + t.string "ogrn" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["inn"], name: "index_auditors_on_inn" + end + + create_table "document_types", force: :cascade do |t| + t.string "name", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "financial_statements", force: :cascade do |t| + t.bigint "yearly_file_id", null: false + t.bigint "document_type_id", null: false + t.integer "sheet_number" + t.jsonb "data", default: {} + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["document_type_id"], name: "index_financial_statements_on_document_type_id" + t.index ["yearly_file_id"], name: "index_financial_statements_on_yearly_file_id" + end + + create_table "organizations", force: :cascade do |t| + t.string "inn", null: false + t.string "full_name" + t.string "kpp" + t.string "okpo" + t.string "okfs" + t.string "okopf" + t.string "okved2" + t.string "address" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["inn"], name: "index_organizations_on_inn" + end + create_table "reports", force: :cascade do |t| t.string "inn" t.string "status" @@ -76,6 +116,20 @@ ActiveRecord::Schema[7.1].define(version: 2025_12_09_142642) do t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" end + create_table "yearly_files", force: :cascade do |t| + t.bigint "organization_id", null: false + t.integer "year", null: false + t.bigint "auditor_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["auditor_id"], name: "index_yearly_files_on_auditor_id" + t.index ["organization_id"], name: "index_yearly_files_on_organization_id" + end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" + add_foreign_key "financial_statements", "document_types" + add_foreign_key "financial_statements", "yearly_files" + add_foreign_key "yearly_files", "auditors" + add_foreign_key "yearly_files", "organizations" end