132 lines
9.2 KiB
C#
132 lines
9.2 KiB
C#
using System;
|
||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||
using Microsoft.EntityFrameworkCore.Migrations;
|
||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||
using TakeoutSaaS.Infrastructure.App.Persistence;
|
||
|
||
#nullable disable
|
||
|
||
namespace TakeoutSaaS.Infrastructure.Migrations;
|
||
|
||
/// <summary>
|
||
/// 新增财务中心发票管理表结构。
|
||
/// </summary>
|
||
[DbContext(typeof(TakeoutAppDbContext))]
|
||
[Migration("20260305103000_AddFinanceInvoiceModule")]
|
||
public sealed class AddFinanceInvoiceModule : Migration
|
||
{
|
||
/// <inheritdoc />
|
||
protected override void Up(MigrationBuilder migrationBuilder)
|
||
{
|
||
migrationBuilder.CreateTable(
|
||
name: "finance_invoice_records",
|
||
columns: table => new
|
||
{
|
||
Id = table.Column<long>(type: "bigint", nullable: false, comment: "实体唯一标识。")
|
||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||
InvoiceNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "发票号码。"),
|
||
ApplicantName = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "申请人。"),
|
||
CompanyName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false, comment: "开票抬头(公司名)。"),
|
||
TaxpayerNumber = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "纳税人识别号快照。"),
|
||
InvoiceType = table.Column<int>(type: "integer", nullable: false, comment: "发票类型。"),
|
||
Amount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "开票金额。"),
|
||
OrderNo = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, comment: "关联订单号。"),
|
||
ContactEmail = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true, comment: "接收邮箱。"),
|
||
ContactPhone = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "联系电话。"),
|
||
ApplyRemark = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "申请备注。"),
|
||
Status = table.Column<int>(type: "integer", nullable: false, comment: "发票状态。"),
|
||
AppliedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "申请时间(UTC)。"),
|
||
IssuedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "开票时间(UTC)。"),
|
||
IssuedByUserId = table.Column<long>(type: "bigint", nullable: true, comment: "开票人 ID。"),
|
||
IssueRemark = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "开票备注。"),
|
||
VoidedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "作废时间(UTC)。"),
|
||
VoidedByUserId = table.Column<long>(type: "bigint", nullable: true, comment: "作废人 ID。"),
|
||
VoidReason = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "作废原因。"),
|
||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"),
|
||
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"),
|
||
DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"),
|
||
CreatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
|
||
UpdatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
|
||
DeletedBy = table.Column<long>(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
|
||
TenantId = table.Column<long>(type: "bigint", nullable: false, comment: "所属租户 ID。")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_finance_invoice_records", x => x.Id);
|
||
},
|
||
comment: "租户发票记录。");
|
||
|
||
migrationBuilder.CreateTable(
|
||
name: "finance_invoice_settings",
|
||
columns: table => new
|
||
{
|
||
Id = table.Column<long>(type: "bigint", nullable: false, comment: "实体唯一标识。")
|
||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||
CompanyName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false, comment: "企业名称。"),
|
||
TaxpayerNumber = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "纳税人识别号。"),
|
||
RegisteredAddress = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true, comment: "注册地址。"),
|
||
RegisteredPhone = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "注册电话。"),
|
||
BankName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true, comment: "开户银行。"),
|
||
BankAccount = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true, comment: "银行账号。"),
|
||
EnableElectronicNormalInvoice = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用电子普通发票。"),
|
||
EnableElectronicSpecialInvoice = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用电子专用发票。"),
|
||
EnableAutoIssue = table.Column<bool>(type: "boolean", nullable: false, comment: "是否启用自动开票。"),
|
||
AutoIssueMaxAmount = table.Column<decimal>(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false, comment: "自动开票单张最大金额。"),
|
||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "创建时间(UTC)。"),
|
||
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "最近一次更新时间(UTC),从未更新时为 null。"),
|
||
DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true, comment: "软删除时间(UTC),未删除时为 null。"),
|
||
CreatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "创建人用户标识,匿名或系统操作时为 null。"),
|
||
UpdatedBy = table.Column<long>(type: "bigint", nullable: true, comment: "最后更新人用户标识,匿名或系统操作时为 null。"),
|
||
DeletedBy = table.Column<long>(type: "bigint", nullable: true, comment: "删除人用户标识(软删除),未删除时为 null。"),
|
||
TenantId = table.Column<long>(type: "bigint", nullable: false, comment: "所属租户 ID。")
|
||
},
|
||
constraints: table =>
|
||
{
|
||
table.PrimaryKey("PK_finance_invoice_settings", x => x.Id);
|
||
},
|
||
comment: "租户发票开票基础设置。");
|
||
|
||
migrationBuilder.CreateIndex(
|
||
name: "IX_finance_invoice_records_TenantId_InvoiceNo",
|
||
table: "finance_invoice_records",
|
||
columns: new[] { "TenantId", "InvoiceNo" },
|
||
unique: true);
|
||
|
||
migrationBuilder.CreateIndex(
|
||
name: "IX_finance_invoice_records_TenantId_InvoiceType_AppliedAt",
|
||
table: "finance_invoice_records",
|
||
columns: new[] { "TenantId", "InvoiceType", "AppliedAt" });
|
||
|
||
migrationBuilder.CreateIndex(
|
||
name: "IX_finance_invoice_records_TenantId_OrderNo",
|
||
table: "finance_invoice_records",
|
||
columns: new[] { "TenantId", "OrderNo" });
|
||
|
||
migrationBuilder.CreateIndex(
|
||
name: "IX_finance_invoice_records_TenantId_Status_AppliedAt",
|
||
table: "finance_invoice_records",
|
||
columns: new[] { "TenantId", "Status", "AppliedAt" });
|
||
|
||
migrationBuilder.CreateIndex(
|
||
name: "IX_finance_invoice_records_TenantId_Status_IssuedAt",
|
||
table: "finance_invoice_records",
|
||
columns: new[] { "TenantId", "Status", "IssuedAt" });
|
||
|
||
migrationBuilder.CreateIndex(
|
||
name: "IX_finance_invoice_settings_TenantId",
|
||
table: "finance_invoice_settings",
|
||
column: "TenantId",
|
||
unique: true);
|
||
}
|
||
|
||
/// <inheritdoc />
|
||
protected override void Down(MigrationBuilder migrationBuilder)
|
||
{
|
||
migrationBuilder.DropTable(
|
||
name: "finance_invoice_records");
|
||
|
||
migrationBuilder.DropTable(
|
||
name: "finance_invoice_settings");
|
||
}
|
||
}
|