Fix getUserNameMap location filter; fix detail cost filter to match aggregate

This commit is contained in:
jtricerolph 2026-07-23 11:32:28 +00:00
parent cf0cd0a5e4
commit 6661189127

View file

@ -75,13 +75,10 @@ async function getDeptNameMap() {
} }
async function getUserNameMap() { async function getUserNameMap() {
const creds = await getWorkforceCreds() const all = await wfFetchPaged('/api/v2/users')
const locationId = creds.location_id ? String(creds.location_id) : null if (all.length > 0) console.log('USER_SAMPLE', JSON.stringify(all[0]))
const all = await wfFetchPaged('/api/v2/users')
const filtered = locationId ? all.filter(u => String(u.location_id) === locationId) : all
if (filtered.length > 0) console.log('USER_SAMPLE', JSON.stringify(filtered[0]))
return Object.fromEntries( return Object.fromEntries(
filtered.map(u => [String(u.id), `${u.first_name || ''} ${u.last_name || ''}`.trim() || `User ${u.id}`]) all.map(u => [String(u.id), `${u.first_name || ''} ${u.last_name || ''}`.trim() || `User ${u.id}`])
) )
} }
@ -125,8 +122,8 @@ export async function syncActuals(from, to) {
byDateDept[key].total_cost += totalCost byDateDept[key].total_cost += totalCost
byDateDept[key].shift_count += 1 byDateDept[key].shift_count += 1
// detail by date+dept+employee (APPROVED only — pending have cost 0 but clutter the list) // detail by date+dept+employee — include any shift that contributed cost to the aggregate
if (s.status === 'APPROVED') { if (totalCost > 0 || baseCost > 0) {
const empId = String(s.user_id) const empId = String(s.user_id)
const empName = userNameMap[empId] || `Employee ${empId}` const empName = userNameMap[empId] || `Employee ${empId}`
const empKey = `${date}:${deptId}:${empId}` const empKey = `${date}:${deptId}:${empId}`