Phase G: Add Recurring Transactions (BackgroundService + CRUD UI)

- RecurringTemplate entity with Frequency/IntervalCount/NextFireDate/EndDate/MaxOccurrences/TemplateData JSON
- RecurringFrequency + RecurringTemplateType enums
- RecurringTransactionService BackgroundService: hourly check, creates Draft bills or immediate expenses, advances NextFireDate, auto-deactivates on limits
- RecurringTemplatesController: Index/Create/Edit/ToggleActive/Delete/GenerateNow (on-demand fire)
- Three views + external JS for type-toggle and dynamic bill line items
- Finance sidebar nav: Recurring Transactions
- Migration: AddRecurringTemplates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 11:08:36 -04:00
parent d3a5d827f9
commit 42eff3357e
16 changed files with 12046 additions and 6 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,171 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PowderCoating.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddRecurringTemplates : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_VendorCreditApplications_Bills_BillId",
table: "VendorCreditApplications");
migrationBuilder.DropForeignKey(
name: "FK_VendorCreditApplications_VendorCredits_VendorCreditId",
table: "VendorCreditApplications");
migrationBuilder.AddColumn<int>(
name: "VendorCreditId1",
table: "VendorCreditApplications",
type: "int",
nullable: true);
migrationBuilder.CreateTable(
name: "RecurringTemplates",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
TemplateType = table.Column<int>(type: "int", nullable: false),
Frequency = table.Column<int>(type: "int", nullable: false),
IntervalCount = table.Column<int>(type: "int", nullable: false),
NextFireDate = table.Column<DateTime>(type: "datetime2", nullable: false),
EndDate = table.Column<DateTime>(type: "datetime2", nullable: true),
MaxOccurrences = table.Column<int>(type: "int", nullable: true),
OccurrenceCount = table.Column<int>(type: "int", nullable: false),
IsActive = table.Column<bool>(type: "bit", nullable: false),
TemplateData = table.Column<string>(type: "nvarchar(max)", nullable: false),
LastError = 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_RecurringTemplates", x => x.Id);
});
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 1,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 15, 1, 54, 769, DateTimeKind.Utc).AddTicks(6262));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 2,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 15, 1, 54, 769, DateTimeKind.Utc).AddTicks(6270));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 3,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 15, 1, 54, 769, DateTimeKind.Utc).AddTicks(6271));
migrationBuilder.CreateIndex(
name: "IX_VendorCreditApplications_VendorCreditId1",
table: "VendorCreditApplications",
column: "VendorCreditId1");
migrationBuilder.AddForeignKey(
name: "FK_VendorCreditApplications_Bills_BillId",
table: "VendorCreditApplications",
column: "BillId",
principalTable: "Bills",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_VendorCreditApplications_VendorCredits_VendorCreditId",
table: "VendorCreditApplications",
column: "VendorCreditId",
principalTable: "VendorCredits",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_VendorCreditApplications_VendorCredits_VendorCreditId1",
table: "VendorCreditApplications",
column: "VendorCreditId1",
principalTable: "VendorCredits",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_VendorCreditApplications_Bills_BillId",
table: "VendorCreditApplications");
migrationBuilder.DropForeignKey(
name: "FK_VendorCreditApplications_VendorCredits_VendorCreditId",
table: "VendorCreditApplications");
migrationBuilder.DropForeignKey(
name: "FK_VendorCreditApplications_VendorCredits_VendorCreditId1",
table: "VendorCreditApplications");
migrationBuilder.DropTable(
name: "RecurringTemplates");
migrationBuilder.DropIndex(
name: "IX_VendorCreditApplications_VendorCreditId1",
table: "VendorCreditApplications");
migrationBuilder.DropColumn(
name: "VendorCreditId1",
table: "VendorCreditApplications");
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 1,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 14, 48, 51, 545, DateTimeKind.Utc).AddTicks(3903));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 2,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 14, 48, 51, 545, DateTimeKind.Utc).AddTicks(3909));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 3,
column: "CreatedAt",
value: new DateTime(2026, 5, 10, 14, 48, 51, 545, DateTimeKind.Utc).AddTicks(3910));
migrationBuilder.AddForeignKey(
name: "FK_VendorCreditApplications_Bills_BillId",
table: "VendorCreditApplications",
column: "BillId",
principalTable: "Bills",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_VendorCreditApplications_VendorCredits_VendorCreditId",
table: "VendorCreditApplications",
column: "VendorCreditId",
principalTable: "VendorCredits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}
@@ -6293,7 +6293,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 1,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 14, 48, 51, 545, DateTimeKind.Utc).AddTicks(3903),
CreatedAt = new DateTime(2026, 5, 10, 15, 1, 54, 769, DateTimeKind.Utc).AddTicks(6262),
Description = "Standard pricing for regular customers",
DiscountPercent = 0m,
IsActive = true,
@@ -6304,7 +6304,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 2,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 14, 48, 51, 545, DateTimeKind.Utc).AddTicks(3909),
CreatedAt = new DateTime(2026, 5, 10, 15, 1, 54, 769, DateTimeKind.Utc).AddTicks(6270),
Description = "5% discount for preferred customers",
DiscountPercent = 5m,
IsActive = true,
@@ -6315,7 +6315,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 3,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 10, 14, 48, 51, 545, DateTimeKind.Utc).AddTicks(3910),
CreatedAt = new DateTime(2026, 5, 10, 15, 1, 54, 769, DateTimeKind.Utc).AddTicks(6271),
Description = "10% discount for premium customers",
DiscountPercent = 10m,
IsActive = true,
@@ -7272,6 +7272,78 @@ namespace PowderCoating.Infrastructure.Migrations
b.ToTable("QuoteStatusLookups");
});
modelBuilder.Entity("PowderCoating.Core.Entities.RecurringTemplate", 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<DateTime?>("EndDate")
.HasColumnType("datetime2");
b.Property<int>("Frequency")
.HasColumnType("int");
b.Property<int>("IntervalCount")
.HasColumnType("int");
b.Property<bool>("IsActive")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<string>("LastError")
.HasColumnType("nvarchar(max)");
b.Property<int?>("MaxOccurrences")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("NextFireDate")
.HasColumnType("datetime2");
b.Property<int>("OccurrenceCount")
.HasColumnType("int");
b.Property<string>("TemplateData")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TemplateType")
.HasColumnType("int");
b.Property<DateTime?>("UpdatedAt")
.HasColumnType("datetime2");
b.Property<string>("UpdatedBy")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("RecurringTemplates");
});
modelBuilder.Entity("PowderCoating.Core.Entities.Refund", b =>
{
b.Property<int>("Id")
@@ -8099,12 +8171,17 @@ namespace PowderCoating.Infrastructure.Migrations
b.Property<int>("VendorCreditId")
.HasColumnType("int");
b.Property<int?>("VendorCreditId1")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BillId");
b.HasIndex("VendorCreditId");
b.HasIndex("VendorCreditId1");
b.ToTable("VendorCreditApplications");
});
@@ -9802,15 +9879,19 @@ namespace PowderCoating.Infrastructure.Migrations
b.HasOne("PowderCoating.Core.Entities.Bill", "Bill")
.WithMany()
.HasForeignKey("BillId")
.OnDelete(DeleteBehavior.Cascade)
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("PowderCoating.Core.Entities.VendorCredit", "VendorCredit")
.WithMany("Applications")
.WithMany()
.HasForeignKey("VendorCreditId")
.OnDelete(DeleteBehavior.Cascade)
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("PowderCoating.Core.Entities.VendorCredit", null)
.WithMany("Applications")
.HasForeignKey("VendorCreditId1");
b.Navigation("Bill");
b.Navigation("VendorCredit");