@fayz-ai/plugin-fiscal-br 0.15.13 → 0.16.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/InvoiceNotesButton-4L7SLYMA.js +6 -0
- package/dist/{InvoiceNotesButton-SC3G7FUR.js.map → InvoiceNotesButton-4L7SLYMA.js.map} +1 -1
- package/dist/NotasFiscaisView-LU4A65J7.js +6 -0
- package/dist/NotasFiscaisView-LU4A65J7.js.map +1 -0
- package/dist/OrderNoteCard-NZOVNTR3.js +5 -0
- package/dist/{OrderNoteCard-PDSK2AS3.js.map → OrderNoteCard-NZOVNTR3.js.map} +1 -1
- package/dist/UnitFiscalWidgets-XSED3WPQ.js +564 -0
- package/dist/UnitFiscalWidgets-XSED3WPQ.js.map +1 -0
- package/dist/{chunk-ODMEESFD.js → chunk-CWYTWKXW.js} +23 -3
- package/dist/chunk-CWYTWKXW.js.map +1 -0
- package/dist/chunk-E5TUJOGT.js +644 -0
- package/dist/chunk-E5TUJOGT.js.map +1 -0
- package/dist/{chunk-SSPDH22E.js → chunk-ITWWGLEV.js} +3 -3
- package/dist/{chunk-SSPDH22E.js.map → chunk-ITWWGLEV.js.map} +1 -1
- package/dist/chunk-U4TQSVWI.js +269 -0
- package/dist/chunk-U4TQSVWI.js.map +1 -0
- package/dist/chunk-YSRG5JQI.js +205 -0
- package/dist/chunk-YSRG5JQI.js.map +1 -0
- package/dist/data/issued.d.ts +97 -0
- package/dist/data/issued.d.ts.map +1 -1
- package/dist/data/registries.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -20
- package/dist/index.js.map +1 -1
- package/dist/lib/notes.d.ts +35 -1
- package/dist/lib/notes.d.ts.map +1 -1
- package/dist/migrations/index.d.ts +4 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +5 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +400 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/views/InvoiceNotesButton.d.ts.map +1 -1
- package/dist/views/NotasFiscaisView.d.ts +4 -0
- package/dist/views/NotasFiscaisView.d.ts.map +1 -0
- package/dist/views/UnitFiscalWidgets.d.ts +6 -4
- package/dist/views/UnitFiscalWidgets.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/InvoiceNotesButton-SC3G7FUR.js +0 -5
- package/dist/OrderNoteCard-PDSK2AS3.js +0 -5
- package/dist/UnitFiscalWidgets-K4PX3HWG.js +0 -503
- package/dist/UnitFiscalWidgets-K4PX3HWG.js.map +0 -1
- package/dist/chunk-F325US5P.js +0 -387
- package/dist/chunk-F325US5P.js.map +0 -1
- package/dist/chunk-ODMEESFD.js.map +0 -1
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
import { listInvoiceNotes, previewInvoiceNfse, listNoteEvents, issueInvoiceNfse, refreshNote, fetchNotePdf, saveTomadorDocument, saveTomadorAddress, cancelNote } from './chunk-U4TQSVWI.js';
|
|
2
|
+
import { summarizeNotes, notesButtonState, isWithoutEffect, STATUS_META, MODEL_LABEL, statusLabel, explainRejection, recipientLabel, EVENT_LABEL, eventStatusLabel } from './chunk-CWYTWKXW.js';
|
|
3
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
4
|
+
import { CheckCircle2, Loader2, FileCheck2, AlertTriangle, ChevronDown, Pencil, RefreshCw, FileText, XCircle, Building2 } from 'lucide-react';
|
|
5
|
+
import { TooltipProvider, Tooltip, TooltipTrigger, Button, TooltipContent, Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalBody, Skeleton, ModalFooter, Input, Badge, SegmentedControl, toast } from '@fayz-ai/ui';
|
|
6
|
+
import { usePermissionOptional } from '@fayz-ai/admin';
|
|
7
|
+
import { describeError, formatCurrency } from '@fayz-ai/core';
|
|
8
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
var TONE_VARIANT = {
|
|
11
|
+
success: "success",
|
|
12
|
+
warning: "warning",
|
|
13
|
+
danger: "destructive",
|
|
14
|
+
muted: "default"
|
|
15
|
+
};
|
|
16
|
+
var dateTime = (v) => v ? new Date(v).toLocaleString("pt-BR", { dateStyle: "short", timeStyle: "short" }) : "\u2014";
|
|
17
|
+
var dayOrDateTime = (v) => {
|
|
18
|
+
if (!v) return "\u2014";
|
|
19
|
+
const d = new Date(v);
|
|
20
|
+
return d.getHours() === 0 && d.getMinutes() === 0 && d.getSeconds() === 0 ? d.toLocaleDateString("pt-BR") : dateTime(v);
|
|
21
|
+
};
|
|
22
|
+
var money = (v) => v == null ? "\u2014" : formatCurrency(v);
|
|
23
|
+
function buttonHint(s) {
|
|
24
|
+
const parts = [s.hasValid ? "Notas fiscais desta conta \u2014 h\xE1 uma nota v\xE1lida" : "Notas fiscais desta conta"];
|
|
25
|
+
if (s.withoutEffect > 0) parts.push(`${s.withoutEffect} cancelada(s), rejeitada(s) ou com erro`);
|
|
26
|
+
if (s.validIsTest) parts.push("a nota v\xE1lida \xE9 de TESTE, sem valor fiscal");
|
|
27
|
+
return parts.join(" \xB7 ");
|
|
28
|
+
}
|
|
29
|
+
function InvoiceNotesButton({ invoiceId, direction, cancelled }) {
|
|
30
|
+
const [notes, setNotes] = useState(null);
|
|
31
|
+
const [open, setOpen] = useState(false);
|
|
32
|
+
const can = usePermissionOptional();
|
|
33
|
+
const canCancel = can("financial", "edit");
|
|
34
|
+
const reload = useCallback(async () => {
|
|
35
|
+
if (!invoiceId || direction !== "credit") return;
|
|
36
|
+
try {
|
|
37
|
+
setNotes(await listInvoiceNotes(invoiceId));
|
|
38
|
+
} catch {
|
|
39
|
+
setNotes((prev) => prev ?? []);
|
|
40
|
+
}
|
|
41
|
+
}, [invoiceId, direction]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
void reload();
|
|
44
|
+
}, [reload]);
|
|
45
|
+
if (!notes) return null;
|
|
46
|
+
const canIssue = can("financial", "edit");
|
|
47
|
+
const summary = summarizeNotes(notes);
|
|
48
|
+
const state = notesButtonState(summary);
|
|
49
|
+
const hasLive = notes.some((n) => n.status === "authorized" || n.status === "processing" || n.status === "draft");
|
|
50
|
+
const tone = state === "authorized" ? "success" : state === "processing" ? "warning" : summary.withoutEffect > 0 ? "destructive" : "neutral";
|
|
51
|
+
const toneClass = tone === "success" ? "border-success/40 text-success" : tone === "warning" ? "border-warning/40 text-warning" : tone === "destructive" ? "border-destructive/40 text-destructive" : "";
|
|
52
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
|
+
/* @__PURE__ */ jsx(TooltipProvider, { delayDuration: 200, children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
54
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", size: "sm", className: `relative h-9 gap-1.5 ${toneClass}`, "aria-label": "Nota Fiscal", onClick: () => setOpen(true), children: [
|
|
55
|
+
state === "authorized" ? /* @__PURE__ */ jsx(CheckCircle2, { className: "h-4 w-4 text-success", "aria-hidden": true }) : state === "processing" ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin text-warning", "aria-hidden": true }) : /* @__PURE__ */ jsx(FileCheck2, { className: "h-4 w-4", "aria-hidden": true }),
|
|
56
|
+
/* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "Nota Fiscal" }),
|
|
57
|
+
summary.withoutEffect > 0 && /* @__PURE__ */ jsx("span", { className: "inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-destructive px-1 text-[10px] font-bold text-destructive-foreground", children: summary.withoutEffect }),
|
|
58
|
+
summary.validIsTest && /* @__PURE__ */ jsx("span", { className: "rounded border border-destructive px-1 text-[10px] font-semibold text-destructive", children: "TESTE" })
|
|
59
|
+
] }) }),
|
|
60
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: notes.length ? buttonHint(summary) : "Notas fiscais desta conta \u2014 nenhuma emitida ainda" })
|
|
61
|
+
] }) }),
|
|
62
|
+
/* @__PURE__ */ jsx(Modal, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(ModalContent, { size: "2xl", children: [
|
|
63
|
+
/* @__PURE__ */ jsxs(ModalHeader, { children: [
|
|
64
|
+
/* @__PURE__ */ jsx(ModalTitle, { children: "Nota Fiscal" }),
|
|
65
|
+
/* @__PURE__ */ jsx(ModalDescription, { children: "Notas de servi\xE7o (NFS-e) desta conta." })
|
|
66
|
+
] }),
|
|
67
|
+
canIssue && !hasLive && invoiceId ? /* @__PURE__ */ jsx(EmitNfseFlow, { invoiceId, hadRejections: notes.length > 0, onIssued: reload, notes, canCancel }) : /* @__PURE__ */ jsxs(ModalBody, { className: "gap-2", children: [
|
|
68
|
+
notes.map((n) => /* @__PURE__ */ jsx(NoteRow, { note: n, canCancel, onChanged: reload }, n.documentId)),
|
|
69
|
+
!notes.length && !canIssue && /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-sm text-muted-foreground", children: "Nenhuma nota emitida para esta conta." })
|
|
70
|
+
] })
|
|
71
|
+
] }) })
|
|
72
|
+
] });
|
|
73
|
+
}
|
|
74
|
+
var ISSUE_POLL = [2500, 3500, 5e3, 8e3];
|
|
75
|
+
var onlyDigits = (s) => s.replace(/\D/g, "");
|
|
76
|
+
var docValid = (raw) => {
|
|
77
|
+
const d = onlyDigits(raw ?? "");
|
|
78
|
+
return d.length === 11 || d.length === 14;
|
|
79
|
+
};
|
|
80
|
+
function formatDoc(raw) {
|
|
81
|
+
const d = onlyDigits(raw ?? "");
|
|
82
|
+
if (d.length === 11) return d.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
|
|
83
|
+
if (d.length === 14) return d.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "$1.$2.$3/$4-$5");
|
|
84
|
+
return raw ?? "";
|
|
85
|
+
}
|
|
86
|
+
var formatCep = (raw) => {
|
|
87
|
+
const d = onlyDigits(raw).slice(0, 8);
|
|
88
|
+
return d.length > 5 ? `${d.slice(0, 5)}-${d.slice(5)}` : d;
|
|
89
|
+
};
|
|
90
|
+
function addressSummary(a) {
|
|
91
|
+
if (!a || !a.street) return null;
|
|
92
|
+
return [a.street, a.number, a.district, [a.city, a.state].filter(Boolean).join("/")].filter(Boolean).join(", ");
|
|
93
|
+
}
|
|
94
|
+
var certDay = (v) => new Date(v).toLocaleDateString("pt-BR");
|
|
95
|
+
function EmitterHeader({ emitter }) {
|
|
96
|
+
if (!emitter) return null;
|
|
97
|
+
const cert = emitter.certificate;
|
|
98
|
+
const expired = cert.expiresAt ? new Date(cert.expiresAt) < /* @__PURE__ */ new Date() : false;
|
|
99
|
+
const ok = cert.configured && !expired;
|
|
100
|
+
const certText = !cert.configured ? "Certificado n\xE3o configurado" : expired ? "Certificado vencido" : "Certificado ativo";
|
|
101
|
+
const goSettings = () => {
|
|
102
|
+
if (emitter.unitId) window.location.assign(`/settings/locations/${emitter.unitId}/fields:tax`);
|
|
103
|
+
};
|
|
104
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-md border bg-muted/30 px-3 py-2", children: [
|
|
105
|
+
/* @__PURE__ */ jsx(Building2, { className: "h-4 w-4 shrink-0 text-muted-foreground", "aria-hidden": true }),
|
|
106
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
107
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-sm font-medium", children: emitter.company ?? "Empresa emitente" }),
|
|
108
|
+
/* @__PURE__ */ jsxs("p", { className: "truncate text-xs text-muted-foreground", children: [
|
|
109
|
+
emitter.cnpj ? formatDoc(emitter.cnpj) : "CNPJ n\xE3o informado",
|
|
110
|
+
" \xB7 ",
|
|
111
|
+
/* @__PURE__ */ jsxs("span", { className: ok ? "text-success" : "text-destructive", children: [
|
|
112
|
+
certText,
|
|
113
|
+
cert.configured && cert.expiresAt ? ` (val. ${certDay(cert.expiresAt)})` : ""
|
|
114
|
+
] })
|
|
115
|
+
] })
|
|
116
|
+
] }),
|
|
117
|
+
/* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "shrink-0", onClick: goSettings, children: [
|
|
118
|
+
/* @__PURE__ */ jsx(Pencil, { className: "h-3.5 w-3.5", "aria-hidden": true }),
|
|
119
|
+
" Editar"
|
|
120
|
+
] })
|
|
121
|
+
] });
|
|
122
|
+
}
|
|
123
|
+
function EmitNfseFlow({ invoiceId, hadRejections, onIssued, notes, canCancel }) {
|
|
124
|
+
const [preview, setPreview] = useState(null);
|
|
125
|
+
const [loadError, setLoadError] = useState(null);
|
|
126
|
+
const [obs, setObs] = useState("");
|
|
127
|
+
const [phase, setPhase] = useState("idle");
|
|
128
|
+
const [error, setError] = useState(null);
|
|
129
|
+
const load = useCallback(async () => {
|
|
130
|
+
setLoadError(null);
|
|
131
|
+
try {
|
|
132
|
+
setPreview(await previewInvoiceNfse(invoiceId));
|
|
133
|
+
} catch (e) {
|
|
134
|
+
setLoadError(describeError(e));
|
|
135
|
+
}
|
|
136
|
+
}, [invoiceId]);
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
void load();
|
|
139
|
+
}, [load]);
|
|
140
|
+
const hasDoc = docValid(preview?.tomador?.document ?? null);
|
|
141
|
+
const canEmit = !!preview?.personId && hasDoc && phase === "idle";
|
|
142
|
+
const emit = async () => {
|
|
143
|
+
setError(null);
|
|
144
|
+
setPhase("sending");
|
|
145
|
+
try {
|
|
146
|
+
let note = await issueInvoiceNfse(invoiceId, obs.trim() || void 0);
|
|
147
|
+
setPhase("waiting");
|
|
148
|
+
for (const delay of ISSUE_POLL) {
|
|
149
|
+
if (note.status !== "processing") break;
|
|
150
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
151
|
+
try {
|
|
152
|
+
note = { ...note, status: await refreshNote(note.documentId) };
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (note.status === "authorized") toast.success(`NFS-e n\xBA ${note.number ?? ""} autorizada`);
|
|
157
|
+
else if (note.status === "rejected" || note.status === "error") toast.error("A prefeitura rejeitou a nota", { description: "Veja o motivo nos detalhes da nota." });
|
|
158
|
+
else toast("NFS-e enviada \u2014 em processamento", { description: "Use \xABAtualizar\xBB para acompanhar." });
|
|
159
|
+
await onIssued();
|
|
160
|
+
} catch (e) {
|
|
161
|
+
setError(describeError(e));
|
|
162
|
+
} finally {
|
|
163
|
+
setPhase("idle");
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
167
|
+
/* @__PURE__ */ jsxs(ModalBody, { className: "gap-3", children: [
|
|
168
|
+
/* @__PURE__ */ jsx(EmitterHeader, { emitter: preview?.emitter ?? null }),
|
|
169
|
+
preview === null && !loadError ? /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-md border bg-background p-3", children: [
|
|
170
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-40" }),
|
|
171
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-56" }),
|
|
172
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-48" })
|
|
173
|
+
] }) : loadError ? /* @__PURE__ */ jsxs("p", { className: "flex items-start gap-1.5 rounded-md border border-destructive/40 bg-destructive-soft p-2 text-xs text-destructive-soft-foreground", children: [
|
|
174
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "mt-0.5 h-3.5 w-3.5 shrink-0", "aria-hidden": true }),
|
|
175
|
+
" ",
|
|
176
|
+
/* @__PURE__ */ jsx("span", { className: "break-words", children: loadError })
|
|
177
|
+
] }) : preview && /* @__PURE__ */ jsx(NfsePreviewCard, { preview, onSaved: load }),
|
|
178
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
179
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
180
|
+
"A nota \xE9 gerada na prefeitura e n\xE3o pode ser editada depois.",
|
|
181
|
+
hadRejections ? " As tentativas anteriores est\xE3o listadas abaixo \u2014 confira o motivo antes de reemitir." : ""
|
|
182
|
+
] }),
|
|
183
|
+
/* @__PURE__ */ jsx(
|
|
184
|
+
"textarea",
|
|
185
|
+
{
|
|
186
|
+
value: obs,
|
|
187
|
+
onChange: (e) => setObs(e.target.value),
|
|
188
|
+
maxLength: 2e3,
|
|
189
|
+
rows: 2,
|
|
190
|
+
disabled: phase !== "idle",
|
|
191
|
+
placeholder: "Observa\xE7\xF5es (opcional) \u2014 entram junto com o texto padr\xE3o da unidade, n\xE3o no lugar dele.",
|
|
192
|
+
className: "w-full resize-y rounded-md border bg-background px-3 py-2 text-sm"
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
error && /* @__PURE__ */ jsxs("p", { className: "flex items-start gap-1.5 rounded-md border border-destructive/40 bg-destructive-soft p-2 text-xs text-destructive-soft-foreground", children: [
|
|
196
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "mt-0.5 h-3.5 w-3.5 shrink-0", "aria-hidden": true }),
|
|
197
|
+
" ",
|
|
198
|
+
/* @__PURE__ */ jsx("span", { className: "break-words", children: error })
|
|
199
|
+
] })
|
|
200
|
+
] }),
|
|
201
|
+
notes.map((n) => /* @__PURE__ */ jsx(NoteRow, { note: n, canCancel, onChanged: onIssued }, n.documentId))
|
|
202
|
+
] }),
|
|
203
|
+
/* @__PURE__ */ jsxs(ModalFooter, { children: [
|
|
204
|
+
preview?.personId && !hasDoc && /* @__PURE__ */ jsx("span", { className: "mr-auto self-center text-xs text-warning", children: "Falta o CPF/CNPJ do tomador para emitir." }),
|
|
205
|
+
/* @__PURE__ */ jsxs(Button, { onClick: emit, disabled: !canEmit, children: [
|
|
206
|
+
phase !== "idle" ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin", "aria-hidden": true }) : /* @__PURE__ */ jsx(FileCheck2, { className: "h-4 w-4", "aria-hidden": true }),
|
|
207
|
+
phase === "waiting" ? "Aguardando a prefeitura\u2026" : phase === "sending" ? "Enviando\u2026" : "Emitir NFS-e"
|
|
208
|
+
] })
|
|
209
|
+
] })
|
|
210
|
+
] });
|
|
211
|
+
}
|
|
212
|
+
function PreviewRow({ label, value, full }) {
|
|
213
|
+
return /* @__PURE__ */ jsxs("div", { className: `min-w-0 ${full ? "sm:col-span-2" : ""}`, children: [
|
|
214
|
+
/* @__PURE__ */ jsx("dt", { className: "text-xs text-muted-foreground", children: label }),
|
|
215
|
+
/* @__PURE__ */ jsx("dd", { className: "mt-0.5 min-w-0 break-words", children: value })
|
|
216
|
+
] });
|
|
217
|
+
}
|
|
218
|
+
var pct = (v) => `${v.toLocaleString("pt-BR", { maximumFractionDigits: 2 })}%`;
|
|
219
|
+
var muted = (t) => /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t });
|
|
220
|
+
function NfsePreviewCard({ preview, onSaved }) {
|
|
221
|
+
const { tomador, items, serviceDescription, fiscal } = preview;
|
|
222
|
+
const total = preview.invoice.total ?? 0;
|
|
223
|
+
const issRate = fiscal?.issRate ?? null;
|
|
224
|
+
const issValue = issRate != null ? total * issRate / 100 : null;
|
|
225
|
+
const serviceCode = fiscal?.serviceCodeNational || fiscal?.serviceCodeMunicipal || null;
|
|
226
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-2 text-sm", children: [
|
|
227
|
+
/* @__PURE__ */ jsxs(PreviewGroup, { title: "Tomador", defaultOpen: true, children: [
|
|
228
|
+
/* @__PURE__ */ jsx(PreviewRow, { label: "Nome", value: tomador.name ?? muted("Sem cliente") }),
|
|
229
|
+
preview.personId && /* @__PURE__ */ jsx(DocField, { personId: preview.personId, document: tomador.document, onSaved }),
|
|
230
|
+
preview.personId && /* @__PURE__ */ jsx(AddressField, { personId: preview.personId, address: tomador.address, onSaved })
|
|
231
|
+
] }),
|
|
232
|
+
/* @__PURE__ */ jsxs(PreviewGroup, { title: "Servi\xE7o", defaultOpen: true, children: [
|
|
233
|
+
serviceDescription && /* @__PURE__ */ jsx(PreviewRow, { full: true, label: "Discrimina\xE7\xE3o", value: serviceDescription }),
|
|
234
|
+
items.length > 0 ? items.map((it, i) => /* @__PURE__ */ jsx(ItemRow, { item: it }, i)) : !serviceDescription && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground sm:col-span-2", children: "Sem itens detalhados nesta conta." })
|
|
235
|
+
] }),
|
|
236
|
+
/* @__PURE__ */ jsxs(PreviewGroup, { title: "Valores", children: [
|
|
237
|
+
/* @__PURE__ */ jsx(PreviewRow, { label: "Servi\xE7os", value: /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: money(total) }) }),
|
|
238
|
+
preview.invoice.discount ? /* @__PURE__ */ jsx(PreviewRow, { label: "Desconto", value: /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: money(preview.invoice.discount) }) }) : null,
|
|
239
|
+
issValue != null && /* @__PURE__ */ jsx(PreviewRow, { label: `ISS (${pct(issRate)})`, value: /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: money(issValue) }) }),
|
|
240
|
+
/* @__PURE__ */ jsx(PreviewRow, { label: "Valor da nota", value: /* @__PURE__ */ jsx("span", { className: "font-semibold tabular-nums", children: money(total) }) })
|
|
241
|
+
] }),
|
|
242
|
+
/* @__PURE__ */ jsxs(PreviewGroup, { title: "Tributa\xE7\xE3o", children: [
|
|
243
|
+
/* @__PURE__ */ jsx(PreviewRow, { label: "Al\xEDquota ISS", value: issRate != null ? pct(issRate) : muted("definir na unidade") }),
|
|
244
|
+
/* @__PURE__ */ jsx(PreviewRow, { label: "C\xF3digo servi\xE7o", value: serviceCode ? /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: serviceCode }) : muted("definir na unidade") }),
|
|
245
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground sm:col-span-2", children: "Os valores finais s\xE3o calculados pela prefeitura na emiss\xE3o, a partir da configura\xE7\xE3o fiscal da unidade." })
|
|
246
|
+
] })
|
|
247
|
+
] });
|
|
248
|
+
}
|
|
249
|
+
function PreviewGroup({ title, defaultOpen, children }) {
|
|
250
|
+
const [open, setOpen] = useState(!!defaultOpen);
|
|
251
|
+
return /* @__PURE__ */ jsxs("div", { className: "rounded-md border bg-background", children: [
|
|
252
|
+
/* @__PURE__ */ jsxs(
|
|
253
|
+
Button,
|
|
254
|
+
{
|
|
255
|
+
variant: "bare",
|
|
256
|
+
size: "bare",
|
|
257
|
+
type: "button",
|
|
258
|
+
className: "flex w-full items-center justify-between px-3 py-2 text-left font-normal",
|
|
259
|
+
onClick: () => setOpen((v) => !v),
|
|
260
|
+
"aria-expanded": open,
|
|
261
|
+
children: [
|
|
262
|
+
/* @__PURE__ */ jsx("span", { className: "text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: title }),
|
|
263
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: `h-4 w-4 shrink-0 text-muted-foreground transition-transform ${open ? "rotate-180" : ""}`, "aria-hidden": true })
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
),
|
|
267
|
+
open && /* @__PURE__ */ jsx("dl", { className: "grid grid-cols-1 gap-x-6 gap-y-3 border-t p-3 sm:grid-cols-2", children })
|
|
268
|
+
] });
|
|
269
|
+
}
|
|
270
|
+
function ItemRow({ item }) {
|
|
271
|
+
const hasUnit = item.quantity != null && item.unitPrice != null;
|
|
272
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3 border-t pt-2 first:border-0 first:pt-0 sm:col-span-2", children: [
|
|
273
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
274
|
+
/* @__PURE__ */ jsx("span", { className: "block break-words", children: item.name || item.description || "Item" }),
|
|
275
|
+
hasUnit && /* @__PURE__ */ jsxs("span", { className: "text-[11px] text-muted-foreground", children: [
|
|
276
|
+
item.quantity,
|
|
277
|
+
" \xD7 ",
|
|
278
|
+
money(item.unitPrice)
|
|
279
|
+
] })
|
|
280
|
+
] }),
|
|
281
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0 tabular-nums font-medium", children: money(item.total) })
|
|
282
|
+
] });
|
|
283
|
+
}
|
|
284
|
+
function DocField({ personId, document: document2, onSaved }) {
|
|
285
|
+
const valid = docValid(document2);
|
|
286
|
+
const [editing, setEditing] = useState(!valid);
|
|
287
|
+
const [value, setValue] = useState(document2 ?? "");
|
|
288
|
+
const [saving, setSaving] = useState(false);
|
|
289
|
+
const save = async () => {
|
|
290
|
+
const digits = onlyDigits(value);
|
|
291
|
+
if (digits.length !== 11 && digits.length !== 14) {
|
|
292
|
+
toast.error("CPF (11) ou CNPJ (14) \u2014 confira os d\xEDgitos");
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
setSaving(true);
|
|
296
|
+
try {
|
|
297
|
+
await saveTomadorDocument(personId, digits);
|
|
298
|
+
await onSaved();
|
|
299
|
+
setEditing(false);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
toast.error("N\xE3o foi poss\xEDvel salvar o documento", { description: describeError(e) });
|
|
302
|
+
} finally {
|
|
303
|
+
setSaving(false);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
return /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
307
|
+
/* @__PURE__ */ jsx("dt", { className: "text-xs text-muted-foreground", children: "CPF/CNPJ" }),
|
|
308
|
+
/* @__PURE__ */ jsx("dd", { className: "mt-0.5 min-w-0", children: editing ? /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
309
|
+
/* @__PURE__ */ jsx(Input, { value, onChange: (e) => setValue(e.target.value), inputMode: "numeric", placeholder: "S\xF3 n\xFAmeros", className: "h-8 flex-1", autoFocus: true }),
|
|
310
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", className: "h-8", onClick: save, disabled: saving, children: saving ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin", "aria-hidden": true }) : "Salvar" })
|
|
311
|
+
] }) : /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
|
|
312
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: formatDoc(document2) }),
|
|
313
|
+
/* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "h-6 shrink-0 px-1.5 text-xs text-muted-foreground", onClick: () => {
|
|
314
|
+
setValue(document2 ?? "");
|
|
315
|
+
setEditing(true);
|
|
316
|
+
}, children: [
|
|
317
|
+
/* @__PURE__ */ jsx(Pencil, { className: "h-3 w-3", "aria-hidden": true }),
|
|
318
|
+
" editar"
|
|
319
|
+
] })
|
|
320
|
+
] }) })
|
|
321
|
+
] });
|
|
322
|
+
}
|
|
323
|
+
function AddressField({ personId, address, onSaved }) {
|
|
324
|
+
const summary = addressSummary(address);
|
|
325
|
+
const [editing, setEditing] = useState(false);
|
|
326
|
+
const [form, setForm] = useState(() => address ?? { id: null, postalCode: "", street: "", number: "", district: "", city: "", state: "" });
|
|
327
|
+
const [saving, setSaving] = useState(false);
|
|
328
|
+
const [cepLoading, setCepLoading] = useState(false);
|
|
329
|
+
const set = (k, v) => setForm((f) => ({ ...f, [k]: v }));
|
|
330
|
+
const lookupCep = async (raw) => {
|
|
331
|
+
const cep = onlyDigits(raw);
|
|
332
|
+
if (cep.length !== 8) return;
|
|
333
|
+
setCepLoading(true);
|
|
334
|
+
try {
|
|
335
|
+
const r = await fetch(`https://brasilapi.com.br/api/cep/v2/${cep}`);
|
|
336
|
+
if (r.ok) {
|
|
337
|
+
const d = await r.json();
|
|
338
|
+
setForm((f) => ({ ...f, street: d.street || f.street, district: d.neighborhood || f.district, city: d.city || f.city, state: d.state || f.state }));
|
|
339
|
+
}
|
|
340
|
+
} catch {
|
|
341
|
+
} finally {
|
|
342
|
+
setCepLoading(false);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const save = async () => {
|
|
346
|
+
const cep = onlyDigits(form.postalCode ?? "");
|
|
347
|
+
if (form.street && cep.length !== 8) {
|
|
348
|
+
toast.error("O CEP precisa ter 8 d\xEDgitos para a NFS-e");
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
setSaving(true);
|
|
352
|
+
try {
|
|
353
|
+
const id = await saveTomadorAddress(personId, { ...form, postalCode: cep || null });
|
|
354
|
+
setForm((f) => ({ ...f, id }));
|
|
355
|
+
await onSaved();
|
|
356
|
+
setEditing(false);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
toast.error("N\xE3o foi poss\xEDvel salvar o endere\xE7o", { description: describeError(e) });
|
|
359
|
+
} finally {
|
|
360
|
+
setSaving(false);
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
return /* @__PURE__ */ jsxs("div", { className: "min-w-0 sm:col-span-2", children: [
|
|
364
|
+
/* @__PURE__ */ jsx("dt", { className: "text-xs text-muted-foreground", children: "Endere\xE7o" }),
|
|
365
|
+
/* @__PURE__ */ jsx("dd", { className: "mt-0.5 min-w-0", children: !editing ? /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
|
|
366
|
+
/* @__PURE__ */ jsx("span", { className: `truncate ${summary ? "" : "text-muted-foreground"}`, children: summary ?? "N\xE3o informado" }),
|
|
367
|
+
/* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "h-6 shrink-0 px-1.5 text-xs text-muted-foreground", onClick: () => setEditing(true), children: [
|
|
368
|
+
/* @__PURE__ */ jsx(Pencil, { className: "h-3 w-3", "aria-hidden": true }),
|
|
369
|
+
" ",
|
|
370
|
+
summary ? "editar" : "completar"
|
|
371
|
+
] })
|
|
372
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
373
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
374
|
+
/* @__PURE__ */ jsx(Input, { value: formatCep(form.postalCode ?? ""), onChange: (e) => set("postalCode", e.target.value), onBlur: (e) => lookupCep(e.target.value), inputMode: "numeric", placeholder: "CEP", className: "h-8 w-28" }),
|
|
375
|
+
cepLoading && /* @__PURE__ */ jsx(Loader2, { className: "mt-2 h-3.5 w-3.5 animate-spin text-muted-foreground", "aria-hidden": true })
|
|
376
|
+
] }),
|
|
377
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
378
|
+
/* @__PURE__ */ jsx(Input, { value: form.street ?? "", onChange: (e) => set("street", e.target.value), placeholder: "Logradouro", className: "h-8 flex-1" }),
|
|
379
|
+
/* @__PURE__ */ jsx(Input, { value: form.number ?? "", onChange: (e) => set("number", e.target.value), placeholder: "N\xBA", className: "h-8 w-20" })
|
|
380
|
+
] }),
|
|
381
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
382
|
+
/* @__PURE__ */ jsx(Input, { value: form.district ?? "", onChange: (e) => set("district", e.target.value), placeholder: "Bairro", className: "h-8 flex-1" }),
|
|
383
|
+
/* @__PURE__ */ jsx(Input, { value: form.city ?? "", onChange: (e) => set("city", e.target.value), placeholder: "Cidade", className: "h-8 flex-1" }),
|
|
384
|
+
/* @__PURE__ */ jsx(Input, { value: form.state ?? "", onChange: (e) => set("state", e.target.value.toUpperCase().slice(0, 2)), placeholder: "UF", className: "h-8 w-16" })
|
|
385
|
+
] }),
|
|
386
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
387
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", className: "h-8", onClick: () => {
|
|
388
|
+
setForm(address ?? { id: null, postalCode: "", street: "", number: "", district: "", city: "", state: "" });
|
|
389
|
+
setEditing(false);
|
|
390
|
+
}, children: "Cancelar" }),
|
|
391
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", className: "h-8", onClick: save, disabled: saving, children: saving ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin", "aria-hidden": true }) : "Salvar" })
|
|
392
|
+
] })
|
|
393
|
+
] }) })
|
|
394
|
+
] });
|
|
395
|
+
}
|
|
396
|
+
var POLL_DELAYS = [3e3, 5e3, 8e3, 12e3, 2e4];
|
|
397
|
+
function NoteRow({ note, canCancel, onChanged }) {
|
|
398
|
+
const [expanded, setExpanded] = useState(false);
|
|
399
|
+
const [cancelling, setCancelling] = useState(false);
|
|
400
|
+
const [busy, setBusy] = useState(null);
|
|
401
|
+
const dimmed = isWithoutEffect(note.status);
|
|
402
|
+
const tone = (STATUS_META[note.status] ?? STATUS_META.error).tone;
|
|
403
|
+
const usable = note.status === "authorized" || note.status === "cancelled";
|
|
404
|
+
const inFlight = note.status === "processing" || note.status === "draft";
|
|
405
|
+
const cancellable = canCancel && note.status === "authorized" && !note.cancelledAt;
|
|
406
|
+
const openPdf = async () => {
|
|
407
|
+
setBusy("pdf");
|
|
408
|
+
try {
|
|
409
|
+
const blob = await fetchNotePdf(note.documentId);
|
|
410
|
+
const url = URL.createObjectURL(blob);
|
|
411
|
+
const a = document.createElement("a");
|
|
412
|
+
a.href = url;
|
|
413
|
+
a.download = `nfse-${note.number ?? note.documentId}.pdf`;
|
|
414
|
+
document.body.appendChild(a);
|
|
415
|
+
a.click();
|
|
416
|
+
a.remove();
|
|
417
|
+
setTimeout(() => URL.revokeObjectURL(url), 6e4);
|
|
418
|
+
} catch (e) {
|
|
419
|
+
toast.error("PDF indispon\xEDvel", { description: describeError(e) });
|
|
420
|
+
} finally {
|
|
421
|
+
setBusy(null);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const refresh = async () => {
|
|
425
|
+
setBusy("refresh");
|
|
426
|
+
try {
|
|
427
|
+
const status = await refreshNote(note.documentId);
|
|
428
|
+
await onChanged();
|
|
429
|
+
toast(status === note.status ? "Ainda em processamento na SEFAZ/prefeitura" : `Nota ${statusLabel({ status, cancelledAt: null }).toLowerCase()}`);
|
|
430
|
+
} catch (e) {
|
|
431
|
+
toast.error("N\xE3o foi poss\xEDvel consultar", { description: describeError(e) });
|
|
432
|
+
} finally {
|
|
433
|
+
setBusy(null);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
return /* @__PURE__ */ jsxs("div", { className: `rounded-lg border ${dimmed ? "bg-muted/30" : ""}`, children: [
|
|
437
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 p-3", children: [
|
|
438
|
+
/* @__PURE__ */ jsxs(
|
|
439
|
+
"div",
|
|
440
|
+
{
|
|
441
|
+
role: "button",
|
|
442
|
+
tabIndex: 0,
|
|
443
|
+
className: "flex min-w-0 flex-1 cursor-pointer flex-wrap items-center gap-2 text-left",
|
|
444
|
+
onClick: () => setExpanded((v) => !v),
|
|
445
|
+
onKeyDown: (e) => {
|
|
446
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
447
|
+
e.preventDefault();
|
|
448
|
+
setExpanded((v) => !v);
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
"aria-expanded": expanded,
|
|
452
|
+
children: [
|
|
453
|
+
/* @__PURE__ */ jsx(Badge, { variant: "outline", children: MODEL_LABEL[note.model] ?? note.model }),
|
|
454
|
+
note.number && /* @__PURE__ */ jsxs("span", { className: "font-mono text-sm", children: [
|
|
455
|
+
"n\xBA ",
|
|
456
|
+
note.number
|
|
457
|
+
] }),
|
|
458
|
+
/* @__PURE__ */ jsx(Badge, { variant: TONE_VARIANT[tone], children: statusLabel(note) }),
|
|
459
|
+
note.environment === "homologacao" && /* @__PURE__ */ jsx("span", { className: "rounded border border-destructive px-1 text-[10px] font-semibold text-destructive", children: "TESTE" })
|
|
460
|
+
]
|
|
461
|
+
}
|
|
462
|
+
),
|
|
463
|
+
inFlight && /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", className: "h-7 shrink-0 text-xs", disabled: busy === "refresh", onClick: refresh, children: [
|
|
464
|
+
busy === "refresh" ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin", "aria-hidden": true }) : /* @__PURE__ */ jsx(RefreshCw, { className: "h-3.5 w-3.5", "aria-hidden": true }),
|
|
465
|
+
"Atualizar"
|
|
466
|
+
] }),
|
|
467
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs tabular-nums text-muted-foreground", children: dateTime(note.createdAt) }),
|
|
468
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => setExpanded((v) => !v), "aria-label": "Detalhes da nota", className: "shrink-0", children: /* @__PURE__ */ jsx(ChevronDown, { className: `h-4 w-4 text-muted-foreground transition-transform ${expanded ? "rotate-180" : ""}`, "aria-hidden": true }) })
|
|
469
|
+
] }),
|
|
470
|
+
note.cancelReason && !expanded && /* @__PURE__ */ jsxs("p", { className: "flex items-start gap-1.5 px-3 pb-2 text-xs text-muted-foreground", children: [
|
|
471
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "mt-0.5 h-3.5 w-3.5 shrink-0", "aria-hidden": true }),
|
|
472
|
+
/* @__PURE__ */ jsxs("span", { className: "break-words", children: [
|
|
473
|
+
"Motivo: ",
|
|
474
|
+
note.cancelReason
|
|
475
|
+
] })
|
|
476
|
+
] }),
|
|
477
|
+
(usable || inFlight || note.cancelledAt) && !cancelling && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-1.5 px-3 pb-3", children: [
|
|
478
|
+
usable && /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", className: "h-7 text-xs", disabled: busy === "pdf", onClick: openPdf, children: [
|
|
479
|
+
busy === "pdf" ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin", "aria-hidden": true }) : /* @__PURE__ */ jsx(FileText, { className: "h-3.5 w-3.5", "aria-hidden": true }),
|
|
480
|
+
"PDF"
|
|
481
|
+
] }),
|
|
482
|
+
note.cancelledAt && note.status === "authorized" && /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", className: "h-7 text-xs", disabled: busy === "refresh", onClick: refresh, children: [
|
|
483
|
+
busy === "refresh" ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin", "aria-hidden": true }) : /* @__PURE__ */ jsx(RefreshCw, { className: "h-3.5 w-3.5", "aria-hidden": true }),
|
|
484
|
+
"Atualizar"
|
|
485
|
+
] }),
|
|
486
|
+
cancellable && /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "ml-auto h-7 text-xs text-destructive hover:text-destructive", onClick: () => setCancelling(true), children: [
|
|
487
|
+
/* @__PURE__ */ jsx(XCircle, { className: "h-3.5 w-3.5", "aria-hidden": true }),
|
|
488
|
+
" Cancelar nota"
|
|
489
|
+
] })
|
|
490
|
+
] }),
|
|
491
|
+
cancelling && /* @__PURE__ */ jsx(CancelNotePanel, { note, onClose: () => setCancelling(false), onDone: async () => {
|
|
492
|
+
setCancelling(false);
|
|
493
|
+
await onChanged();
|
|
494
|
+
} }),
|
|
495
|
+
expanded && /* @__PURE__ */ jsx(NoteDetails, { note })
|
|
496
|
+
] });
|
|
497
|
+
}
|
|
498
|
+
var NFSE_REASONS = [
|
|
499
|
+
{ value: "1", label: "Erro na emiss\xE3o" },
|
|
500
|
+
{ value: "2", label: "Servi\xE7o n\xE3o prestado" },
|
|
501
|
+
{ value: "9", label: "Outros" }
|
|
502
|
+
];
|
|
503
|
+
function CancelNotePanel({ note, onClose, onDone }) {
|
|
504
|
+
const isNfse = note.model === "nfse";
|
|
505
|
+
const [code, setCode] = useState("2");
|
|
506
|
+
const [text, setText] = useState("");
|
|
507
|
+
const [working, setWorking] = useState(null);
|
|
508
|
+
const [error, setError] = useState(null);
|
|
509
|
+
const min = isNfse ? 10 : 15;
|
|
510
|
+
const missing = Math.max(0, min - text.trim().length);
|
|
511
|
+
const confirm = async () => {
|
|
512
|
+
setError(null);
|
|
513
|
+
setWorking("sending");
|
|
514
|
+
try {
|
|
515
|
+
let status = await cancelNote(note.documentId, text.trim());
|
|
516
|
+
setWorking("waiting");
|
|
517
|
+
for (const delay of POLL_DELAYS) {
|
|
518
|
+
if (status === "cancelled" || status === "authorized") break;
|
|
519
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
520
|
+
try {
|
|
521
|
+
status = await refreshNote(note.documentId);
|
|
522
|
+
} catch {
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (status === "cancelled") toast.success(`${MODEL_LABEL[note.model]} n\xBA ${note.number ?? ""} cancelada`);
|
|
526
|
+
else if (status === "authorized") toast.error("A SEFAZ/prefeitura recusou o cancelamento", { description: "A nota continua v\xE1lida. Veja o hist\xF3rico nos detalhes." });
|
|
527
|
+
else toast("Cancelamento solicitado", { description: "A SEFAZ/prefeitura ainda est\xE1 processando. Use \xABAtualizar\xBB para conferir." });
|
|
528
|
+
await onDone();
|
|
529
|
+
} catch (e) {
|
|
530
|
+
setError(describeError(e));
|
|
531
|
+
setWorking(null);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-3 border-t bg-destructive-soft/40 px-3 py-3", children: [
|
|
535
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm font-semibold", children: [
|
|
536
|
+
"Cancelar ",
|
|
537
|
+
MODEL_LABEL[note.model],
|
|
538
|
+
" ",
|
|
539
|
+
note.number ? `n\xBA ${note.number}` : ""
|
|
540
|
+
] }),
|
|
541
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
542
|
+
isNfse ? "O prazo de cancelamento da NFS-e \xE9 definido pelo munic\xEDpio." : "O prazo de cancelamento da NFC-e \xE9 curto (em geral ~30 minutos ap\xF3s a autoriza\xE7\xE3o, conforme a UF). Fora do prazo, a SEFAZ recusa.",
|
|
543
|
+
" ",
|
|
544
|
+
"Cancelar n\xE3o pode ser desfeito."
|
|
545
|
+
] }),
|
|
546
|
+
isNfse && /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
547
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium", children: "Motivo" }),
|
|
548
|
+
/* @__PURE__ */ jsx(SegmentedControl, { size: "sm", "aria-label": "Motivo do cancelamento", options: NFSE_REASONS, value: code, onChange: setCode })
|
|
549
|
+
] }),
|
|
550
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
551
|
+
/* @__PURE__ */ jsx("label", { htmlFor: `cancel-${note.documentId}`, className: "text-xs font-medium", children: "Justificativa" }),
|
|
552
|
+
/* @__PURE__ */ jsx(
|
|
553
|
+
"textarea",
|
|
554
|
+
{
|
|
555
|
+
id: `cancel-${note.documentId}`,
|
|
556
|
+
value: text,
|
|
557
|
+
onChange: (e) => setText(e.target.value),
|
|
558
|
+
maxLength: 255,
|
|
559
|
+
rows: 3,
|
|
560
|
+
disabled: !!working,
|
|
561
|
+
placeholder: isNfse ? "Descreva o motivo\u2026" : "Ex.: Emiss\xE3o em duplicidade por erro operacional",
|
|
562
|
+
className: "w-full resize-y rounded-md border bg-background px-3 py-2 text-sm",
|
|
563
|
+
autoFocus: true
|
|
564
|
+
}
|
|
565
|
+
),
|
|
566
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: missing > 0 ? `Faltam ${missing} caractere(s) \u2014 a justificativa vai para a SEFAZ/prefeitura.` : "Vai para a SEFAZ/prefeitura junto do pedido." })
|
|
567
|
+
] }),
|
|
568
|
+
error && /* @__PURE__ */ jsxs("p", { className: "flex items-start gap-1.5 rounded-md border border-destructive/40 bg-destructive-soft p-2 text-xs text-destructive-soft-foreground", children: [
|
|
569
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "mt-0.5 h-3.5 w-3.5 shrink-0", "aria-hidden": true }),
|
|
570
|
+
" ",
|
|
571
|
+
/* @__PURE__ */ jsx("span", { className: "break-words", children: error })
|
|
572
|
+
] }),
|
|
573
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap justify-end gap-2", children: [
|
|
574
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: onClose, disabled: !!working, children: "Voltar" }),
|
|
575
|
+
/* @__PURE__ */ jsxs(Button, { variant: "destructive", size: "sm", onClick: confirm, disabled: !!working || missing > 0, children: [
|
|
576
|
+
working ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin", "aria-hidden": true }) : /* @__PURE__ */ jsx(XCircle, { className: "h-3.5 w-3.5", "aria-hidden": true }),
|
|
577
|
+
working === "waiting" ? "Aguardando a SEFAZ/prefeitura\u2026" : working ? "Enviando\u2026" : "Confirmar cancelamento"
|
|
578
|
+
] })
|
|
579
|
+
] })
|
|
580
|
+
] });
|
|
581
|
+
}
|
|
582
|
+
function NoteDetails({ note }) {
|
|
583
|
+
const [events, setEvents] = useState(null);
|
|
584
|
+
useEffect(() => {
|
|
585
|
+
let alive = true;
|
|
586
|
+
listNoteEvents(note.documentId).then((e) => {
|
|
587
|
+
if (alive) setEvents(e);
|
|
588
|
+
}).catch(() => {
|
|
589
|
+
if (alive) setEvents([]);
|
|
590
|
+
});
|
|
591
|
+
return () => {
|
|
592
|
+
alive = false;
|
|
593
|
+
};
|
|
594
|
+
}, [note.documentId]);
|
|
595
|
+
const failed = ["rejected", "denied", "error"].includes(note.status);
|
|
596
|
+
const rejection = failed ? explainRejection(note.rejection) : null;
|
|
597
|
+
const rows = [
|
|
598
|
+
["Refer\xEAncia", note.integrationId && /* @__PURE__ */ jsx("span", { className: "break-all font-mono text-xs", children: note.integrationId })],
|
|
599
|
+
["Chave de acesso", note.accessKey && /* @__PURE__ */ jsx("span", { className: "break-all font-mono text-xs", children: note.accessKey })],
|
|
600
|
+
["C\xF3digo de verifica\xE7\xE3o", note.verificationCode],
|
|
601
|
+
["Valor", money(note.totalValue)],
|
|
602
|
+
["Tomador", recipientLabel(note.recipient)],
|
|
603
|
+
["Criada em", dateTime(note.createdAt)],
|
|
604
|
+
["Autorizada em", note.authorizedAt && dayOrDateTime(note.authorizedAt)],
|
|
605
|
+
["Cancelada em", note.cancelledAt && `${dateTime(note.cancelledAt)}${note.cancelReason ? ` \u2014 ${note.cancelReason}` : ""}`]
|
|
606
|
+
];
|
|
607
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-3 border-t px-3 py-3", children: [
|
|
608
|
+
/* @__PURE__ */ jsx("dl", { className: "text-sm", children: rows.filter(([, v]) => v).map(([label, value]) => /* @__PURE__ */ jsxs("div", { className: "flex gap-3 border-b py-1.5 last:border-0", children: [
|
|
609
|
+
/* @__PURE__ */ jsx("dt", { className: "w-28 shrink-0 text-muted-foreground sm:w-36", children: label }),
|
|
610
|
+
/* @__PURE__ */ jsx("dd", { className: "min-w-0 flex-1 break-words font-medium", children: value })
|
|
611
|
+
] }, label)) }),
|
|
612
|
+
rejection && /* @__PURE__ */ jsxs("div", { className: "space-y-1.5 rounded-md border border-destructive/40 bg-destructive-soft p-3", children: [
|
|
613
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-destructive-soft-foreground", children: "Por que foi rejeitada?" }),
|
|
614
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-foreground", children: rejection.summary }),
|
|
615
|
+
rejection.fields.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-1 text-xs text-foreground", children: rejection.fields.map((f) => /* @__PURE__ */ jsxs("li", { children: [
|
|
616
|
+
/* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
617
|
+
f.label,
|
|
618
|
+
":"
|
|
619
|
+
] }),
|
|
620
|
+
" ",
|
|
621
|
+
f.message
|
|
622
|
+
] }, f.field)) })
|
|
623
|
+
] }),
|
|
624
|
+
events === null ? /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
625
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-3/4" }),
|
|
626
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-2/3" })
|
|
627
|
+
] }) : events.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
628
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1.5 text-sm font-semibold", children: "Hist\xF3rico" }),
|
|
629
|
+
/* @__PURE__ */ jsx("ul", { className: "space-y-1", children: events.map((e) => /* @__PURE__ */ jsxs("li", { className: "flex flex-wrap items-center gap-2 text-xs", children: [
|
|
630
|
+
/* @__PURE__ */ jsx("span", { className: "whitespace-nowrap tabular-nums text-muted-foreground", children: dateTime(e.createdAt) }),
|
|
631
|
+
/* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-[10px]", children: EVENT_LABEL[e.eventType] ?? "Evento" }),
|
|
632
|
+
eventStatusLabel(e.status) && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: eventStatusLabel(e.status) }),
|
|
633
|
+
e.justification && /* @__PURE__ */ jsxs("span", { className: "min-w-0 truncate", children: [
|
|
634
|
+
"\u2014 ",
|
|
635
|
+
e.justification
|
|
636
|
+
] })
|
|
637
|
+
] }, e.id)) })
|
|
638
|
+
] })
|
|
639
|
+
] });
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
export { InvoiceNotesButton };
|
|
643
|
+
//# sourceMappingURL=chunk-E5TUJOGT.js.map
|
|
644
|
+
//# sourceMappingURL=chunk-E5TUJOGT.js.map
|