Phase G: Add Budgeting and Year-End Close

Budgeting:
- Budget + BudgetLine entities with Jan–Dec monthly columns per GL account
- BudgetsController: Index, Create, Edit, SetDefault, Copy, Delete
- Copy action rolls a budget forward to a new fiscal year
- Budget vs. Actual report (BudgetVsActual): compares monthly budget amounts to
  real P&L by calling GetProfitAndLossAsync once per month; variance shown as
  favorable/unfavorable; year + budget selectors in header
- Views: Budgets/Index, Create, Edit with inline annual totals via budget-edit.js
- Nav link + report card on Landing

Year-End Close:
- YearEndClose entity records each closed year + JE reference for audit trail
- AccountsController.YearEndClose GET (history + form) + CloseYear POST
- Close zeroes all Revenue and Expense/COGS account balances into Retained Earnings
  via IAccountBalanceService and posts a supporting JE dated Dec 31
- Idempotency: rejects attempt to close an already-closed year
- Pre-close checklist in view to guide the workflow
- Nav link under Finance

Migration AddBudgetsAndYearEndClose applied

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 13:01:56 -04:00
parent fde24b09c9
commit 4fd9c52aaf
19 changed files with 12527 additions and 3 deletions
@@ -1269,6 +1269,139 @@ namespace PowderCoating.Infrastructure.Migrations
b.ToTable("BillPayments");
});
modelBuilder.Entity("PowderCoating.Core.Entities.Budget", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CompanyId")
.HasColumnType("int");
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<int>("FiscalYear")
.HasColumnType("int");
b.Property<bool>("IsDefault")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Notes")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime2");
b.Property<string>("UpdatedBy")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Budgets");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BudgetLine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AccountId")
.HasColumnType("int");
b.Property<decimal>("Apr")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Aug")
.HasColumnType("decimal(18,2)");
b.Property<int>("BudgetId")
.HasColumnType("int");
b.Property<int>("CompanyId")
.HasColumnType("int");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<decimal>("Dec")
.HasColumnType("decimal(18,2)");
b.Property<DateTime?>("DeletedAt")
.HasColumnType("datetime2");
b.Property<string>("DeletedBy")
.HasColumnType("nvarchar(max)");
b.Property<decimal>("Feb")
.HasColumnType("decimal(18,2)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<decimal>("Jan")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Jul")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Jun")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Mar")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("May")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Nov")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Oct")
.HasColumnType("decimal(18,2)");
b.Property<decimal>("Sep")
.HasColumnType("decimal(18,2)");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime2");
b.Property<string>("UpdatedBy")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AccountId");
b.HasIndex("BudgetId");
b.ToTable("BudgetLines");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BugReport", b =>
{
b.Property<int>("Id")
@@ -6432,7 +6565,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 1,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 16, 0, 49, 626, DateTimeKind.Utc).AddTicks(4004),
CreatedAt = new DateTime(2026, 5, 10, 16, 55, 8, 322, DateTimeKind.Utc).AddTicks(966),
Description = "Standard pricing for regular customers",
DiscountPercent = 0m,
IsActive = true,
@@ -6443,7 +6576,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 2,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 16, 0, 49, 626, DateTimeKind.Utc).AddTicks(4009),
CreatedAt = new DateTime(2026, 5, 10, 16, 55, 8, 322, DateTimeKind.Utc).AddTicks(974),
Description = "5% discount for preferred customers",
DiscountPercent = 5m,
IsActive = true,
@@ -6454,7 +6587,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 3,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 16, 0, 49, 626, DateTimeKind.Utc).AddTicks(4011),
CreatedAt = new DateTime(2026, 5, 10, 16, 55, 8, 322, DateTimeKind.Utc).AddTicks(976),
Description = "10% discount for premium customers",
DiscountPercent = 10m,
IsActive = true,
@@ -8376,6 +8509,57 @@ namespace PowderCoating.Infrastructure.Migrations
b.ToTable("VendorCreditLineItems");
});
modelBuilder.Entity("PowderCoating.Core.Entities.YearEndClose", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("ClosedAt")
.HasColumnType("datetime2");
b.Property<string>("ClosedBy")
.HasColumnType("nvarchar(max)");
b.Property<int>("ClosedYear")
.HasColumnType("int");
b.Property<int>("CompanyId")
.HasColumnType("int");
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<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<int>("JournalEntryId")
.HasColumnType("int");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime2");
b.Property<string>("UpdatedBy")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("JournalEntryId");
b.ToTable("YearEndCloses");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
@@ -8589,6 +8773,25 @@ namespace PowderCoating.Infrastructure.Migrations
b.Navigation("Vendor");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BudgetLine", b =>
{
b.HasOne("PowderCoating.Core.Entities.Account", "Account")
.WithMany()
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("PowderCoating.Core.Entities.Budget", "Budget")
.WithMany("Lines")
.HasForeignKey("BudgetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Account");
b.Navigation("Budget");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BugReportAttachment", b =>
{
b.HasOne("PowderCoating.Core.Entities.BugReport", "BugReport")
@@ -10090,6 +10293,17 @@ namespace PowderCoating.Infrastructure.Migrations
b.Navigation("VendorCredit");
});
modelBuilder.Entity("PowderCoating.Core.Entities.YearEndClose", b =>
{
b.HasOne("PowderCoating.Core.Entities.JournalEntry", "JournalEntry")
.WithMany()
.HasForeignKey("JournalEntryId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("JournalEntry");
});
modelBuilder.Entity("PowderCoating.Core.Entities.Account", b =>
{
b.Navigation("BillLineItems");
@@ -10134,6 +10348,11 @@ namespace PowderCoating.Infrastructure.Migrations
b.Navigation("Payments");
});
modelBuilder.Entity("PowderCoating.Core.Entities.Budget", b =>
{
b.Navigation("Lines");
});
modelBuilder.Entity("PowderCoating.Core.Entities.BugReport", b =>
{
b.Navigation("Attachments");