@fayz-ai/plugin-fiscal-br 0.13.7 → 0.15.0

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.
Files changed (73) hide show
  1. package/dist/InboundNotesPage-CZVSXCJA.js +6 -0
  2. package/dist/{InboundNotesPage-R72EC5E4.js.map → InboundNotesPage-CZVSXCJA.js.map} +1 -1
  3. package/dist/InvoiceNotesButton-SC3G7FUR.js +5 -0
  4. package/dist/{InvoiceNotesButton-3SMNHWMQ.js.map → InvoiceNotesButton-SC3G7FUR.js.map} +1 -1
  5. package/dist/NoteReceiptCard-H5BMFPU7.js +4 -0
  6. package/dist/{NoteReconcileView-3KVXZLCG.js.map → NoteReceiptCard-H5BMFPU7.js.map} +1 -1
  7. package/dist/NoteReconcileView-QSRL6NKQ.js +5 -0
  8. package/dist/NoteReconcileView-QSRL6NKQ.js.map +1 -0
  9. package/dist/OrderNoteCard-PDSK2AS3.js +5 -0
  10. package/dist/{OrderNoteCard-H6P66R4J.js.map → OrderNoteCard-PDSK2AS3.js.map} +1 -1
  11. package/dist/{UnitFiscalWidgets-KCHSISBS.js → UnitFiscalWidgets-K4PX3HWG.js} +3 -3
  12. package/dist/{UnitFiscalWidgets-KCHSISBS.js.map → UnitFiscalWidgets-K4PX3HWG.js.map} +1 -1
  13. package/dist/chunk-3BDFMEYY.js +231 -0
  14. package/dist/chunk-3BDFMEYY.js.map +1 -0
  15. package/dist/{chunk-OGXYHL3Z.js → chunk-DBWRGUIV.js} +20 -5
  16. package/dist/chunk-DBWRGUIV.js.map +1 -0
  17. package/dist/chunk-DHCCZXUM.js +50 -0
  18. package/dist/chunk-DHCCZXUM.js.map +1 -0
  19. package/dist/{chunk-WID54RUV.js → chunk-F325US5P.js} +4 -115
  20. package/dist/chunk-F325US5P.js.map +1 -0
  21. package/dist/chunk-ODMEESFD.js +222 -0
  22. package/dist/chunk-ODMEESFD.js.map +1 -0
  23. package/dist/{chunk-G7T5YMNY.js → chunk-SSPDH22E.js} +78 -41
  24. package/dist/chunk-SSPDH22E.js.map +1 -0
  25. package/dist/{chunk-UYGGBJCR.js → chunk-TZH7AWBD.js} +187 -54
  26. package/dist/chunk-TZH7AWBD.js.map +1 -0
  27. package/dist/{chunk-7NW3EBOQ.js → chunk-ZJGXUJKM.js} +5 -3
  28. package/dist/chunk-ZJGXUJKM.js.map +1 -0
  29. package/dist/data/inbox.d.ts +5 -1
  30. package/dist/data/inbox.d.ts.map +1 -1
  31. package/dist/data/receipt.d.ts +45 -0
  32. package/dist/data/receipt.d.ts.map +1 -0
  33. package/dist/index.d.ts +3 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +188 -16
  36. package/dist/index.js.map +1 -1
  37. package/dist/lib/emitters.d.ts +7 -0
  38. package/dist/lib/emitters.d.ts.map +1 -1
  39. package/dist/lib/notes.d.ts +19 -3
  40. package/dist/lib/notes.d.ts.map +1 -1
  41. package/dist/lib/receipt.d.ts +39 -0
  42. package/dist/lib/receipt.d.ts.map +1 -0
  43. package/dist/locales/en.d.ts +2 -0
  44. package/dist/locales/en.d.ts.map +1 -0
  45. package/dist/locales/index.d.ts +2 -0
  46. package/dist/locales/index.d.ts.map +1 -0
  47. package/dist/locales/pt-BR.d.ts +2 -0
  48. package/dist/locales/pt-BR.d.ts.map +1 -0
  49. package/dist/migrations/index.d.ts +2 -0
  50. package/dist/migrations/index.d.ts.map +1 -1
  51. package/dist/migrations/main.browser.js +3 -1
  52. package/dist/migrations/main.browser.js.map +1 -1
  53. package/dist/migrations/main.js +762 -2
  54. package/dist/migrations/main.js.map +1 -1
  55. package/dist/types.d.ts +8 -1
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/views/InboundNotesView.d.ts.map +1 -1
  58. package/dist/views/NoteReceiptCard.d.ts +4 -0
  59. package/dist/views/NoteReceiptCard.d.ts.map +1 -0
  60. package/dist/views/NoteReconcileView.d.ts.map +1 -1
  61. package/dist/views/OrderNoteCard.d.ts.map +1 -1
  62. package/package.json +5 -5
  63. package/dist/InboundNotesPage-R72EC5E4.js +0 -5
  64. package/dist/InvoiceNotesButton-3SMNHWMQ.js +0 -5
  65. package/dist/NoteReconcileView-3KVXZLCG.js +0 -4
  66. package/dist/OrderNoteCard-H6P66R4J.js +0 -5
  67. package/dist/chunk-7NW3EBOQ.js.map +0 -1
  68. package/dist/chunk-G7T5YMNY.js.map +0 -1
  69. package/dist/chunk-OGXYHL3Z.js.map +0 -1
  70. package/dist/chunk-RZT2BO6E.js +0 -64
  71. package/dist/chunk-RZT2BO6E.js.map +0 -1
  72. package/dist/chunk-UYGGBJCR.js.map +0 -1
  73. package/dist/chunk-WID54RUV.js.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import { packagingCount } from './chunk-5LI2FDOM.js';
