diff --git a/src/screens/supplier/Runs.tsx b/src/screens/supplier/Runs.tsx index c57f834..1c7f446 100644 --- a/src/screens/supplier/Runs.tsx +++ b/src/screens/supplier/Runs.tsx @@ -8,6 +8,15 @@ import { DataTable, StateBadge } from '../../components/widgets'; import { date, inr, mt } from '../../format'; import { useScope } from './scope'; +/** The previous calendar month, the natural default for a monthly run. */ +function lastMonth(): { period_from: string; period_to: string } { + const now = new Date(); + const from = new Date(now.getFullYear(), now.getMonth() - 1, 1); + const to = new Date(now.getFullYear(), now.getMonth(), 0); + const iso = (d: Date) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; + return { period_from: iso(from), period_to: iso(to) }; +} + export function Runs() { const { client } = useZino(); const scope = useScope(); @@ -43,7 +52,7 @@ export function Runs() { cols={[{ key: 'dealer_name', label: 'Dealer' }, { key: 'scheme_name', label: 'Scheme', render: (r) => `${String(r.scheme_name)} ยท ${String(r.component_name)}` }, { key: 'measured_qty', label: 'MT', align: 'right', render: (r) => mt(r.measured_qty, 0) }, { key: 'slab_label', label: 'Slab', render: (r) => (r.gate_passed ? String(r.slab_label ?? '') : {String(r.gate_reason ?? '')}) }, { key: 'incentive_amount', label: 'Amount', align: 'right', render: (r) => inr(r.incentive_amount) }, { key: 'status', label: 'Status', render: (r) => {String(r.status)} }]} /> setReq(false)} workflow={WF.RUN} activityUid={ACT.RUN_REQUEST} title="Request a settlement run" subtitle="Pick the period; the engine computes it provisionally and the Analyst reports." - prefill={{ frequency: 'MONTHLY', period_from: '2026-09-01', period_to: '2026-09-30' }} onDone={() => runs.refetch()} /> + prefill={{ frequency: 'MONTHLY', ...lastMonth() }} onDone={() => runs.refetch()} /> {decide && setDecide(null)} workflow={WF.RUN} activityUid={decide.act} instanceId={decide.id} title={decide.title} danger={decide.danger} onDone={() => runs.refetch()} />} );