# ✅ DONE: Shift-adjusted date for daily performance grid

## Problem

Shifts run midnight-crossing (e.g. Mon shift starts 06:00 Mon, ends ~06:00 Tue).
Any scan (confirm, scrap, downtime) done between **00:00–05:59** on date D+1
belongs logically to the **shift of date D**.

Currently all queries use `DATE(date_scan)` / `DATE(date_entry)` which splits
midnight-crossing shifts across two calendar days:
- Scrap done at 02:00 Tue gets `date_scan = 2026-04-14` → falls in Tuesday bucket
- But the worker is still on the Monday shift → should appear in Monday column

The `activeDateThru` / `shiftStarted` logic in `info_board.php` tried to
compensate by hiding today until `PLANNING_SHIFT_START_DEFAULT` (default 06:00),
but that just makes the whole day invisible — it does NOT move midnight-crossing
records back to the previous day.

## Correct Fix

All aggregate queries in `info_board.php` that group by date should use:

```sql
DATE(date_scan - INTERVAL 6 HOUR)   -- or whatever PLANNING_SHIFT_START_DEFAULT is
```

e.g.:
```sql
DATE(sl.date_scan - INTERVAL 6 HOUR) BETWEEN '2026-04-13' AND '2026-04-13'
```

This way records from 00:00–05:59 on Tue are grouped under Mon.

The shift offset should come from `getDolGlobalInt('PLANNING_SHIFT_START_DEFAULT', 6)`.

## Affected queries in info_board.php — ✅ ALL DONE (commit `03d6de4`)

- `$rPSP` — pending scrap per WS+day: ✅ `DATE(sl.date_scan - INTERVAL h HOUR)`
- `$perfActual` (optracking): ✅ `DATE(ot.date_entry - INTERVAL h HOUR)`
- `$perfDtMins` (downtime): ✅ `downtime_date BETWEEN` — date-only column, no offset needed
- `$perfScrapQty` (booked scrap): ✅ `DATE(scrap_date - INTERVAL h HOUR)`
- `perfDays` loop: ✅ ends at `activeDateThru`, `shiftStarted` skip removed
- `activeDateThru`: ✅ `date('Y-m-d', time() - shiftOffsetSec)`

## Also affected — ✅ DONE

- `tracking_log.php` — filter uses `DATE(sl.date_scan)` ranges → fixed in commit `c0548cc`
- `scanstation_log` records generally — wherever grouped by date

## Date range for grid columns

`$perfDays` must also use shift-offset logic when determining which date label
to show. Column header = logical shift date, not calendar date.

Current `$perfDays` builds from `filterFrom`/`filterTo` using calendar days.
With shift offset: the last column should be "today's shift date" =
`DATE(NOW() - INTERVAL {shiftHour} HOUR)`.

## Notes

- `PLANNING_SHIFT_START_DEFAULT` = 6 (default), stored in Dolibarr global conf
- PHP equivalent: `strtotime('-6 hours')` applied before `date('Y-m-d', ...)`
- The `$activeDateThru` var + `$shiftStarted` var in info_board.php can likely
  be simplified once shift-offset grouping is in place
