fix(collection-map): use ISO 8601 UTC bounds for assigned_at day filter

This commit is contained in:
SJCoetz 2026-07-10 00:51:17 +02:00
parent 1846e86b9e
commit 961d09a798

View file

@ -339,8 +339,13 @@ export default function CollectionMapPage() {
setLoading(true);
try {
const pb = getPocketBase();
const dayStart = `${date} 00:00:00`;
const dayEnd = `${date} 23:59:59`;
// Build a UTC ISO 8601 day window. `assigned_at` is stored at
// "YYYY-MM-DDT00:00:00.000Z" (see /api/v1/collection-map/items/[id]/assign),
// so the bounds need the same "T" and trailing "Z" or string
// comparison puts `T` (0x54) before the space (0x20) and the bound
// excludes every real row.
const dayStart = `${date}T00:00:00.000Z`;
const dayEnd = `${date}T23:59:59.999Z`;
// Union of:
// (a) assigned items whose assigned_at lands on the picked date,
// (b) un-dated pool items (collection_pool + empty assigned_at) so
@ -394,7 +399,7 @@ export default function CollectionMapPage() {
// Also collect items whose suppliers have NO coordinates — show in
// the sidebar so the operator knows they exist but can't be mapped.
const unmappedRows = (await pb.collection("order_items").getFullList({
filter: `(item_status = "assigned" || item_status = "collection_pool") && ((assigned_at >= "${dayStart}" && assigned_at <= "${dayEnd}") || assigned_at = "" || assigned_at = null)`,
filter: `(item_status = "assigned" || item_status = "collection_pool") && ((assigned_at >= "${date}T00:00:00.000Z" && assigned_at <= "${date}T23:59:59.999Z") || assigned_at = "" || assigned_at = null)`,
expand: "purchase_order.supplier",
fields: "id,purchase_order",
$autoCancel: false,