@fayz-ai/plugin-financial 0.29.8 → 0.29.10-canary.20261027153628

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.
@@ -0,0 +1,5 @@
1
+ export { CashRegistersView } from './chunk-NS2XEAQQ.js';
2
+ import './chunk-MTYUOE76.js';
3
+ import './chunk-CNXAVGSW.js';
4
+ //# sourceMappingURL=CashRegistersView-MIULZ4ID.js.map
5
+ //# sourceMappingURL=CashRegistersView-MIULZ4ID.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"CashRegistersView-5U252GGF.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"CashRegistersView-MIULZ4ID.js"}
@@ -2,7 +2,8 @@ import { InvoiceFormView, InvoiceDetailView, marcarItemParaAbrir, AccountIcon, c
2
2
  import { chartTreeProps, chartAccountWithDescendants, chartRowsFor } from './chunk-XGBGRXZ3.js';
3
3
  import { startReceiptCapture, RECEIVABLE_RECEIPT_INSTRUCTIONS, RECEIPT_INSTRUCTIONS, createReceiptTools } from './chunk-7VKJLBYY.js';
4
4
  import { FINANCIAL_MODULE_DEFAULTS, FinancialGeneralSettings } from './chunk-POYZFEAN.js';
5
- import { CashRegistersView } from './chunk-G3BID4RP.js';
5
+ import { CashRegistersView } from './chunk-NS2XEAQQ.js';
6
+ import './chunk-MTYUOE76.js';
6
7
  import { formatCurrency, FinancialContextProvider, useFinancialConfig, useFinancialStore, useFinancialProvider } from './chunk-CNXAVGSW.js';
7
8
  import * as React15 from 'react';
8
9
  import React15__default, { memo, useState, useMemo, useCallback, useEffect, useRef } from 'react';
@@ -16,7 +17,7 @@ import { cnabPayeeGaps, inferPixKeyType, generateCnab240, splitAccountDigit, sug
16
17
  import { invoiceOpensForEditing, availableInvoiceItemTypes } from '@fayz-ai/financial/domain/invoice';
17
18
  import { createPortal } from 'react-dom';
18
19
  import { newestStatementEntriesFirst } from '@fayz-ai/financial/domain/statement';
19
- import { resolveCandidates, sumItems, itemsMismatch, adjustmentGap, adjustmentsMismatch, adjustmentDirection, reconciliationPaymentNote } from '@fayz-ai/financial/domain/reconciliation';
20
+ import { resolveCandidates, sumItems, itemsMismatch, adjustmentGap, adjustmentsMismatch, adjustmentDirection, reconciliationPaymentNote, descriptionShape, statementLineKey } from '@fayz-ai/financial/domain/reconciliation';
20
21
  import { postableAccounts } from '@fayz-ai/financial/domain/chart-of-accounts';
21
22
  import { round2 as round2$1 } from '@fayz-ai/financial/domain/money';
22
23
  import { counterpartyAccountingPolicy, resolveCounterpartyAccountingPolicy } from '@fayz-ai/financial/domain/counterparty';
@@ -4634,15 +4635,12 @@ function ReconcileFlow({ line, initialIntent, initialTarget, initialStep = 0, on
4634
4635
  }
4635
4636
  );
4636
4637
  }
4637
- function descriptionShape(description) {
4638
- return description.toUpperCase().normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/\d+([./-]\d+)*/g, " ").replace(/[^A-Z ]+/g, " ").replace(/\s+/g, " ").trim();
4639
- }
4640
4638
  function groupLines(lines) {
4641
4639
  const groups = /* @__PURE__ */ new Map();
4642
4640
  for (const line of lines) {
4643
4641
  const doc = (line.counterpartyDocument ?? "").replace(/\D/g, "") || null;
4644
4642
  const shape = descriptionShape(line.description || line.counterpartyName || "");
4645
- const key = `${line.direction}:${doc ? `doc:${doc}` : `shape:${shape}`}`;
4643
+ const key = statementLineKey(line);
4646
4644
  const g = groups.get(key) ?? {
4647
4645
  key,
4648
4646
  direction: line.direction,
@@ -4690,6 +4688,7 @@ function BatchClassifyModal({ provider, bankAccountId, dateRange, onClose, onDon
4690
4688
  counterAccountId: "",
4691
4689
  excluded: /* @__PURE__ */ new Set()
4692
4690
  }])));
