@open-mercato/core 0.10.1-develop.7723.1.3b2ea82ea7 → 0.10.1-develop.7726.1.a447cc5525
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/.turbo/turbo-build.log +1 -1
- package/dist/generated/entities/sales_order/index.js +2 -0
- package/dist/generated/entities/sales_order/index.js.map +2 -2
- package/dist/generated/entities/sales_order_line/index.js +2 -0
- package/dist/generated/entities/sales_order_line/index.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +2 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/planner/api/availability-date-specific.js +2 -7
- package/dist/modules/planner/api/availability-date-specific.js.map +2 -2
- package/dist/modules/planner/commands/availability-date-specific.js +14 -31
- package/dist/modules/planner/commands/availability-date-specific.js.map +2 -2
- package/dist/modules/planner/commands/availability-weekly.js +8 -22
- package/dist/modules/planner/commands/availability-weekly.js.map +2 -2
- package/dist/modules/planner/lib/availabilityMerge.js +10 -18
- package/dist/modules/planner/lib/availabilityMerge.js.map +2 -2
- package/dist/modules/planner/lib/availabilityTimezone.js +161 -0
- package/dist/modules/planner/lib/availabilityTimezone.js.map +7 -0
- package/dist/modules/sales/api/documents/factory.js +3 -0
- package/dist/modules/sales/api/documents/factory.js.map +2 -2
- package/dist/modules/sales/api/order-lines/route.js +2 -1
- package/dist/modules/sales/api/order-lines/route.js.map +2 -2
- package/dist/modules/sales/backend/sales/documents/[id]/page.js +83 -6
- package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +141 -18
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/commands/returns.js +24 -7
- package/dist/modules/sales/commands/returns.js.map +2 -2
- package/dist/modules/sales/components/documents/AdjustmentsSection.js +17 -11
- package/dist/modules/sales/components/documents/AdjustmentsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/DocumentTotals.js +21 -3
- package/dist/modules/sales/components/documents/DocumentTotals.js.map +2 -2
- package/dist/modules/sales/components/documents/ItemsSection.js +23 -12
- package/dist/modules/sales/components/documents/ItemsSection.js.map +2 -2
- package/dist/modules/sales/data/entities.js +10 -0
- package/dist/modules/sales/data/entities.js.map +2 -2
- package/dist/modules/sales/data/validators.js +9 -1
- package/dist/modules/sales/data/validators.js.map +2 -2
- package/dist/modules/sales/lib/calculations.js +85 -6
- package/dist/modules/sales/lib/calculations.js.map +2 -2
- package/dist/modules/sales/lib/externalAmounts.js +143 -0
- package/dist/modules/sales/lib/externalAmounts.js.map +7 -0
- package/dist/modules/sales/lib/lineSnapshots.js +6 -1
- package/dist/modules/sales/lib/lineSnapshots.js.map +2 -2
- package/dist/modules/sales/lib/makeSalesLineRoute.js +8 -2
- package/dist/modules/sales/lib/makeSalesLineRoute.js.map +2 -2
- package/dist/modules/sales/lib/providers/totals.js +3 -2
- package/dist/modules/sales/lib/providers/totals.js.map +2 -2
- package/dist/modules/sales/migrations/Migration20260910120000_sales_external_amounts_mode.js +19 -0
- package/dist/modules/sales/migrations/Migration20260910120000_sales_external_amounts_mode.js.map +7 -0
- package/generated/entities/sales_order/index.ts +1 -0
- package/generated/entities/sales_order_line/index.ts +1 -0
- package/generated/entity-fields-registry.ts +2 -0
- package/package.json +8 -7
- package/src/modules/planner/api/availability-date-specific.ts +5 -10
- package/src/modules/planner/commands/availability-date-specific.ts +14 -33
- package/src/modules/planner/commands/availability-weekly.ts +15 -24
- package/src/modules/planner/lib/availabilityMerge.ts +13 -19
- package/src/modules/planner/lib/availabilityTimezone.ts +242 -0
- package/src/modules/sales/api/documents/factory.ts +3 -0
- package/src/modules/sales/api/order-lines/route.ts +2 -1
- package/src/modules/sales/backend/sales/documents/[id]/page.tsx +96 -0
- package/src/modules/sales/commands/documents.ts +219 -44
- package/src/modules/sales/commands/returns.ts +27 -3
- package/src/modules/sales/components/documents/AdjustmentsSection.tsx +34 -25
- package/src/modules/sales/components/documents/DocumentTotals.tsx +26 -2
- package/src/modules/sales/components/documents/ItemsSection.tsx +27 -12
- package/src/modules/sales/data/entities.ts +14 -0
- package/src/modules/sales/data/validators.ts +10 -0
- package/src/modules/sales/i18n/de.json +12 -0
- package/src/modules/sales/i18n/en.json +12 -0
- package/src/modules/sales/i18n/es.json +12 -0
- package/src/modules/sales/i18n/ko.json +12 -0
- package/src/modules/sales/i18n/pl.json +12 -0
- package/src/modules/sales/lib/calculations.ts +99 -4
- package/src/modules/sales/lib/externalAmounts.ts +174 -0
- package/src/modules/sales/lib/lineSnapshots.ts +6 -1
- package/src/modules/sales/lib/makeSalesLineRoute.ts +8 -0
- package/src/modules/sales/lib/providers/totals.ts +5 -2
- package/src/modules/sales/lib/types.ts +19 -2
- package/src/modules/sales/migrations/.snapshot-open-mercato.json +33 -1
- package/src/modules/sales/migrations/Migration20260910120000_sales_external_amounts_mode.ts +25 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/sales/components/documents/AdjustmentsSection.tsx"],
|
|
4
|
-
"sourcesContent": ["// @ts-nocheck\n\n\"use client\"\n\nimport * as React from 'react'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport { Badge } from '@open-mercato/ui/primitives/badge'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { ErrorMessage, LoadingMessage, TabEmptyState } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useSalesDocumentMutation } from './useSalesDocumentMutation'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { createCrud, deleteCrud, updateCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { handleSectionMutationError } from './optimisticLock'\nimport { RowActions } from '@open-mercato/ui/backend/RowActions'\nimport { type DictionaryOption } from '@open-mercato/core/modules/dictionaries/components/DictionaryEntrySelect'\nimport {\n emitSalesDocumentTotalsRefresh,\n subscribeSalesDocumentTotalsRefresh,\n} from '@open-mercato/core/modules/sales/lib/frontend/documentTotalsEvents'\nimport type { SectionAction } from '@open-mercato/core/modules/customers/components/detail/types'\nimport type { SalesAdjustmentKind } from '../../data/entities'\nimport { PriceWithCurrency } from '../PriceWithCurrency'\nimport { AdjustmentDialog, type AdjustmentRowData, type AdjustmentSubmitPayload } from './AdjustmentDialog'\nimport { useT, useLocale } from '@open-mercato/shared/lib/i18n/context'\nimport { useOrganizationScopeDetail } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport { extractCustomFieldValues } from './customFieldHelpers'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('sales')\n\ntype AdjustmentRow = AdjustmentRowData\n\ntype SalesDocumentAdjustmentsSectionProps = {\n documentId: string\n kind: 'order' | 'quote'\n currencyCode: string | null | undefined\n documentUpdatedAt?: string | null\n organizationId?: string | null\n tenantId?: string | null\n onActionChange?: (action: SectionAction | null) => void\n onRowsChange?: (rows: AdjustmentRow[]) => void\n}\n\nconst FALLBACK_ADJUSTMENT_KIND_VALUES: SalesAdjustmentKind[] = [\n 'discount',\n 'tax',\n 'shipping',\n 'surcharge',\n 'custom',\n]\n\nfunction normalizeNumber(value: unknown, fallback = 0): number {\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string' && value.trim().length) {\n const parsed = Number(value)\n if (!Number.isNaN(parsed)) return parsed\n }\n return fallback\n}\n\nexport function formatPercent(value: number | null | undefined, locale?: string): string {\n if (value === null || value === undefined) return '\u2014'\n const formatter = new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 2 })\n return formatter.format(value / 100)\n}\n\nexport function SalesDocumentAdjustmentsSection({\n documentId,\n kind,\n currencyCode,\n documentUpdatedAt,\n organizationId: orgFromProps,\n tenantId: tenantFromProps,\n onActionChange,\n onRowsChange,\n}: SalesDocumentAdjustmentsSectionProps) {\n const t = useT()\n const runDocumentMutation = useSalesDocumentMutation(kind, documentId)\n const locale = useLocale()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n const resolvedOrganizationId = orgFromProps ?? organizationId ?? null\n const resolvedTenantId = tenantFromProps ?? tenantId ?? null\n const [rows, setRows] = React.useState<AdjustmentRow[]>([])\n const [loading, setLoading] = React.useState(false)\n const [error, setError] = React.useState<string | null>(null)\n const [dialogOpen, setDialogOpen] = React.useState(false)\n const [activeAdjustment, setActiveAdjustment] = React.useState<AdjustmentRow | null>(null)\n const [kindOptions, setKindOptions] = React.useState<DictionaryOption[]>([])\n const kindLoadingRef = React.useRef(false)\n\n const apiResourcePath = React.useMemo(\n () => (kind === 'order' ? '/api/sales/order-adjustments' : '/api/sales/quote-adjustments'),\n [kind]\n )\n const crudResourcePath = React.useMemo(\n () => (kind === 'order' ? 'sales/order-adjustments' : 'sales/quote-adjustments'),\n [kind]\n )\n const documentKey = kind === 'order' ? 'orderId' : 'quoteId'\n const fallbackKindOptions = React.useMemo<DictionaryOption[]>(\n () =>\n FALLBACK_ADJUSTMENT_KIND_VALUES.map((value) => ({\n value,\n label: t(`sales.documents.adjustments.kindLabels.${value}`, value),\n color: null,\n icon: null,\n })),\n [t]\n )\n const kindOptionMap = React.useMemo(\n () =>\n kindOptions.reduce<Record<string, DictionaryOption>>((acc, entry) => {\n acc[entry.value] = entry\n return acc\n }, {}),\n [kindOptions]\n )\n const loadKindOptions = React.useCallback(async (): Promise<DictionaryOption[]> => {\n if (kindOptions.length) return kindOptions\n if (kindLoadingRef.current) return kindOptions.length ? kindOptions : fallbackKindOptions\n kindLoadingRef.current = true\n try {\n const params = new URLSearchParams({ page: '1', pageSize: '100' })\n const response = await apiCall<{ items?: Array<Record<string, unknown>> }>(\n `/api/sales/adjustment-kinds?${params.toString()}`,\n undefined,\n { fallback: { items: [] } }\n )\n const items = Array.isArray(response.result?.items) ? response.result.items : []\n const parsed = items\n .map((item) => {\n const value = typeof (item as any).value === 'string' ? (item as any).value.trim() : ''\n if (!value) return null\n const label =\n typeof (item as any).label === 'string' && (item as any).label.trim().length\n ? (item as any).label.trim()\n : value\n const color =\n typeof (item as any).color === 'string' && /^#([0-9a-fA-F]{6})$/.test((item as any).color)\n ? `#${(item as any).color.slice(1).toLowerCase()}`\n : null\n const icon =\n typeof (item as any).icon === 'string' && (item as any).icon.trim().length\n ? (item as any).icon.trim()\n : null\n return { value, label, color, icon }\n })\n .filter((entry): entry is DictionaryOption => Boolean(entry))\n const merged = new Map<string, DictionaryOption>()\n fallbackKindOptions.forEach((entry) => merged.set(entry.value, entry))\n parsed.forEach((entry) => merged.set(entry.value, entry))\n const options = Array.from(merged.values()).sort((a, b) =>\n a.label.localeCompare(b.label, undefined, { sensitivity: 'base' })\n )\n setKindOptions(options)\n kindLoadingRef.current = false\n return options\n } catch (err) {\n logger.error('sales.adjustment-kinds.fetch', { err })\n kindLoadingRef.current = false\n setKindOptions(fallbackKindOptions)\n return fallbackKindOptions\n }\n }, [fallbackKindOptions, kindOptions])\n\n React.useEffect(() => {\n loadKindOptions().catch(() => {})\n }, [loadKindOptions, resolvedOrganizationId, resolvedTenantId])\n\n const loadAdjustments = React.useCallback(async () => {\n setLoading(true)\n setError(null)\n try {\n const params = new URLSearchParams({ page: '1', pageSize: '100', [documentKey]: documentId })\n const response = await apiCall<{ items?: Array<Record<string, unknown>> }>(\n `${apiResourcePath}?${params.toString()}`,\n undefined,\n { fallback: { items: [] } }\n )\n const items = Array.isArray(response.result?.items) ? response.result.items : []\n const mapped: AdjustmentRow[] = items\n .map((item) => {\n const id = typeof item.id === 'string' ? item.id : null\n if (!id) return null\n const amountNet = normalizeNumber(\n (item as any).amount_net ?? (item as any).amountNet ?? (item as any).amount_net_amount,\n NaN\n )\n const amountGross = normalizeNumber(\n (item as any).amount_gross ?? (item as any).amountGross ?? (item as any).amount_gross_amount,\n NaN\n )\n const rateRaw = normalizeNumber((item as any).rate, NaN)\n const kindValue =\n typeof item.kind === 'string' && item.kind.trim().length\n ? (item.kind.trim() as SalesAdjustmentKind)\n : 'custom'\n const currency =\n typeof (item as any).currency_code === 'string'\n ? (item as any).currency_code\n : typeof (item as any).currencyCode === 'string'\n ? (item as any).currencyCode\n : currencyCode ?? null\n const customFields = extractCustomFieldValues(item as Record<string, unknown>)\n const customFieldSetId =\n typeof (item as any).custom_field_set_id === 'string'\n ? (item as any).custom_field_set_id\n : typeof (item as any).customFieldSetId === 'string'\n ? (item as any).customFieldSetId\n : null\n const metadata =\n typeof (item as any).metadata === 'object' && (item as any).metadata\n ? ((item as any).metadata as Record<string, unknown>)\n : null\n return {\n id,\n label: typeof item.label === 'string' ? item.label : null,\n code: typeof item.code === 'string' ? item.code : null,\n kind: kindValue,\n calculatorKey:\n typeof (item as any).calculator_key === 'string'\n ? (item as any).calculator_key\n : typeof (item as any).calculatorKey === 'string'\n ? (item as any).calculatorKey\n : null,\n rate: Number.isFinite(rateRaw) ? rateRaw : null,\n amountNet: Number.isFinite(amountNet) ? amountNet : null,\n amountGross: Number.isFinite(amountGross) ? amountGross : null,\n currencyCode: currency,\n position:\n typeof item.position === 'number'\n ? item.position\n : typeof (item as any).position === 'string'\n ? Number((item as any).position)\n : 0,\n customFields: Object.keys(customFields).length ? customFields : null,\n customFieldSetId,\n metadata,\n }\n })\n .filter((entry): entry is AdjustmentRow => Boolean(entry))\n const ordered = [...mapped].sort((a, b) => (a.position ?? 0) - (b.position ?? 0))\n setRows(ordered)\n if (onRowsChange) onRowsChange(ordered)\n } catch (err) {\n logger.error('sales.document.adjustments.load', { err })\n setError(t('sales.documents.adjustments.errorLoad', 'Failed to load adjustments.'))\n } finally {\n setLoading(false)\n }\n }, [apiResourcePath, currencyCode, documentId, documentKey, onRowsChange, t])\n\n React.useEffect(() => {\n void loadAdjustments()\n }, [loadAdjustments])\n\n React.useEffect(\n () =>\n subscribeSalesDocumentTotalsRefresh((detail) => {\n if (detail.documentId !== documentId) return\n if (detail.kind && detail.kind !== kind) return\n void loadAdjustments()\n }),\n [documentId, kind, loadAdjustments],\n )\n\n const resolveKindLabel = React.useCallback(\n (kindValue: SalesAdjustmentKind) => {\n const option = kindOptionMap[kindValue]\n if (option) return option.label\n return t(`sales.documents.adjustments.kindLabels.${kindValue}`, typeof kindValue === 'string' ? kindValue : String(kindValue))\n },\n [kindOptionMap, t]\n )\n\n const handleOpenCreate = React.useCallback(() => {\n setActiveAdjustment(null)\n setDialogOpen(true)\n }, [])\n\n const handleEdit = React.useCallback((row: AdjustmentRow) => {\n setActiveAdjustment(row)\n setDialogOpen(true)\n }, [])\n\n const handleCloseDialog = React.useCallback(() => {\n setDialogOpen(false)\n setActiveAdjustment(null)\n }, [])\n\n React.useEffect(() => {\n if (!onActionChange) return\n onActionChange({\n label: t('sales.documents.adjustments.add', 'Add adjustment'),\n onClick: handleOpenCreate,\n disabled: false,\n })\n return () => onActionChange(null)\n }, [handleOpenCreate, onActionChange, t])\n\n const handleFormSubmit = React.useCallback(\n async (values: AdjustmentSubmitPayload) => {\n if (!resolvedOrganizationId || !resolvedTenantId) {\n throw createCrudFormError(\n t('sales.documents.adjustments.errorScope', 'Organization and tenant are required.')\n )\n }\n const payload: Record<string, unknown> = {\n [documentKey]: String(documentId),\n organizationId: String(resolvedOrganizationId),\n tenantId: String(resolvedTenantId),\n scope: 'order',\n kind: values.kind ?? 'custom',\n code: values.code ?? undefined,\n label: values.label ?? undefined,\n calculatorKey: values.calculatorKey ?? undefined,\n rate: Number.isFinite(values.rate) ? values.rate : undefined,\n amountNet: Number.isFinite(values.amountNet) ? values.amountNet : undefined,\n amountGross: Number.isFinite(values.amountGross) ? values.amountGross : undefined,\n currencyCode: (values.currencyCode ?? currencyCode ?? '').toUpperCase(),\n position: Number.isFinite(values.position) ? values.position : undefined,\n customFields: values.customFields ?? undefined,\n metadata: values.metadata ?? undefined,\n }\n\n const action = values.id ? updateCrud : createCrud\n try {\n const result = await runDocumentMutation(() => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(documentUpdatedAt),\n () =>\n action(\n crudResourcePath,\n values.id ? { id: values.id, ...payload } : payload,\n {\n successMessage: values.id\n ? t('sales.documents.adjustments.updated', 'Adjustment updated.')\n : t('sales.documents.adjustments.created', 'Adjustment added.'),\n errorMessage: t('sales.documents.adjustments.errorSave', 'Failed to save adjustment.'),\n }\n )\n ), values.id ? { id: values.id, ...payload } : payload)\n if (result.ok) {\n await loadAdjustments()\n emitSalesDocumentTotalsRefresh({ documentId, kind })\n setDialogOpen(false)\n setActiveAdjustment(null)\n }\n } catch (err) {\n if (\n handleSectionMutationError(err, t, () => void loadAdjustments())\n ) {\n setDialogOpen(false)\n setActiveAdjustment(null)\n return\n }\n throw err\n }\n },\n [\n currencyCode,\n documentId,\n documentKey,\n documentUpdatedAt,\n kind,\n loadAdjustments,\n crudResourcePath,\n resolvedOrganizationId,\n resolvedTenantId,\n runDocumentMutation,\n t,\n ]\n )\n\n const handleDelete = React.useCallback(\n async (row: AdjustmentRow) => {\n try {\n const result = await runDocumentMutation(() => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(documentUpdatedAt),\n () =>\n deleteCrud(crudResourcePath, {\n body: {\n id: row.id,\n [documentKey]: documentId,\n organizationId: resolvedOrganizationId ?? undefined,\n tenantId: resolvedTenantId ?? undefined,\n },\n errorMessage: t('sales.documents.adjustments.errorDelete', 'Failed to delete adjustment.'),\n })\n ), { id: row.id, [documentKey]: documentId })\n if (result.ok) {\n await loadAdjustments()\n emitSalesDocumentTotalsRefresh({ documentId, kind })\n }\n } catch (err) {\n if (handleSectionMutationError(err, t, () => void loadAdjustments())) return\n logger.error('sales.document.adjustments.delete', { err })\n flash(t('sales.documents.adjustments.errorDelete', 'Failed to delete adjustment.'), 'error')\n }\n },\n [crudResourcePath, documentId, documentKey, documentUpdatedAt, kind, loadAdjustments, resolvedOrganizationId, resolvedTenantId, runDocumentMutation, t]\n )\n\n const columns = React.useMemo<ColumnDef<AdjustmentRow>[]>(\n () => [\n {\n id: 'label',\n header: t('sales.documents.adjustments.label', 'Label'),\n cell: ({ row }) => (\n <div className=\"flex flex-col\">\n <span className=\"font-medium text-foreground\">{row.original.label ?? t('sales.documents.adjustments.untitled', 'Untitled')}</span>\n {row.original.code ? <span className=\"text-xs text-muted-foreground\">{row.original.code}</span> : null}\n </div>\n ),\n },\n {\n id: 'kind',\n header: t('sales.documents.adjustments.kindLabel', 'Kind'),\n cell: ({ row }) => <Badge variant=\"outline\">{resolveKindLabel(row.original.kind)}</Badge>,\n },\n {\n id: 'amountNet',\n header: t('sales.documents.adjustments.amountNet', 'Net amount'),\n cell: ({ row }) => (\n <PriceWithCurrency amount={row.original.amountNet} currency={row.original.currencyCode ?? currencyCode} className=\"font-mono text-sm\" />\n ),\n },\n {\n id: 'amountGross',\n header: t('sales.documents.adjustments.amountGross', 'Gross amount'),\n cell: ({ row }) => (\n <PriceWithCurrency amount={row.original.amountGross} currency={row.original.currencyCode ?? currencyCode} className=\"font-mono text-sm\" />\n ),\n },\n {\n id: 'rate',\n header: t('sales.documents.adjustments.rate', 'Rate'),\n cell: ({ row }) => <span className=\"font-mono text-sm text-muted-foreground\">{formatPercent(row.original.rate, locale)}</span>,\n },\n {\n id: 'position',\n header: t('sales.documents.adjustments.position', 'Position'),\n cell: ({ row }) => <span className=\"text-sm text-muted-foreground\">{row.original.position}</span>,\n },\n ],\n [currencyCode, locale, resolveKindLabel, t]\n )\n\n const showLoadingState = loading && rows.length === 0\n\n const renderRowActions = React.useCallback(\n (row: AdjustmentRow) => (\n <RowActions\n items={[\n {\n id: 'edit',\n label: t('ui.actions.edit', 'Edit'),\n onSelect: () => handleEdit(row),\n },\n {\n id: 'delete',\n label: t('ui.actions.delete', 'Delete'),\n destructive: true,\n onSelect: () => handleDelete(row),\n },\n ]}\n />\n ),\n [handleDelete, handleEdit, t]\n )\n\n return (\n <div className=\"space-y-4\">\n {error ? (\n <ErrorMessage title={t('sales.documents.adjustments.errorLoad', 'Failed to load adjustments.')} description={error} onRetry={() => void loadAdjustments()} />\n ) : null}\n {showLoadingState ? (\n <LoadingMessage\n label={t('sales.documents.adjustments.loading', 'Loading adjustments\u2026')}\n className=\"border-0 bg-transparent p-0 py-8 justify-center\"\n />\n ) : (\n <DataTable<AdjustmentRow>\n data={rows}\n columns={columns}\n isLoading={loading && rows.length > 0}\n embedded\n onRowClick={handleEdit}\n rowActions={renderRowActions}\n emptyState={\n <TabEmptyState\n title={t('sales.documents.empty.adjustments.title', 'No adjustments yet.')}\n description={t('sales.documents.empty.adjustments.description', 'Add discounts, fees, or taxes to refine totals.')}\n actionLabel={t('sales.documents.adjustments.add', 'Add adjustment')}\n onAction={handleOpenCreate}\n />\n }\n />\n )}\n\n <AdjustmentDialog\n open={dialogOpen}\n onOpenChange={(open) => {\n if (!open) {\n handleCloseDialog()\n } else {\n setDialogOpen(true)\n }\n }}\n kind={kind}\n currencyCode={currencyCode ?? null}\n kindOptions={kindOptions.length ? kindOptions : fallbackKindOptions}\n loadKindOptions={loadKindOptions}\n labels={{\n addTitle: t('sales.documents.adjustments.addTitle', 'Add adjustment'),\n editTitle: t('sales.documents.adjustments.editTitle', 'Edit adjustment'),\n submitCreate: t('sales.documents.adjustments.submitCreate', 'Add adjustment'),\n submitUpdate: t('sales.documents.adjustments.submitUpdate', 'Save changes'),\n }}\n initialAdjustment={activeAdjustment}\n onSubmit={handleFormSubmit}\n />\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AA2ZU,SACE,KADF;AAvZV,YAAY,WAAW;AAEvB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,cAAc,gBAAgB,qBAAqB;AAC5D,SAAS,aAAa;AACtB,SAAS,SAAS,mCAAmC;AACrD,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,YAAY,YAAY,kBAAkB;AACnD,SAAS,2BAA2B;AACpC,SAAS,kCAAkC;AAC3C,SAAS,kBAAkB;AAE3B;AAAA,EACE;AAAA,EACA;AAAA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c;AAAA,QAChD;AAAA,QACA,QAAQ;AAAA,UACN,UAAU,EAAE,wCAAwC,gBAAgB;AAAA,UACpE,WAAW,EAAE,yCAAyC,iBAAiB;AAAA,UACvE,cAAc,EAAE,4CAA4C,gBAAgB;AAAA,UAC5E,cAAc,EAAE,4CAA4C,cAAc;AAAA,QAC5E;AAAA,QACA,mBAAmB;AAAA,QACnB,UAAU;AAAA;AAAA,IACZ;AAAA,KACF;AAEJ;",
|
|
4
|
+
"sourcesContent": ["// @ts-nocheck\n\n\"use client\"\n\nimport * as React from 'react'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport { Badge } from '@open-mercato/ui/primitives/badge'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { ErrorMessage, LoadingMessage, TabEmptyState } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useSalesDocumentMutation } from './useSalesDocumentMutation'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { createCrud, deleteCrud, updateCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { handleSectionMutationError } from './optimisticLock'\nimport { RowActions } from '@open-mercato/ui/backend/RowActions'\nimport { type DictionaryOption } from '@open-mercato/core/modules/dictionaries/components/DictionaryEntrySelect'\nimport {\n emitSalesDocumentTotalsRefresh,\n subscribeSalesDocumentTotalsRefresh,\n} from '@open-mercato/core/modules/sales/lib/frontend/documentTotalsEvents'\nimport type { SectionAction } from '@open-mercato/core/modules/customers/components/detail/types'\nimport type { SalesAdjustmentKind } from '../../data/entities'\nimport { PriceWithCurrency } from '../PriceWithCurrency'\nimport { AdjustmentDialog, type AdjustmentRowData, type AdjustmentSubmitPayload } from './AdjustmentDialog'\nimport { useT, useLocale } from '@open-mercato/shared/lib/i18n/context'\nimport { useOrganizationScopeDetail } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport { extractCustomFieldValues } from './customFieldHelpers'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('sales')\n\ntype AdjustmentRow = AdjustmentRowData\n\ntype SalesDocumentAdjustmentsSectionProps = {\n documentId: string\n kind: 'order' | 'quote'\n currencyCode: string | null | undefined\n documentUpdatedAt?: string | null\n organizationId?: string | null\n tenantId?: string | null\n onActionChange?: (action: SectionAction | null) => void\n onRowsChange?: (rows: AdjustmentRow[]) => void\n /** Withdraws adjustment writes: on an external order they would all be refused. */\n amountsReadOnly?: boolean\n}\n\nconst FALLBACK_ADJUSTMENT_KIND_VALUES: SalesAdjustmentKind[] = [\n 'discount',\n 'tax',\n 'shipping',\n 'surcharge',\n 'custom',\n]\n\nfunction normalizeNumber(value: unknown, fallback = 0): number {\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string' && value.trim().length) {\n const parsed = Number(value)\n if (!Number.isNaN(parsed)) return parsed\n }\n return fallback\n}\n\nexport function formatPercent(value: number | null | undefined, locale?: string): string {\n if (value === null || value === undefined) return '\u2014'\n const formatter = new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 2 })\n return formatter.format(value / 100)\n}\n\nexport function SalesDocumentAdjustmentsSection({\n documentId,\n kind,\n currencyCode,\n documentUpdatedAt,\n organizationId: orgFromProps,\n tenantId: tenantFromProps,\n onActionChange,\n onRowsChange,\n amountsReadOnly = false,\n}: SalesDocumentAdjustmentsSectionProps) {\n const t = useT()\n const runDocumentMutation = useSalesDocumentMutation(kind, documentId)\n const locale = useLocale()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n const resolvedOrganizationId = orgFromProps ?? organizationId ?? null\n const resolvedTenantId = tenantFromProps ?? tenantId ?? null\n const [rows, setRows] = React.useState<AdjustmentRow[]>([])\n const [loading, setLoading] = React.useState(false)\n const [error, setError] = React.useState<string | null>(null)\n const [dialogOpen, setDialogOpen] = React.useState(false)\n const [activeAdjustment, setActiveAdjustment] = React.useState<AdjustmentRow | null>(null)\n const [kindOptions, setKindOptions] = React.useState<DictionaryOption[]>([])\n const kindLoadingRef = React.useRef(false)\n\n const apiResourcePath = React.useMemo(\n () => (kind === 'order' ? '/api/sales/order-adjustments' : '/api/sales/quote-adjustments'),\n [kind]\n )\n const crudResourcePath = React.useMemo(\n () => (kind === 'order' ? 'sales/order-adjustments' : 'sales/quote-adjustments'),\n [kind]\n )\n const documentKey = kind === 'order' ? 'orderId' : 'quoteId'\n const fallbackKindOptions = React.useMemo<DictionaryOption[]>(\n () =>\n FALLBACK_ADJUSTMENT_KIND_VALUES.map((value) => ({\n value,\n label: t(`sales.documents.adjustments.kindLabels.${value}`, value),\n color: null,\n icon: null,\n })),\n [t]\n )\n const kindOptionMap = React.useMemo(\n () =>\n kindOptions.reduce<Record<string, DictionaryOption>>((acc, entry) => {\n acc[entry.value] = entry\n return acc\n }, {}),\n [kindOptions]\n )\n const loadKindOptions = React.useCallback(async (): Promise<DictionaryOption[]> => {\n if (kindOptions.length) return kindOptions\n if (kindLoadingRef.current) return kindOptions.length ? kindOptions : fallbackKindOptions\n kindLoadingRef.current = true\n try {\n const params = new URLSearchParams({ page: '1', pageSize: '100' })\n const response = await apiCall<{ items?: Array<Record<string, unknown>> }>(\n `/api/sales/adjustment-kinds?${params.toString()}`,\n undefined,\n { fallback: { items: [] } }\n )\n const items = Array.isArray(response.result?.items) ? response.result.items : []\n const parsed = items\n .map((item) => {\n const value = typeof (item as any).value === 'string' ? (item as any).value.trim() : ''\n if (!value) return null\n const label =\n typeof (item as any).label === 'string' && (item as any).label.trim().length\n ? (item as any).label.trim()\n : value\n const color =\n typeof (item as any).color === 'string' && /^#([0-9a-fA-F]{6})$/.test((item as any).color)\n ? `#${(item as any).color.slice(1).toLowerCase()}`\n : null\n const icon =\n typeof (item as any).icon === 'string' && (item as any).icon.trim().length\n ? (item as any).icon.trim()\n : null\n return { value, label, color, icon }\n })\n .filter((entry): entry is DictionaryOption => Boolean(entry))\n const merged = new Map<string, DictionaryOption>()\n fallbackKindOptions.forEach((entry) => merged.set(entry.value, entry))\n parsed.forEach((entry) => merged.set(entry.value, entry))\n const options = Array.from(merged.values()).sort((a, b) =>\n a.label.localeCompare(b.label, undefined, { sensitivity: 'base' })\n )\n setKindOptions(options)\n kindLoadingRef.current = false\n return options\n } catch (err) {\n logger.error('sales.adjustment-kinds.fetch', { err })\n kindLoadingRef.current = false\n setKindOptions(fallbackKindOptions)\n return fallbackKindOptions\n }\n }, [fallbackKindOptions, kindOptions])\n\n React.useEffect(() => {\n loadKindOptions().catch(() => {})\n }, [loadKindOptions, resolvedOrganizationId, resolvedTenantId])\n\n const loadAdjustments = React.useCallback(async () => {\n setLoading(true)\n setError(null)\n try {\n const params = new URLSearchParams({ page: '1', pageSize: '100', [documentKey]: documentId })\n const response = await apiCall<{ items?: Array<Record<string, unknown>> }>(\n `${apiResourcePath}?${params.toString()}`,\n undefined,\n { fallback: { items: [] } }\n )\n const items = Array.isArray(response.result?.items) ? response.result.items : []\n const mapped: AdjustmentRow[] = items\n .map((item) => {\n const id = typeof item.id === 'string' ? item.id : null\n if (!id) return null\n const amountNet = normalizeNumber(\n (item as any).amount_net ?? (item as any).amountNet ?? (item as any).amount_net_amount,\n NaN\n )\n const amountGross = normalizeNumber(\n (item as any).amount_gross ?? (item as any).amountGross ?? (item as any).amount_gross_amount,\n NaN\n )\n const rateRaw = normalizeNumber((item as any).rate, NaN)\n const kindValue =\n typeof item.kind === 'string' && item.kind.trim().length\n ? (item.kind.trim() as SalesAdjustmentKind)\n : 'custom'\n const currency =\n typeof (item as any).currency_code === 'string'\n ? (item as any).currency_code\n : typeof (item as any).currencyCode === 'string'\n ? (item as any).currencyCode\n : currencyCode ?? null\n const customFields = extractCustomFieldValues(item as Record<string, unknown>)\n const customFieldSetId =\n typeof (item as any).custom_field_set_id === 'string'\n ? (item as any).custom_field_set_id\n : typeof (item as any).customFieldSetId === 'string'\n ? (item as any).customFieldSetId\n : null\n const metadata =\n typeof (item as any).metadata === 'object' && (item as any).metadata\n ? ((item as any).metadata as Record<string, unknown>)\n : null\n return {\n id,\n label: typeof item.label === 'string' ? item.label : null,\n code: typeof item.code === 'string' ? item.code : null,\n kind: kindValue,\n calculatorKey:\n typeof (item as any).calculator_key === 'string'\n ? (item as any).calculator_key\n : typeof (item as any).calculatorKey === 'string'\n ? (item as any).calculatorKey\n : null,\n rate: Number.isFinite(rateRaw) ? rateRaw : null,\n amountNet: Number.isFinite(amountNet) ? amountNet : null,\n amountGross: Number.isFinite(amountGross) ? amountGross : null,\n currencyCode: currency,\n position:\n typeof item.position === 'number'\n ? item.position\n : typeof (item as any).position === 'string'\n ? Number((item as any).position)\n : 0,\n customFields: Object.keys(customFields).length ? customFields : null,\n customFieldSetId,\n metadata,\n }\n })\n .filter((entry): entry is AdjustmentRow => Boolean(entry))\n const ordered = [...mapped].sort((a, b) => (a.position ?? 0) - (b.position ?? 0))\n setRows(ordered)\n if (onRowsChange) onRowsChange(ordered)\n } catch (err) {\n logger.error('sales.document.adjustments.load', { err })\n setError(t('sales.documents.adjustments.errorLoad', 'Failed to load adjustments.'))\n } finally {\n setLoading(false)\n }\n }, [apiResourcePath, currencyCode, documentId, documentKey, onRowsChange, t])\n\n React.useEffect(() => {\n void loadAdjustments()\n }, [loadAdjustments])\n\n React.useEffect(\n () =>\n subscribeSalesDocumentTotalsRefresh((detail) => {\n if (detail.documentId !== documentId) return\n if (detail.kind && detail.kind !== kind) return\n void loadAdjustments()\n }),\n [documentId, kind, loadAdjustments],\n )\n\n const resolveKindLabel = React.useCallback(\n (kindValue: SalesAdjustmentKind) => {\n const option = kindOptionMap[kindValue]\n if (option) return option.label\n return t(`sales.documents.adjustments.kindLabels.${kindValue}`, typeof kindValue === 'string' ? kindValue : String(kindValue))\n },\n [kindOptionMap, t]\n )\n\n const handleOpenCreate = React.useCallback(() => {\n setActiveAdjustment(null)\n setDialogOpen(true)\n }, [])\n\n const handleEdit = React.useCallback(\n (row: AdjustmentRow) => {\n if (amountsReadOnly) return\n setActiveAdjustment(row)\n setDialogOpen(true)\n },\n [amountsReadOnly]\n )\n\n const handleCloseDialog = React.useCallback(() => {\n setDialogOpen(false)\n setActiveAdjustment(null)\n }, [])\n\n React.useEffect(() => {\n if (!onActionChange) return\n onActionChange({\n label: t('sales.documents.adjustments.add', 'Add adjustment'),\n onClick: handleOpenCreate,\n disabled: amountsReadOnly,\n })\n return () => onActionChange(null)\n }, [amountsReadOnly, handleOpenCreate, onActionChange, t])\n\n const handleFormSubmit = React.useCallback(\n async (values: AdjustmentSubmitPayload) => {\n if (!resolvedOrganizationId || !resolvedTenantId) {\n throw createCrudFormError(\n t('sales.documents.adjustments.errorScope', 'Organization and tenant are required.')\n )\n }\n const payload: Record<string, unknown> = {\n [documentKey]: String(documentId),\n organizationId: String(resolvedOrganizationId),\n tenantId: String(resolvedTenantId),\n scope: 'order',\n kind: values.kind ?? 'custom',\n code: values.code ?? undefined,\n label: values.label ?? undefined,\n calculatorKey: values.calculatorKey ?? undefined,\n rate: Number.isFinite(values.rate) ? values.rate : undefined,\n amountNet: Number.isFinite(values.amountNet) ? values.amountNet : undefined,\n amountGross: Number.isFinite(values.amountGross) ? values.amountGross : undefined,\n currencyCode: (values.currencyCode ?? currencyCode ?? '').toUpperCase(),\n position: Number.isFinite(values.position) ? values.position : undefined,\n customFields: values.customFields ?? undefined,\n metadata: values.metadata ?? undefined,\n }\n\n const action = values.id ? updateCrud : createCrud\n try {\n const result = await runDocumentMutation(() => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(documentUpdatedAt),\n () =>\n action(\n crudResourcePath,\n values.id ? { id: values.id, ...payload } : payload,\n {\n successMessage: values.id\n ? t('sales.documents.adjustments.updated', 'Adjustment updated.')\n : t('sales.documents.adjustments.created', 'Adjustment added.'),\n errorMessage: t('sales.documents.adjustments.errorSave', 'Failed to save adjustment.'),\n }\n )\n ), values.id ? { id: values.id, ...payload } : payload)\n if (result.ok) {\n await loadAdjustments()\n emitSalesDocumentTotalsRefresh({ documentId, kind })\n setDialogOpen(false)\n setActiveAdjustment(null)\n }\n } catch (err) {\n if (\n handleSectionMutationError(err, t, () => void loadAdjustments())\n ) {\n setDialogOpen(false)\n setActiveAdjustment(null)\n return\n }\n throw err\n }\n },\n [\n currencyCode,\n documentId,\n documentKey,\n documentUpdatedAt,\n kind,\n loadAdjustments,\n crudResourcePath,\n resolvedOrganizationId,\n resolvedTenantId,\n runDocumentMutation,\n t,\n ]\n )\n\n const handleDelete = React.useCallback(\n async (row: AdjustmentRow) => {\n try {\n const result = await runDocumentMutation(() => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(documentUpdatedAt),\n () =>\n deleteCrud(crudResourcePath, {\n body: {\n id: row.id,\n [documentKey]: documentId,\n organizationId: resolvedOrganizationId ?? undefined,\n tenantId: resolvedTenantId ?? undefined,\n },\n errorMessage: t('sales.documents.adjustments.errorDelete', 'Failed to delete adjustment.'),\n })\n ), { id: row.id, [documentKey]: documentId })\n if (result.ok) {\n await loadAdjustments()\n emitSalesDocumentTotalsRefresh({ documentId, kind })\n }\n } catch (err) {\n if (handleSectionMutationError(err, t, () => void loadAdjustments())) return\n logger.error('sales.document.adjustments.delete', { err })\n flash(t('sales.documents.adjustments.errorDelete', 'Failed to delete adjustment.'), 'error')\n }\n },\n [crudResourcePath, documentId, documentKey, documentUpdatedAt, kind, loadAdjustments, resolvedOrganizationId, resolvedTenantId, runDocumentMutation, t]\n )\n\n const columns = React.useMemo<ColumnDef<AdjustmentRow>[]>(\n () => [\n {\n id: 'label',\n header: t('sales.documents.adjustments.label', 'Label'),\n cell: ({ row }) => (\n <div className=\"flex flex-col\">\n <span className=\"font-medium text-foreground\">{row.original.label ?? t('sales.documents.adjustments.untitled', 'Untitled')}</span>\n {row.original.code ? <span className=\"text-xs text-muted-foreground\">{row.original.code}</span> : null}\n </div>\n ),\n },\n {\n id: 'kind',\n header: t('sales.documents.adjustments.kindLabel', 'Kind'),\n cell: ({ row }) => <Badge variant=\"outline\">{resolveKindLabel(row.original.kind)}</Badge>,\n },\n {\n id: 'amountNet',\n header: t('sales.documents.adjustments.amountNet', 'Net amount'),\n cell: ({ row }) => (\n <PriceWithCurrency amount={row.original.amountNet} currency={row.original.currencyCode ?? currencyCode} className=\"font-mono text-sm\" />\n ),\n },\n {\n id: 'amountGross',\n header: t('sales.documents.adjustments.amountGross', 'Gross amount'),\n cell: ({ row }) => (\n <PriceWithCurrency amount={row.original.amountGross} currency={row.original.currencyCode ?? currencyCode} className=\"font-mono text-sm\" />\n ),\n },\n {\n id: 'rate',\n header: t('sales.documents.adjustments.rate', 'Rate'),\n cell: ({ row }) => <span className=\"font-mono text-sm text-muted-foreground\">{formatPercent(row.original.rate, locale)}</span>,\n },\n {\n id: 'position',\n header: t('sales.documents.adjustments.position', 'Position'),\n cell: ({ row }) => <span className=\"text-sm text-muted-foreground\">{row.original.position}</span>,\n },\n ],\n [currencyCode, locale, resolveKindLabel, t]\n )\n\n const showLoadingState = loading && rows.length === 0\n\n const renderRowActions = React.useCallback(\n (row: AdjustmentRow) =>\n amountsReadOnly ? null : (\n <RowActions\n items={[\n {\n id: 'edit',\n label: t('ui.actions.edit', 'Edit'),\n onSelect: () => handleEdit(row),\n },\n {\n id: 'delete',\n label: t('ui.actions.delete', 'Delete'),\n destructive: true,\n onSelect: () => handleDelete(row),\n },\n ]}\n />\n ),\n [amountsReadOnly, handleDelete, handleEdit, t]\n )\n\n return (\n <div className=\"space-y-4\">\n {error ? (\n <ErrorMessage title={t('sales.documents.adjustments.errorLoad', 'Failed to load adjustments.')} description={error} onRetry={() => void loadAdjustments()} />\n ) : null}\n {showLoadingState ? (\n <LoadingMessage\n label={t('sales.documents.adjustments.loading', 'Loading adjustments\u2026')}\n className=\"border-0 bg-transparent p-0 py-8 justify-center\"\n />\n ) : (\n <DataTable<AdjustmentRow>\n data={rows}\n columns={columns}\n isLoading={loading && rows.length > 0}\n embedded\n onRowClick={amountsReadOnly ? undefined : handleEdit}\n rowActions={renderRowActions}\n emptyState={\n <TabEmptyState\n title={t('sales.documents.empty.adjustments.title', 'No adjustments yet.')}\n description={t('sales.documents.empty.adjustments.description', 'Add discounts, fees, or taxes to refine totals.')}\n actionLabel={t('sales.documents.adjustments.add', 'Add adjustment')}\n onAction={handleOpenCreate}\n disabled={amountsReadOnly}\n />\n }\n />\n )}\n\n <AdjustmentDialog\n open={dialogOpen}\n onOpenChange={(open) => {\n if (!open) {\n handleCloseDialog()\n } else {\n setDialogOpen(true)\n }\n }}\n kind={kind}\n currencyCode={currencyCode ?? null}\n kindOptions={kindOptions.length ? kindOptions : fallbackKindOptions}\n loadKindOptions={loadKindOptions}\n labels={{\n addTitle: t('sales.documents.adjustments.addTitle', 'Add adjustment'),\n editTitle: t('sales.documents.adjustments.editTitle', 'Edit adjustment'),\n submitCreate: t('sales.documents.adjustments.submitCreate', 'Add adjustment'),\n submitUpdate: t('sales.documents.adjustments.submitUpdate', 'Save changes'),\n }}\n initialAdjustment={activeAdjustment}\n onSubmit={handleFormSubmit}\n />\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAkaU,SACE,KADF;AA9ZV,YAAY,WAAW;AAEvB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,cAAc,gBAAgB,qBAAqB;AAC5D,SAAS,aAAa;AACtB,SAAS,SAAS,mCAAmC;AACrD,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,YAAY,YAAY,kBAAkB;AACnD,SAAS,2BAA2B;AACpC,SAAS,kCAAkC;AAC3C,SAAS,kBAAkB;AAE3B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP,SAAS,yBAAyB;AAClC,SAAS,wBAA8E;AACvF,SAAS,MAAM,iBAAiB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,OAAO;AAiBnC,MAAM,k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AE,wCAAwC,gBAAgB;AAAA,UACpE,WAAW,EAAE,yCAAyC,iBAAiB;AAAA,UACvE,cAAc,EAAE,4CAA4C,gBAAgB;AAAA,UAC5E,cAAc,EAAE,4CAA4C,cAAc;AAAA,QAC5E;AAAA,QACA,mBAAmB;AAAA,QACnB,UAAU;AAAA;AAAA,IACZ;AAAA,KACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,7 +4,14 @@ import * as React from "react";
|
|
|
4
4
|
import { cn } from "@open-mercato/shared/lib/utils";
|
|
5
5
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
6
|
import { PriceWithCurrency } from "../PriceWithCurrency.js";
|
|
7
|
-
function DocumentTotals({
|
|
7
|
+
function DocumentTotals({
|
|
8
|
+
title,
|
|
9
|
+
currency,
|
|
10
|
+
items,
|
|
11
|
+
className,
|
|
12
|
+
sourceBadge,
|
|
13
|
+
footerAction
|
|
14
|
+
}) {
|
|
8
15
|
const t = useT();
|
|
9
16
|
const emphasizedRows = items.filter((item) => item.emphasize);
|
|
10
17
|
const heading = title ?? t("sales.documents.detail.totals.title");
|
|
@@ -32,7 +39,17 @@ function DocumentTotals({ title, currency, items, className }) {
|
|
|
32
39
|
if (!items.length) return null;
|
|
33
40
|
return /* @__PURE__ */ jsx("div", { className: cn("space-y-3", className), children: /* @__PURE__ */ jsxs("div", { className: "overflow-hidden rounded-xl border bg-card shadow-sm", children: [
|
|
34
41
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b bg-muted/50 px-4 py-3", children: [
|
|
35
|
-
/* @__PURE__ */
|
|
42
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: [
|
|
43
|
+
heading,
|
|
44
|
+
sourceBadge ? /* @__PURE__ */ jsx(
|
|
45
|
+
"span",
|
|
46
|
+
{
|
|
47
|
+
title: sourceBadge.hint,
|
|
48
|
+
className: "rounded-full bg-status-info-bg px-2 py-0.5 text-xs font-semibold normal-case tracking-normal text-status-info-text",
|
|
49
|
+
children: sourceBadge.label
|
|
50
|
+
}
|
|
51
|
+
) : null
|
|
52
|
+
] }),
|
|
36
53
|
currency ? /* @__PURE__ */ jsx("span", { className: "rounded-full border border-border/70 bg-background/80 px-3 py-1 text-xs font-semibold tracking-wide text-foreground", children: currency }) : null
|
|
37
54
|
] }),
|
|
38
55
|
/* @__PURE__ */ jsxs("table", { className: "w-full text-sm", children: [
|
|
@@ -63,7 +80,8 @@ function DocumentTotals({ title, currency, items, className }) {
|
|
|
63
80
|
children: expanded ? t("sales.documents.detail.totals.hideDetails") : t("sales.documents.detail.totals.showDetails")
|
|
64
81
|
}
|
|
65
82
|
)
|
|
66
|
-
] }) : null
|
|
83
|
+
] }) : null,
|
|
84
|
+
footerAction ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end border-t bg-muted/30 px-4 py-3", children: footerAction }) : null
|
|
67
85
|
] }) });
|
|
68
86
|
}
|
|
69
87
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/sales/components/documents/DocumentTotals.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { PriceWithCurrency } from '../PriceWithCurrency'\n\nexport type DocumentTotalItem = {\n key: string\n label: string\n amount: number | string | null | undefined\n emphasize?: boolean\n}\n\ntype DocumentTotalsProps = {\n title?: string\n currency: string | null | undefined\n items: DocumentTotalItem[]\n className?: string\n}\n\nexport function DocumentTotals({
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { PriceWithCurrency } from '../PriceWithCurrency'\n\nexport type DocumentTotalItem = {\n key: string\n label: string\n amount: number | string | null | undefined\n emphasize?: boolean\n}\n\ntype DocumentTotalsProps = {\n title?: string\n currency: string | null | undefined\n items: DocumentTotalItem[]\n className?: string\n /** Marks the header as caller-asserted, e.g. \"Amounts from source\". */\n sourceBadge?: { label: string; hint?: string } | null\n /** Rendered under the table \u2014 the explicit action that leaves the source-owned mode. */\n footerAction?: React.ReactNode\n}\n\nexport function DocumentTotals({\n title,\n currency,\n items,\n className,\n sourceBadge,\n footerAction,\n}: DocumentTotalsProps) {\n const t = useT()\n const emphasizedRows = items.filter((item) => item.emphasize)\n const heading = title ?? t('sales.documents.detail.totals.title')\n const [expanded, setExpanded] = React.useState(false)\n const paidItem = React.useMemo(() => {\n const entry = items.find((item) => item.key === 'paidTotalAmount')\n if (!entry) return null\n const numeric =\n typeof entry.amount === 'number'\n ? entry.amount\n : typeof entry.amount === 'string'\n ? Number(entry.amount)\n : null\n if (numeric === null || Number.isNaN(numeric) || numeric <= 0) return null\n return entry\n }, [items])\n const collapsedItems = React.useMemo(() => {\n const base = emphasizedRows.length ? [...emphasizedRows] : items.slice(0, 3)\n const augmented = paidItem && !base.some((item) => item.key === paidItem.key) ? [...base, paidItem] : base\n const seen = new Set<string>()\n return augmented.filter((item) => {\n if (seen.has(item.key)) return false\n seen.add(item.key)\n return true\n })\n }, [emphasizedRows, items, paidItem])\n const visibleItems = expanded ? items : collapsedItems\n const uniqueItemCount = React.useMemo(() => new Set(items.map((item) => item.key)).size, [items])\n const hiddenCount = Math.max(0, uniqueItemCount - visibleItems.length)\n\n if (!items.length) return null\n\n return (\n <div className={cn('space-y-3', className)}>\n <div className=\"overflow-hidden rounded-xl border bg-card shadow-sm\">\n <div className=\"flex items-center justify-between border-b bg-muted/50 px-4 py-3\">\n <span className=\"flex items-center gap-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground\">\n {heading}\n {sourceBadge ? (\n <span\n title={sourceBadge.hint}\n className=\"rounded-full bg-status-info-bg px-2 py-0.5 text-xs font-semibold normal-case tracking-normal text-status-info-text\"\n >\n {sourceBadge.label}\n </span>\n ) : null}\n </span>\n {currency ? (\n <span className=\"rounded-full border border-border/70 bg-background/80 px-3 py-1 text-xs font-semibold tracking-wide text-foreground\">\n {currency}\n </span>\n ) : null}\n </div>\n <table className=\"w-full text-sm\">\n <tbody className=\"divide-y divide-border/80\">\n {visibleItems\n .filter((item) => !item.emphasize)\n .map((item) => (\n <tr key={item.key} className=\"bg-background/80 transition-colors hover:bg-muted/30\">\n <td className=\"px-4 py-3 font-medium text-foreground/90\">{item.label}</td>\n <td className=\"px-4 py-3 text-right\">\n <PriceWithCurrency amount={item.amount} currency={currency} className=\"font-mono text-base\" />\n </td>\n </tr>\n ))}\n </tbody>\n {visibleItems.some((item) => item.emphasize) ? (\n <tfoot className=\"border-t-2 border-primary/40 bg-primary/5\">\n {visibleItems\n .filter((item) => item.emphasize)\n .map((item) => (\n <tr key={item.key}>\n <td className=\"px-4 py-3 font-semibold uppercase tracking-wide text-foreground\">\n {item.label}\n </td>\n <td className=\"px-4 py-3 text-right\">\n <PriceWithCurrency\n amount={item.amount}\n currency={currency}\n className=\"font-mono text-lg font-semibold text-foreground\"\n />\n </td>\n </tr>\n ))}\n </tfoot>\n ) : null}\n </table>\n {hiddenCount > 0 ? (\n <div className=\"flex items-center justify-between border-t bg-muted/30 px-4 py-3\">\n <span className=\"text-xs text-muted-foreground\">\n {expanded\n ? t('sales.documents.detail.totals.showingAll')\n : t('sales.documents.detail.totals.showingKey', { count: hiddenCount })}\n </span>\n <button\n type=\"button\"\n className=\"text-xs font-semibold text-primary transition-colors hover:text-primary/80\"\n onClick={() => setExpanded((prev) => !prev)}\n >\n {expanded ? t('sales.documents.detail.totals.hideDetails') : t('sales.documents.detail.totals.showDetails')}\n </button>\n </div>\n ) : null}\n {footerAction ? (\n <div className=\"flex items-center justify-end border-t bg-muted/30 px-4 py-3\">{footerAction}</div>\n ) : null}\n </div>\n </div>\n )\n}\n"],
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,KAAK,GAWd,CACD,GACL,IACE;AAAA,OACN;AAAA,IACC,cAAc,IACb,qBAAC,SAAI,WAAU,oEACb;AAAA,0BAAC,UAAK,WAAU,iCACb,qBACG,EAAE,0CAA0C,IAC5C,EAAE,4CAA4C,EAAE,OAAO,YAAY,CAAC,GAC1E;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,WAAU;AAAA,UACV,SAAS,MAAM,YAAY,CAAC,SAAS,CAAC,IAAI;AAAA,UAEzC,qBAAW,EAAE,2CAA2C,IAAI,EAAE,2CAA2C;AAAA;AAAA,MAC5G;AAAA,OACF,IACE;AAAA,IACH,eACC,oBAAC,SAAI,WAAU,gEAAgE,wBAAa,IAC1F;AAAA,KACN,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
createDictionaryMap,
|
|
16
16
|
normalizeDictionaryEntries
|
|
17
17
|
} from "@open-mercato/core/modules/dictionaries/components/dictionaryAppearance";
|
|
18
|
+
import { cn } from "@open-mercato/shared/lib/utils";
|
|
18
19
|
import { useT, useLocale } from "@open-mercato/shared/lib/i18n/context";
|
|
19
20
|
import { useOrganizationScopeDetail } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
|
|
20
21
|
import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
|
|
@@ -89,7 +90,8 @@ function SalesDocumentItemsSection({
|
|
|
89
90
|
organizationId: orgFromProps,
|
|
90
91
|
tenantId: tenantFromProps,
|
|
91
92
|
onActionChange,
|
|
92
|
-
onItemsChange
|
|
93
|
+
onItemsChange,
|
|
94
|
+
amountsReadOnly = false
|
|
93
95
|
}) {
|
|
94
96
|
const t = useT();
|
|
95
97
|
const runDocumentMutation = useSalesDocumentMutation(kind, documentId);
|
|
@@ -376,14 +378,18 @@ function SalesDocumentItemsSection({
|
|
|
376
378
|
onActionChange({
|
|
377
379
|
label: t("sales.documents.items.add", "Add item"),
|
|
378
380
|
onClick: openCreate,
|
|
379
|
-
disabled:
|
|
381
|
+
disabled: amountsReadOnly
|
|
380
382
|
});
|
|
381
383
|
return () => onActionChange(null);
|
|
382
|
-
}, [onActionChange, openCreate, t]);
|
|
383
|
-
const handleEdit = React.useCallback(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
384
|
+
}, [amountsReadOnly, onActionChange, openCreate, t]);
|
|
385
|
+
const handleEdit = React.useCallback(
|
|
386
|
+
(line) => {
|
|
387
|
+
if (amountsReadOnly) return;
|
|
388
|
+
setLineForEdit(line);
|
|
389
|
+
setDialogOpen(true);
|
|
390
|
+
},
|
|
391
|
+
[amountsReadOnly]
|
|
392
|
+
);
|
|
387
393
|
const resolveVariantInfo = React.useCallback((record) => {
|
|
388
394
|
const meta = record.metadata ?? null;
|
|
389
395
|
const snapshot = record.catalogSnapshot ?? null;
|
|
@@ -510,10 +516,11 @@ function SalesDocumentItemsSection({
|
|
|
510
516
|
),
|
|
511
517
|
action: {
|
|
512
518
|
label: t("sales.documents.items.add", "Add item"),
|
|
513
|
-
onClick: openCreate
|
|
519
|
+
onClick: openCreate,
|
|
520
|
+
disabled: amountsReadOnly
|
|
514
521
|
}
|
|
515
522
|
}
|
|
516
|
-
) : /* @__PURE__ */ jsx("div", { className: "overflow-
|
|
523
|
+
) : /* @__PURE__ */ jsx("div", { className: "relative overflow-x-auto rounded border", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm", children: [
|
|
517
524
|
/* @__PURE__ */ jsx("thead", { className: "bg-muted", children: /* @__PURE__ */ jsxs("tr", { className: "text-left", children: [
|
|
518
525
|
/* @__PURE__ */ jsx("th", { className: "px-3 py-2 font-medium", children: t("sales.documents.items.table.product", "Product") }),
|
|
519
526
|
/* @__PURE__ */ jsx("th", { className: "px-3 py-2 font-medium", children: t("sales.documents.items.table.status", "Status") }),
|
|
@@ -551,7 +558,10 @@ function SalesDocumentItemsSection({
|
|
|
551
558
|
return /* @__PURE__ */ jsxs(
|
|
552
559
|
"tr",
|
|
553
560
|
{
|
|
554
|
-
className:
|
|
561
|
+
className: cn(
|
|
562
|
+
"border-t transition-colors",
|
|
563
|
+
amountsReadOnly ? "" : "cursor-pointer hover:bg-muted/50"
|
|
564
|
+
),
|
|
555
565
|
onClick: () => handleEdit(item),
|
|
556
566
|
children: [
|
|
557
567
|
/* @__PURE__ */ jsx("td", { className: "px-3 py-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
@@ -690,6 +700,7 @@ function SalesDocumentItemsSection({
|
|
|
690
700
|
variant: "ghost",
|
|
691
701
|
className: "h-8 w-8",
|
|
692
702
|
"aria-label": t("ui.actions.edit", "Edit"),
|
|
703
|
+
disabled: amountsReadOnly,
|
|
693
704
|
onClick: (event) => {
|
|
694
705
|
event.stopPropagation();
|
|
695
706
|
handleEdit(item);
|
|
@@ -700,7 +711,7 @@ function SalesDocumentItemsSection({
|
|
|
700
711
|
/* @__PURE__ */ jsx(
|
|
701
712
|
"span",
|
|
702
713
|
{
|
|
703
|
-
title: kind === "order" && items.length === 1 ? t("sales.documents.items.errorDeleteLast", "An order must contain at least one line item.") : void 0,
|
|
714
|
+
title: amountsReadOnly ? t("sales.documents.amountsExternalHint", "Totals on this document come from an external system and are stored as supplied.") : kind === "order" && items.length === 1 ? t("sales.documents.items.errorDeleteLast", "An order must contain at least one line item.") : void 0,
|
|
704
715
|
children: /* @__PURE__ */ jsx(
|
|
705
716
|
Button,
|
|
706
717
|
{
|
|
@@ -708,7 +719,7 @@ function SalesDocumentItemsSection({
|
|
|
708
719
|
variant: "ghost",
|
|
709
720
|
className: "h-8 w-8 text-destructive",
|
|
710
721
|
"aria-label": t("ui.actions.delete", "Delete"),
|
|
711
|
-
disabled: kind === "order" && items.length === 1,
|
|
722
|
+
disabled: amountsReadOnly || kind === "order" && items.length === 1,
|
|
712
723
|
onClick: (event) => {
|
|
713
724
|
event.stopPropagation();
|
|
714
725
|
void handleDelete(item);
|