diff --git a/app/(clock)/clock/stock/page.tsx b/app/(clock)/clock/stock/page.tsx index 644ce15..2d05d95 100644 --- a/app/(clock)/clock/stock/page.tsx +++ b/app/(clock)/clock/stock/page.tsx @@ -1,7 +1,6 @@ import { requireClockUser } from '@/lib/auth'; import { clockPB } from '@/lib/clock-store'; -import { movementAt } from '@/lib/oil-log'; -import { StockOut, type StockLogRow } from '@/components/StockOut'; +import { StockOut } from '@/components/StockOut'; export const dynamic = 'force-dynamic'; export const metadata = { title: 'Book out oil & diesel · Mega Plant' }; @@ -14,13 +13,8 @@ export default async function StockPage() { pb.collection('oil_stock_movements').getFullList({ expand: 'item,asset' }), ]); const onHand = (id: string) => moves.filter(m => m.item === id).reduce((s, m) => s + (m.kind === 'used' ? -(m.litres || 0) : m.litres || 0), 0); - const log: StockLogRow[] = moves.filter(m => m.kind === 'used').map((m): any => ({ ...m, at: movementAt(m) })).sort((a, b) => b.at.localeCompare(a.at)).slice(0, 15).map(m => ({ - id: m.id, at: m.at, litres: m.litres, item: String(m.expand?.item?.name || ''), - colour: String(m.expand?.item?.colour || ''), asset: String(m.expand?.asset?.code || ''), by: String(m.booked_by || ''), - })); return ({ id: i.id, code: i.code, name: i.name, colour: i.colour || '#30638E', onHand: Math.round(onHand(i.id) * 100) / 100, tank: String(i.code).startsWith('FUEL') }))} assets={assets.map(a => ({ id: a.id, code: a.code, name: a.name }))} - log={log} />; } diff --git a/components/StockOut.tsx b/components/StockOut.tsx index 31343fe..a3c2155 100644 --- a/components/StockOut.tsx +++ b/components/StockOut.tsx @@ -1,19 +1,17 @@ 'use client'; import { useRef, useState } from 'react'; import { useRouter } from 'next/navigation'; -import { AlertTriangle, CheckCircle2, Droplets, ScanLine, X } from 'lucide-react'; +import { AlertTriangle, CheckCircle2, Droplets, X } from 'lucide-react'; import { BadgeCamera } from './BadgeCamera'; -import { clockDate, clockTime } from '@/lib/clock-display'; import { oilCodeFromQr } from '@/lib/stock-out'; type Item = { id: string; code: string; name: string; colour: string; onHand: number; tank: boolean }; type Asset = { id: string; code: string; name: string }; -export type StockLogRow = { id: string; at: string; litres: number; item: string; colour: string; asset: string; by: string }; const fmt = (n: number) => n.toLocaleString('en-ZA', { maximumFractionDigits: 2 }); /** Scan the drum/tank QR, say how many litres and which vehicle, and it is booked out. */ -export function StockOut({ items, assets, log }: { items: Item[]; assets: Asset[]; log: StockLogRow[] }) { +export function StockOut({ items, assets }: { items: Item[]; assets: Asset[] }) { const router = useRouter(); const [item, setItem] = useState(null); const [litres, setLitres] = useState(''); @@ -64,11 +62,7 @@ export function StockOut({ items, assets, log }: { items: Item[]; assets: Asset[ {!item ? <>
- {unknownScan &&

That QR is not an oil or diesel label ({unknownScan}). Scan the label on the drum or tank, or pick below.

} -

Or choose the product

-
{items.map(i => - )}
+ {unknownScan &&

That QR is not an oil or diesel label ({unknownScan}). Scan the label on the drum or tank.

} :

{item.name}

@@ -84,15 +78,6 @@ export function StockOut({ items, assets, log }: { items: Item[]; assets: Asset[ {busy ? 'Saving…' : 'Book out'} } -
-

Booked out

- {log.length === 0 ?

Nothing booked out yet.

- :
    {log.map(r =>
  • - - {fmt(r.litres)} L {r.item} → {r.asset || 'no vehicle'} - {r.at?clockDate(r.at.replace(' ','T')):''}{r.by ? ` · ${r.by}` : ''} - {r.at.includes('T')?clockTime(r.at):''}
  • )}
} -
; }