@fayz-ai/plugin-fiscal-br 0.14.0 → 0.15.1
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/InboundNotesPage-UQH2YG3E.js +6 -0
- package/dist/{InboundNotesPage-R72EC5E4.js.map → InboundNotesPage-UQH2YG3E.js.map} +1 -1
- package/dist/NoteReceiptCard-H5BMFPU7.js +4 -0
- package/dist/{NoteReconcileView-3KVXZLCG.js.map → NoteReceiptCard-H5BMFPU7.js.map} +1 -1
- package/dist/NoteReconcileView-QSRL6NKQ.js +5 -0
- package/dist/NoteReconcileView-QSRL6NKQ.js.map +1 -0
- package/dist/chunk-3BDFMEYY.js +231 -0
- package/dist/chunk-3BDFMEYY.js.map +1 -0
- package/dist/chunk-DHCCZXUM.js +50 -0
- package/dist/chunk-DHCCZXUM.js.map +1 -0
- package/dist/{chunk-OGXYHL3Z.js → chunk-LHH2YIDB.js} +30 -15
- package/dist/chunk-LHH2YIDB.js.map +1 -0
- package/dist/{chunk-UYGGBJCR.js → chunk-TZH7AWBD.js} +187 -54
- package/dist/chunk-TZH7AWBD.js.map +1 -0
- package/dist/data/inbox.d.ts +5 -1
- package/dist/data/inbox.d.ts.map +1 -1
- package/dist/data/receipt.d.ts +45 -0
- package/dist/data/receipt.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/receipt.d.ts +39 -0
- package/dist/lib/receipt.d.ts.map +1 -0
- package/dist/locales/en.d.ts +2 -0
- package/dist/locales/en.d.ts.map +1 -0
- package/dist/locales/index.d.ts +2 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/pt-BR.d.ts +2 -0
- package/dist/locales/pt-BR.d.ts.map +1 -0
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +2 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +524 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/views/InboundNotesView.d.ts.map +1 -1
- package/dist/views/NoteReceiptCard.d.ts +4 -0
- package/dist/views/NoteReceiptCard.d.ts.map +1 -0
- package/dist/views/NoteReconcileView.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/InboundNotesPage-R72EC5E4.js +0 -5
- package/dist/NoteReconcileView-3KVXZLCG.js +0 -4
- package/dist/chunk-OGXYHL3Z.js.map +0 -1
- package/dist/chunk-UYGGBJCR.js.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { InboundNotesPage, makeInboundNotesRoute } from './chunk-LHH2YIDB.js';
|
|
2
|
+
import './chunk-TZH7AWBD.js';
|
|
3
|
+
import './chunk-5LI2FDOM.js';
|
|
4
|
+
import './chunk-DHCCZXUM.js';
|
|
5
|
+
//# sourceMappingURL=InboundNotesPage-UQH2YG3E.js.map
|
|
6
|
+
//# sourceMappingURL=InboundNotesPage-UQH2YG3E.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"InboundNotesPage-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"InboundNotesPage-UQH2YG3E.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"NoteReceiptCard-H5BMFPU7.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"NoteReconcileView-QSRL6NKQ.js"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { shortageReasonKey } from './chunk-DHCCZXUM.js';
|
|
2
|
+
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
3
|
+
import { Loader2 } from 'lucide-react';
|
|
4
|
+
import { Button, Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalBody, CurrencyInput, Input, ModalFooter, toast } from '@fayz-ai/ui';
|
|
5
|
+
import { usePermissionOptional } from '@fayz-ai/admin';
|
|
6
|
+
import { useTranslation, getSupabaseClientOptional, formatCurrency } from '@fayz-ai/core';
|
|
7
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
function sb() {
|
|
10
|
+
const supabase = getSupabaseClientOptional();
|
|
11
|
+
if (!supabase) throw new Error("Supabase not initialized");
|
|
12
|
+
return supabase;
|
|
13
|
+
}
|
|
14
|
+
var n = (v) => Number(v ?? 0) || 0;
|
|
15
|
+
async function getReceiptOccurrence(invoiceId) {
|
|
16
|
+
const { data, error } = await sb().rpc("fiscalbr_note_receipt_occurrences", { p_invoice_id: invoiceId });
|
|
17
|
+
if (error) throw error;
|
|
18
|
+
const lines = (data ?? []).map((r) => ({
|
|
19
|
+
inboxItemId: String(r.inbox_item_id),
|
|
20
|
+
documentId: String(r.document_id),
|
|
21
|
+
nfeNumber: r.nfe_number ?? null,
|
|
22
|
+
itemNumber: n(r.item_number),
|
|
23
|
+
description: String(r.description ?? ""),
|
|
24
|
+
unit: String(r.unit ?? ""),
|
|
25
|
+
noteQuantity: n(r.note_quantity),
|
|
26
|
+
shortageQuantity: n(r.shortage_quantity),
|
|
27
|
+
reason: r.shortage_reason ?? null,
|
|
28
|
+
note: r.shortage_note ?? null,
|
|
29
|
+
shortageValue: n(r.shortage_value),
|
|
30
|
+
receivedValue: n(r.received_value),
|
|
31
|
+
invoiceItemId: r.invoice_item_id ?? null,
|
|
32
|
+
invoiceItemTotal: r.invoice_item_total == null ? null : n(r.invoice_item_total),
|
|
33
|
+
invoiceItemCancelled: Boolean(r.invoice_item_cancelled),
|
|
34
|
+
pending: n(r.pending)
|
|
35
|
+
}));
|
|
36
|
+
if (lines.length === 0) return null;
|
|
37
|
+
return {
|
|
38
|
+
nfeNumber: lines[0].nfeNumber,
|
|
39
|
+
lines,
|
|
40
|
+
pendingTotal: Math.round(lines.reduce((s, l) => s + l.pending, 0) * 100) / 100
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var ABATE_REFUSALS = [
|
|
44
|
+
"ABATE_EXCEEDS_OPEN",
|
|
45
|
+
"ABATE_EXCEEDS_LINE",
|
|
46
|
+
"ABATE_NO_AMOUNT",
|
|
47
|
+
"ABATE_LINE_CANCELLED",
|
|
48
|
+
"ABATE_INVOICE_CANCELLED",
|
|
49
|
+
"ABATE_NOT_PAYABLE",
|
|
50
|
+
"ABATE_BAD_DISTRIBUTION"
|
|
51
|
+
];
|
|
52
|
+
function abateRefusalOf(error) {
|
|
53
|
+
const hint = error?.hint;
|
|
54
|
+
return typeof hint === "string" && ABATE_REFUSALS.includes(hint) ? hint : null;
|
|
55
|
+
}
|
|
56
|
+
async function abateInvoiceItem(input) {
|
|
57
|
+
const { data, error } = await sb().rpc("financial_abate_invoice_item", {
|
|
58
|
+
p_item_id: input.invoiceItemId,
|
|
59
|
+
p_amount: input.amount,
|
|
60
|
+
p_distribution: input.distribution,
|
|
61
|
+
p_note: input.note ?? null,
|
|
62
|
+
p_idempotency_key: input.idempotencyKey
|
|
63
|
+
});
|
|
64
|
+
if (error) throw error;
|
|
65
|
+
const res = data ?? {};
|
|
66
|
+
return {
|
|
67
|
+
amount: n(res.amount),
|
|
68
|
+
itemCancelled: Boolean(res.item_cancelled),
|
|
69
|
+
installments: Array.isArray(res.installments) ? res.installments.length : 0,
|
|
70
|
+
replayed: Boolean(res.replayed)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
var money = (v) => formatCurrency(v || 0, "BRL");
|
|
74
|
+
var qty = (v) => new Intl.NumberFormat("pt-BR", { maximumFractionDigits: 4 }).format(v || 0);
|
|
75
|
+
var DISTRIBUTIONS = ["next", "last", "proportional"];
|
|
76
|
+
function NoteReceiptCard({ invoiceId, direction, cancelled, onChanged }) {
|
|
77
|
+
const t = useTranslation();
|
|
78
|
+
const can = usePermissionOptional();
|
|
79
|
+
const canAbate = can("financial", "edit") && !cancelled;
|
|
80
|
+
const [occurrence, setOccurrence] = useState(null);
|
|
81
|
+
const [abating, setAbating] = useState(null);
|
|
82
|
+
const reload = useCallback(async () => {
|
|
83
|
+
if (!invoiceId || direction !== "debit") {
|
|
84
|
+
setOccurrence(null);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
setOccurrence(await getReceiptOccurrence(invoiceId));
|
|
89
|
+
} catch {
|
|
90
|
+
setOccurrence(null);
|
|
91
|
+
}
|
|
92
|
+
}, [invoiceId, direction]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
void reload();
|
|
95
|
+
}, [reload]);
|
|
96
|
+
if (!occurrence) return null;
|
|
97
|
+
const open = occurrence.pendingTotal > 4e-3;
|
|
98
|
+
return /* @__PURE__ */ jsxs(
|
|
99
|
+
"div",
|
|
100
|
+
{
|
|
101
|
+
"data-testid": "note-receipt-occurrence",
|
|
102
|
+
className: `rounded-card border px-4 py-3 text-sm ${open ? "border-warning bg-warning-soft text-warning-soft-foreground" : "border-success bg-success-soft text-success-soft-foreground"}`,
|
|
103
|
+
children: [
|
|
104
|
+
/* @__PURE__ */ jsx("p", { className: "font-semibold", children: open ? t("fiscalbr.receipt.payable.pending", { value: money(occurrence.pendingTotal) }) : t("fiscalbr.receipt.payable.done") }),
|
|
105
|
+
/* @__PURE__ */ jsx("ul", { className: "mt-1.5 space-y-1.5", children: occurrence.lines.map((l) => /* @__PURE__ */ jsxs("li", { className: "flex flex-wrap items-center justify-between gap-2", children: [
|
|
106
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0", children: t("fiscalbr.receipt.payable.line", {
|
|
107
|
+
description: l.description,
|
|
108
|
+
missing: qty(l.shortageQuantity),
|
|
109
|
+
billed: qty(l.noteQuantity),
|
|
110
|
+
unit: l.unit,
|
|
111
|
+
reason: t(shortageReasonKey(l.reason)) + (l.note ? ` \u2014 ${l.note}` : ""),
|
|
112
|
+
value: money(l.shortageValue)
|
|
113
|
+
}) }),
|
|
114
|
+
l.pending > 4e-3 && l.invoiceItemId && canAbate ? /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => setAbating(l), children: t("fiscalbr.receipt.payable.abate", { value: money(l.pending) }) }) : /* @__PURE__ */ jsx("span", { className: "text-xs opacity-80", children: l.invoiceItemId ? t("fiscalbr.receipt.payable.abated") : t("fiscalbr.receipt.payable.outside") })
|
|
115
|
+
] }, l.inboxItemId)) }),
|
|
116
|
+
/* @__PURE__ */ jsx(
|
|
117
|
+
AbateDialog,
|
|
118
|
+
{
|
|
119
|
+
line: abating,
|
|
120
|
+
onClose: () => setAbating(null),
|
|
121
|
+
onDone: () => {
|
|
122
|
+
setAbating(null);
|
|
123
|
+
void reload();
|
|
124
|
+
onChanged?.();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
function AbateDialog({ line, onClose, onDone }) {
|
|
133
|
+
const t = useTranslation();
|
|
134
|
+
const [amount, setAmount] = useState(0);
|
|
135
|
+
const [distribution, setDistribution] = useState("next");
|
|
136
|
+
const [note, setNote] = useState("");
|
|
137
|
+
const [submitting, setSubmitting] = useState(false);
|
|
138
|
+
const key = useMemo(() => line ? `abate:${line.invoiceItemId}:${crypto.randomUUID()}` : "", [line]);
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (!line) return;
|
|
141
|
+
setAmount(line.pending);
|
|
142
|
+
setDistribution("next");
|
|
143
|
+
setNote(line.note ?? "");
|
|
144
|
+
}, [line]);
|
|
145
|
+
const submit = async () => {
|
|
146
|
+
if (!line?.invoiceItemId) return;
|
|
147
|
+
if (!(amount > 0)) {
|
|
148
|
+
toast.error(t("fiscalbr.receipt.abate.noAmount"));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
setSubmitting(true);
|
|
152
|
+
try {
|
|
153
|
+
const res = await abateInvoiceItem({
|
|
154
|
+
invoiceItemId: line.invoiceItemId,
|
|
155
|
+
amount,
|
|
156
|
+
distribution,
|
|
157
|
+
note: note.trim() || null,
|
|
158
|
+
idempotencyKey: key
|
|
159
|
+
});
|
|
160
|
+
toast.success(t("fiscalbr.receipt.abate.done", { value: money(res.amount) }), {
|
|
161
|
+
description: res.itemCancelled ? t("fiscalbr.receipt.abate.doneCancelled", { count: res.installments }) : t("fiscalbr.receipt.abate.doneInstallments", { count: res.installments })
|
|
162
|
+
});
|
|
163
|
+
onDone();
|
|
164
|
+
} catch (e) {
|
|
165
|
+
const refusal = abateRefusalOf(e);
|
|
166
|
+
toast.error(t("fiscalbr.receipt.abate.failed"), {
|
|
167
|
+
description: refusal ? t(`fiscalbr.receipt.abate.refusal.${refusal}`) : e?.message
|
|
168
|
+
});
|
|
169
|
+
} finally {
|
|
170
|
+
setSubmitting(false);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return /* @__PURE__ */ jsx(Modal, { open: !!line, onOpenChange: (o) => {
|
|
174
|
+
if (!o) onClose();
|
|
175
|
+
}, children: /* @__PURE__ */ jsxs(ModalContent, { size: "md", children: [
|
|
176
|
+
/* @__PURE__ */ jsxs(ModalHeader, { children: [
|
|
177
|
+
/* @__PURE__ */ jsx(ModalTitle, { children: t("fiscalbr.receipt.abate.title") }),
|
|
178
|
+
line && /* @__PURE__ */ jsx(ModalDescription, { children: t("fiscalbr.receipt.abate.description", {
|
|
179
|
+
description: line.description,
|
|
180
|
+
missing: qty(line.shortageQuantity),
|
|
181
|
+
billed: qty(line.noteQuantity),
|
|
182
|
+
unit: line.unit,
|
|
183
|
+
reason: t(shortageReasonKey(line.reason))
|
|
184
|
+
}) })
|
|
185
|
+
] }),
|
|
186
|
+
line && /* @__PURE__ */ jsxs(ModalBody, { className: "space-y-4", children: [
|
|
187
|
+
/* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
|
|
188
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: t("fiscalbr.receipt.abate.amount") }),
|
|
189
|
+
/* @__PURE__ */ jsx(CurrencyInput, { value: amount, onChange: setAmount }),
|
|
190
|
+
/* @__PURE__ */ jsx("span", { className: "block text-xs text-muted-foreground", children: t("fiscalbr.receipt.abate.amountHint", { pending: money(line.pending), received: money(line.receivedValue) }) })
|
|
191
|
+
] }),
|
|
192
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1.5", role: "radiogroup", "aria-label": t("fiscalbr.receipt.abate.distribution"), children: [
|
|
193
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: t("fiscalbr.receipt.abate.distribution") }),
|
|
194
|
+
DISTRIBUTIONS.map((d) => /* @__PURE__ */ jsxs(
|
|
195
|
+
Button,
|
|
196
|
+
{
|
|
197
|
+
variant: "bare",
|
|
198
|
+
size: "bare",
|
|
199
|
+
type: "button",
|
|
200
|
+
role: "radio",
|
|
201
|
+
"aria-checked": distribution === d,
|
|
202
|
+
onClick: () => setDistribution(d),
|
|
203
|
+
className: `flex w-full flex-col items-start gap-0 rounded-md border px-3 py-2 text-left font-normal transition-colors ${distribution === d ? "border-primary bg-primary/10" : "border-input hover:bg-muted"}`,
|
|
204
|
+
children: [
|
|
205
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm", children: t(`fiscalbr.receipt.abate.${d}`) }),
|
|
206
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t(`fiscalbr.receipt.abate.${d}Hint`) })
|
|
207
|
+
]
|
|
208
|
+
},
|
|
209
|
+
d
|
|
210
|
+
))
|
|
211
|
+
] }),
|
|
212
|
+
/* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
|
|
213
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground", children: t("fiscalbr.receipt.abate.note") }),
|
|
214
|
+
/* @__PURE__ */ jsx(Input, { value: note, onChange: (e) => setNote(e.target.value), placeholder: t("fiscalbr.receipt.abate.notePlaceholder") })
|
|
215
|
+
] })
|
|
216
|
+
] }),
|
|
217
|
+
/* @__PURE__ */ jsxs(ModalFooter, { children: [
|
|
218
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onClose, disabled: submitting, children: t("fiscalbr.receipt.abate.back") }),
|
|
219
|
+
/* @__PURE__ */ jsxs(Button, { onClick: () => {
|
|
220
|
+
void submit();
|
|
221
|
+
}, disabled: submitting || !line, children: [
|
|
222
|
+
submitting && /* @__PURE__ */ jsx(Loader2, { className: "mr-1.5 h-4 w-4 animate-spin" }),
|
|
223
|
+
t("fiscalbr.receipt.abate.submit")
|
|
224
|
+
] })
|
|
225
|
+
] })
|
|
226
|
+
] }) });
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export { ABATE_REFUSALS, NoteReceiptCard, abateInvoiceItem, abateRefusalOf, getReceiptOccurrence };
|
|
230
|
+
//# sourceMappingURL=chunk-3BDFMEYY.js.map
|
|
231
|
+
//# sourceMappingURL=chunk-3BDFMEYY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/data/receipt.ts","../src/views/NoteReceiptCard.tsx"],"names":[],"mappings":";;;;;;;;AAaA,SAAS,EAAA,GAAK;AACZ,EAAA,MAAM,WAAW,yBAAA,EAA0B;AAC3C,EAAA,IAAI,CAAC,QAAA,EAAU,MAAM,IAAI,MAAM,0BAA0B,CAAA;AACzD,EAAA,OAAO,QAAA;AACT;AA4BA,IAAM,IAAI,CAAC,CAAA,KAAe,MAAA,CAAO,CAAA,IAAK,CAAC,CAAA,IAAK,CAAA;AAG5C,eAAsB,qBAAqB,SAAA,EAAsD;AAC/F,EAAA,MAAM,EAAE,IAAA,EAAM,KAAA,EAAM,GAAI,MAAM,EAAA,EAAG,CAAE,GAAA,CAAI,mCAAA,EAAqC,EAAE,YAAA,EAAc,SAAA,EAAW,CAAA;AACvG,EA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E,+BAA+B;AAAA,OAAA,EACpC;AAAA,KAAA,EACF;AAAA,GAAA,EACF,CAAA,EACF,CAAA;AAEJ","file":"chunk-3BDFMEYY.js","sourcesContent":["// ---------------------------------------------------------------------------\n// receipt — what did not arrive of a note, as its payable sees it, and the\n// gesture that abates it (V1 beautyplace #1031: \"Ocorrência no recebimento\",\n// \"Abater\").\n// ---------------------------------------------------------------------------\n// Both go through one RPC each: the read is fiscal-br/034's\n// `fiscalbr_note_receipt_occurrences`, the write is financial/137's\n// `financial_abate_invoice_item`, which owns every rule (open balance only,\n// never the paid part, three ways to spread it). This module only sends and\n// reads; the refusal codes come back in the error's `hint`.\n// ---------------------------------------------------------------------------\nimport { getSupabaseClientOptional } from '@fayz-ai/core'\n\nfunction sb() {\n const supabase = getSupabaseClientOptional() as any\n if (!supabase) throw new Error('Supabase not initialized')\n return supabase\n}\n\nexport interface ReceiptOccurrenceLine {\n inboxItemId: string\n documentId: string\n nfeNumber: string | null\n itemNumber: number\n description: string\n unit: string\n noteQuantity: number\n shortageQuantity: number\n reason: string | null\n note: string | null\n shortageValue: number\n receivedValue: number\n invoiceItemId: string | null\n invoiceItemTotal: number | null\n invoiceItemCancelled: boolean\n /** Still to abate on the payable (0 = abated, or no payable line). */\n pending: number\n}\n\nexport interface ReceiptOccurrence {\n nfeNumber: string | null\n lines: ReceiptOccurrenceLine[]\n pendingTotal: number\n}\n\nconst n = (v: unknown) => Number(v ?? 0) || 0\n\n/** What did not arrive on the note(s) behind this payable. `null` when nothing is missing. */\nexport async function getReceiptOccurrence(invoiceId: string): Promise<ReceiptOccurrence | null> {\n const { data, error } = await sb().rpc('fiscalbr_note_receipt_occurrences', { p_invoice_id: invoiceId })\n if (error) throw error\n const lines: ReceiptOccurrenceLine[] = ((data ?? []) as Array<Record<string, unknown>>).map((r) => ({\n inboxItemId: String(r.inbox_item_id),\n documentId: String(r.document_id),\n nfeNumber: (r.nfe_number as string) ?? null,\n itemNumber: n(r.item_number),\n description: String(r.description ?? ''),\n unit: String(r.unit ?? ''),\n noteQuantity: n(r.note_quantity),\n shortageQuantity: n(r.shortage_quantity),\n reason: (r.shortage_reason as string) ?? null,\n note: (r.shortage_note as string) ?? null,\n shortageValue: n(r.shortage_value),\n receivedValue: n(r.received_value),\n invoiceItemId: (r.invoice_item_id as string) ?? null,\n invoiceItemTotal: r.invoice_item_total == null ? null : n(r.invoice_item_total),\n invoiceItemCancelled: Boolean(r.invoice_item_cancelled),\n pending: n(r.pending),\n }))\n if (lines.length === 0) return null\n return {\n nfeNumber: lines[0].nfeNumber,\n lines,\n pendingTotal: Math.round(lines.reduce((s, l) => s + l.pending, 0) * 100) / 100,\n }\n}\n\nexport type AbateDistribution = 'next' | 'last' | 'proportional'\n\nexport interface AbateResult {\n amount: number\n itemCancelled: boolean\n installments: number\n replayed: boolean\n}\n\n/** The refusal codes financial/137 raises, as the error's `hint`. */\nexport const ABATE_REFUSALS = [\n 'ABATE_EXCEEDS_OPEN', 'ABATE_EXCEEDS_LINE', 'ABATE_NO_AMOUNT', 'ABATE_LINE_CANCELLED',\n 'ABATE_INVOICE_CANCELLED', 'ABATE_NOT_PAYABLE', 'ABATE_BAD_DISTRIBUTION',\n] as const\nexport type AbateRefusal = typeof ABATE_REFUSALS[number]\n\nexport function abateRefusalOf(error: unknown): AbateRefusal | null {\n const hint = (error as { hint?: unknown } | null)?.hint\n return typeof hint === 'string' && (ABATE_REFUSALS as readonly string[]).includes(hint) ? hint as AbateRefusal : null\n}\n\nexport async function abateInvoiceItem(input: {\n invoiceItemId: string\n amount: number\n distribution: AbateDistribution\n note?: string | null\n idempotencyKey: string\n}): Promise<AbateResult> {\n const { data, error } = await sb().rpc('financial_abate_invoice_item', {\n p_item_id: input.invoiceItemId,\n p_amount: input.amount,\n p_distribution: input.distribution,\n p_note: input.note ?? null,\n p_idempotency_key: input.idempotencyKey,\n })\n if (error) throw error\n const res = (data ?? {}) as Record<string, unknown>\n return {\n amount: n(res.amount),\n itemCancelled: Boolean(res.item_cancelled),\n installments: Array.isArray(res.installments) ? res.installments.length : 0,\n replayed: Boolean(res.replayed),\n }\n}\n","// ---------------------------------------------------------------------------\n// NoteReceiptCard — on a payable opened by a supplier's note: what did not\n// arrive, and «Abater» per line (V1 beautyplace #1031, PayablesForm's\n// \"Ocorrência no recebimento\" + AbatePurchaseItemDialog).\n// ---------------------------------------------------------------------------\n// The payable is born at the note's full value; this card is how finance\n// sees the shortfall the receiver recorded and takes it off the open\n// instalments. Every rule is the database's (financial/137); the card sends\n// the gesture and turns a refusal code into a sentence.\n// ---------------------------------------------------------------------------\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport { Loader2 } from 'lucide-react'\nimport {\n Button, CurrencyInput, Input, Modal, ModalBody, ModalContent, ModalDescription, ModalFooter, ModalHeader, ModalTitle, toast,\n} from '@fayz-ai/ui'\nimport { usePermissionOptional } from '@fayz-ai/admin'\nimport { formatCurrency, useTranslation } from '@fayz-ai/core'\nimport type { InvoiceNoticeSlotProps } from '@fayz-ai/financial/views/zones'\nimport {\n abateInvoiceItem, abateRefusalOf, getReceiptOccurrence,\n type AbateDistribution, type ReceiptOccurrence, type ReceiptOccurrenceLine,\n} from '../data/receipt'\nimport { shortageReasonKey } from '../lib/receipt'\n\nconst money = (v: number) => formatCurrency(v || 0, 'BRL')\nconst qty = (v: number) => new Intl.NumberFormat('pt-BR', { maximumFractionDigits: 4 }).format(v || 0)\n\nconst DISTRIBUTIONS: AbateDistribution[] = ['next', 'last', 'proportional']\n\nexport function NoteReceiptCard({ invoiceId, direction, cancelled, onChanged }: InvoiceNoticeSlotProps) {\n const t = useTranslation()\n const can = usePermissionOptional()\n const canAbate = can('financial', 'edit') && !cancelled\n const [occurrence, setOccurrence] = useState<ReceiptOccurrence | null>(null)\n const [abating, setAbating] = useState<ReceiptOccurrenceLine | null>(null)\n\n const reload = useCallback(async () => {\n if (!invoiceId || direction !== 'debit') { setOccurrence(null); return }\n try {\n setOccurrence(await getReceiptOccurrence(invoiceId))\n } catch {\n // A fiscal read failing must not take the bill screen down with it.\n setOccurrence(null)\n }\n }, [invoiceId, direction])\n\n useEffect(() => { void reload() }, [reload])\n\n if (!occurrence) return null\n const open = occurrence.pendingTotal > 0.004\n\n return (\n <div\n data-testid=\"note-receipt-occurrence\"\n className={`rounded-card border px-4 py-3 text-sm ${open\n ? 'border-warning bg-warning-soft text-warning-soft-foreground'\n : 'border-success bg-success-soft text-success-soft-foreground'}`}\n >\n <p className=\"font-semibold\">\n {open\n ? t('fiscalbr.receipt.payable.pending', { value: money(occurrence.pendingTotal) })\n : t('fiscalbr.receipt.payable.done')}\n </p>\n <ul className=\"mt-1.5 space-y-1.5\">\n {occurrence.lines.map((l) => (\n <li key={l.inboxItemId} className=\"flex flex-wrap items-center justify-between gap-2\">\n <span className=\"min-w-0\">\n {t('fiscalbr.receipt.payable.line', {\n description: l.description,\n missing: qty(l.shortageQuantity),\n billed: qty(l.noteQuantity),\n unit: l.unit,\n reason: t(shortageReasonKey(l.reason)) + (l.note ? ` — ${l.note}` : ''),\n value: money(l.shortageValue),\n })}\n </span>\n {l.pending > 0.004 && l.invoiceItemId && canAbate ? (\n <Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={() => setAbating(l)}>\n {t('fiscalbr.receipt.payable.abate', { value: money(l.pending) })}\n </Button>\n ) : (\n <span className=\"text-xs opacity-80\">\n {l.invoiceItemId ? t('fiscalbr.receipt.payable.abated') : t('fiscalbr.receipt.payable.outside')}\n </span>\n )}\n </li>\n ))}\n </ul>\n <AbateDialog\n line={abating}\n onClose={() => setAbating(null)}\n onDone={() => { setAbating(null); void reload(); onChanged?.() }}\n />\n </div>\n )\n}\n\nfunction AbateDialog({ line, onClose, onDone }: {\n line: ReceiptOccurrenceLine | null\n onClose: () => void\n onDone: () => void\n}) {\n const t = useTranslation()\n const [amount, setAmount] = useState(0)\n const [distribution, setDistribution] = useState<AbateDistribution>('next')\n const [note, setNote] = useState('')\n const [submitting, setSubmitting] = useState(false)\n // One key per opening: a double click replays instead of abating twice.\n const key = useMemo(() => (line ? `abate:${line.invoiceItemId}:${crypto.randomUUID()}` : ''), [line])\n\n useEffect(() => {\n if (!line) return\n setAmount(line.pending)\n setDistribution('next')\n setNote(line.note ?? '')\n }, [line])\n\n const submit = async () => {\n if (!line?.invoiceItemId) return\n if (!(amount > 0)) { toast.error(t('fiscalbr.receipt.abate.noAmount')); return }\n setSubmitting(true)\n try {\n const res = await abateInvoiceItem({\n invoiceItemId: line.invoiceItemId, amount, distribution, note: note.trim() || null, idempotencyKey: key,\n })\n toast.success(t('fiscalbr.receipt.abate.done', { value: money(res.amount) }), {\n description: res.itemCancelled\n ? t('fiscalbr.receipt.abate.doneCancelled', { count: res.installments })\n : t('fiscalbr.receipt.abate.doneInstallments', { count: res.installments }),\n })\n onDone()\n } catch (e) {\n const refusal = abateRefusalOf(e)\n toast.error(t('fiscalbr.receipt.abate.failed'), {\n description: refusal ? t(`fiscalbr.receipt.abate.refusal.${refusal}`) : (e as { message?: string })?.message,\n })\n } finally {\n setSubmitting(false)\n }\n }\n\n return (\n <Modal open={!!line} onOpenChange={(o) => { if (!o) onClose() }}>\n <ModalContent size=\"md\">\n <ModalHeader>\n <ModalTitle>{t('fiscalbr.receipt.abate.title')}</ModalTitle>\n {line && (\n <ModalDescription>\n {t('fiscalbr.receipt.abate.description', {\n description: line.description,\n missing: qty(line.shortageQuantity),\n billed: qty(line.noteQuantity),\n unit: line.unit,\n reason: t(shortageReasonKey(line.reason)),\n })}\n </ModalDescription>\n )}\n </ModalHeader>\n {line && (\n <ModalBody className=\"space-y-4\">\n <label className=\"block space-y-1\">\n <span className=\"text-xs font-medium text-muted-foreground\">{t('fiscalbr.receipt.abate.amount')}</span>\n <CurrencyInput value={amount} onChange={setAmount} />\n <span className=\"block text-xs text-muted-foreground\">\n {t('fiscalbr.receipt.abate.amountHint', { pending: money(line.pending), received: money(line.receivedValue) })}\n </span>\n </label>\n <div className=\"space-y-1.5\" role=\"radiogroup\" aria-label={t('fiscalbr.receipt.abate.distribution')}>\n <span className=\"text-xs font-medium text-muted-foreground\">{t('fiscalbr.receipt.abate.distribution')}</span>\n {DISTRIBUTIONS.map((d) => (\n <Button variant=\"bare\" size=\"bare\"\n key={d}\n type=\"button\"\n role=\"radio\"\n aria-checked={distribution === d}\n onClick={() => setDistribution(d)}\n className={`flex w-full flex-col items-start gap-0 rounded-md border px-3 py-2 text-left font-normal transition-colors ${\n distribution === d ? 'border-primary bg-primary/10' : 'border-input hover:bg-muted'\n }`}\n >\n <span className=\"text-sm\">{t(`fiscalbr.receipt.abate.${d}`)}</span>\n <span className=\"text-xs text-muted-foreground\">{t(`fiscalbr.receipt.abate.${d}Hint`)}</span>\n </Button>\n ))}\n </div>\n <label className=\"block space-y-1\">\n <span className=\"text-xs font-medium text-muted-foreground\">{t('fiscalbr.receipt.abate.note')}</span>\n <Input value={note} onChange={(e) => setNote(e.target.value)} placeholder={t('fiscalbr.receipt.abate.notePlaceholder')} />\n </label>\n </ModalBody>\n )}\n <ModalFooter>\n <Button variant=\"outline\" onClick={onClose} disabled={submitting}>{t('fiscalbr.receipt.abate.back')}</Button>\n <Button onClick={() => { void submit() }} disabled={submitting || !line}>\n {submitting && <Loader2 className=\"mr-1.5 h-4 w-4 animate-spin\" />}\n {t('fiscalbr.receipt.abate.submit')}\n </Button>\n </ModalFooter>\n </ModalContent>\n </Modal>\n )\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/lib/receipt.ts
|
|
2
|
+
var SHORTAGE_REASONS = ["faltou", "avariado", "vencido", "recusado", "outro"];
|
|
3
|
+
var isShortageReason = (v) => typeof v === "string" && SHORTAGE_REASONS.includes(v);
|
|
4
|
+
var shortageReasonKey = (v) => `fiscalbr.receipt.reason.${isShortageReason(v) ? v : "unknown"}`;
|
|
5
|
+
var round2 = (n) => Math.round(n * 100) / 100;
|
|
6
|
+
var EPS = 1e-9;
|
|
7
|
+
function shortageQty(line) {
|
|
8
|
+
const q = Number(line.quantity) || 0;
|
|
9
|
+
const s = Number(line.shortageQuantity) || 0;
|
|
10
|
+
return Math.min(Math.max(s, 0), Math.max(q, 0));
|
|
11
|
+
}
|
|
12
|
+
function receivedFraction(line) {
|
|
13
|
+
const q = Number(line.quantity) || 0;
|
|
14
|
+
if (q <= 0) return 1;
|
|
15
|
+
return 1 - shortageQty(line) / q;
|
|
16
|
+
}
|
|
17
|
+
function receivedQty(line) {
|
|
18
|
+
return Math.max((Number(line.quantity) || 0) - shortageQty(line), 0);
|
|
19
|
+
}
|
|
20
|
+
function hasShortage(line) {
|
|
21
|
+
return shortageQty(line) > EPS;
|
|
22
|
+
}
|
|
23
|
+
function shortageValue(line) {
|
|
24
|
+
return round2((Number(line.total) || 0) * (1 - receivedFraction(line)));
|
|
25
|
+
}
|
|
26
|
+
function receivedValue(line) {
|
|
27
|
+
return round2((Number(line.total) || 0) - shortageValue(line));
|
|
28
|
+
}
|
|
29
|
+
function receivedStockQty(line, factor) {
|
|
30
|
+
const billed = (Number(line.quantity) || 0) * (Number(factor) || 1);
|
|
31
|
+
return Math.round(billed * receivedFraction(line) * 1e4) / 1e4;
|
|
32
|
+
}
|
|
33
|
+
function pendingAbatement(line, payableLine) {
|
|
34
|
+
if (!hasShortage(line) || !payableLine || payableLine.cancelled) return 0;
|
|
35
|
+
return Math.max(0, round2((Number(payableLine.total) || 0) - receivedValue(line)));
|
|
36
|
+
}
|
|
37
|
+
function summarizeOccurrence(lines) {
|
|
38
|
+
const short = lines.filter(hasShortage);
|
|
39
|
+
return { count: short.length, value: round2(short.reduce((s, l) => s + shortageValue(l), 0)) };
|
|
40
|
+
}
|
|
41
|
+
function parseQty(raw) {
|
|
42
|
+
const t = raw.trim();
|
|
43
|
+
if (!t) return null;
|
|
44
|
+
const n = Number(t.replace(",", "."));
|
|
45
|
+
return Number.isFinite(n) ? n : NaN;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { SHORTAGE_REASONS, hasShortage, isShortageReason, parseQty, pendingAbatement, receivedFraction, receivedQty, receivedStockQty, receivedValue, shortageQty, shortageReasonKey, shortageValue, summarizeOccurrence };
|
|
49
|
+
//# sourceMappingURL=chunk-DHCCZXUM.js.map
|
|
50
|
+
//# sourceMappingURL=chunk-DHCCZXUM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/receipt.ts"],"names":[],"mappings":";AAcO,IAAM,mBAAmB,CAAC,QAAA,EAAU,UAAA,EAAY,SAAA,EAAW,YAAY,OAAO;AAG9E,IAAM,gBAAA,GAAmB,CAAC,CAAA,KAC/B,OAAO,MAAM,QAAA,IAAa,gBAAA,CAAuC,SAAS,CAAC;AAGtE,IAAM,iBAAA,GAAoB,CAAC,CAAA,KAChC,CAAA,wBAAA,EAA2B,iBAAiB,CAAC,CAAA,GAAI,IAAI,SAAS,CAAA;AAQhE,IAAM,SAAS,CAAC,CAAA,KAAc,KAAK,KAAA,CAAM,CAAA,GAAI,GAAG,CAAA,GAAI,GAAA;AACpD,IAAM,GAAA,GAAM,IAAA;AAGL,SAAS,YAAY,IAAA,EAA2B;AACrD,EAAA,MAAM,CAAA,GAAI,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA,IAAK,CAAA;AACnC,EAAA,MAAM,CAAA,GAAI,MAAA,CAAO,IAAA,CAAK,gBAAgB,CAAA,IAAK,CAAA;AAC3C,EAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAC,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAC,CAAC,CAAA;AAChD;AAGO,SAAS,iBAAiB,IAAA,EAA2B;AAC1D,EAAA,MAAM,CAAA,GAAI,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA,IAAK,CAAA;AACnC,EAAA,IAAI,CAAA,IAAK,GAAG,OAAO,CAAA;AACnB,EAAA,OAAO,CAAA,GAAI,WAAA,CAAY,IAAI,CAAA,GAAI,CAAA;AACjC;AAEO,S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AAM,MAAA,CAAO,WAAW,CAAA;AACtC,EAAA,OAAO,EAAE,KAAA,EAAO,KAAA,CAAM,MAAA,EAAQ,KAAA,EAAO,OAAO,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,EAAG,MAAM,CAAA,GAAI,aAAA,CAAc,CAAC,CAAA,EAAG,CAAC,CAAC,CAAA,EAAE;AAC/F;AAGO,SAAS,SAAS,GAAA,EAA4B;AACnD,EAAA,MAAM,CAAA,GAAI,IAAI,IAAA,EAAK;AACnB,EAAA,IAAI,CAAC,GAAG,OAAO,IAAA;AACf,EAAA,MAAM,IAAI,MAAA,CAAO,CAAA,CAAE,OAAA,CAAQ,GAAA,EAAK,GAAG,CAAC,CAAA;AACpC,EAAA,OAAO,MAAA,CAAO,QAAA,CAAS,CAAC,CAAA,GAAI,CAAA,GAAI,GAAA;AAClC","file":"chunk-DHCCZXUM.js","sourcesContent":["// ---------------------------------------------------------------------------\n// receipt — what arrived of a supplier's note (V1 beautyplace #1031,\n// src/lib/danfeReceipt.ts, ported as-is).\n// ---------------------------------------------------------------------------\n// Whoever receives the goods records, per line, how much did NOT arrive and\n// why. `shortageQuantity` is in the NOTE's unit (the paper in their hand: 8 UN,\n// 3 CX), and stock takes only what arrived. The payable is born at the note's\n// full value; what is still to abate is DERIVED (payable line − value\n// received), so no second state can drift from the bill. The database applies\n// the same arithmetic (fiscal-br/034); this module is what the screens show\n// before anyone presses Accept.\n// ---------------------------------------------------------------------------\n\n/** The V1 vocabulary. Values are stored; labels are the locale keys' defaults. */\nexport const SHORTAGE_REASONS = ['faltou', 'avariado', 'vencido', 'recusado', 'outro'] as const\nexport type ShortageReason = typeof SHORTAGE_REASONS[number]\n\nexport const isShortageReason = (v: unknown): v is ShortageReason =>\n typeof v === 'string' && (SHORTAGE_REASONS as readonly string[]).includes(v)\n\n/** The locale key of a reason's label (`fiscalbr.receipt.reason.<value>`). */\nexport const shortageReasonKey = (v: string | null | undefined): string =>\n `fiscalbr.receipt.reason.${isShortageReason(v) ? v : 'unknown'}`\n\nexport interface ReceiptLine {\n quantity: number | string | null\n total?: number | string | null\n shortageQuantity?: number | string | null\n}\n\nconst round2 = (n: number) => Math.round(n * 100) / 100\nconst EPS = 1e-9\n\n/** How much did not arrive, clamped to [0, billed]. */\nexport function shortageQty(line: ReceiptLine): number {\n const q = Number(line.quantity) || 0\n const s = Number(line.shortageQuantity) || 0\n return Math.min(Math.max(s, 0), Math.max(q, 0))\n}\n\n/** The fraction that arrived (1 = all of it, 0 = nothing). */\nexport function receivedFraction(line: ReceiptLine): number {\n const q = Number(line.quantity) || 0\n if (q <= 0) return 1\n return 1 - shortageQty(line) / q\n}\n\nexport function receivedQty(line: ReceiptLine): number {\n return Math.max((Number(line.quantity) || 0) - shortageQty(line), 0)\n}\n\nexport function hasShortage(line: ReceiptLine): boolean {\n return shortageQty(line) > EPS\n}\n\n/** The value of what did not arrive, in proportion to the line's total on the note. */\nexport function shortageValue(line: ReceiptLine): number {\n return round2((Number(line.total) || 0) * (1 - receivedFraction(line)))\n}\n\n/** What the payable line is worth once abated: the value of what arrived. */\nexport function receivedValue(line: ReceiptLine): number {\n return round2((Number(line.total) || 0) - shortageValue(line))\n}\n\n/** What enters stock: the billed stock quantity × the received fraction. */\nexport function receivedStockQty(line: ReceiptLine, factor: number): number {\n const billed = (Number(line.quantity) || 0) * (Number(factor) || 1)\n return Math.round(billed * receivedFraction(line) * 10000) / 10000\n}\n\n/**\n * What is still to abate on the payable: its line bills more than what\n * arrived is worth. A cancelled line was abated in full; no line, nothing to abate.\n */\nexport function pendingAbatement(\n line: ReceiptLine,\n payableLine: { total: number | string | null; cancelled?: boolean } | null | undefined,\n): number {\n if (!hasShortage(line) || !payableLine || payableLine.cancelled) return 0\n return Math.max(0, round2((Number(payableLine.total) || 0) - receivedValue(line)))\n}\n\nexport interface OccurrenceSummary { count: number; value: number }\n\nexport function summarizeOccurrence(lines: ReceiptLine[]): OccurrenceSummary {\n const short = lines.filter(hasShortage)\n return { count: short.length, value: round2(short.reduce((s, l) => s + shortageValue(l), 0)) }\n}\n\n/** Parses what a person typed (\"1,5\", \"2\") into a number, or null when blank. */\nexport function parseQty(raw: string): number | null {\n const t = raw.trim()\n if (!t) return null\n const n = Number(t.replace(',', '.'))\n return Number.isFinite(n) ? n : NaN\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { listInboxNotes, getInboxIntakeHealth, syncNewNotes, stageNoteFromXml, getInboxNoteXml, getInboxNotePdf, rejectNote, PullByKeyDialog, findInboxNoteByOperation, NoteReconcileView } from './chunk-
|
|
1
|
+
import { listInboxNotes, getInboxIntakeHealth, syncNewNotes, stageNoteFromXml, getInboxNoteXml, getInboxNotePdf, rejectNote, PullByKeyDialog, findInboxNoteByOperation, NoteReconcileView } from './chunk-TZH7AWBD.js';
|
|
2
2
|
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
3
3
|
import { useFilterDraft, Button, RowActions, PageHeaderActions, Card, FilterPanel, FilterPanelField, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, SearchField, TooltipProvider, DataTable, ChevronPager, Tooltip, TooltipTrigger, TooltipContent, Modal, ModalContent } from '@fayz-ai/ui';
|
|
4
4
|
import { Eye, ListChecks, FileCode2, FileText, Trash2, Loader2, UploadCloud, RefreshCw, KeyRound, FileDown, Inbox } from 'lucide-react';
|
|
5
5
|
import { useUnitFilter, PageActions, adminNavigateTo } from '@fayz-ai/admin';
|
|
6
|
-
import { currentAppPath, appHref, onAppPathChange, navigateApp, formatCurrency } from '@fayz-ai/core';
|
|
6
|
+
import { useTranslation, currentAppPath, appHref, onAppPathChange, navigateApp, formatCurrency } from '@fayz-ai/core';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
|
|
9
9
|
var money = (value) => formatCurrency(value || 0, "BRL");
|
|
@@ -33,14 +33,14 @@ function InboundNotesView({ onOpenNote }) {
|
|
|
33
33
|
const [pullOpen, setPullOpen] = useState(false);
|
|
34
34
|
const fileInput = useRef(null);
|
|
35
35
|
const unidades = useUnitFilter({ scope: "list" });
|
|
36
|
-
const { draft, applied, patch, setDraft,
|
|
36
|
+
const { draft, applied, patch, setDraft, apply, reset } = useFilterDraft({
|
|
37
37
|
filter: "all",
|
|
38
38
|
unitId: unidades.value ?? "",
|
|
39
|
-
//
|
|
40
|
-
//
|
|
39
|
+
// No period by default: V1 opens on «Todos os registros», and a 30-day
|
|
40
|
+
// window would hide exactly the old note that was never stocked.
|
|
41
41
|
from: "",
|
|
42
42
|
to: ""
|
|
43
|
-
});
|
|
43
|
+
}, { persistKey: "fiscal.inbound-notes", persistExclude: ["unitId"] });
|
|
44
44
|
const ancora = unidades.value ?? "";
|
|
45
45
|
const ancoraAnterior = useRef(ancora);
|
|
46
46
|
useEffect(() => {
|
|
@@ -49,19 +49,22 @@ function InboundNotesView({ onOpenNote }) {
|
|
|
49
49
|
setDraft((atual) => ({ ...atual, unitId: ancora }));
|
|
50
50
|
apply();
|
|
51
51
|
}, [ancora, setDraft, apply]);
|
|
52
|
+
const requestSeq = useRef(0);
|
|
52
53
|
const reload = useCallback(async () => {
|
|
54
|
+
const seq = ++requestSeq.current;
|
|
53
55
|
setLoading(true);
|
|
54
56
|
try {
|
|
55
|
-
|
|
57
|
+
const rows = await listInboxNotes({
|
|
56
58
|
filter: applied.filter,
|
|
57
59
|
unitId: applied.unitId || void 0,
|
|
58
60
|
from: applied.from || void 0,
|
|
59
61
|
to: applied.to || void 0,
|
|
60
62
|
// The list pages on screen; the default 200 would silently drop the rest.
|
|
61
63
|
limit: 5e3
|
|
62
|
-
})
|
|
64
|
+
});
|
|
65
|
+
if (seq === requestSeq.current) setNotes(rows);
|
|
63
66
|
} finally {
|
|
64
|
-
setLoading(false);
|
|
67
|
+
if (seq === requestSeq.current) setLoading(false);
|
|
65
68
|
}
|
|
66
69
|
}, [applied]);
|
|
67
70
|
useEffect(() => {
|
|
@@ -236,7 +239,10 @@ function InboundNotesView({ onOpenNote }) {
|
|
|
236
239
|
id: "stock",
|
|
237
240
|
header: () => /* @__PURE__ */ jsx("span", { className: "block text-center", children: "Estoque" }),
|
|
238
241
|
accessorFn: (note) => note.stockedAt ? 2 : note.status === "rejected" ? 0 : 1,
|
|
239
|
-
cell: ({ row }) => /* @__PURE__ */
|
|
242
|
+
cell: ({ row }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-1", children: [
|
|
243
|
+
/* @__PURE__ */ jsx(StockBadge, { stockedAt: row.original.stockedAt, status: row.original.status }),
|
|
244
|
+
row.original.shortageCount > 0 && /* @__PURE__ */ jsx(ShortageBadge, {})
|
|
245
|
+
] })
|
|
240
246
|
},
|
|
241
247
|
{
|
|
242
248
|
id: "actions",
|
|
@@ -417,11 +423,8 @@ function InboundNotesView({ onOpenNote }) {
|
|
|
417
423
|
FilterPanel,
|
|
418
424
|
{
|
|
419
425
|
title: "Filtros",
|
|
420
|
-
dirty,
|
|
421
426
|
onApply: apply,
|
|
422
427
|
applyLabel: "Buscar",
|
|
423
|
-
pendingTitle: "Filtros n\xE3o aplicados",
|
|
424
|
-
pendingHint: "A lista ainda mostra o recorte anterior.",
|
|
425
428
|
onClear: activeCount > 0 ? limpar : void 0,
|
|
426
429
|
clearLabel: "Limpar",
|
|
427
430
|
busy: loading,
|
|
@@ -498,6 +501,18 @@ function ReconcileBadge({ done, total }) {
|
|
|
498
501
|
}
|
|
499
502
|
);
|
|
500
503
|
}
|
|
504
|
+
function ShortageBadge() {
|
|
505
|
+
const t = useTranslation();
|
|
506
|
+
return /* @__PURE__ */ jsx(
|
|
507
|
+
"span",
|
|
508
|
+
{
|
|
509
|
+
className: "inline-flex items-center rounded-full border border-warning bg-warning-soft px-1.5 py-0 text-[10px] text-warning-soft-foreground",
|
|
510
|
+
title: t("fiscalbr.receipt.listBadgeHint"),
|
|
511
|
+
"data-testid": "note-shortage-badge",
|
|
512
|
+
children: t("fiscalbr.receipt.listBadge")
|
|
513
|
+
}
|
|
514
|
+
);
|
|
515
|
+
}
|
|
501
516
|
function StockBadge({ stockedAt, status }) {
|
|
502
517
|
if (status === "rejected") {
|
|
503
518
|
return /* @__PURE__ */ jsx("span", { className: "inline-flex items-center rounded-full bg-muted px-2 py-0.5 text-[11px] text-muted-foreground line-through", children: "Recusada" });
|
|
@@ -586,5 +601,5 @@ function makeInboundNotesRoute(options = {}) {
|
|
|
586
601
|
}
|
|
587
602
|
|
|
588
603
|
export { InboundNotesPage, InboundNotesView, makeInboundNotesRoute };
|
|
589
|
-
//# sourceMappingURL=chunk-
|
|
590
|
-
//# sourceMappingURL=chunk-
|
|
604
|
+
//# sourceMappingURL=chunk-LHH2YIDB.js.map
|
|
605
|
+
//# sourceMappingURL=chunk-LHH2YIDB.js.map
|