Phase E: Add Bank Reconciliation

- IsCleared + ClearedDate added to Payment, BillPayment, Expense entities
- BankReconciliation entity (account, statement date, beginning/ending balance, status)
- BankReconciliationStatus enum (InProgress, Completed)
- Migration AddBankReconciliation: new BankReconciliations table + IsCleared/ClearedDate columns
- IUnitOfWork/UnitOfWork wired with BankReconciliations repo
- BankReconciliationsController: Index, Create, Reconcile, ToggleCleared (AJAX), Complete, Report
- Reconcile view: deposit/payment checkboxes with live running balance and difference via JS
- Complete is gated: only enabled when difference == $0.00
- Nav: Bank Reconciliation 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:10:38 -04:00
parent cf9dcfb4c1
commit 1229081436
15 changed files with 11111 additions and 3 deletions
@@ -329,6 +329,9 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IDataPro
/// <summary>Individual debit/credit lines within a journal entry; soft-delete only (access controlled through parent JournalEntry).</summary>
public DbSet<JournalEntryLine> JournalEntryLines { get; set; }
/// <summary>Bank reconciliation sessions matching GL transactions to bank statements; tenant-filtered with soft delete.</summary>
public DbSet<BankReconciliation> BankReconciliations { get; set; }
/// <summary>Credit notes received from vendors (returned goods, pricing disputes); tenant-filtered with soft delete.</summary>
public DbSet<VendorCredit> VendorCredits { get; set; }
/// <summary>Expense-reversal line items on a vendor credit; soft-delete only.</summary>
@@ -631,6 +634,10 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IDataPro
!e.IsDeleted && (IsPlatformAdmin || e.CompanyId == CurrentCompanyId));
modelBuilder.Entity<JournalEntryLine>().HasQueryFilter(e => !e.IsDeleted);
// Bank Reconciliation: tenant-filtered
modelBuilder.Entity<BankReconciliation>().HasQueryFilter(e =>
!e.IsDeleted && (IsPlatformAdmin || e.CompanyId == CurrentCompanyId));
// Vendor Credits: tenant-filtered; child rows soft-delete only
modelBuilder.Entity<VendorCredit>().HasQueryFilter(e =>
!e.IsDeleted && (IsPlatformAdmin || e.CompanyId == CurrentCompanyId));
@@ -663,6 +670,13 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IDataPro
.HasForeignKey(je => je.ReversalOfId)
.OnDelete(DeleteBehavior.Restrict);
// BankReconciliation → Account (no cascade)
modelBuilder.Entity<BankReconciliation>()
.HasOne(br => br.Account)
.WithMany()
.HasForeignKey(br => br.AccountId)
.OnDelete(DeleteBehavior.Restrict);
// VendorCredit → APAccount (no cascade)
modelBuilder.Entity<VendorCredit>()
.HasOne(vc => vc.APAccount)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,166 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PowderCoating.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddBankReconciliation : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "ClearedDate",
table: "Payments",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsCleared",
table: "Payments",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<DateTime>(
name: "ClearedDate",
table: "Expenses",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsCleared",
table: "Expenses",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<DateTime>(
name: "ClearedDate",
table: "BillPayments",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsCleared",
table: "BillPayments",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.CreateTable(
name: "BankReconciliations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AccountId = table.Column<int>(type: "int", nullable: false),
StatementDate = table.Column<DateTime>(type: "datetime2", nullable: false),
BeginningBalance = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
EndingBalance = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
CompletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CompletedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
Notes = 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_BankReconciliations", x => x.Id);
table.ForeignKey(
name: "FK_BankReconciliations_Accounts_AccountId",
column: x => x.AccountId,
principalTable: "Accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 1,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 4, 6, 6, 200, DateTimeKind.Utc).AddTicks(8472));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 2,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 4, 6, 6, 200, DateTimeKind.Utc).AddTicks(8478));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 3,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 4, 6, 6, 200, DateTimeKind.Utc).AddTicks(8479));
migrationBuilder.CreateIndex(
name: "IX_BankReconciliations_AccountId",
table: "BankReconciliations",
column: "AccountId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BankReconciliations");
migrationBuilder.DropColumn(
name: "ClearedDate",
table: "Payments");
migrationBuilder.DropColumn(
name: "IsCleared",
table: "Payments");
migrationBuilder.DropColumn(
name: "ClearedDate",
table: "Expenses");
migrationBuilder.DropColumn(
name: "IsCleared",
table: "Expenses");
migrationBuilder.DropColumn(
name: "ClearedDate",
table: "BillPayments");
migrationBuilder.DropColumn(
name: "IsCleared",
table: "BillPayments");
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));
}
}
}
@@ -936,6 +936,69 @@ namespace PowderCoating.Infrastructure.Migrations
b.ToTable("AuditLogs");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BankReconciliation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AccountId")
.HasColumnType("int");
b.Property<decimal>("BeginningBalance")
.HasColumnType("decimal(18,2)");
b.Property<int>("CompanyId")
.HasColumnType("int");
b.Property<DateTime?>("CompletedAt")
.HasColumnType("datetime2");
b.Property<string>("CompletedBy")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("datetime2");
b.Property<string>("DeletedBy")
.HasColumnType("nvarchar(max)");
b.Property<decimal>("EndingBalance")
.HasColumnType("decimal(18,2)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<string>("Notes")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("StatementDate")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime2");
b.Property<string>("UpdatedBy")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AccountId");
b.ToTable("BankReconciliations");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BannedIp", b =>
{
b.Property<int>("Id")
@@ -1149,6 +1212,9 @@ namespace PowderCoating.Infrastructure.Migrations
b.Property<string>("CheckNumber")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("ClearedDate")
.HasColumnType("datetime2");
b.Property<int>("CompanyId")
.HasColumnType("int");
@@ -1164,6 +1230,9 @@ namespace PowderCoating.Infrastructure.Migrations
b.Property<string>("DeletedBy")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsCleared")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
@@ -2854,6 +2923,9 @@ namespace PowderCoating.Infrastructure.Migrations
b.Property<decimal>("Amount")
.HasColumnType("decimal(18,2)");
b.Property<DateTime?>("ClearedDate")
.HasColumnType("datetime2");
b.Property<int>("CompanyId")
.HasColumnType("int");
@@ -2879,6 +2951,9 @@ namespace PowderCoating.Infrastructure.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsCleared")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
@@ -5775,6 +5850,9 @@ namespace PowderCoating.Infrastructure.Migrations
b.Property<decimal>("Amount")
.HasColumnType("decimal(18,2)");
b.Property<DateTime?>("ClearedDate")
.HasColumnType("datetime2");
b.Property<int>("CompanyId")
.HasColumnType("int");
@@ -5796,6 +5874,9 @@ namespace PowderCoating.Infrastructure.Migrations
b.Property<int>("InvoiceId")
.HasColumnType("int");
b.Property<bool>("IsCleared")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
@@ -6206,7 +6287,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 1,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 3, 58, 27, 360, DateTimeKind.Utc).AddTicks(6994),
CreatedAt = new DateTime(2026, 5, 10, 4, 6, 6, 200, DateTimeKind.Utc).AddTicks(8472),
Description = "Standard pricing for regular customers",
DiscountPercent = 0m,
IsActive = true,
@@ -6217,7 +6298,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 2,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 3, 58, 27, 360, DateTimeKind.Utc).AddTicks(7001),
CreatedAt = new DateTime(2026, 5, 10, 4, 6, 6, 200, DateTimeKind.Utc).AddTicks(8478),
Description = "5% discount for preferred customers",
DiscountPercent = 5m,
IsActive = true,
@@ -6228,7 +6309,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 3,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 3, 58, 27, 360, DateTimeKind.Utc).AddTicks(7003),
CreatedAt = new DateTime(2026, 5, 10, 4, 6, 6, 200, DateTimeKind.Utc).AddTicks(8479),
Description = "10% discount for premium customers",
DiscountPercent = 10m,
IsActive = true,
@@ -8151,6 +8232,17 @@ namespace PowderCoating.Infrastructure.Migrations
b.Navigation("Job");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BankReconciliation", b =>
{
b.HasOne("PowderCoating.Core.Entities.Account", "Account")
.WithMany()
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Account");
});
modelBuilder.Entity("PowderCoating.Core.Entities.Bill", b =>
{
b.HasOne("PowderCoating.Core.Entities.Account", "APAccount")
@@ -151,6 +151,9 @@ public class UnitOfWork : IUnitOfWork
private IRepository<VendorCreditLineItem>? _vendorCreditLineItems;
private IRepository<VendorCreditApplication>? _vendorCreditApplications;
// Bank Reconciliation
private IRepository<BankReconciliation>? _bankReconciliations;
/// <summary>
/// Initialises the unit of work with the scoped <paramref name="context"/>.
/// The context is shared across all repositories created by this instance so that
@@ -544,6 +547,11 @@ public class UnitOfWork : IUnitOfWork
public IRepository<VendorCreditApplication> VendorCreditApplications =>
_vendorCreditApplications ??= new Repository<VendorCreditApplication>(_context);
// Bank Reconciliation
/// <summary>Repository for <see cref="BankReconciliation"/> sessions reconciling a bank account against a statement.</summary>
public IRepository<BankReconciliation> BankReconciliations =>
_bankReconciliations ??= new Repository<BankReconciliation>(_context);
/// <summary>
/// Flushes all pending changes in the EF Core change tracker to the database.
/// Returns the number of state entries written.