mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 07:13:12 +00:00
Work-order requests store the requested increase in RequestedNTE; vendor portal requests store the requested NTE total. The queue Delta, the pending and approved exposure totals, the work-order uplift list, the board summary and the notification Delta now all read one definition (UpliftAmount) that honours both meanings and translates to SQL. Approving a work-order request now adds its increase to the dispatch NTE instead of replacing the NTE with the increase; vendor requests still end at their requested total. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.4 KiB
C#
33 lines
1.4 KiB
C#
using System.Linq.Expressions;
|
|
using Data.SeaHavenIndustries;
|
|
|
|
namespace SeaHaven.DataServices.Helpers
|
|
{
|
|
/// <summary>
|
|
/// The single definition of an uplift's amount: the NTE increase being requested.
|
|
/// The two creation paths store different meanings in RequestedNTE. Vendor-portal
|
|
/// requests store the requested new NTE total, so the amount is RequestedNTE minus
|
|
/// the NTE at request time. Work-order requests store the increase itself. Vendor
|
|
/// sessions have no identity user, so createdby is null only on vendor-portal rows.
|
|
/// </summary>
|
|
public static class UpliftAmount
|
|
{
|
|
/// <summary>Translatable form for EF queries and aggregates.</summary>
|
|
public static readonly Expression<Func<DispatchUpliftRequest, decimal>> ForQuery =
|
|
u => u.createdby == null
|
|
? u.RequestedNTE - (u.CurrentNTE ?? 0m)
|
|
: u.RequestedNTE;
|
|
|
|
private static readonly Func<DispatchUpliftRequest, decimal> Compiled = ForQuery.Compile();
|
|
|
|
public static decimal Of(DispatchUpliftRequest request) => Compiled(request);
|
|
|
|
public static decimal Of(string? createdBy, decimal requestedNte, decimal? currentNte) =>
|
|
Compiled(new DispatchUpliftRequest
|
|
{
|
|
createdby = createdBy,
|
|
RequestedNTE = requestedNte,
|
|
CurrentNTE = currentNte,
|
|
});
|
|
}
|
|
}
|