Skip to content

Commit 9429d34

Browse files
renemadsenclaude
andcommitted
fix(payroll-export): resolve Worker.EmployeeNo via SiteWorker join, not Site
Site entity doesn't have EmployeeNo — it's on the Worker entity, linked via SiteWorker. Fixed the lookup to follow Site → SiteWorker → Worker and read Worker.EmployeeNo for the CSV export rows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1a9dba0 commit 9429d34

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

eFormAPI/Plugins/TimePlanning.Pn/TimePlanning.Pn/Services/PayrollExportService/PayrollExportService.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,35 @@ public async Task<PayrollExportResult> ExportPayroll(DateTime periodStart, DateT
6767
};
6868
}
6969

70-
// Resolve Worker.EmployeeNo from the eForm SDK context
70+
// Resolve Worker.EmployeeNo via Site → SiteWorker → Worker
7171
var sdkCore = await _coreHelper.GetCore();
7272
var sdkDbContext = sdkCore.DbContextHelper.GetDbContext();
7373
var siteIds = payLines.Select(x => x.PlanRegistration.SdkSitId).Distinct().ToList();
74-
var sites = await sdkDbContext.Sites
75-
.Where(s => siteIds.Contains(s.MicrotingUid!.Value))
76-
.Select(s => new { s.MicrotingUid, s.Name, EmployeeNo = s.EmployeeNo ?? string.Empty })
74+
var siteWorkerData = await sdkDbContext.SiteWorkers
75+
.Include(sw => sw.Worker)
76+
.Where(sw => sw.SiteId.HasValue
77+
&& siteIds.Contains(
78+
sdkDbContext.Sites
79+
.Where(s => s.Id == sw.SiteId)
80+
.Select(s => s.MicrotingUid!.Value)
81+
.FirstOrDefault())
82+
&& sw.WorkflowState != Constants.WorkflowStates.Removed)
7783
.ToListAsync();
78-
var siteLookup = sites.ToDictionary(s => s.MicrotingUid!.Value, s => s);
84+
85+
// Build a lookup from Site.MicrotingUid → Worker info
86+
var siteToMicrotingUid = await sdkDbContext.Sites
87+
.Where(s => siteIds.Contains(s.MicrotingUid!.Value))
88+
.ToDictionaryAsync(s => s.Id, s => new { s.MicrotingUid, s.Name });
89+
90+
var siteLookup = siteWorkerData
91+
.Where(sw => sw.SiteId.HasValue && siteToMicrotingUid.ContainsKey(sw.SiteId!.Value))
92+
.ToDictionary(
93+
sw => siteToMicrotingUid[sw.SiteId!.Value].MicrotingUid!.Value,
94+
sw => new
95+
{
96+
Name = siteToMicrotingUid[sw.SiteId!.Value].Name,
97+
EmployeeNo = sw.Worker?.EmployeeNo ?? string.Empty
98+
});
7999

80100
var workerGroups = payLines
81101
.GroupBy(x => x.PlanRegistration.SdkSitId)

0 commit comments

Comments
 (0)