2
+ import { summarizeOccurrence, receivedStockQty, hasShortage, shortageQty, shortageReasonKey, shortageValue, receivedQty, SHORTAGE_REASONS, parseQty } from './chunk-DHCCZXUM.js';
2
3
  import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
3
4
  import { KeyRound, Loader2, Download, ChevronDown, FileCode2, FileText, RefreshCw, UserPlus, Gift, AlertTriangle, ChevronRight, Check, Trash2, Plus, Image, UploadCloud, Paperclip, ScanLine, X } from 'lucide-react';
4
- import { getSupabaseClientOptional, formatCurrency } from '@fayz-ai/core';
5
+ import { useTranslation, getSupabaseClientOptional, formatCurrency } from '@fayz-ai/core';
5
6
  import { getActiveTenantId, PersonLink } from '@fayz-ai/admin';
6
7
  import { Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalBody, Input, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, ModalFooter, Button, AiActionButton, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, Hint, Card, InlineLink, SearchSelect, EmBreve, DatePicker, SubpageHeader, Skeleton } from '@fayz-ai/ui';
7
8
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -332,7 +333,7 @@ var NOTE_COLUMNS = `
332
333
  total_value, total_products, total_discount, total_freight,
333
334
  invoice_id, inventory_operation_id, stocked_at, reviewed_at,
334
335
  default_chart_account_id, default_location_id, unit_id, document_id, metadata,
335
- items:plg_fiscalbr_inbox_items(id, reconciled, entry_type),
336
+ items:plg_fiscalbr_inbox_items(id, reconciled, entry_type, shortage_quantity),
336
337
  duplicates:plg_fiscalbr_inbox_duplicates(id, value)
337
338
  `;
338
339
  function rowToNote(row) {
@@ -356,6 +357,7 @@ function rowToNote(row) {
356
357
  total: Number(row.total_value ?? 0),
357
358
  itemCount: items.length,
358
359
  reconciledCount: items.filter((i) => i.reconciled).length,
360
+ shortageCount: items.filter((i) => Number(i.shortage_quantity ?? 0) > 0).length,
359
361
  instalmentCount: duplicates.length,
360
362
  // The sum of instalments, because that is the total the payable is opened
361
363
  // with (financial/084) — showing the note total here would make the list and
@@ -565,9 +567,9 @@ async function saveNoteDecision(input) {
565
567
  cost_mode: i.costMode ?? "novo",
566
568
  suggested_by: i.suggestedBy ?? null,
567
569
  suggestion_confidence: i.suggestionConfidence ?? null,
568
- shortage_quantity: i.shortageQuantity ?? null,
569
- shortage_reason: i.shortageReason ?? null,
570
- shortage_note: i.shortageNote ?? null
570
+ // `missing_quantity` (note units) is the key the save RPC reads since
571
+ // fiscal-br/034; without it the receipt already saved is kept.
572
+ ...i.missingQuantity !== void 0 ? { missing_quantity: i.missingQuantity, shortage_reason: i.shortageReason ?? null, shortage_note: i.shortageNote ?? null } : {}
571
573
  })),
