shoc-backend/SeaHaven.DataServices/Helpers/UpliftAmount.cs
Alexandre Brandizzi eb2b442775 fix(uplifts): one per-path uplift amount for queue, approval and exposure
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>
2026-09-25 02:32:58 -03:00

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,
});
}
}