Compare commits

...

2 commits

Author SHA1 Message Date
91bdb63a90 Compare: add salaried staff diagnostic (C) using users?show_wages=true
Fetches all active users with salary field set whose report_department_id
is in a No 4 department. Reports raw salary field shape, prorated period
cost, and combined (shifts oncostExLeave + prorated salary) to test whether
salaried staff account for the gap vs WF native report.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 15:42:26 +00:00
2543e09387 Add include_oncosts=true to timesheets/on/{date} fetch
Without this parameter, nested shifts[] only return shift.cost with no
cost_with_oncosts field. The FD's PBI uses show_costs=true on timesheets
and may also require include_oncosts=true to get employer oncost fields.
This is the missing parameter that may explain the B.oncostTotal == baseCost issue.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 15:14:17 +00:00

View file

@ -94,10 +94,9 @@ function weeklyFetchDates(from, to) {
}
// Fetch timesheets for a single date — no location param (mirrors PBI pattern).
// Returns the weekly timesheet record(s) containing this date.
// Each record: { id, user_id, shifts: [{ department_id, date, cost, leave_request_id, ... }] }
// include_oncosts=true is required to get cost_with_oncosts on nested shifts[].
async function fetchTimesheetsForDate(dateStr) {
try { return await wfFetchPaged(`/api/v2/timesheets/on/${dateStr}?show_costs=true`) }
try { return await wfFetchPaged(`/api/v2/timesheets/on/${dateStr}?show_costs=true&include_oncosts=true`) }
catch { return [] }
}
@ -469,13 +468,42 @@ export async function compareEndpoints(from, to) {
// A3: Same shifts, no client-side dept filter (trust the API filter entirely)
// B: Per-day timesheets + shift.id dedup, filtered by locationDeptIds
const [a, a2, a3, b] = await Promise.all([
// C: Salaried staff — users with salary field, report_department_id in location depts
const [a, a2, a3, b, allUsers] = await Promise.all([
fetchShiftsAndSummarise(shiftsReportLoc, locationDeptIds),
fetchShiftsAndSummarise(shiftsReportLoc, reportLocationDeptIds),
fetchShiftsAndSummarise(shiftsReportLoc, null), // trust API filter entirely
fetchShiftsAndSummarise(shiftsReportLoc, null),
fetchTimesheetsByDay(from, to, locationDeptIds),
wfFetchPaged('/api/v2/users?show_wages=true&show_inactive=false'),
])
// Find salaried staff based at this location (report_department_id in a location dept)
const salaryUsers = locationDeptIds
? allUsers.filter(u => u.salary != null && locationDeptIds.has(String(u.report_department_id)))
: allUsers.filter(u => u.salary != null)
// Prorate salary for the query period: annual / 365 * days, or monthly / 31 * days
const days = Math.max(1, Math.ceil((new Date(to) - new Date(from)) / 86_400_000) + 1)
const salaryDetails = salaryUsers.map(u => {
const sal = u.salary
// salary field structure unknown until we see it — expose the raw value
return {
user_id: u.id,
name: u.name || `${u.legal_first_name || ''} ${u.legal_last_name || ''}`.trim(),
report_department_id: u.report_department_id,
salary_raw: sal,
// Attempt prorations based on common WF salary field shapes
// If salary is a number: assume annual amount
annual_if_number: typeof sal === 'number' ? sal : null,
monthly_if_number: typeof sal === 'number' ? +(sal / 12).toFixed(2) : null,
period_prorated: typeof sal === 'number' ? +(sal / 365 * days).toFixed(2) : null,
}
})
const totalSalaryAnnual = salaryDetails.reduce((s, u) => s + (u.annual_if_number ?? 0), 0)
const totalSalaryMonthly = salaryDetails.reduce((s, u) => s + (u.monthly_if_number ?? 0), 0)
const totalSalaryProrated = salaryDetails.reduce((s, u) => s + (u.period_prorated ?? 0), 0)
// Dept breakdown for report_location_id depts — to see which extra depts A2 picks up vs A
const extraDepts = reportLocationDeptIds && locationDeptIds
? allDepts
@ -493,6 +521,17 @@ export async function compareEndpoints(from, to) {
A2_shifts_api_filtered_report_dept_filter: { ...a2, note: 'shifts + report_location_id API filter + client dept filter (location_id OR report_location_id match)' },
A3_shifts_api_filtered_no_client_filter: { ...a3, note: 'shifts + report_location_id API filter only — no client-side dept filter' },
B_timesheets_per_day_dept_filter: b,
C_salaried_staff: {
count: salaryUsers.length,
period_days: days,
total_annual: +totalSalaryAnnual.toFixed(2),
total_monthly: +totalSalaryMonthly.toFixed(2),
total_prorated: +totalSalaryProrated.toFixed(2),
// Combined: A shifts oncostExLeave + prorated salary
combined_oncostExLeave_plus_salary_prorated: +(a.oncostExLeave + totalSalaryProrated).toFixed(2),
note: 'users with salary field set, report_department_id in location depts. salary_raw shows the actual API field shape.',
staff: salaryDetails,
},
wf_report_reference: {
note: 'Target: WF "Cost by Location and Team" — Timesheet exc. leave inc. allowances',
timesheet_exc_leave: 51005.72,