572
574
  p_default_chart_account_id: input.defaultChartAccountId ?? null,
573
575
  p_default_location_id: input.defaultLocationId ?? null,
@@ -613,7 +615,9 @@ async function acceptNote(documentId, locationId) {
613
615
  invoiceTotal: Number(res.invoice_total ?? 0),
614
616
  instalments: Number(res.installments ?? 0),
615
617
  operationId: res.operation_id ?? null,
616
- stockLines: Number(res.stock_lines ?? 0)
618
+ stockLines: Number(res.stock_lines ?? 0),
619
+ shortageLines: Number(res.shortage_lines ?? 0),
620
+ shortageValue: Number(res.shortage_value ?? 0)
617
621
  };
618
622
  }
619
623
  async function rejectNote(documentId, reason) {
@@ -1237,11 +1241,34 @@ var draftOf = (item) => ({
1237
1241
  conversionFactor: String(item.conversionFactor ?? 1),
1238
1242
  costMode: item.costMode === "media" ? "media" : "novo",
1239
1243
  shortageQuantity: item.shortageQuantity == null ? "" : String(item.shortageQuantity),
1244
+ shortageReason: item.shortageReason ?? "faltou",
1245
+ shortageNote: item.shortageNote ?? "",
1240
1246
  // Vem do SERVIDOR: é o que faz o selo sobreviver a recarregar a página.
1241
1247
  suggestedBy: item.suggestedBy,
1242
1248
  suggestionConfidence: item.suggestionConfidence
1243
1249
  });
1250
+ function receiptOf(item, d) {
1251
+ const missing = parseQty(d.shortageQuantity);
1252
+ if (missing === null || Number.isNaN(missing) || missing <= 0) {
1253
+ return { missingQuantity: null, shortageReason: null, shortageNote: null };
1254
+ }
1255
+ return {
1256
+ missingQuantity: Math.min(missing, item.quantity),
1257
+ shortageReason: d.shortageReason || "faltou",
1258
+ shortageNote: d.shortageNote.trim() || null
1259
+ };
1260
+ }
1261
+ function receiptInvalid(item, d) {
1262
+ const missing = parseQty(d.shortageQuantity);
1263
+ if (missing === null) return false;
1264
+ return Number.isNaN(missing) || missing < 0 || missing > item.quantity + 1e-9;
1265
+ }
1266
+ var receiptLine = (item, d) => {
1267
+ const missing = parseQty(d.shortageQuantity);
1268
+ return { quantity: item.quantity, total: item.total, shortageQuantity: missing && !Number.isNaN(missing) ? missing : 0 };
1269
+ };
1244
1270
  function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1271
+ const t = useTranslation();
1245
1272
  const emModal = chrome === "modal";
1246
1273
  const sangria = emModal ? "-mx-6 px-6" : "-mx-4 px-4";
1247
1274
  const cabecalho = (titulo) => emModal ? null : /* @__PURE__ */ jsx(SubpageHeader, { title: titulo, onBack, parentLabel: "Manifesto de Notas" });
@@ -1383,20 +1410,29 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1383
1410
  costMode: d.costMode,
1384
1411
  suggestedBy: d.suggestedBy,
1385
1412
  suggestionConfidence: d.suggestionConfidence,
1386
- shortageQuantity: d.shortageQuantity === "" ? null : Number(d.shortageQuantity.replace(",", "."))
1413
+ // The receipt travels as `missing_quantity` (note units); nothing missing is null.
1414
+ ...receiptOf(item, d)
1387
1415
  };
1388
1416
  });
1389
1417
  }, [note, defaultAccount]);
1390
1418
  const decisions = useMemo(() => buildDecisions(drafts), [buildDecisions, drafts]);
