Runs: default the request to the previous calendar month instead of a pinned date

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Yashas 2026-10-22 17:19:59 +05:30
parent 92c6988b80
commit 00d819c8c6

View File

@ -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 ?? '') : <span className="text-warn">{String(r.gate_reason ?? '')}</span>) }, { key: 'incentive_amount', label: 'Amount', align: 'right', render: (r) => inr(r.incentive_amount) }, { key: 'status', label: 'Status', render: (r) => <Badge tone={r.status === 'FINAL' ? 'emerald' : 'amber'}>{String(r.status)}</Badge> }]} />
</Modal>
<ActivityForm open={req} onClose={() => 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 && <ActivityForm open onClose={() => setDecide(null)} workflow={WF.RUN} activityUid={decide.act} instanceId={decide.id} title={decide.title} danger={decide.danger} onDone={() => runs.refetch()} />}
</div>
);