@fayz-ai/financial 0.3.7 → 0.4.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.
@@ -1,11 +1,11 @@
1
- import { T } from './chunk-4FWWKKZB.js';
2
1
  import { hasCriteriaValue } from './chunk-J7BWATQU.js';
2
+ import { T } from './chunk-4FWWKKZB.js';
3
3
  import { ensureReferenceRates } from './chunk-4S5GK776.js';
4
4
  import { createIdempotencyKey } from './chunk-IP5YH4S5.js';
5
5
  import { NAME_AMOUNT_TOLERANCE, matchStatementLines, scorePair } from './chunk-ZFUQBYBG.js';
6
6
  import { emptyStatement, ledgerBalance, buildStatement } from './chunk-HJPUHTI2.js';
7
7
  import { transferLegs } from './chunk-YUNLQYOZ.js';
8
- import { cancellationReason, invoiceTotal, itemsDescription, summarizeInvoiceLines, lineTotal } from './chunk-HPJDTBVB.js';
8
+ import { cancellationReason, invoiceTotal, itemsDescription, summarizeInvoiceLines, lineTotal } from './chunk-MUXDSFL5.js';
9
9
  import { paymentFee, ledgerMethod, toLedgerDirection, fromLedgerDirection } from './chunk-4GXBOEI3.js';
10
10
  import { sessionCashFlow } from './chunk-56NQHYL7.js';
11
11
  import { runReconcileAsBill, runReconcileLink } from './chunk-NONT5MVW.js';
@@ -638,7 +638,7 @@ function createSupabaseFinancialProvider() {
638
638
  },
639
639
  async getInvoiceAttachments(invoiceId) {
640
640
  const { pub } = getClients();
641
- const { data, error } = await pub.from("documents").select("id, file_name, file_size, mime_type, file_url, storage_bucket, storage_path, storage_provider, created_at").eq("subject_type", "financial_invoice").eq("subject_id", invoiceId).eq("is_active", true).order("created_at");
641
+ const { data, error } = await pub.from("documents").select("id, file_name, file_size, mime_type, file_url, storage_bucket, storage_path, storage_provider, created_at, metadata").eq("subject_type", "financial_invoice").eq("subject_id", invoiceId).eq("is_active", true).order("created_at");
642
642
  if (error) throw error;
643
643
  const linhas = data ?? [];
644
644
  const assinadas = /* @__PURE__ */ new Map();
@@ -669,11 +669,12 @@ function createSupabaseFinancialProvider() {
669
669
  // Pendente é o que NÃO ABRE: os bytes ainda no V1, ou a assinatura
670
670
  // que não veio. O `file_url` gravado não conta — ele responde 400.
671
671
  pending: !url,
672
- createdAt: r.created_at
672
+ createdAt: r.created_at,
673
+ installmentNumber: Number(r.metadata?.installment_number) || void 0
673
674
  };
674
675
  });
675
676
  },
676
- async addInvoiceAttachment(invoiceId, file) {
677
+ async addInvoiceAttachment(invoiceId, file, opts) {
677
678
  const { pub } = getClients();
678
679
  const tenantId = getActiveTenantId();
679
680
  if (!tenantId) throw new Error("Conta sem empresa ativa");
@@ -692,7 +693,10 @@ function createSupabaseFinancialProvider() {
692
693
  mime_type: file.type || null,
693
694
  storage_provider: "supabase",
694
695
  storage_bucket: "attachments",
695
- storage_path: path
696
+ storage_path: path,
697
+ // The installment this receipt proves: the file stays on the invoice,
698
+ // and the installment's clip counts only its own.
699
+ metadata: opts?.installmentNumber ? { installment_number: opts.installmentNumber } : {}
696
700
  });
697
701
  if (error) {
698
702
  await pub.storage.from("attachments").remove([path]).catch(() => {
@@ -700,6 +704,11 @@ function createSupabaseFinancialProvider() {
700
704
  throw error;
701
705
  }
702
706
  },
707
+ async removeInvoiceAttachment(attachmentId) {
708
+ const { pub } = getClients();
709
+ const { error } = await pub.from("documents").update({ is_active: false }).eq("id", attachmentId).eq("subject_type", "financial_invoice");
710
+ if (error) throw error;
711
+ },
703
712
  async createInvoice(input) {
704
713
  const { pub } = getClients();
705
714
  getActiveTenantId();
@@ -2923,5 +2932,5 @@ function createSupabaseFinancialProvider() {
2923
2932
  }
2924
2933
 
2925
2934
  export { createSupabaseFinancialProvider, invoiceLineOrFilter };
2926
- //# sourceMappingURL=chunk-Y6XGQLEV.js.map
2927
- //# sourceMappingURL=chunk-Y6XGQLEV.js.map
2935
+ //# sourceMappingURL=chunk-FSYWDO42.js.map
2936
+ //# sourceMappingURL=chunk-FSYWDO42.js.map