1391
- const stockLines = decisions.filter((d) => isStockBearing(d.entryType));
1419
+ const nothingArrived = (id) => {
1420
+ const item = note?.items.find((i) => i.id === id);
1421
+ if (!item) return false;
1422
+ const d = drafts[id] ?? draftOf(item);
1423
+ return !receiptInvalid(item, d) && receivedQty(receiptLine(item, d)) <= 1e-9;
1424
+ };
1425
+ const stockLines = decisions.filter((d) => isStockBearing(d.entryType) && !nothingArrived(d.id));
1392
1426
  const missingProduct = stockLines.filter((d) => !d.productId).length;
1393
1427
  const missingUnit = stockLines.filter((d) => {
1394
1428
  const item = note?.items.find((i) => i.id === d.id);
1395
1429
  return !d.stockUnitId && !item?.stockMovementId;
1396
1430
  }).length;
1397
1431
  const missingType = decisions.filter((d) => !d.entryType).length;
1432
+ const badReceipt = note ? note.items.filter((i) => receiptInvalid(i, drafts[i.id] ?? draftOf(i))).length : 0;
1433
+ const occurrence = note ? summarizeOccurrence(note.items.map((i) => receiptLine(i, drafts[i.id] ?? draftOf(i)))) : { count: 0, value: 0 };
1398
1434
  const suspectFactor = (item, d) => packagingCount(item.unit) !== null && isStockBearing(d.entryType) && ((Number(d.conversionFactor.replace(",", ".")) || 1) === 1 || !d.stockUnitId);
1399
- const unverifiedFactor = note ? note.items.filter((i) => suspectFactor(i, drafts[i.id] ?? draftOf(i))).length : 0;
1435
+ const unverifiedFactor = note ? note.items.filter((i) => suspectFactor(i, drafts[i.id] ?? draftOf(i)) && !nothingArrived(i.id)).length : 0;
1400
1436
  const instalmentSum = instalments.reduce((acc, d) => acc + (Number(d.amount) || 0), 0);
1401
1437
  const hasPayable = Boolean(note?.invoiceId);
1402
1438
  const pendingStock = (note?.items ?? []).some((i) => !i.stockMovementId && (!i.entryType || isStockBearing(i.entryType)));
@@ -1657,7 +1693,8 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1657
1693
  unverifiedFactor > 0 && `${unverifiedFactor} com fator por conferir`,
1658
1694
  missingType > 0 && `${missingType} sem tipo`,
1659
1695
  missingProduct > 0 && `${missingProduct} sem produto`,
1660
- missingUnit > 0 && `${missingUnit} sem unidade de estoque`
1696
+ missingUnit > 0 && `${missingUnit} sem unidade de estoque`,
1697
+ badReceipt > 0 && t("fiscalbr.receipt.pending", { count: badReceipt })
1661
1698
  ].filter(Boolean).join(" \xB7 ");
