using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace PowderCoating.Infrastructure.Migrations { /// public partial class AddRefundsAndCreditMemos : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "CreditApplied", table: "Invoices", type: "decimal(18,2)", nullable: false, defaultValue: 0m); migrationBuilder.AddColumn( name: "CreditBalance", table: "Customers", type: "decimal(18,2)", nullable: false, defaultValue: 0m); migrationBuilder.CreateTable( name: "CreditMemos", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), MemoNumber = table.Column(type: "nvarchar(450)", nullable: false), CustomerId = table.Column(type: "int", nullable: false), OriginalInvoiceId = table.Column(type: "int", nullable: true), ReworkRecordId = table.Column(type: "int", nullable: true), Amount = table.Column(type: "decimal(18,2)", nullable: false), AmountApplied = table.Column(type: "decimal(18,2)", nullable: false), IssueDate = table.Column(type: "datetime2", nullable: false), ExpiryDate = table.Column(type: "datetime2", nullable: true), Reason = table.Column(type: "nvarchar(max)", nullable: false), Notes = table.Column(type: "nvarchar(max)", nullable: true), Status = table.Column(type: "int", nullable: false), IssuedById = table.Column(type: "nvarchar(450)", nullable: true), CompanyId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true), CreatedBy = table.Column(type: "nvarchar(max)", nullable: true), UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), DeletedAt = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CreditMemos", x => x.Id); table.ForeignKey( name: "FK_CreditMemos_AspNetUsers_IssuedById", column: x => x.IssuedById, principalTable: "AspNetUsers", principalColumn: "Id"); table.ForeignKey( name: "FK_CreditMemos_Customers_CustomerId", column: x => x.CustomerId, principalTable: "Customers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_CreditMemos_Invoices_OriginalInvoiceId", column: x => x.OriginalInvoiceId, principalTable: "Invoices", principalColumn: "Id"); table.ForeignKey( name: "FK_CreditMemos_ReworkRecords_ReworkRecordId", column: x => x.ReworkRecordId, principalTable: "ReworkRecords", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Refunds", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), InvoiceId = table.Column(type: "int", nullable: false), PaymentId = table.Column(type: "int", nullable: true), Amount = table.Column(type: "decimal(18,2)", nullable: false), RefundDate = table.Column(type: "datetime2", nullable: false), RefundMethod = table.Column(type: "int", nullable: false), Reason = table.Column(type: "nvarchar(max)", nullable: false), Reference = table.Column(type: "nvarchar(max)", nullable: true), Notes = table.Column(type: "nvarchar(max)", nullable: true), Status = table.Column(type: "int", nullable: false), IssuedDate = table.Column(type: "datetime2", nullable: true), IssuedById = table.Column(type: "nvarchar(450)", nullable: true), CompanyId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true), CreatedBy = table.Column(type: "nvarchar(max)", nullable: true), UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), DeletedAt = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Refunds", x => x.Id); table.ForeignKey( name: "FK_Refunds_AspNetUsers_IssuedById", column: x => x.IssuedById, principalTable: "AspNetUsers", principalColumn: "Id"); table.ForeignKey( name: "FK_Refunds_Invoices_InvoiceId", column: x => x.InvoiceId, principalTable: "Invoices", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Refunds_Payments_PaymentId", column: x => x.PaymentId, principalTable: "Payments", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "CreditMemoApplications", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CreditMemoId = table.Column(type: "int", nullable: false), InvoiceId = table.Column(type: "int", nullable: false), AmountApplied = table.Column(type: "decimal(18,2)", nullable: false), AppliedDate = table.Column(type: "datetime2", nullable: false), AppliedById = table.Column(type: "nvarchar(450)", nullable: true), CompanyId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true), CreatedBy = table.Column(type: "nvarchar(max)", nullable: true), UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), DeletedAt = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CreditMemoApplications", x => x.Id); table.ForeignKey( name: "FK_CreditMemoApplications_AspNetUsers_AppliedById", column: x => x.AppliedById, principalTable: "AspNetUsers", principalColumn: "Id"); table.ForeignKey( name: "FK_CreditMemoApplications_CreditMemos_CreditMemoId", column: x => x.CreditMemoId, principalTable: "CreditMemos", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_CreditMemoApplications_Invoices_InvoiceId", column: x => x.InvoiceId, principalTable: "Invoices", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 3, 18, 22, 26, 44, 934, DateTimeKind.Utc).AddTicks(9567)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 3, 18, 22, 26, 44, 934, DateTimeKind.Utc).AddTicks(9573)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 3, 18, 22, 26, 44, 934, DateTimeKind.Utc).AddTicks(9575)); migrationBuilder.CreateIndex( name: "IX_CreditMemoApplications_AppliedById", table: "CreditMemoApplications", column: "AppliedById"); migrationBuilder.CreateIndex( name: "IX_CreditMemoApplications_CreditMemoId", table: "CreditMemoApplications", column: "CreditMemoId"); migrationBuilder.CreateIndex( name: "IX_CreditMemoApplications_InvoiceId", table: "CreditMemoApplications", column: "InvoiceId"); migrationBuilder.CreateIndex( name: "IX_CreditMemos_CompanyId_MemoNumber", table: "CreditMemos", columns: new[] { "CompanyId", "MemoNumber" }, unique: true); migrationBuilder.CreateIndex( name: "IX_CreditMemos_CustomerId", table: "CreditMemos", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_CreditMemos_IssuedById", table: "CreditMemos", column: "IssuedById"); migrationBuilder.CreateIndex( name: "IX_CreditMemos_OriginalInvoiceId", table: "CreditMemos", column: "OriginalInvoiceId"); migrationBuilder.CreateIndex( name: "IX_CreditMemos_ReworkRecordId", table: "CreditMemos", column: "ReworkRecordId"); migrationBuilder.CreateIndex( name: "IX_Refunds_InvoiceId", table: "Refunds", column: "InvoiceId"); migrationBuilder.CreateIndex( name: "IX_Refunds_IssuedById", table: "Refunds", column: "IssuedById"); migrationBuilder.CreateIndex( name: "IX_Refunds_PaymentId", table: "Refunds", column: "PaymentId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "CreditMemoApplications"); migrationBuilder.DropTable( name: "Refunds"); migrationBuilder.DropTable( name: "CreditMemos"); migrationBuilder.DropColumn( name: "CreditApplied", table: "Invoices"); migrationBuilder.DropColumn( name: "CreditBalance", table: "Customers"); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 3, 18, 13, 42, 32, 909, DateTimeKind.Utc).AddTicks(2998)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 3, 18, 13, 42, 32, 909, DateTimeKind.Utc).AddTicks(3003)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 3, 18, 13, 42, 32, 909, DateTimeKind.Utc).AddTicks(3005)); } } }