@burdenoff/microfe-healthybowl 2026.720.1 → 2026.720.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/healthybowl/HealthyBowlRoutes.js +72 -68
- package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlContracts.js +227 -0
- package/dist/healthybowl/hooks/useHealthyBowlContracts.js.map +1 -0
- package/dist/healthybowl/pages/contracts/ContractsPage.js +524 -0
- package/dist/healthybowl/pages/contracts/ContractsPage.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/CreateContractModal.js +151 -0
- package/dist/healthybowl/pages/contracts/contract-forms/CreateContractModal.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/DeliveryActionModal.js +130 -0
- package/dist/healthybowl/pages/contracts/contract-forms/DeliveryActionModal.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/InviteFarmModal.js +103 -0
- package/dist/healthybowl/pages/contracts/contract-forms/InviteFarmModal.js.map +1 -0
- package/dist/healthybowl/pages/contracts/contract-forms/RecordDeliveryModal.js +118 -0
- package/dist/healthybowl/pages/contracts/contract-forms/RecordDeliveryModal.js.map +1 -0
- package/dist/healthybowl/utils/contracts.js +76 -0
- package/dist/healthybowl/utils/contracts.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHealthyBowlContracts.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlContracts.ts"],"sourcesContent":["/**\n * Contract & Managed Farming (#29 · BOFF-4718) — data hook.\n *\n * Documents are declared inline with `gql` (not `src/operations/wspace/*.graphql`) because\n * codegen validates operations against the committed `graphql/wspace.graphql` snapshot, which\n * doesn't carry the contract subgraph yet (schema:pull needs a live gateway) — the same escape\n * hatch the mandi / sensor hooks use. Types mirror the deployed `wspace-healthybowl-svc`\n * contract schema (see ../utils/contracts.ts).\n *\n * Sponsor reads (dashboard, contracts) + farmer reads (my invitations/obligations) share one\n * hook; the two context-scoped queries pass `context: ContextInput!`, the two self-scoped\n * \"my …\" queries rely on the shell's workspace-token transport scoping. Reads are\n * cache-and-network; every write refetches the lists it invalidates.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport type {\n ContractAssignment,\n ContractDashboard,\n ContractDelivery,\n ContractObligation,\n FarmingContract,\n} from '../utils/contracts';\n\nconst FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\nconst EMPTY_CONTRACTS: FarmingContract[] = [];\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ──\nconst CONTRACT_FIELDS = `\n id\n crop\n variety\n quotaQty\n unit\n qualitySpec\n pricingModel\n agreedPrice\n deliverySchedule\n inputSupportTerms\n documentFileId\n status\n acceptedFarmCount\n createdAt\n`;\n\nconst ASSIGNMENT_FIELDS = `\n id\n contractId\n crop\n farmWorkspaceId\n farmName\n allocationQty\n status\n invitedAt\n acceptedAt\n`;\n\nconst DELIVERY_FIELDS = `\n id\n contractId\n assignmentId\n farmWorkspaceId\n farmName\n deliveryWindow\n windowDate\n committedQty\n deliveredQty\n acceptedQty\n rejectedQty\n harvestRecordId\n orderId\n gradeResult\n valuedAmount\n status\n settledAt\n createdAt\n`;\n\nconst CARD_FIELDS = `\n contractId\n crop\n status\n quotaQty\n deliveredQty\n acceptedQty\n fulfilmentPct\n agreedPrice\n unit\n contractedFarms\n rejectRatePct\n settlementDue\n health\n`;\n\nconst OBLIGATION_FIELDS = `\n assignmentId\n contractId\n crop\n sponsorWorkspaceId\n quotaQty\n unit\n agreedPrice\n qualitySpec\n status\n deliveredQty\n acceptedQty\n paymentsReceived\n`;\n\n// ── queries ──\nconst GET_DASHBOARD = gql`\n query GetHealthyBowlContractDashboard($context: ContextInput!) {\n getHealthyBowlContractDashboard(context: $context) {\n activeContracts\n contractedFarms\n avgFulfilmentPct\n settlementDue\n contracts { ${CARD_FIELDS} }\n }\n }\n`;\nconst GET_CONTRACTS = gql`\n query GetHealthyBowlFarmingContracts($context: ContextInput!) {\n getHealthyBowlFarmingContracts(context: $context) { ${CONTRACT_FIELDS} }\n }\n`;\nconst GET_INVITATIONS = gql`\n query GetMyHealthyBowlContractInvitations {\n getMyHealthyBowlContractInvitations { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst GET_OBLIGATIONS = gql`\n query GetMyHealthyBowlContractObligations {\n getMyHealthyBowlContractObligations { ${OBLIGATION_FIELDS} }\n }\n`;\nconst GET_ASSIGNMENTS = gql`\n query GetHealthyBowlContractAssignments($contractId: ID!, $context: ContextInput!) {\n getHealthyBowlContractAssignments(contractId: $contractId, context: $context) { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst GET_DELIVERIES = gql`\n query GetHealthyBowlContractDeliveries($contractId: ID!, $context: ContextInput!) {\n getHealthyBowlContractDeliveries(contractId: $contractId, context: $context) { ${DELIVERY_FIELDS} }\n }\n`;\n\n// ── mutations ──\nconst CREATE_CONTRACT = gql`\n mutation CreateHealthyBowlFarmingContract($input: CreateHealthyBowlFarmingContractInput!) {\n createHealthyBowlFarmingContract(input: $input) { ${CONTRACT_FIELDS} }\n }\n`;\nconst ACTIVATE_CONTRACT = gql`\n mutation ActivateHealthyBowlFarmingContract($id: ID!, $context: ContextInput!) {\n activateHealthyBowlFarmingContract(id: $id, context: $context) { ${CONTRACT_FIELDS} }\n }\n`;\nconst INVITE_FARM = gql`\n mutation InviteHealthyBowlContractFarm($input: InviteHealthyBowlContractFarmInput!) {\n inviteHealthyBowlContractFarm(input: $input) { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst ACCEPT_ASSIGNMENT = gql`\n mutation AcceptHealthyBowlContractAssignment($id: ID!, $context: ContextInput!) {\n acceptHealthyBowlContractAssignment(id: $id, context: $context) { ${ASSIGNMENT_FIELDS} }\n }\n`;\nconst REVOKE_ASSIGNMENT = gql`\n mutation RevokeHealthyBowlContractAssignment($id: ID!, $context: ContextInput!) {\n revokeHealthyBowlContractAssignment(id: $id, context: $context)\n }\n`;\nconst RECORD_DELIVERY = gql`\n mutation RecordHealthyBowlContractDelivery($input: RecordHealthyBowlContractDeliveryInput!) {\n recordHealthyBowlContractDelivery(input: $input) { ${DELIVERY_FIELDS} }\n }\n`;\nconst GRADE_DELIVERY = gql`\n mutation AcceptHealthyBowlContractDelivery($input: AcceptHealthyBowlContractDeliveryInput!) {\n acceptHealthyBowlContractDelivery(input: $input) { ${DELIVERY_FIELDS} }\n }\n`;\nconst SETTLE_DELIVERY = gql`\n mutation SettleHealthyBowlContractDelivery($input: SettleHealthyBowlContractDeliveryInput!) {\n settleHealthyBowlContractDelivery(input: $input) { ${DELIVERY_FIELDS} }\n }\n`;\n\nexport function useHealthyBowlContracts() {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n\n const dashboardQuery = useQuery<{ getHealthyBowlContractDashboard: ContractDashboard }, { context: HbContext }>(\n GET_DASHBOARD,\n { variables: { context: ctx }, fetchPolicy: 'cache-and-network' }\n );\n const contractsQuery = useQuery<{ getHealthyBowlFarmingContracts: FarmingContract[] }, { context: HbContext }>(\n GET_CONTRACTS,\n { variables: { context: ctx }, fetchPolicy: 'cache-and-network' }\n );\n const invitationsQuery = useQuery<{ getMyHealthyBowlContractInvitations: ContractAssignment[] }>(GET_INVITATIONS, {\n fetchPolicy: 'cache-and-network',\n });\n const obligationsQuery = useQuery<{ getMyHealthyBowlContractObligations: ContractObligation[] }>(GET_OBLIGATIONS, {\n fetchPolicy: 'cache-and-network',\n });\n\n const refetchDashboard = dashboardQuery.refetch;\n const refetchContracts = contractsQuery.refetch;\n const refetchInvitations = invitationsQuery.refetch;\n const refetchObligations = obligationsQuery.refetch;\n\n const reconcile = useCallback(async (...refetchers: Array<() => Promise<unknown>>) => {\n await Promise.all(refetchers.map((run) => run().catch(() => undefined)));\n }, []);\n\n const [createContractMutation] = useMutation<\n { createHealthyBowlFarmingContract: FarmingContract },\n { input: Record<string, unknown> }\n >(CREATE_CONTRACT);\n const [activateContractMutation] = useMutation(ACTIVATE_CONTRACT);\n const [inviteFarmMutation] = useMutation<\n { inviteHealthyBowlContractFarm: ContractAssignment },\n { input: Record<string, unknown> }\n >(INVITE_FARM);\n const [acceptAssignmentMutation] = useMutation(ACCEPT_ASSIGNMENT);\n const [revokeAssignmentMutation] = useMutation(REVOKE_ASSIGNMENT);\n const [recordDeliveryMutation] = useMutation<\n { recordHealthyBowlContractDelivery: ContractDelivery },\n { input: Record<string, unknown> }\n >(RECORD_DELIVERY);\n const [gradeDeliveryMutation] = useMutation<\n { acceptHealthyBowlContractDelivery: ContractDelivery },\n { input: Record<string, unknown> }\n >(GRADE_DELIVERY);\n const [settleDeliveryMutation] = useMutation<\n { settleHealthyBowlContractDelivery: ContractDelivery },\n { input: Record<string, unknown> }\n >(SETTLE_DELIVERY);\n\n const withCtx = useCallback((input: Record<string, unknown>) => ({ ...input, context: ctx }), [ctx]);\n\n const refetchSponsor = useCallback(\n () => reconcile(refetchDashboard, refetchContracts),\n [reconcile, refetchDashboard, refetchContracts]\n );\n const refetchFarmer = useCallback(\n () => reconcile(refetchInvitations, refetchObligations),\n [reconcile, refetchInvitations, refetchObligations]\n );\n\n return {\n dashboard: dashboardQuery.data?.getHealthyBowlContractDashboard ?? null,\n contracts: contractsQuery.data?.getHealthyBowlFarmingContracts ?? EMPTY_CONTRACTS,\n invitations: invitationsQuery.data?.getMyHealthyBowlContractInvitations ?? [],\n obligations: obligationsQuery.data?.getMyHealthyBowlContractObligations ?? [],\n\n loading: contractsQuery.loading || dashboardQuery.loading,\n error: contractsQuery.error ?? dashboardQuery.error ?? null,\n invitationsLoading: invitationsQuery.loading,\n obligationsLoading: obligationsQuery.loading,\n\n refetchAll: useCallback(\n () => reconcile(refetchDashboard, refetchContracts, refetchInvitations, refetchObligations),\n [reconcile, refetchDashboard, refetchContracts, refetchInvitations, refetchObligations]\n ),\n refetchSponsor,\n refetchFarmer,\n\n createContract: useCallback(\n async (input: Record<string, unknown>): Promise<FarmingContract | null> => {\n const res = await createContractMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.createHealthyBowlFarmingContract ?? null;\n },\n [createContractMutation, withCtx, refetchSponsor]\n ),\n activateContract: useCallback(\n async (id: string) => {\n const res = await activateContractMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await refetchSponsor();\n },\n [activateContractMutation, ctx, refetchSponsor]\n ),\n inviteFarm: useCallback(\n async (input: Record<string, unknown>): Promise<ContractAssignment | null> => {\n const res = await inviteFarmMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.inviteHealthyBowlContractFarm ?? null;\n },\n [inviteFarmMutation, withCtx, refetchSponsor]\n ),\n acceptAssignment: useCallback(\n async (id: string) => {\n const res = await acceptAssignmentMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await refetchFarmer();\n },\n [acceptAssignmentMutation, ctx, refetchFarmer]\n ),\n revokeAssignment: useCallback(\n async (id: string) => {\n const res = await revokeAssignmentMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchDashboard, refetchContracts, refetchInvitations, refetchObligations);\n },\n [\n revokeAssignmentMutation,\n ctx,\n reconcile,\n refetchDashboard,\n refetchContracts,\n refetchInvitations,\n refetchObligations,\n ]\n ),\n recordDelivery: useCallback(\n async (input: Record<string, unknown>): Promise<ContractDelivery | null> => {\n const res = await recordDeliveryMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.recordHealthyBowlContractDelivery ?? null;\n },\n [recordDeliveryMutation, withCtx, refetchSponsor]\n ),\n gradeDelivery: useCallback(\n async (input: Record<string, unknown>): Promise<ContractDelivery | null> => {\n const res = await gradeDeliveryMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await refetchSponsor();\n return res.data?.acceptHealthyBowlContractDelivery ?? null;\n },\n [gradeDeliveryMutation, withCtx, refetchSponsor]\n ),\n settleDelivery: useCallback(\n async (input: Record<string, unknown>): Promise<ContractDelivery | null> => {\n const res = await settleDeliveryMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchDashboard, refetchContracts, refetchObligations);\n return res.data?.settleHealthyBowlContractDelivery ?? null;\n },\n [settleDeliveryMutation, withCtx, reconcile, refetchDashboard, refetchContracts, refetchObligations]\n ),\n\n context: ctx,\n };\n}\n\n/** Lazy per-contract detail: assignments + deliveries for the selected contract (drawer). */\nexport function useHealthyBowlContractDetail(contractId: string | null) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const skip = !contractId;\n\n const assignmentsQuery = useQuery<\n { getHealthyBowlContractAssignments: ContractAssignment[] },\n { contractId: string; context: HbContext }\n >(GET_ASSIGNMENTS, {\n variables: { contractId: contractId ?? '', context: ctx },\n skip,\n fetchPolicy: 'cache-and-network',\n });\n const deliveriesQuery = useQuery<\n { getHealthyBowlContractDeliveries: ContractDelivery[] },\n { contractId: string; context: HbContext }\n >(GET_DELIVERIES, {\n variables: { contractId: contractId ?? '', context: ctx },\n skip,\n fetchPolicy: 'cache-and-network',\n });\n\n const refetchAssignments = assignmentsQuery.refetch;\n const refetchDeliveries = deliveriesQuery.refetch;\n const refetch = useCallback(async () => {\n await Promise.all([refetchAssignments().catch(() => undefined), refetchDeliveries().catch(() => undefined)]);\n }, [refetchAssignments, refetchDeliveries]);\n\n return {\n assignments: assignmentsQuery.data?.getHealthyBowlContractAssignments ?? [],\n deliveries: deliveriesQuery.data?.getHealthyBowlContractDeliveries ?? [],\n loading: assignmentsQuery.loading || deliveriesQuery.loading,\n refetch,\n };\n}\n\nexport type {\n ContractAssignment,\n ContractDashboard,\n ContractDelivery,\n ContractObligation,\n FarmingContract,\n} from '../utils/contracts';\n"],"mappings":";;;;;AA2BA,IAAM,IAAwB,wCACxB,IAAqC,EAAE,EAOvC,IAAkB,wMAiBlB,IAAoB,uHAYpB,IAAkB,wQAqBlB,IAAc,wLAgBd,IAAoB,iLAgBpB,IAAgB,CAAG;;;;;;;oBAOL,EAAY;;;GAI1B,IAAgB,CAAG;;0DAEiC,EAAgB;;GAGpE,IAAkB,CAAG;;4CAEiB,EAAkB;;GAGxD,IAAkB,CAAG;;4CAEiB,EAAkB;;GAGxD,IAAkB,CAAG;;sFAE2D,EAAkB;;GAGlG,IAAiB,CAAG;;qFAE2D,EAAgB;;GAK/F,IAAkB,CAAG;;wDAE6B,EAAgB;;GAGlE,IAAoB,CAAG;;uEAE0C,EAAgB;;GAGjF,IAAc,CAAG;;qDAE8B,EAAkB;;GAGjE,IAAoB,CAAG;;wEAE2C,EAAkB;;GAGpF,IAAoB,CAAG;;;;GAKvB,IAAkB,CAAG;;yDAE8B,EAAgB;;GAGnE,IAAiB,CAAG;;yDAE+B,EAAgB;;GAGnE,IAAkB,CAAG;;yDAE8B,EAAgB;;;AAIzE,SAAgB,IAA0B;CACxC,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAuB,KAAe,GACtC,IAAM,SAA0B,EAAE,aAAa,GAAsB,GAAG,CAAC,EAAqB,CAAC,EAE/F,IAAiB,EACrB,GACA;EAAE,WAAW,EAAE,SAAS,GAAK;EAAE,aAAa;EAAqB,CAClE,EACK,IAAiB,EACrB,GACA;EAAE,WAAW,EAAE,SAAS,GAAK;EAAE,aAAa;EAAqB,CAClE,EACK,IAAmB,EAAwE,GAAiB,EAChH,aAAa,qBACd,CAAC,EACI,IAAmB,EAAwE,GAAiB,EAChH,aAAa,qBACd,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M,oCAAoC,EAAE;EACxE,SAAS,EAAiB,WAAW,EAAgB;EACrD;EACD"}
|
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
import { formatCurrency as e, formatDateOnly as t } from "../../utils/helpers.js";
|
|
2
|
+
import { PageLayout as n } from "../../components/PageLayout.js";
|
|
3
|
+
import { StatCard as r } from "../../components/StatCard.js";
|
|
4
|
+
import { StatusBadge as i } from "../../components/StatusBadge.js";
|
|
5
|
+
import { EmptyState as a } from "../../components/EmptyState.js";
|
|
6
|
+
import { ErrorState as o } from "../../components/ErrorState.js";
|
|
7
|
+
import { useConfirm as s } from "../../components/ConfirmDialog.js";
|
|
8
|
+
import { PageLoader as c } from "../../components/PageLoader.js";
|
|
9
|
+
import { Modal as l } from "../../components/Modal.js";
|
|
10
|
+
import { useToast as u } from "../../hooks/useToast.js";
|
|
11
|
+
import "../../components/index.js";
|
|
12
|
+
import { useHealthyBowlContractDetail as d, useHealthyBowlContracts as f } from "../../hooks/useHealthyBowlContracts.js";
|
|
13
|
+
import { assignmentStatusVariant as ee, contractStatusVariant as p, deliveryStatusVariant as te, formatQty as m, fulfilmentLabel as ne, healthLabel as re, healthVariant as h, humanizeEnum as g } from "../../utils/contracts.js";
|
|
14
|
+
import { CreateContractModal as ie } from "./contract-forms/CreateContractModal.js";
|
|
15
|
+
import { InviteFarmModal as ae } from "./contract-forms/InviteFarmModal.js";
|
|
16
|
+
import { RecordDeliveryModal as oe } from "./contract-forms/RecordDeliveryModal.js";
|
|
17
|
+
import { DeliveryActionModal as _ } from "./contract-forms/DeliveryActionModal.js";
|
|
18
|
+
import { useMemo as v, useState as y } from "react";
|
|
19
|
+
import { useI18n as se } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
20
|
+
import { BadgeIndianRupee as b, CheckCircle2 as x, ClipboardCheck as ce, FileSignature as S, Gauge as le, Handshake as ue, Inbox as de, Plus as C, Trash2 as fe, Truck as w, UserPlus as T, Users as E, Wallet as D } from "lucide-react";
|
|
21
|
+
import { Fragment as O, jsx as k, jsxs as A } from "react/jsx-runtime";
|
|
22
|
+
import { Button as j } from "@burdenoff/fe-libs/ui";
|
|
23
|
+
//#region src/healthybowl/pages/contracts/ContractsPage.tsx
|
|
24
|
+
var M = "px-3 py-2 text-left text-xs font-medium uppercase tracking-wide text-text-secondary", N = "px-3 py-2 text-sm text-text-primary";
|
|
25
|
+
function P() {
|
|
26
|
+
let { t: P } = se(), { toast: F } = u(), I = s(), { dashboard: L, contracts: R, invitations: z, obligations: B, loading: V, error: pe, refetchAll: me, createContract: he, activateContract: ge, inviteFarm: _e, acceptAssignment: ve, revokeAssignment: ye, recordDelivery: be, gradeDelivery: xe, settleDelivery: Se } = f(), [Ce, H] = y(!1), [we, U] = y(!1), [Te, W] = y(!1), [G, K] = y(null), [q, J] = y(null), Y = d(G), X = v(() => R.find((e) => e.id === G) ?? null, [R, G]), Z = (e) => F({
|
|
27
|
+
title: P("healthybowl.common.error", "Something went wrong"),
|
|
28
|
+
description: e instanceof Error ? e.message : void 0,
|
|
29
|
+
variant: "error"
|
|
30
|
+
}), Ee = async (e) => {
|
|
31
|
+
await he(e), F({
|
|
32
|
+
title: P("healthybowl.contracts.toast.created", "Contract created"),
|
|
33
|
+
variant: "success"
|
|
34
|
+
});
|
|
35
|
+
}, De = async (e) => {
|
|
36
|
+
G && (await _e({
|
|
37
|
+
...e,
|
|
38
|
+
contractId: G
|
|
39
|
+
}), await Y.refetch(), F({
|
|
40
|
+
title: P("healthybowl.contracts.toast.invited", "Farm invited"),
|
|
41
|
+
variant: "success"
|
|
42
|
+
}));
|
|
43
|
+
}, Oe = async (e) => {
|
|
44
|
+
await be(e), await Y.refetch(), F({
|
|
45
|
+
title: P("healthybowl.contracts.toast.recorded", "Delivery recorded"),
|
|
46
|
+
variant: "success"
|
|
47
|
+
});
|
|
48
|
+
}, ke = async (e) => {
|
|
49
|
+
q && (q.mode === "grade" ? (await xe(e), F({
|
|
50
|
+
title: P("healthybowl.contracts.toast.graded", "Delivery graded"),
|
|
51
|
+
variant: "success"
|
|
52
|
+
})) : (await Se(e), F({
|
|
53
|
+
title: P("healthybowl.contracts.toast.settled", "Delivery settled"),
|
|
54
|
+
variant: "success"
|
|
55
|
+
})), await Y.refetch());
|
|
56
|
+
}, Ae = async (e) => {
|
|
57
|
+
try {
|
|
58
|
+
await ge(e.id), await Y.refetch(), F({
|
|
59
|
+
title: P("healthybowl.contracts.toast.activated", "Contract activated"),
|
|
60
|
+
variant: "success"
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
Z(e);
|
|
64
|
+
}
|
|
65
|
+
}, Q = async (e) => {
|
|
66
|
+
try {
|
|
67
|
+
await ve(e), F({
|
|
68
|
+
title: P("healthybowl.contracts.toast.accepted", "Invitation accepted"),
|
|
69
|
+
variant: "success"
|
|
70
|
+
});
|
|
71
|
+
} catch (e) {
|
|
72
|
+
Z(e);
|
|
73
|
+
}
|
|
74
|
+
}, je = async (e, t) => {
|
|
75
|
+
if (await I({
|
|
76
|
+
title: P("healthybowl.contracts.revoke.title", "Revoke assignment?"),
|
|
77
|
+
message: P("healthybowl.contracts.revoke.body", "This immediately stops all data sharing with {{f}}.", { f: t }),
|
|
78
|
+
okButtonTitle: P("healthybowl.common.remove", "Revoke"),
|
|
79
|
+
destructive: !0
|
|
80
|
+
})) try {
|
|
81
|
+
await ye(e), await Y.refetch(), F({
|
|
82
|
+
title: P("healthybowl.contracts.toast.revoked", "Assignment revoked"),
|
|
83
|
+
variant: "success"
|
|
84
|
+
});
|
|
85
|
+
} catch (e) {
|
|
86
|
+
Z(e);
|
|
87
|
+
}
|
|
88
|
+
}, $ = z.length > 0 || B.length > 0, Me = R.length > 0 || !$, Ne = /* @__PURE__ */ A(j, {
|
|
89
|
+
size: "sm",
|
|
90
|
+
onClick: () => H(!0),
|
|
91
|
+
children: [/* @__PURE__ */ k(C, { className: "h-3.5 w-3.5" }), P("healthybowl.contracts.newContract", "New contract")]
|
|
92
|
+
}), Pe = /* @__PURE__ */ A(O, { children: [
|
|
93
|
+
/* @__PURE__ */ k(ie, {
|
|
94
|
+
open: Ce,
|
|
95
|
+
onClose: () => H(!1),
|
|
96
|
+
onSubmit: Ee
|
|
97
|
+
}),
|
|
98
|
+
/* @__PURE__ */ k(ae, {
|
|
99
|
+
open: we,
|
|
100
|
+
onClose: () => U(!1),
|
|
101
|
+
contractCrop: X?.crop,
|
|
102
|
+
onSubmit: De
|
|
103
|
+
}),
|
|
104
|
+
/* @__PURE__ */ k(oe, {
|
|
105
|
+
open: Te,
|
|
106
|
+
onClose: () => W(!1),
|
|
107
|
+
contractId: G ?? "",
|
|
108
|
+
assignments: Y.assignments,
|
|
109
|
+
onSubmit: Oe
|
|
110
|
+
}),
|
|
111
|
+
/* @__PURE__ */ k(_, {
|
|
112
|
+
open: q != null,
|
|
113
|
+
mode: q?.mode ?? "grade",
|
|
114
|
+
delivery: q?.delivery ?? null,
|
|
115
|
+
agreedPrice: X?.agreedPrice ?? 0,
|
|
116
|
+
unit: X?.unit,
|
|
117
|
+
onClose: () => J(null),
|
|
118
|
+
onSubmit: ke
|
|
119
|
+
})
|
|
120
|
+
] });
|
|
121
|
+
return /* @__PURE__ */ A(n, {
|
|
122
|
+
title: P("healthybowl.contracts.title", "Contracts"),
|
|
123
|
+
description: P("healthybowl.contracts.subtitle", "Contract & managed farming"),
|
|
124
|
+
purpose: "Run forward crop programmes across your contracted farms: agree a crop, quota, quality spec and price, invite farms (they accept from their own workspace before any data is shared), then track fulfilment as harvest is delivered, graded, and settled back to the farm — net of any input advance. Contracted farmers see their own quota, agreed price and payments received.",
|
|
125
|
+
actions: Ne,
|
|
126
|
+
children: [V && R.length === 0 && !$ ? /* @__PURE__ */ k(c, {}) : pe && R.length === 0 && !$ ? /* @__PURE__ */ k(o, { onRetry: me }) : /* @__PURE__ */ A("div", {
|
|
127
|
+
className: "space-y-8",
|
|
128
|
+
children: [
|
|
129
|
+
Me ? /* @__PURE__ */ A("section", {
|
|
130
|
+
className: "space-y-4",
|
|
131
|
+
children: [/* @__PURE__ */ A("div", {
|
|
132
|
+
className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",
|
|
133
|
+
children: [
|
|
134
|
+
/* @__PURE__ */ k(r, {
|
|
135
|
+
hero: !0,
|
|
136
|
+
label: P("healthybowl.contracts.kpi.active", "Active contracts"),
|
|
137
|
+
value: L?.activeContracts ?? 0,
|
|
138
|
+
icon: /* @__PURE__ */ k(ue, { className: "h-4 w-4" })
|
|
139
|
+
}),
|
|
140
|
+
/* @__PURE__ */ k(r, {
|
|
141
|
+
label: P("healthybowl.contracts.kpi.farms", "Contracted farms"),
|
|
142
|
+
value: L?.contractedFarms ?? 0,
|
|
143
|
+
icon: /* @__PURE__ */ k(E, { className: "h-4 w-4" })
|
|
144
|
+
}),
|
|
145
|
+
/* @__PURE__ */ k(r, {
|
|
146
|
+
label: P("healthybowl.contracts.kpi.fulfilment", "Avg fulfilment %"),
|
|
147
|
+
value: `${L?.avgFulfilmentPct ?? 0}%`,
|
|
148
|
+
icon: /* @__PURE__ */ k(le, { className: "h-4 w-4" })
|
|
149
|
+
}),
|
|
150
|
+
/* @__PURE__ */ k(r, {
|
|
151
|
+
label: P("healthybowl.contracts.kpi.settlementDue", "Settlement due"),
|
|
152
|
+
value: e(L?.settlementDue ?? 0, "INR"),
|
|
153
|
+
icon: /* @__PURE__ */ k(D, { className: "h-4 w-4" })
|
|
154
|
+
})
|
|
155
|
+
]
|
|
156
|
+
}), R.length === 0 ? /* @__PURE__ */ k(a, {
|
|
157
|
+
icon: /* @__PURE__ */ k(S, { className: "h-8 w-8 text-success" }),
|
|
158
|
+
title: P("healthybowl.contracts.empty.title", "No contracts yet"),
|
|
159
|
+
description: P("healthybowl.contracts.empty.description", "Create a forward crop programme, invite your contracted farms, and track fulfilment and settlement here."),
|
|
160
|
+
action: /* @__PURE__ */ A(j, {
|
|
161
|
+
onClick: () => H(!0),
|
|
162
|
+
children: [/* @__PURE__ */ k(C, { className: "h-4 w-4" }), P("healthybowl.contracts.newContract", "New contract")]
|
|
163
|
+
})
|
|
164
|
+
}) : /* @__PURE__ */ k("div", {
|
|
165
|
+
className: "overflow-x-auto rounded-lg border border-border-subtle",
|
|
166
|
+
children: /* @__PURE__ */ A("table", {
|
|
167
|
+
className: "min-w-full divide-y divide-border-subtle",
|
|
168
|
+
children: [/* @__PURE__ */ k("thead", {
|
|
169
|
+
className: "bg-bg-surface",
|
|
170
|
+
children: /* @__PURE__ */ A("tr", { children: [
|
|
171
|
+
/* @__PURE__ */ k("th", {
|
|
172
|
+
className: M,
|
|
173
|
+
children: P("healthybowl.contracts.col.crop", "Crop")
|
|
174
|
+
}),
|
|
175
|
+
/* @__PURE__ */ k("th", {
|
|
176
|
+
className: M,
|
|
177
|
+
children: P("healthybowl.contracts.col.status", "Status")
|
|
178
|
+
}),
|
|
179
|
+
/* @__PURE__ */ k("th", {
|
|
180
|
+
className: M,
|
|
181
|
+
children: P("healthybowl.contracts.col.fulfilment", "Delivered / quota")
|
|
182
|
+
}),
|
|
183
|
+
/* @__PURE__ */ k("th", {
|
|
184
|
+
className: M,
|
|
185
|
+
children: P("healthybowl.contracts.col.pct", "Fulfilment")
|
|
186
|
+
}),
|
|
187
|
+
/* @__PURE__ */ k("th", {
|
|
188
|
+
className: M,
|
|
189
|
+
children: P("healthybowl.contracts.col.price", "Price")
|
|
190
|
+
}),
|
|
191
|
+
/* @__PURE__ */ k("th", {
|
|
192
|
+
className: M,
|
|
193
|
+
children: P("healthybowl.contracts.col.farms", "Farms")
|
|
194
|
+
}),
|
|
195
|
+
/* @__PURE__ */ k("th", {
|
|
196
|
+
className: M,
|
|
197
|
+
children: P("healthybowl.contracts.col.due", "Settlement due")
|
|
198
|
+
}),
|
|
199
|
+
/* @__PURE__ */ k("th", {
|
|
200
|
+
className: M,
|
|
201
|
+
children: P("healthybowl.contracts.col.health", "Health")
|
|
202
|
+
})
|
|
203
|
+
] })
|
|
204
|
+
}), /* @__PURE__ */ k("tbody", {
|
|
205
|
+
className: "divide-y divide-border-subtle",
|
|
206
|
+
children: R.map((t) => {
|
|
207
|
+
let n = L?.contracts.find((e) => e.contractId === t.id);
|
|
208
|
+
return /* @__PURE__ */ A("tr", {
|
|
209
|
+
className: "cursor-pointer hover:bg-bg-surface",
|
|
210
|
+
onClick: () => K(t.id),
|
|
211
|
+
children: [
|
|
212
|
+
/* @__PURE__ */ A("td", {
|
|
213
|
+
className: N,
|
|
214
|
+
children: [/* @__PURE__ */ k("div", {
|
|
215
|
+
className: "font-medium",
|
|
216
|
+
children: t.crop
|
|
217
|
+
}), t.variety ? /* @__PURE__ */ k("div", {
|
|
218
|
+
className: "text-xs text-text-secondary",
|
|
219
|
+
children: t.variety
|
|
220
|
+
}) : null]
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ k("td", {
|
|
223
|
+
className: N,
|
|
224
|
+
children: /* @__PURE__ */ k(i, {
|
|
225
|
+
variant: p(t.status),
|
|
226
|
+
label: g(t.status)
|
|
227
|
+
})
|
|
228
|
+
}),
|
|
229
|
+
/* @__PURE__ */ k("td", {
|
|
230
|
+
className: `${N} tabular-nums`,
|
|
231
|
+
children: ne(n?.deliveredQty ?? 0, t.quotaQty, t.unit)
|
|
232
|
+
}),
|
|
233
|
+
/* @__PURE__ */ A("td", {
|
|
234
|
+
className: `${N} tabular-nums`,
|
|
235
|
+
children: [n?.fulfilmentPct ?? 0, "%"]
|
|
236
|
+
}),
|
|
237
|
+
/* @__PURE__ */ A("td", {
|
|
238
|
+
className: `${N} tabular-nums`,
|
|
239
|
+
children: [e(t.agreedPrice, "INR"), /* @__PURE__ */ A("span", {
|
|
240
|
+
className: "text-xs text-text-secondary",
|
|
241
|
+
children: ["/", t.unit]
|
|
242
|
+
})]
|
|
243
|
+
}),
|
|
244
|
+
/* @__PURE__ */ k("td", {
|
|
245
|
+
className: `${N} tabular-nums`,
|
|
246
|
+
children: t.acceptedFarmCount
|
|
247
|
+
}),
|
|
248
|
+
/* @__PURE__ */ k("td", {
|
|
249
|
+
className: `${N} tabular-nums`,
|
|
250
|
+
children: e(n?.settlementDue ?? 0, "INR")
|
|
251
|
+
}),
|
|
252
|
+
/* @__PURE__ */ k("td", {
|
|
253
|
+
className: N,
|
|
254
|
+
children: n ? /* @__PURE__ */ k(i, {
|
|
255
|
+
variant: h(n.health),
|
|
256
|
+
label: re(n.health)
|
|
257
|
+
}) : "—"
|
|
258
|
+
})
|
|
259
|
+
]
|
|
260
|
+
}, t.id);
|
|
261
|
+
})
|
|
262
|
+
})]
|
|
263
|
+
})
|
|
264
|
+
})]
|
|
265
|
+
}) : null,
|
|
266
|
+
z.length > 0 ? /* @__PURE__ */ A("section", {
|
|
267
|
+
className: "space-y-3",
|
|
268
|
+
children: [/* @__PURE__ */ A("h2", {
|
|
269
|
+
className: "flex items-center gap-2 text-lg font-semibold text-text-primary",
|
|
270
|
+
children: [/* @__PURE__ */ k(de, { className: "h-5 w-5 text-info" }), P("healthybowl.contracts.invitations.title", "Contract invitations")]
|
|
271
|
+
}), /* @__PURE__ */ k("ul", {
|
|
272
|
+
className: "space-y-2",
|
|
273
|
+
children: z.map((e) => /* @__PURE__ */ A("li", {
|
|
274
|
+
className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border-subtle bg-bg-surface px-4 py-3",
|
|
275
|
+
children: [/* @__PURE__ */ A("div", { children: [/* @__PURE__ */ A("div", {
|
|
276
|
+
className: "font-medium text-text-primary",
|
|
277
|
+
children: [e.crop ?? P("healthybowl.contracts.aContract", "A contract"), e.allocationQty ? /* @__PURE__ */ A("span", {
|
|
278
|
+
className: "ml-2 text-sm text-text-secondary",
|
|
279
|
+
children: [
|
|
280
|
+
m(e.allocationQty),
|
|
281
|
+
" ",
|
|
282
|
+
P("healthybowl.contracts.allocated", "allocated")
|
|
283
|
+
]
|
|
284
|
+
}) : null]
|
|
285
|
+
}), /* @__PURE__ */ k("div", {
|
|
286
|
+
className: "text-xs text-text-secondary",
|
|
287
|
+
children: P("healthybowl.contracts.invitedOn", "Invited {{d}}", { d: t(e.invitedAt) })
|
|
288
|
+
})] }), /* @__PURE__ */ A(j, {
|
|
289
|
+
size: "sm",
|
|
290
|
+
onClick: () => Q(e.id),
|
|
291
|
+
children: [/* @__PURE__ */ k(x, { className: "h-3.5 w-3.5" }), P("healthybowl.contracts.accept", "Accept")]
|
|
292
|
+
})]
|
|
293
|
+
}, e.id))
|
|
294
|
+
})]
|
|
295
|
+
}) : null,
|
|
296
|
+
B.length > 0 ? /* @__PURE__ */ A("section", {
|
|
297
|
+
className: "space-y-3",
|
|
298
|
+
children: [/* @__PURE__ */ A("h2", {
|
|
299
|
+
className: "flex items-center gap-2 text-lg font-semibold text-text-primary",
|
|
300
|
+
children: [/* @__PURE__ */ k(b, { className: "h-5 w-5 text-success" }), P("healthybowl.contracts.obligations.title", "My contract obligations")]
|
|
301
|
+
}), /* @__PURE__ */ k("div", {
|
|
302
|
+
className: "grid grid-cols-1 gap-3 md:grid-cols-2",
|
|
303
|
+
children: B.map((t) => /* @__PURE__ */ A("div", {
|
|
304
|
+
className: "rounded-lg border border-border-subtle bg-bg-surface p-4",
|
|
305
|
+
children: [/* @__PURE__ */ A("div", {
|
|
306
|
+
className: "flex items-center justify-between",
|
|
307
|
+
children: [/* @__PURE__ */ k("div", {
|
|
308
|
+
className: "font-semibold text-text-primary",
|
|
309
|
+
children: t.crop
|
|
310
|
+
}), /* @__PURE__ */ k(i, {
|
|
311
|
+
variant: "success",
|
|
312
|
+
label: P("healthybowl.contracts.status.active", "Active")
|
|
313
|
+
})]
|
|
314
|
+
}), /* @__PURE__ */ A("dl", {
|
|
315
|
+
className: "mt-3 grid grid-cols-2 gap-x-4 gap-y-2 text-sm",
|
|
316
|
+
children: [
|
|
317
|
+
/* @__PURE__ */ k("dt", {
|
|
318
|
+
className: "text-text-secondary",
|
|
319
|
+
children: P("healthybowl.contracts.obl.quota", "My quota")
|
|
320
|
+
}),
|
|
321
|
+
/* @__PURE__ */ k("dd", {
|
|
322
|
+
className: "text-right tabular-nums text-text-primary",
|
|
323
|
+
children: m(t.quotaQty, t.unit)
|
|
324
|
+
}),
|
|
325
|
+
/* @__PURE__ */ k("dt", {
|
|
326
|
+
className: "text-text-secondary",
|
|
327
|
+
children: P("healthybowl.contracts.obl.price", "Agreed price")
|
|
328
|
+
}),
|
|
329
|
+
/* @__PURE__ */ A("dd", {
|
|
330
|
+
className: "text-right tabular-nums text-text-primary",
|
|
331
|
+
children: [
|
|
332
|
+
e(t.agreedPrice, "INR"),
|
|
333
|
+
"/",
|
|
334
|
+
t.unit
|
|
335
|
+
]
|
|
336
|
+
}),
|
|
337
|
+
/* @__PURE__ */ k("dt", {
|
|
338
|
+
className: "text-text-secondary",
|
|
339
|
+
children: P("healthybowl.contracts.obl.delivered", "Delivered / accepted")
|
|
340
|
+
}),
|
|
341
|
+
/* @__PURE__ */ A("dd", {
|
|
342
|
+
className: "text-right tabular-nums text-text-primary",
|
|
343
|
+
children: [
|
|
344
|
+
m(t.deliveredQty, t.unit),
|
|
345
|
+
" / ",
|
|
346
|
+
m(t.acceptedQty, t.unit)
|
|
347
|
+
]
|
|
348
|
+
}),
|
|
349
|
+
/* @__PURE__ */ k("dt", {
|
|
350
|
+
className: "text-text-secondary",
|
|
351
|
+
children: P("healthybowl.contracts.obl.paid", "Payments received")
|
|
352
|
+
}),
|
|
353
|
+
/* @__PURE__ */ k("dd", {
|
|
354
|
+
className: "text-right font-semibold tabular-nums text-success",
|
|
355
|
+
children: e(t.paymentsReceived, "INR")
|
|
356
|
+
})
|
|
357
|
+
]
|
|
358
|
+
})]
|
|
359
|
+
}, t.assignmentId))
|
|
360
|
+
})]
|
|
361
|
+
}) : null,
|
|
362
|
+
/* @__PURE__ */ k(l, {
|
|
363
|
+
open: G != null,
|
|
364
|
+
onClose: () => K(null),
|
|
365
|
+
title: X ? P("healthybowl.contracts.detail.title", "{{crop}} contract", { crop: X.crop }) : P("healthybowl.contracts.detail.titleGeneric", "Contract"),
|
|
366
|
+
description: X ? `${g(X.pricingModel)} · ${e(X.agreedPrice, "INR")}/${X.unit} · ${P("healthybowl.contracts.quota", "quota")} ${m(X.quotaQty, X.unit)}` : void 0,
|
|
367
|
+
size: "xl",
|
|
368
|
+
footer: X && String(X.status).toLowerCase() === "draft" ? /* @__PURE__ */ A(j, {
|
|
369
|
+
onClick: () => Ae(X),
|
|
370
|
+
disabled: X.acceptedFarmCount < 1,
|
|
371
|
+
title: X.acceptedFarmCount < 1 ? P("healthybowl.contracts.activateHint", "At least one farm must accept before activating") : void 0,
|
|
372
|
+
children: [/* @__PURE__ */ k(x, { className: "h-4 w-4" }), P("healthybowl.contracts.activate", "Activate contract")]
|
|
373
|
+
}) : null,
|
|
374
|
+
children: X ? /* @__PURE__ */ A("div", {
|
|
375
|
+
className: "space-y-6",
|
|
376
|
+
children: [
|
|
377
|
+
/* @__PURE__ */ A("div", {
|
|
378
|
+
className: "flex items-center gap-2",
|
|
379
|
+
children: [/* @__PURE__ */ k(i, {
|
|
380
|
+
variant: p(X.status),
|
|
381
|
+
label: g(X.status)
|
|
382
|
+
}), X.documentFileId ? /* @__PURE__ */ A("span", {
|
|
383
|
+
className: "inline-flex items-center gap-1 text-xs text-text-secondary",
|
|
384
|
+
children: [/* @__PURE__ */ k(S, { className: "h-3.5 w-3.5" }), P("healthybowl.contracts.signedDoc", "Signed document attached")]
|
|
385
|
+
}) : null]
|
|
386
|
+
}),
|
|
387
|
+
/* @__PURE__ */ A("div", { children: [/* @__PURE__ */ A("div", {
|
|
388
|
+
className: "mb-2 flex items-center justify-between",
|
|
389
|
+
children: [/* @__PURE__ */ k("h3", {
|
|
390
|
+
className: "text-sm font-semibold text-text-primary",
|
|
391
|
+
children: P("healthybowl.contracts.assignments", "Farms")
|
|
392
|
+
}), /* @__PURE__ */ A(j, {
|
|
393
|
+
variant: "outline",
|
|
394
|
+
size: "sm",
|
|
395
|
+
onClick: () => U(!0),
|
|
396
|
+
children: [/* @__PURE__ */ k(T, { className: "h-3.5 w-3.5" }), P("healthybowl.contracts.inviteFarm", "Invite farm")]
|
|
397
|
+
})]
|
|
398
|
+
}), Y.assignments.length === 0 ? /* @__PURE__ */ k("p", {
|
|
399
|
+
className: "text-sm text-text-secondary",
|
|
400
|
+
children: P("healthybowl.contracts.noFarms", "No farms invited yet.")
|
|
401
|
+
}) : /* @__PURE__ */ k("ul", {
|
|
402
|
+
className: "space-y-2",
|
|
403
|
+
children: Y.assignments.map((e) => /* @__PURE__ */ A("li", {
|
|
404
|
+
className: "flex items-center justify-between gap-3 rounded-md border border-border-subtle px-3 py-2",
|
|
405
|
+
children: [/* @__PURE__ */ A("div", { children: [/* @__PURE__ */ k("span", {
|
|
406
|
+
className: "text-sm font-medium text-text-primary",
|
|
407
|
+
children: e.farmName || e.farmWorkspaceId
|
|
408
|
+
}), e.allocationQty ? /* @__PURE__ */ k("span", {
|
|
409
|
+
className: "ml-2 text-xs text-text-secondary",
|
|
410
|
+
children: m(e.allocationQty)
|
|
411
|
+
}) : null] }), /* @__PURE__ */ A("div", {
|
|
412
|
+
className: "flex items-center gap-2",
|
|
413
|
+
children: [/* @__PURE__ */ k(i, {
|
|
414
|
+
variant: ee(e.status),
|
|
415
|
+
label: g(e.status)
|
|
416
|
+
}), String(e.status).toLowerCase() === "revoked" ? null : /* @__PURE__ */ k(j, {
|
|
417
|
+
variant: "ghost",
|
|
418
|
+
size: "icon-sm",
|
|
419
|
+
onClick: () => je(e.id, e.farmName || e.farmWorkspaceId),
|
|
420
|
+
title: P("healthybowl.common.remove", "Revoke"),
|
|
421
|
+
children: /* @__PURE__ */ k(fe, { className: "h-3.5 w-3.5" })
|
|
422
|
+
})]
|
|
423
|
+
})]
|
|
424
|
+
}, e.id))
|
|
425
|
+
})] }),
|
|
426
|
+
/* @__PURE__ */ A("div", { children: [/* @__PURE__ */ A("div", {
|
|
427
|
+
className: "mb-2 flex items-center justify-between",
|
|
428
|
+
children: [/* @__PURE__ */ k("h3", {
|
|
429
|
+
className: "text-sm font-semibold text-text-primary",
|
|
430
|
+
children: P("healthybowl.contracts.deliveries", "Deliveries")
|
|
431
|
+
}), /* @__PURE__ */ A(j, {
|
|
432
|
+
variant: "outline",
|
|
433
|
+
size: "sm",
|
|
434
|
+
onClick: () => W(!0),
|
|
435
|
+
disabled: Y.assignments.filter((e) => String(e.status).toLowerCase() === "accepted").length === 0,
|
|
436
|
+
children: [/* @__PURE__ */ k(w, { className: "h-3.5 w-3.5" }), P("healthybowl.contracts.recordDelivery", "Record delivery")]
|
|
437
|
+
})]
|
|
438
|
+
}), Y.deliveries.length === 0 ? /* @__PURE__ */ k("p", {
|
|
439
|
+
className: "text-sm text-text-secondary",
|
|
440
|
+
children: P("healthybowl.contracts.noDeliveries", "No deliveries recorded yet.")
|
|
441
|
+
}) : /* @__PURE__ */ k("ul", {
|
|
442
|
+
className: "space-y-2",
|
|
443
|
+
children: Y.deliveries.map((t) => {
|
|
444
|
+
let n = String(t.status).toLowerCase();
|
|
445
|
+
return /* @__PURE__ */ A("li", {
|
|
446
|
+
className: "rounded-md border border-border-subtle px-3 py-2",
|
|
447
|
+
children: [
|
|
448
|
+
/* @__PURE__ */ A("div", {
|
|
449
|
+
className: "flex flex-wrap items-center justify-between gap-2",
|
|
450
|
+
children: [/* @__PURE__ */ A("div", {
|
|
451
|
+
className: "text-sm text-text-primary",
|
|
452
|
+
children: [/* @__PURE__ */ k("span", {
|
|
453
|
+
className: "font-medium",
|
|
454
|
+
children: t.farmName || t.farmWorkspaceId
|
|
455
|
+
}), t.deliveryWindow ? /* @__PURE__ */ k("span", {
|
|
456
|
+
className: "ml-2 text-xs text-text-secondary",
|
|
457
|
+
children: t.deliveryWindow
|
|
458
|
+
}) : null]
|
|
459
|
+
}), /* @__PURE__ */ k(i, {
|
|
460
|
+
variant: te(t.status),
|
|
461
|
+
label: g(t.status)
|
|
462
|
+
})]
|
|
463
|
+
}),
|
|
464
|
+
/* @__PURE__ */ A("div", {
|
|
465
|
+
className: "mt-1 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-text-secondary tabular-nums",
|
|
466
|
+
children: [
|
|
467
|
+
/* @__PURE__ */ A("span", { children: [
|
|
468
|
+
P("healthybowl.contracts.delivered", "Delivered"),
|
|
469
|
+
":",
|
|
470
|
+
" ",
|
|
471
|
+
m(t.deliveredQty, X.unit)
|
|
472
|
+
] }),
|
|
473
|
+
t.acceptedQty > 0 || n !== "scheduled" ? /* @__PURE__ */ A("span", { children: [
|
|
474
|
+
P("healthybowl.contracts.acceptedShort", "Accepted"),
|
|
475
|
+
":",
|
|
476
|
+
" ",
|
|
477
|
+
m(t.acceptedQty, X.unit)
|
|
478
|
+
] }) : null,
|
|
479
|
+
t.rejectedQty > 0 ? /* @__PURE__ */ A("span", {
|
|
480
|
+
className: "text-status-error-text",
|
|
481
|
+
children: [
|
|
482
|
+
P("healthybowl.contracts.rejectedShort", "Rejected"),
|
|
483
|
+
":",
|
|
484
|
+
" ",
|
|
485
|
+
m(t.rejectedQty, X.unit)
|
|
486
|
+
]
|
|
487
|
+
}) : null,
|
|
488
|
+
t.valuedAmount > 0 ? /* @__PURE__ */ k("span", { children: e(t.valuedAmount, "INR") }) : null
|
|
489
|
+
]
|
|
490
|
+
}),
|
|
491
|
+
/* @__PURE__ */ A("div", {
|
|
492
|
+
className: "mt-2 flex items-center gap-2",
|
|
493
|
+
children: [n === "scheduled" || n === "partial" || n === "accepted" ? /* @__PURE__ */ A(j, {
|
|
494
|
+
variant: "outline",
|
|
495
|
+
size: "sm",
|
|
496
|
+
onClick: () => J({
|
|
497
|
+
mode: "grade",
|
|
498
|
+
delivery: t
|
|
499
|
+
}),
|
|
500
|
+
children: [/* @__PURE__ */ k(ce, { className: "h-3.5 w-3.5" }), P("healthybowl.contracts.grade", "Grade")]
|
|
501
|
+
}) : null, n === "accepted" || n === "partial" ? /* @__PURE__ */ A(j, {
|
|
502
|
+
size: "sm",
|
|
503
|
+
onClick: () => J({
|
|
504
|
+
mode: "settle",
|
|
505
|
+
delivery: t
|
|
506
|
+
}),
|
|
507
|
+
children: [/* @__PURE__ */ k(b, { className: "h-3.5 w-3.5" }), P("healthybowl.contracts.settle", "Settle")]
|
|
508
|
+
}) : null]
|
|
509
|
+
})
|
|
510
|
+
]
|
|
511
|
+
}, t.id);
|
|
512
|
+
})
|
|
513
|
+
})] })
|
|
514
|
+
]
|
|
515
|
+
}) : null
|
|
516
|
+
})
|
|
517
|
+
]
|
|
518
|
+
}), Pe]
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
//#endregion
|
|
522
|
+
export { P as ContractsPage };
|
|
523
|
+
|
|
524
|
+
//# sourceMappingURL=ContractsPage.js.map
|