1662
1699
  const rodape = readOnly ? null : {
1663
1700
  start: /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -1694,7 +1731,7 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1694
1731
  onClick: () => {
1695
1732
  void accept();
1696
1733
  },
1697
- disabled: accepting || saving || missingType > 0 || missingProduct > 0 || missingUnit > 0 || unverifiedFactor > 0,
1734
+ disabled: accepting || saving || missingType > 0 || missingProduct > 0 || missingUnit > 0 || unverifiedFactor > 0 || badReceipt > 0,
1698
1735
  children: [
1699
1736
  accepting ? /* @__PURE__ */ jsx(Loader2, { className: "mr-1.5 h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ jsx(Check, { className: "mr-1.5 h-3.5 w-3.5" }),
1700
1737
  hasPayable ? "Dar entrada no estoque" : "Aceitar"
@@ -1707,6 +1744,7 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1707
1744
  cabecalho(`Concilia\xE7\xE3o \xB7 NF-e ${note.number}`),
1708
1745
  accepted && /* @__PURE__ */ jsxs(Card, { className: "border-success bg-success-soft p-4", children: [
1709
1746
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-success-soft-foreground", children: accepted.alreadyAccepted ? "Esta nota j\xE1 havia sido aceita \u2014 nada foi lan\xE7ado de novo." : accepted.instalments === 0 ? `Entrada no estoque: ${accepted.stockLines} ${accepted.stockLines === 1 ? "linha" : "linhas"}, ligadas \xE0 conta a pagar que a nota j\xE1 tinha (${money2(accepted.invoiceTotal)}).` : `Aceita: ${accepted.stockLines} ${accepted.stockLines === 1 ? "linha" : "linhas"} de estoque e um t\xEDtulo de ${money2(accepted.invoiceTotal)} em ${accepted.instalments} ${accepted.instalments === 1 ? "parcela" : "parcelas"}.` }),
1747
+ !accepted.alreadyAccepted && accepted.shortageLines > 0 && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-success-soft-foreground", "data-testid": "note-accepted-shortage", children: t("fiscalbr.receipt.accepted", { count: accepted.shortageLines, value: money2(accepted.shortageValue) }) }),
1710
1748
  accepted.invoiceId && onOpenInvoice && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", className: "mt-2", onClick: () => onOpenInvoice(accepted.invoiceId), children: "Abrir a conta a pagar" })
1711
1749
  ] }),
1712
1750
  payableLost && !readOnly && /* @__PURE__ */ jsxs(Card, { className: "border-warning bg-warning-soft p-4", "data-testid": "note-payable-lost", children: [
@@ -1898,14 +1936,16 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1898
1936
  note.items.map((item) => {
1899
1937
  const d = drafts[item.id] ?? draftOf(item);
1900
1938
  const factor = Number(d.conversionFactor.replace(",", ".")) || 1;
1901
- const shortage = d.shortageQuantity === "" ? 0 : Number(d.shortageQuantity.replace(",", ".")) || 0;
1902
- const stockQty = item.quantity * factor - shortage;
1939
+ const rLine = receiptLine(item, d);
1940
+ const stockQty = receivedStockQty(rLine, factor);
1941
+ const rInvalid = receiptInvalid(item, d);
1942
+ const rShort = hasShortage(rLine);
1903
1943
  const unitCost = factor > 0 ? item.unitPrice / factor : item.unitPrice;
1904
1944
  const bearing = isStockBearing(d.entryType);
1905
1945
  const open = openIds.includes(item.id);
1906
1946
  const done = Boolean(checked[item.id]);
1907
1947
  const ready = isReady(item, d);
1908
- const typeLabel = ENTRY_TYPES.find((t) => t.value === d.entryType)?.label;
1948
+ const typeLabel = ENTRY_TYPES.find((t2) => t2.value === d.entryType)?.label;
1909
1949
  return /* @__PURE__ */ jsxs(Card, { className: "overflow-hidden", children: [
1910
1950
  /* @__PURE__ */ jsxs(
1911
1951
  Button,
@@ -1938,6 +1978,15 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1938
1978
  ] }),
1939
1979
  /* @__PURE__ */ jsx("span", { className: "shrink-0 text-sm tabular-nums", children: money2(item.total) }),
1940
1980
  d.suggestedBy && !done && /* @__PURE__ */ jsx(AuthorBadge, { draft: d }),
1981
+ rShort && /* @__PURE__ */ jsx(
1982
+ "span",
1983
+ {
1984
+ className: "shrink-0 rounded-full border border-warning bg-warning-soft px-1.5 py-0.5 text-[10px] text-warning-soft-foreground",
1985
+ title: `${t(shortageReasonKey(d.shortageReason))}${d.shortageNote ? ` \u2014 ${d.shortageNote}` : ""} \xB7 ${money2(shortageValue(rLine))}`,
1986
+ "data-testid": "item-shortage-badge",
1987
+ children: t("fiscalbr.receipt.badge", { missing: qty(shortageQty(rLine)), unit: item.unit ?? "" })
1988
+ }
1989
+ ),
1941
1990
  /* @__PURE__ */ jsx(ItemState, { done: done && ready, ready })
1942
1991
  ]
1943
1992
  }
@@ -1959,30 +2008,110 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
1959
2008
  /* @__PURE__ */ jsx(Field, { small: true, label: "NCM", value: item.ncm ?? "\u2014", mono: true }),
1960
2009
  /* @__PURE__ */ jsx(Field, { small: true, label: "CFOP", value: item.cfop ?? "\u2014", mono: true }),
1961
2010
  /* @__PURE__ */ jsx(Field, { small: true, label: "CST/CSOSN", value: item.icmsCst ?? item.icmsCsosn ?? "\u2014", mono: true })
2011
+ ] }),
2012
+ /* @__PURE__ */ jsxs("div", { className: "mt-3 space-y-2 rounded-md border p-3", "data-testid": "item-receipt", children: [
2013
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline justify-between gap-2", children: [
2014
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: t("fiscalbr.receipt.title") }),
2015
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: rShort ? t("fiscalbr.receipt.summary", {
2016
+ missing: qty(shortageQty(rLine)),
2017
+ billed: qty(item.quantity),
2018
+ unit: item.unit ?? "",
2019
+ reason: t(shortageReasonKey(d.shortageReason)),
2020
+ value: money2(shortageValue(rLine))
2021
+ }) : t("fiscalbr.receipt.allArrived") })
2022
+ ] }),
2023
+ readOnly ? /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: t("fiscalbr.receipt.locked") }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2024
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
2025
+ /* @__PURE__ */ jsxs("label", { className: "block", children: [
2026
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: t("fiscalbr.receipt.received", { unit: item.unit ?? "" }) }),
2027
+ /* @__PURE__ */ jsx(
2028
+ ReceivedInput,
2029
+ {
2030
+ received: rInvalid ? null : receivedQty(rLine),
2031
+ onChange: (got) => patch(item.id, {
2032
+ shortageQuantity: got >= item.quantity - 1e-9 ? "" : decimalText(Math.max(Math.round((item.quantity - got) * 1e4) / 1e4, 0))
2033
+ })
2034
+ }
2035
+ )
2036
+ ] }),
2037
+ /* @__PURE__ */ jsxs("label", { className: "block", children: [
2038
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: t("fiscalbr.receipt.missing", { unit: item.unit ?? "" }) }),
2039
+ /* @__PURE__ */ jsx(
2040
+ Input,
2041
+ {
2042
+ value: d.shortageQuantity,
2043
+ inputMode: "decimal",
2044
+ placeholder: "0",
2045
+ "aria-invalid": rInvalid || void 0,
2046
+ onChange: (e) => patch(item.id, { shortageQuantity: e.target.value })
2047
+ }
2048
+ )
2049
+ ] })
2050
+ ] }),
2051
+ rInvalid && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-destructive", children: t("fiscalbr.receipt.tooMuch", { billed: qty(item.quantity), unit: item.unit ?? "" }) }),
2052
+ rShort && /* @__PURE__ */ jsxs(Fragment, { children: [
2053
+ /* @__PURE__ */ jsxs("div", { children: [
2054
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: t("fiscalbr.receipt.reason") }),
2055
+ /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-1", children: SHORTAGE_REASONS.map((r) => /* @__PURE__ */ jsx(
2056
+ Button,
2057
+ {
2058
+ variant: "bare",
2059
+ size: "bare",
2060
+ type: "button",
2061
+ onClick: () => patch(item.id, { shortageReason: r }),
2062
+ className: `gap-0 font-normal rounded-full border px-2.5 py-1 text-[11px] transition-colors ${d.shortageReason === r ? "border-primary bg-primary text-primary-foreground" : "border-input hover:bg-muted"}`,
2063
+ children: t(shortageReasonKey(r))
2064
+ },
2065
+ r
2066
+ )) })
2067
+ ] }),
2068
+ /* @__PURE__ */ jsxs("label", { className: "block", children: [
2069
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground", children: t("fiscalbr.receipt.note") }),
2070
+ /* @__PURE__ */ jsx(
2071
+ Input,
2072
+ {
2073
+ value: d.shortageNote,
2074
+ placeholder: t("fiscalbr.receipt.notePlaceholder"),
2075
+ onChange: (e) => patch(item.id, { shortageNote: e.target.value })
2076
+ }
2077
+ )
2078
+ ] }),
2079
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(
2080
+ Button,
2081
+ {
2082
+ type: "button",
2083
+ size: "sm",
2084
+ variant: "ghost",
2085
+ onClick: () => patch(item.id, { shortageQuantity: "", shortageNote: "" }),
2086
+ children: t("fiscalbr.receipt.clear")
2087
+ }
2088
+ ) })
2089
+ ] })
2090
+ ] })
1962
2091
  ] })
