Phase D: Add Vendor Credits (AP cycle completion)

- VendorCredit, VendorCreditLineItem, VendorCreditApplication entities
- VendorCreditStatus enum (Open, PartiallyApplied, Applied, Voided)
- Migration AddVendorCredits: three new tables
- IUnitOfWork/UnitOfWork wired with all three repositories
- VendorCreditsController: Index (status tabs), Create, Details, Post, Apply, Void
- Post action: DR AP, CR each expense line (reverses original expense)
- Apply action: links credit to bill, updates Bill.AmountPaid and bill status
- Views: Index (summary cards + table), Create (dynamic line grid), Details (apply panel)
- Nav: Vendor Credits added to Finance section in _Layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 00:03:14 -04:00
parent a33687f7bd
commit cf9dcfb4c1
13 changed files with 11387 additions and 3 deletions
@@ -0,0 +1,212 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PowderCoating.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddVendorCredits : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "VendorCredits",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CreditNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
VendorId = table.Column<int>(type: "int", nullable: false),
APAccountId = table.Column<int>(type: "int", nullable: false),
CreditDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
Total = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
RemainingAmount = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Memo = table.Column<string>(type: "nvarchar(max)", nullable: true),
CompanyId = table.Column<int>(type: "int", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
DeletedBy = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VendorCredits", x => x.Id);
table.ForeignKey(
name: "FK_VendorCredits_Accounts_APAccountId",
column: x => x.APAccountId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_VendorCredits_Vendors_VendorId",
column: x => x.VendorId,
principalTable: "Vendors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "VendorCreditApplications",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
VendorCreditId = table.Column<int>(type: "int", nullable: false),
BillId = table.Column<int>(type: "int", nullable: false),
Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
AppliedDate = table.Column<DateTime>(type: "datetime2", nullable: false),
CompanyId = table.Column<int>(type: "int", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
DeletedBy = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VendorCreditApplications", x => x.Id);
table.ForeignKey(
name: "FK_VendorCreditApplications_Bills_BillId",
column: x => x.BillId,
principalTable: "Bills",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_VendorCreditApplications_VendorCredits_VendorCreditId",
column: x => x.VendorCreditId,
principalTable: "VendorCredits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "VendorCreditLineItems",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
VendorCreditId = table.Column<int>(type: "int", nullable: false),
AccountId = table.Column<int>(type: "int", nullable: true),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
CompanyId = table.Column<int>(type: "int", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
UpdatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
DeletedBy = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VendorCreditLineItems", x => x.Id);
table.ForeignKey(
name: "FK_VendorCreditLineItems_Accounts_AccountId",
column: x => x.AccountId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_VendorCreditLineItems_VendorCredits_VendorCreditId",
column: x => x.VendorCreditId,
principalTable: "VendorCredits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 1,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 3, 58, 27, 360, DateTimeKind.Utc).AddTicks(6994));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 2,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 3, 58, 27, 360, DateTimeKind.Utc).AddTicks(7001));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 3,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 3, 58, 27, 360, DateTimeKind.Utc).AddTicks(7003));
migrationBuilder.CreateIndex(
name: "IX_VendorCreditApplications_BillId",
table: "VendorCreditApplications",
column: "BillId");
migrationBuilder.CreateIndex(
name: "IX_VendorCreditApplications_VendorCreditId",
table: "VendorCreditApplications",
column: "VendorCreditId");
migrationBuilder.CreateIndex(
name: "IX_VendorCreditLineItems_AccountId",
table: "VendorCreditLineItems",
column: "AccountId");
migrationBuilder.CreateIndex(
name: "IX_VendorCreditLineItems_VendorCreditId",
table: "VendorCreditLineItems",
column: "VendorCreditId");
migrationBuilder.CreateIndex(
name: "IX_VendorCredits_APAccountId",
table: "VendorCredits",
column: "APAccountId");
migrationBuilder.CreateIndex(
name: "IX_VendorCredits_VendorId",
table: "VendorCredits",
column: "VendorId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "VendorCreditApplications");
migrationBuilder.DropTable(
name: "VendorCreditLineItems");
migrationBuilder.DropTable(
name: "VendorCredits");
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 1,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 3, 45, 31, 524, DateTimeKind.Utc).AddTicks(9350));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 2,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 3, 45, 31, 524, DateTimeKind.Utc).AddTicks(9357));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 3,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 3, 45, 31, 524, DateTimeKind.Utc).AddTicks(9359));
}
}
}