4691
+ void prefill(lines, g).catch((e) => console.warn("[financial] batch suggestions unavailable", e));
4693
4692
  }).catch((e) => {
4694
4693
  toast.error("N\xE3o foi poss\xEDvel ler o extrato", { description: e instanceof Error ? e.message : String(e) });
4695
4694
  setGroups([]);
@@ -4698,6 +4697,32 @@ function BatchClassifyModal({ provider, bankAccountId, dateRange, onClose, onDon
4698
4697
  });
4699
4698
  void provider.getBankAccounts().then((a) => alive && setAccounts(a.filter((x) => x.id !== bankAccountId))).catch(() => {
4700
4699
  });
4700
+ async function prefill(lines, g) {
4701
+ if (!provider.suggestClassifications) return;
4702
+ const [memory, matches] = await Promise.all([
4703
+ provider.suggestClassifications(lines),
4704
+ provider.suggestReconciliationBatch ? provider.suggestReconciliationBatch(lines) : Promise.resolve({})
4705
+ ]);
4706
+ if (!alive) return;
4707
+ setDecisions((prev) => {
4708
+ const next = { ...prev };
4709
+ for (const group of g) {
4710
+ const d = next[group.key];
4711
+ if (!d || d.action !== "skip") continue;
4712
+ if (group.lines.some((line) => (matches[line.id] ?? []).length > 0)) continue;
4713
+ const sug = group.lines.map((line) => memory[line.id]).find(Boolean);
4714
+ if (!sug) continue;
4715
+ next[group.key] = {
4716
+ ...d,
4717
+ action: "bill",
4718
+ accountId: sug.accountId,
4719
+ contactName: d.contactName || sug.contactName || "",
4720
+ suggested: { accountId: sug.accountId, times: sug.times }
4721
+ };
4722
+ }
4723
+ return next;
4724
+ });
4725
+ }
4701
4726
  return () => {
4702
4727
  alive = false;
4703
4728
  };
@@ -4858,6 +4883,11 @@ var GroupRow = memo(function GroupRow2({ g, d, expanded, chart, compare, account
4858
4883
  "Documento ",
4859
4884
  g.document
4860
4885
  ] }),
4886
+ d.suggested && d.action === "bill" && d.accountId === d.suggested.accountId && /* @__PURE__ */ jsxs("p", { className: "ml-6 text-xs text-magic-soft-foreground", children: [
4887
+ "Sugerido: lan\xE7ado assim nas \xFAltimas ",
4888
+ d.suggested.times,
4889
+ " vez(es)"
4890
+ ] }),
4861
4891
  /* @__PURE__ */ jsxs("div", { className: "ml-6 mt-2 grid gap-2 sm:grid-cols-[180px_1fr_1fr]", children: [
4862
4892
  /* @__PURE__ */ jsxs(Select, { value: d.action, onValueChange: (v) => onSet(g.key, { action: v }), children: [
4863
4893
  /* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, {}) }),
@@ -5077,6 +5107,7 @@ function ReconciliationView() {
5077
5107
  const [result, setResult] = useState(null);
5078
5108
  const [loading, setLoading] = useState(false);
5079
5109
  const [candidatos, setCandidatos] = useState({});
5110
+ const [classificacoes, setClassificacoes] = useState({});
5080
5111
  const [sugerindo, setSugerindo] = useState(null);
5081
5112
  const [busy, setBusy] = useState(false);
5082
5113
  const [flow, setFlow] = useState(null);
@@ -5140,6 +5171,34 @@ function ReconciliationView() {
5140
5171
  vivo = false;
5141
5172
  };
5142
5173
  }, [provider, linhasAbertas]);
5174
+ useEffect(() => {
5175
+ if (!provider.suggestClassifications || linhasAbertas.length === 0) return;
5176
+ let vivo = true;
5177
+ provider.suggestClassifications(linhasAbertas).then((achados) => {
5178
+ if (vivo) setClassificacoes((prev) => ({ ...prev, ...achados }));
5179
+ }).catch((error) => console.warn("[financial] classification suggestions unavailable", error));
5180
+ return () => {
5181
+ vivo = false;
5182
+ };
5183
+ }, [provider, linhasAbertas]);
5184
+ async function lancarSugerido(line, sugestao) {
5185
+ if (!provider.reconcileAsBill) return;
5186
+ setBusy(true);
5187
+ try {
5188
+ await provider.reconcileAsBill({
5189
+ bankMovementId: line.id,
5190
+ accountId: sugestao.accountId,
5191
+ contactName: line.counterpartyName || sugestao.contactName || void 0,
5192
+ description: line.description || void 0
5193
+ });
5194
+ toast.success(t("financial.reconciliation.classifiedAs", { account: sugestao.accountName ?? "" }));
5195
+ await load();
5196
+ } catch (e) {
5197
+ toast.error(e instanceof Error ? e.message : t("common.error"));
5198
+ } finally {
5199
+ setBusy(false);
5200
+ }
5201
+ }
5143
5202
  const filtrar = filtros.apply;
5144
5203
  async function sugerir(line) {
5145
5204
  if (!provider.suggestReconciliation) return;
@@ -5429,6 +5488,8 @@ function ReconciliationView() {
5429
5488
  {
5430
5489
  line,
5431
5490
  candidatos: candidatos[line.id],
5491
+ classificacao: classificacoes[line.id],
5492
+ onLancarSugerido: (sug) => void lancarSugerido(line, sug),
5432
5493
  sugerindo: sugerindo === line.id,
5433
5494
  busy,
5434
5495
  fmt,
@@ -5524,10 +5585,12 @@ function CardSkeleton() {
5524
5585
  function StatementCard({
5525
5586
  line,
5526
5587
  candidatos,
5588
+ classificacao,
5527
5589
  sugerindo,
5528
5590
  busy,
5529
5591
  fmt,
5530
5592
  t,
5593
+ onLancarSugerido,
5531
5594
  onSugerir,
5532
5595
  onTransferir,
5533
5596
  onVincular,
@@ -5540,13 +5603,14 @@ function StatementCard({
5540
5603
  const isCredit = line.direction === "credit";
5541
5604
  const conciliada = !!line.reconciledAt;
5542
5605
  const sugestao = candidatos?.[0];
5606
+ const classificar = !conciliada && !sugestao ? classificacao : void 0;
5543
5607
  const delta = sugestao ? round2$1(sugestao.movement.amount - line.amount) : 0;
5544
5608
  return (
5545
5609
  // O cartão inteiro ganha um fundo de leve: a fita diz o estado a dois
5546
5610
  // metros, mas é o fundo que separa as linhas que pedem decisão das que já
5547
5611
  // não pedem, quando se rola cinquenta de uma vez.
5548
- /* @__PURE__ */ jsxs(Card, { className: `relative space-y-3 overflow-hidden p-4 ${conciliada ? "border-2 border-success/50 bg-success-soft/25" : sugestao ? "border-2 border-magic/60 bg-magic-soft/40" : ""}`, children: [
5549
- (conciliada || sugestao) && /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute right-0 top-0 z-10 h-24 w-24 overflow-hidden", "aria-hidden": true, children: /* @__PURE__ */ jsx(
5612
+ /* @__PURE__ */ jsxs(Card, { className: `relative space-y-3 overflow-hidden p-4 ${conciliada ? "border-2 border-success/50 bg-success-soft/25" : sugestao || classificar ? "border-2 border-magic/60 bg-magic-soft/40" : ""}`, children: [
5613
+ (conciliada || sugestao || classificar) && /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute right-0 top-0 z-10 h-24 w-24 overflow-hidden", "aria-hidden": true, children: /* @__PURE__ */ jsx(
5550
5614
  "div",
5551
5615
  {
5552
5616
  className: `absolute py-1 text-center text-[10px] font-bold uppercase tracking-wide text-white shadow-md ${conciliada ? "bg-success" : "bg-magic"}`,
@@ -5554,7 +5618,7 @@ function StatementCard({
5554
5618
  children: conciliada ? t("financial.reconciliation.reconciled") : t("financial.reconciliation.suggestion")
5555
5619
  }
5556
5620
  ) }),
5557
- /* @__PURE__ */ jsxs("div", { className: `flex flex-wrap items-start justify-between gap-4 ${conciliada || sugestao ? "pr-24" : ""}`, children: [
5621
+ /* @__PURE__ */ jsxs("div", { className: `flex flex-wrap items-start justify-between gap-4 ${conciliada || sugestao || classificar ? "pr-24" : ""}`, children: [
5558
5622
  /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [
5559
5623
  /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold tabular-nums", children: line.date ? shortDate3(line.date) : "\u2014" }),
5560
5624
  /* @__PURE__ */ jsx("span", { className: `rounded border px-1.5 py-px text-[11px] font-medium ${isCredit ? "border-success/60 text-success" : "border-destructive/60 text-destructive"}`, children: isCredit ? t("financial.reconciliation.credit") : t("financial.reconciliation.debit") }),
@@ -5636,7 +5700,24 @@ function StatementCard({
5636
5700
  t("financial.reconciliation.match")
5637
5701
  ] })
5638
5702
  ] }),
5639
- !conciliada && candidatos && candidatos.length === 0 && /* @__PURE__ */ jsx("p", { className: "rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground", children: t("financial.reconciliation.noCandidates") }),
5703
+ classificar && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-start gap-3 rounded-md border border-magic/40 bg-card/70 p-3", children: [
5704
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 text-sm", children: [
5705
+ /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1 font-medium text-magic-soft-foreground", children: [
5706
+ /* @__PURE__ */ jsx(Sparkles, { className: "h-3.5 w-3.5 shrink-0", "aria-hidden": true }),
5707
+ t("financial.reconciliation.suggestionLabel")
5708
+ ] }),
5709
+ " ",
5710
+ t("financial.reconciliation.classifyAs"),
5711
+ " ",
5712
+ /* @__PURE__ */ jsx("span", { className: "font-semibold", children: classificar.accountName }),
5713
+ /* @__PURE__ */ jsx("span", { className: "ml-2 text-xs text-muted-foreground", children: t("financial.reconciliation.classifiedBefore", { count: classificar.times }) })
5714
+ ] }),
5715
+ /* @__PURE__ */ jsxs(Button, { size: "sm", className: "shrink-0", disabled: busy, onClick: () => onLancarSugerido(classificar), children: [
5716
+ /* @__PURE__ */ jsx(Receipt, { className: "h-3 w-3" }),
5717
+ t("financial.reconciliation.classifyAction")
5718
+ ] })
5719
+ ] }),
5720
+ !conciliada && !classificar && candidatos && candidatos.length === 0 && /* @__PURE__ */ jsx("p", { className: "rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground", children: t("financial.reconciliation.noCandidates") }),
5640
5721
  /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2 border-t pt-2", children: [
5641
5722
  !conciliada && /* @__PURE__ */ jsxs(Fragment, { children: [
5642
5723
  /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", disabled: busy, onClick: onTransferir, children: [
@@ -5671,13 +5752,13 @@ function StatementCard({
5671
5752
  t("financial.reconciliation.undo")
5672
5753
  ] })
5673
5754
  ] }),
5674
- !conciliada && !sugestao && /* @__PURE__ */ jsx(AiActionButton, { size: "sm", className: "ml-auto", busy: sugerindo, disabled: busy, onClick: onSugerir, children: t("financial.reconciliation.suggest") }),
5755
+ !conciliada && !sugestao && !classificar && /* @__PURE__ */ jsx(AiActionButton, { size: "sm", className: "ml-auto", busy: sugerindo, disabled: busy, onClick: onSugerir, children: t("financial.reconciliation.suggest") }),
5675
5756
  /* @__PURE__ */ jsxs(
5676
5757
  Button,
5677
5758
  {
5678
5759
  variant: "ghost",
5679
5760
  size: "sm",
5680
- className: conciliada || sugestao ? "ml-auto" : "",
5761
+ className: conciliada || sugestao || classificar ? "ml-auto" : "",
5681
5762
  onClick: onDetalhes,
5682
5763
  children: [
5683
5764
  /* @__PURE__ */ jsx(Eye, { className: "h-3 w-3" }),
@@ -6662,5 +6743,5 @@ function FinancialPage({ config: appConfig, provider, store, registries }) {
6662
6743
  }
6663
6744
 
6664
6745
  export { FinancialPage };
6665
- //# sourceMappingURL=FinancialPage-YJUM62B7.js.map
6666
- //# sourceMappingURL=FinancialPage-YJUM62B7.js.map
6746
+ //# sourceMappingURL=FinancialPage-QCUN3TMZ.js.map
6747
+ //# sourceMappingURL=FinancialPage-QCUN3TMZ.js.map