1963
2092
  ] }),
1964
2093
  /* @__PURE__ */ jsxs("div", { className: "space-y-3 lg:border-l lg:pl-4", children: [
1965
2094
  /* @__PURE__ */ jsx("p", { className: "text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: "Item no estoque" }),
1966
2095
  /* @__PURE__ */ jsxs("label", { className: "block", children: [
1967
2096
  /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "Tipo do registro" }),
1968
- /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-1", children: ENTRY_TYPES.map((t) => /* @__PURE__ */ jsxs(
2097
+ /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-1", children: ENTRY_TYPES.map((t2) => /* @__PURE__ */ jsxs(
1969
2098
  Button,
1970
2099
  {
1971
2100
  variant: "bare",
1972
2101
  size: "bare",
1973
2102
  type: "button",
1974
2103
  disabled: readOnly,
1975
- onClick: () => patch(item.id, { entryType: t.value }),
1976
- className: `gap-0 font-normal rounded-full border px-2.5 py-1 text-[11px] transition-colors disabled:opacity-60 ${d.entryType === t.value ? "border-primary bg-primary text-primary-foreground" : "border-input hover:bg-muted"}`,
2104
+ onClick: () => patch(item.id, { entryType: t2.value }),
2105
+ className: `gap-0 font-normal rounded-full border px-2.5 py-1 text-[11px] transition-colors disabled:opacity-60 ${d.entryType === t2.value ? "border-primary bg-primary text-primary-foreground" : "border-input hover:bg-muted"}`,
1977
2106
  children: [
1978
- t.label,
1979
- t.hint && /* @__PURE__ */ jsxs("span", { className: "ml-1 opacity-70", children: [
2107
+ t2.label,
2108
+ t2.hint && /* @__PURE__ */ jsxs("span", { className: "ml-1 opacity-70", children: [
1980
2109
  "\xB7 ",
1981
- t.hint
2110
+ t2.hint
1982
2111
  ] })
1983
2112
  ]
1984
2113
  },
1985
- t.value
2114
+ t2.value
1986
2115
  )) })
1987
2116
  ] }),
1988
2117
  bearing && /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -2103,37 +2232,22 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
2103
2232
  }
2104
2233
  )
