Store powder specific gravity and fix coverage math

This commit is contained in:
2026-05-06 08:46:41 -04:00
parent 11a1b91be1
commit f383339465
18 changed files with 9690 additions and 16 deletions
@@ -0,0 +1,81 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PowderCoating.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddSpecificGravityToPowderCatalogAndInventory : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<decimal>(
name: "SpecificGravity",
table: "PowderCatalogItems",
type: "decimal(18,2)",
nullable: true);
migrationBuilder.AddColumn<decimal>(
name: "SpecificGravity",
table: "InventoryItems",
type: "decimal(18,2)",
nullable: true);
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 1,
column: "CreatedAt",
value: new DateTime(2026, 5, 6, 12, 35, 37, 694, DateTimeKind.Utc).AddTicks(5288));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 2,
column: "CreatedAt",
value: new DateTime(2026, 5, 6, 12, 35, 37, 694, DateTimeKind.Utc).AddTicks(5294));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 3,
column: "CreatedAt",
value: new DateTime(2026, 5, 6, 12, 35, 37, 694, DateTimeKind.Utc).AddTicks(5296));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SpecificGravity",
table: "PowderCatalogItems");
migrationBuilder.DropColumn(
name: "SpecificGravity",
table: "InventoryItems");
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 1,
column: "CreatedAt",
value: new DateTime(2026, 5, 6, 2, 7, 22, 625, DateTimeKind.Utc).AddTicks(2199));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 2,
column: "CreatedAt",
value: new DateTime(2026, 5, 6, 2, 7, 22, 625, DateTimeKind.Utc).AddTicks(2206));
migrationBuilder.UpdateData(
table: "PricingTiers",
keyColumn: "Id",
keyValue: 3,
column: "CreatedAt",
value: new DateTime(2026, 5, 6, 2, 7, 22, 625, DateTimeKind.Utc).AddTicks(2208));
}
}
}
@@ -3332,6 +3332,9 @@ namespace PowderCoating.Infrastructure.Migrations
b.Property<string>("SpecPageUrl")
.HasColumnType("nvarchar(max)");
b.Property<decimal?>("SpecificGravity")
.HasColumnType("decimal(18,2)");
b.Property<string>("TdsUrl")
.HasColumnType("nvarchar(max)");
@@ -5835,6 +5838,9 @@ namespace PowderCoating.Infrastructure.Migrations
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<decimal?>("SpecificGravity")
.HasColumnType("decimal(18,2)");
b.Property<string>("TdsUrl")
.HasColumnType("nvarchar(max)");
@@ -6053,7 +6059,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 1,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 6, 2, 7, 22, 625, DateTimeKind.Utc).AddTicks(2199),
CreatedAt = new DateTime(2026, 5, 6, 12, 35, 37, 694, DateTimeKind.Utc).AddTicks(5288),
Description = "Standard pricing for regular customers",
DiscountPercent = 0m,
IsActive = true,
@@ -6064,7 +6070,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 2,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 6, 2, 7, 22, 625, DateTimeKind.Utc).AddTicks(2206),
CreatedAt = new DateTime(2026, 5, 6, 12, 35, 37, 694, DateTimeKind.Utc).AddTicks(5294),
Description = "5% discount for preferred customers",
DiscountPercent = 5m,
IsActive = true,
@@ -6075,7 +6081,7 @@ namespace PowderCoating.Infrastructure.Migrations
{
Id = 3,
CompanyId = 0,
CreatedAt = new DateTime(2026, 5, 6, 2, 7, 22, 625, DateTimeKind.Utc).AddTicks(2208),
CreatedAt = new DateTime(2026, 5, 6, 12, 35, 37, 694, DateTimeKind.Utc).AddTicks(5296),
Description = "10% discount for premium customers",
DiscountPercent = 10m,
IsActive = true,
@@ -28,7 +28,8 @@ namespace PowderCoating.Infrastructure.Services;
public class InventoryAiLookupService : IInventoryAiLookupService
{
private const decimal DefaultTransferEfficiency = 65m;
private const decimal TheoreticalCoverageAtOneMilFactor = 192.3m;
private const decimal TheoreticalCoverageConstant = 192.3m;
private const decimal DefaultCoverageThicknessMils = 1.5m;
private readonly IConfiguration _config;
private readonly IHttpClientFactory _httpClientFactory;
@@ -1247,7 +1248,7 @@ Rules:
if (!result.CoverageSqFtPerLb.HasValue && result.SpecificGravity is > 0)
{
var calculatedCoverage = TheoreticalCoverageAtOneMilFactor / result.SpecificGravity.Value;
var calculatedCoverage = TheoreticalCoverageConstant / (result.SpecificGravity.Value * DefaultCoverageThicknessMils);
result.CoverageSqFtPerLb = Math.Round(calculatedCoverage, 2, MidpointRounding.AwayFromZero);
}
}