Миграция Phase4_CountryCurrencyOrgDefaults: - countries.DefaultCurrencyId (FK → currencies) - organizations.DefaultCurrencyId, MultiCurrencyEnabled, DefaultVat - Seed: KZ→KZT, RU→RUB, BY→BYN, US→USD, DE→EUR, CN→CNY, TR→TRY - Default для org: KZT, vat=16 Backend: - Organization сущность получила DefaultCurrency/MultiCurrencyEnabled/DefaultVat. - OrganizationSettingsController: GET/PUT /api/organization/settings. - DevDataSeeder при создании/backfill орга выставляет KZT + vat=16. Web: - /settings/organization: форма с выбором страны (авто-подтягивает валюту), чекбоксом multi-currency, ставкой НДС по умолчанию. - useOrgSettings() хук. - SupplyEditPage / RetailSaleEditPage / ProductEditPage: select валюты показывается только если multiCurrencyEnabled=true, иначе подтягивается DefaultCurrency организации и рисуется символ валюты справа от цены. - ProductEditPage при создании нового товара берёт VAT из org.DefaultVat. - В sidebar добавлен раздел 'Настройки → Организация', убран Ставки НДС (сущность удалена раньше).
84 lines
4.4 KiB
C#
84 lines
4.4 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace foodmarket.Infrastructure.Persistence.Migrations
|
|
{
|
|
/// <summary>Country ↔ Currency связка + дефолты организации:
|
|
/// - countries.DefaultCurrencyId (nullable FK → currencies.Id)
|
|
/// - organizations.DefaultCurrencyId (FK → currencies.Id)
|
|
/// - organizations.MultiCurrencyEnabled (bool, default false)
|
|
/// - organizations.DefaultVat (int, default 16)
|
|
/// Seed: KZ→KZT, RU→RUB; org → KZ+KZT.</summary>
|
|
public partial class Phase4_CountryCurrencyOrgDefaults : Migration
|
|
{
|
|
protected override void Up(MigrationBuilder b)
|
|
{
|
|
b.AddColumn<Guid>(
|
|
name: "DefaultCurrencyId", schema: "public", table: "countries",
|
|
type: "uuid", nullable: true);
|
|
|
|
b.AddColumn<Guid>(
|
|
name: "DefaultCurrencyId", schema: "public", table: "organizations",
|
|
type: "uuid", nullable: true);
|
|
b.AddColumn<bool>(
|
|
name: "MultiCurrencyEnabled", schema: "public", table: "organizations",
|
|
type: "boolean", nullable: false, defaultValue: false);
|
|
b.AddColumn<int>(
|
|
name: "DefaultVat", schema: "public", table: "organizations",
|
|
type: "integer", nullable: false, defaultValue: 16);
|
|
|
|
b.CreateIndex(
|
|
name: "IX_countries_DefaultCurrencyId", schema: "public",
|
|
table: "countries", column: "DefaultCurrencyId");
|
|
b.CreateIndex(
|
|
name: "IX_organizations_DefaultCurrencyId", schema: "public",
|
|
table: "organizations", column: "DefaultCurrencyId");
|
|
|
|
b.AddForeignKey(
|
|
name: "FK_countries_currencies_DefaultCurrencyId",
|
|
schema: "public", table: "countries", column: "DefaultCurrencyId",
|
|
principalSchema: "public", principalTable: "currencies", principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
b.AddForeignKey(
|
|
name: "FK_organizations_currencies_DefaultCurrencyId",
|
|
schema: "public", table: "organizations", column: "DefaultCurrencyId",
|
|
principalSchema: "public", principalTable: "currencies", principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
// Backfill: привяжем валюты к странам по ISO-коду.
|
|
b.Sql("""
|
|
UPDATE public.countries SET "DefaultCurrencyId" = c."Id"
|
|
FROM public.currencies c
|
|
WHERE (public.countries."Code" = 'KZ' AND c."Code" = 'KZT')
|
|
OR (public.countries."Code" = 'RU' AND c."Code" = 'RUB')
|
|
OR (public.countries."Code" = 'BY' AND c."Code" = 'BYN')
|
|
OR (public.countries."Code" = 'US' AND c."Code" = 'USD')
|
|
OR (public.countries."Code" = 'DE' AND c."Code" = 'EUR')
|
|
OR (public.countries."Code" = 'CN' AND c."Code" = 'CNY')
|
|
OR (public.countries."Code" = 'TR' AND c."Code" = 'TRY');
|
|
""");
|
|
|
|
// Дефолт для организации — KZT, если существует.
|
|
b.Sql("""
|
|
UPDATE public.organizations SET "DefaultCurrencyId" = c."Id"
|
|
FROM public.currencies c
|
|
WHERE c."Code" = 'KZT' AND public.organizations."DefaultCurrencyId" IS NULL;
|
|
""");
|
|
}
|
|
|
|
protected override void Down(MigrationBuilder b)
|
|
{
|
|
b.DropForeignKey(name: "FK_countries_currencies_DefaultCurrencyId", schema: "public", table: "countries");
|
|
b.DropForeignKey(name: "FK_organizations_currencies_DefaultCurrencyId", schema: "public", table: "organizations");
|
|
b.DropIndex(name: "IX_countries_DefaultCurrencyId", schema: "public", table: "countries");
|
|
b.DropIndex(name: "IX_organizations_DefaultCurrencyId", schema: "public", table: "organizations");
|
|
b.DropColumn(name: "DefaultCurrencyId", schema: "public", table: "countries");
|
|
b.DropColumn(name: "DefaultCurrencyId", schema: "public", table: "organizations");
|
|
b.DropColumn(name: "MultiCurrencyEnabled", schema: "public", table: "organizations");
|
|
b.DropColumn(name: "DefaultVat", schema: "public", table: "organizations");
|
|
}
|
|
}
|
|
}
|