2105
2234
  ] }),
2106
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3", children: [
2107
- /* @__PURE__ */ jsxs("label", { className: "block", children: [
2108
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "Modo de custo" }),
2109
- /* @__PURE__ */ jsx("div", { className: "mt-1 flex gap-1", children: ["novo", "media"].map((mode) => /* @__PURE__ */ jsx(
2110
- Button,
2111
- {
2112
- variant: "bare",
2113
- size: "bare",
2114
- type: "button",
2115
- disabled: readOnly,
2116
- onClick: () => patch(item.id, { costMode: mode }),
2117
- className: `font-normal flex-1 rounded-md border px-2 py-1 text-[11px] disabled:opacity-60 ${d.costMode === mode ? "border-primary bg-primary/10" : "border-input hover:bg-muted"}`,
2118
- children: mode === "novo" ? "Novo" : "M\xE9dia"
2119
- },
2120
- mode
2121
- )) })
2122
- ] }),
2123
- /* @__PURE__ */ jsxs("label", { className: "block", children: [
2124
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "Falta (qtd)" }),
2125
- /* @__PURE__ */ jsx(
2126
- Input,
2127
- {
2128
- value: d.shortageQuantity,
2129
- onChange: (e) => patch(item.id, { shortageQuantity: e.target.value }),
2130
- inputMode: "decimal",
2131
- placeholder: "0",
2132
- disabled: readOnly
2133
- }
2134
- )
2135
- ] })
2136
- ] })
2235
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-3", children: /* @__PURE__ */ jsxs("label", { className: "block", children: [
2236
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "Modo de custo" }),
2237
+ /* @__PURE__ */ jsx("div", { className: "mt-1 flex gap-1", children: ["novo", "media"].map((mode) => /* @__PURE__ */ jsx(
2238
+ Button,
2239
+ {
2240
+ variant: "bare",
2241
+ size: "bare",
2242
+ type: "button",
2243
+ disabled: readOnly,
2244
+ onClick: () => patch(item.id, { costMode: mode }),
2245
+ className: `font-normal flex-1 rounded-md border px-2 py-1 text-[11px] disabled:opacity-60 ${d.costMode === mode ? "border-primary bg-primary/10" : "border-input hover:bg-muted"}`,
2246
+ children: mode === "novo" ? "Novo" : "M\xE9dia"
2247
+ },
2248
+ mode
2249
+ )) })
2250
+ ] }) })
2137
2251
  ] }),
