mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 08:23:12 +00:00
fix(uplifts): calculate granted exposure amounts (SH-207)
This commit is contained in:
parent
3cb1e3e3f3
commit
60e006e8d7
2 changed files with 39 additions and 4 deletions
|
|
@ -86,7 +86,8 @@ public sealed class UpliftQueueReadTests
|
||||||
var vendor = new Vendor { CompanyName = vendorName, IsActive = true };
|
var vendor = new Vendor { CompanyName = vendorName, IsActive = true };
|
||||||
var workOrder = new WorkOrder
|
var workOrder = new WorkOrder
|
||||||
{
|
{
|
||||||
WorkerOrderNumber = number,
|
InternalWONumber = number,
|
||||||
|
WorkerOrderNumber = $"legacy-{number}",
|
||||||
SiteCode = site,
|
SiteCode = site,
|
||||||
Service = service,
|
Service = service,
|
||||||
WorkerOrderTitle = "Repair"
|
WorkerOrderTitle = "Repair"
|
||||||
|
|
@ -407,6 +408,36 @@ public sealed class UpliftQueueReadTests
|
||||||
itemB.WorkOrderApprovedExposureTotal.Should().Be(75m);
|
itemB.WorkOrderApprovedExposureTotal.Should().Be(75m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Exposure_UsesGrantedAmountForVendorPortalAndRequestedAmountForWorkOrderRequests()
|
||||||
|
{
|
||||||
|
using var context = NewContext();
|
||||||
|
var (vendor, workOrder) = await SeedWorkOrderAsync(context, "WO-ORIGIN", "SITE-A", "HVAC");
|
||||||
|
var dispatch = await SeedDispatchAsync(context, vendor, workOrder, "DIS-ORIGIN");
|
||||||
|
context.DispatchUpliftRequests.AddRange(
|
||||||
|
Request(
|
||||||
|
dispatch,
|
||||||
|
"Approved",
|
||||||
|
new DateTime(2026, 3, 1),
|
||||||
|
decided: new DateTime(2026, 3, 2),
|
||||||
|
requested: 400m,
|
||||||
|
currentNte: 100m),
|
||||||
|
Request(
|
||||||
|
dispatch,
|
||||||
|
"Approved",
|
||||||
|
new DateTime(2026, 3, 3),
|
||||||
|
decided: new DateTime(2026, 3, 4),
|
||||||
|
requested: 250m,
|
||||||
|
createdBy: "internal-user",
|
||||||
|
currentNte: 100m));
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
|
var exposure = await new UpliftDataService(context)
|
||||||
|
.GetApprovedExposureForWorkOrdersAsync(new[] { workOrder.Id }, CancellationToken.None);
|
||||||
|
|
||||||
|
exposure.Should().ContainSingle().Which.AdminApprovedTotal.Should().Be(550m);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Exposure_IncludesLinkedDispatchesViaServerDerivedWorkOrderLinks()
|
public async Task Exposure_IncludesLinkedDispatchesViaServerDerivedWorkOrderLinks()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace SeaHaven.DataServices.Implementation
|
||||||
PONumber = x.d.PONumber,
|
PONumber = x.d.PONumber,
|
||||||
WorkOrderId = x.d.WorkOrderId,
|
WorkOrderId = x.d.WorkOrderId,
|
||||||
VendorCompanyName = x.v != null ? x.v.CompanyName : x.u.RequestedByVendorName,
|
VendorCompanyName = x.v != null ? x.v.CompanyName : x.u.RequestedByVendorName,
|
||||||
WorkOrderNumber = x.wo != null ? x.wo.WorkerOrderNumber : null,
|
WorkOrderNumber = x.wo != null ? x.wo.InternalWONumber : null,
|
||||||
WorkOrderSiteCode = x.wo != null ? x.wo.SiteCode : null,
|
WorkOrderSiteCode = x.wo != null ? x.wo.SiteCode : null,
|
||||||
WorkOrderService = x.wo != null ? x.wo.Service : null,
|
WorkOrderService = x.wo != null ? x.wo.Service : null,
|
||||||
RequestedByVendorName = x.u.RequestedByVendorName,
|
RequestedByVendorName = x.u.RequestedByVendorName,
|
||||||
|
|
@ -317,9 +317,13 @@ namespace SeaHaven.DataServices.Implementation
|
||||||
{
|
{
|
||||||
DispatchId = g.Key,
|
DispatchId = g.Key,
|
||||||
AutoApproved = g.Where(x => x.Status == "NoApprovalRequired")
|
AutoApproved = g.Where(x => x.Status == "NoApprovalRequired")
|
||||||
.Sum(x => (decimal?)x.RequestedNTE),
|
.Sum(x => (decimal?)(x.createdby == null
|
||||||
|
? x.RequestedNTE - (x.CurrentNTE ?? 0m)
|
||||||
|
: x.RequestedNTE)),
|
||||||
AdminApproved = g.Where(x => x.Status == "Approved")
|
AdminApproved = g.Where(x => x.Status == "Approved")
|
||||||
.Sum(x => (decimal?)x.RequestedNTE)
|
.Sum(x => (decimal?)(x.createdby == null
|
||||||
|
? x.RequestedNTE - (x.CurrentNTE ?? 0m)
|
||||||
|
: x.RequestedNTE))
|
||||||
})
|
})
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue