From e487c052483bd2ef1f6e872e885d7cb047c9b5b2 Mon Sep 17 00:00:00 2001 From: Samer Salameh Date: Wed, 18 Nov 2026 14:25:54 +0300 Subject: [PATCH] Truck inquiry: match legacy searchTruckDistribution exactly - Status and company come from the first (oldest) permit row of the truck, as in the legacy unordered query - Truck locations listed in allowed-list order, unknown locations kept as empty names Co-Authored-By: Claude Sonnet 5.5 --- src/NTP.Application/Grains/Permits/DistributionService.cs | 3 ++- .../Repositories/Grains/Permits/DistributionRepository.cs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/NTP.Application/Grains/Permits/DistributionService.cs b/src/NTP.Application/Grains/Permits/DistributionService.cs index 3287560..397b8f0 100644 --- a/src/NTP.Application/Grains/Permits/DistributionService.cs +++ b/src/NTP.Application/Grains/Permits/DistributionService.cs @@ -367,7 +367,8 @@ public sealed class DistributionService( ? await destinations.GetTruckDestinationsAsync(tn, ct) : company is long c ? await destinations.GetCompanyLocationsAsync(c, ct) : []; var names = await repo.GetLocationNamesAsync(locations, ct); - result.CompanyLocations = string.Concat(names.Select(n => " - " + n.Name)); + // legacy loops the allowed ids in list order and appends " - " + name (empty when the location is unknown) + result.CompanyLocations = string.Concat(locations.Select(id => " - " + names.FirstOrDefault(n => n.Id == id).Name)); var orders = await repo.GetActiveOrdersInWindowAsync(new ShiftWindow { diff --git a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Permits/DistributionRepository.cs b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Permits/DistributionRepository.cs index 9af3bbc..37a4e59 100644 --- a/src/NTP.Infrastructure/Persistence/Repositories/Grains/Permits/DistributionRepository.cs +++ b/src/NTP.Infrastructure/Persistence/Repositories/Grains/Permits/DistributionRepository.cs @@ -405,14 +405,15 @@ internal sealed class DistributionRepository(IDbSession session, ILogger GetTruckLatestStatusCaptionAsync(string tn, CancellationToken ct = default) => QueryFirstAsync(""" SELECT s.description FROM PERMITS p, STATUS s - WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id DESC + WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id """, new { Tn = tn }, ct); public Task GetTruckLatestCompanyAsync(string tn, CancellationToken ct = default) => QueryFirstAsync(""" SELECT p.companycode FROM PERMITS p, STATUS s - WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id DESC + WHERE p.domain = 'GN' AND p.tn = :Tn AND p.shipmentstatuscode = s.code AND s.domain = 'GN' ORDER BY p.id """, new { Tn = tn }, ct); public Task> GetActiveOrdersInWindowAsync(ShiftWindow window, CancellationToken ct = default) =>