2138
2252
  /* @__PURE__ */ jsxs("label", { className: "block", children: [
2139
2253
  /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: "Plano de contas" }),
@@ -2178,6 +2292,7 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
2178
2292
  ] }, item.id);
2179
2293
  })
2180
2294
  ] }),
2295
+ occurrence.count > 0 && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-warning bg-warning-soft px-3 py-2", "data-testid": "note-receipt-occurrence", children: /* @__PURE__ */ jsx("p", { className: "text-xs text-warning-soft-foreground", children: occurrence.count === 1 ? t("fiscalbr.receipt.occurrence.one", { value: money2(occurrence.value) }) : t("fiscalbr.receipt.occurrence.many", { count: occurrence.count, value: money2(occurrence.value) }) }) }),
2181
2296
  /* @__PURE__ */ jsxs(Card, { className: "p-4", children: [
2182
2297
  /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between", children: [
2183
2298
  /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: "Dados de pagamento" }),
@@ -2283,6 +2398,24 @@ function NoteReconcileView({ noteId, onBack, onOpenInvoice, chrome = "page" }) {
2283
2398
  error && /* @__PURE__ */ jsx(Card, { className: "border-destructive bg-destructive/5 p-4", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }) })
2284
2399
  ] }), `Concilia\xE7\xE3o \xB7 NF-e ${note.number}`, rodape);
2285
2400
  }
2401
+ var decimalText = (v) => String(v).replace(".", ",");
2402
+ function ReceivedInput({ received, onChange }) {
2403
+ const [text, setText] = useState(null);
2404
+ return /* @__PURE__ */ jsx(
2405
+ Input,
2406
+ {
2407
+ value: text ?? (received == null ? "" : decimalText(received)),
2408
+ inputMode: "decimal",
2409
+ onFocus: () => setText(received == null ? "" : decimalText(received)),
2410
+ onBlur: () => setText(null),
2411
+ onChange: (e) => {
2412
+ setText(e.target.value);
2413
+ const got = parseQty(e.target.value);
2414
+ if (got !== null && !Number.isNaN(got) && got >= 0) onChange(got);
2415
+ }
2416
+ }
2417
+ );
2418
+ }
2286
2419
  function AuthorBadge({ draft }) {
2287
2420
  if (draft.suggestedBy === "ai") {
2288
2421
  const confira = draft.suggestionConfidence != null && draft.suggestionConfidence < 0.6;
@@ -2310,5 +2443,5 @@ function Field({ label, value, mono, small }) {
2310
2443
  }
2311
2444
 
2312
2445
  export { NfeParseError, NoteReconcileView, PullByKeyDialog, PullByKeyError, STOCK_BEARING_ENTRY_TYPES, acceptNote, addNoteAttachment, extractPaymentCode, fillInboxLines, findInboxNoteByNumber, findInboxNoteByOperation, getInboxIntakeHealth, getInboxNote, getInboxNotePdf, getInboxNoteXml, getNotePayable, healInboxNote, isStockBearing, linkInboxSupplier, listChartAccounts, listInboxNotes, listMeasurementUnits, listNoteAttachments, listProductStockUnits, listProductsByIds, listStockLocations, listSupplierMap, moveNoteAttachmentsToInvoice, onlyDigits, parseBoleto, parseNfeXml, paymentLabel, paymentTypeFromCode, pullNoteByKey, rejectNote, removeNoteAttachment, saveNoteDecision, searchProducts, stageNoteFromXml, suggestNoteItems, syncNewNotes, toStagePayload };
2313
- //# sourceMappingURL=chunk-UYGGBJCR.js.map
2314
- //# sourceMappingURL=chunk-UYGGBJCR.js.map
2446
+ //# sourceMappingURL=chunk-TZH7AWBD.js.map
2447
+ //# sourceMappingURL=chunk-TZH7AWBD.js.map