@fayz-ai/financial 0.3.1 → 0.3.2
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/{chunk-TU2JMMVO.js → chunk-5FESQBPQ.js} +51 -29
- package/dist/chunk-5FESQBPQ.js.map +1 -0
- package/dist/{chunk-5F6ULA56.js → chunk-HPJDTBVB.js} +3 -3
- package/dist/{chunk-5F6ULA56.js.map → chunk-HPJDTBVB.js.map} +1 -1
- package/dist/{chunk-FNXIAIUZ.js → chunk-IVIMTPAV.js} +3 -3
- package/dist/{chunk-FNXIAIUZ.js.map → chunk-IVIMTPAV.js.map} +1 -1
- package/dist/{chunk-MCSPCXQK.js → chunk-NAEXIF3W.js} +2 -2
- package/dist/chunk-NAEXIF3W.js.map +1 -0
- package/dist/{chunk-PT747UGV.js → chunk-TUYTZEW4.js} +14 -6
- package/dist/chunk-TUYTZEW4.js.map +1 -0
- package/dist/data/mock.d.ts.map +1 -1
- package/dist/data/mock.js +4 -4
- package/dist/data/reconcile.js +2 -2
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/data/supabase.js +4 -4
- package/dist/domain/invoice.d.ts.map +1 -1
- package/dist/domain/invoice.js +1 -1
- package/dist/domain/reconciliation.d.ts +8 -1
- package/dist/domain/reconciliation.d.ts.map +1 -1
- package/dist/domain/reconciliation.js +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +6 -6
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-MCSPCXQK.js.map +0 -1
- package/dist/chunk-PT747UGV.js.map +0 -1
- package/dist/chunk-TU2JMMVO.js.map +0 -1
|
@@ -5,11 +5,11 @@ 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-
|
|
8
|
+
import { cancellationReason, invoiceTotal, itemsDescription, summarizeInvoiceLines, lineTotal } from './chunk-HPJDTBVB.js';
|
|
9
9
|
import { paymentFee, ledgerMethod, toLedgerDirection, fromLedgerDirection } from './chunk-4GXBOEI3.js';
|
|
10
10
|
import { sessionCashFlow } from './chunk-56NQHYL7.js';
|
|
11
|
-
import { runReconcileAsBill, runReconcileLink } from './chunk-
|
|
12
|
-
import { transferForStatementLine, statementLegOf, candidateTolerance, candidateScore, statementLinesPage, pageTotals } from './chunk-
|
|
11
|
+
import { runReconcileAsBill, runReconcileLink } from './chunk-IVIMTPAV.js';
|
|
12
|
+
import { transferForStatementLine, statementLegOf, candidateTolerance, candidateScore, statementLinesPage, pageTotals } from './chunk-NAEXIF3W.js';
|
|
13
13
|
import { round2 } from './chunk-XVELDCSL.js';
|
|
14
14
|
import { summarizeSyncStatus } from './chunk-3QNU7XUB.js';
|
|
15
15
|
import { getActiveTenantId, getSupabaseClientOptional } from '@fayz-ai/core';
|
|
@@ -231,6 +231,22 @@ async function attachCurrency(pub, invoices) {
|
|
|
231
231
|
} catch {
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
+
async function sumStatementLines(build) {
|
|
235
|
+
const CHUNK = 1e3;
|
|
236
|
+
const rows = [];
|
|
237
|
+
try {
|
|
238
|
+
for (let from = 0; from < 5e4; from += CHUNK) {
|
|
239
|
+
const { data, error } = await build().order("id", { ascending: true }).range(from, from + CHUNK - 1);
|
|
240
|
+
if (error) return void 0;
|
|
241
|
+
for (const row of data ?? []) rows.push({ direction: row.direction, amount: Number(row.amount) || 0 });
|
|
242
|
+
if (!data || data.length < CHUNK) break;
|
|
243
|
+
}
|
|
244
|
+
} catch {
|
|
245
|
+
return void 0;
|
|
246
|
+
}
|
|
247
|
+
const { pageCredits, pageDebits, pageBalance } = pageTotals(rows);
|
|
248
|
+
return { credits: pageCredits, debits: pageDebits, balance: pageBalance };
|
|
249
|
+
}
|
|
234
250
|
async function sumInvoiceLines(build) {
|
|
235
251
|
const CHUNK = 1e3;
|
|
236
252
|
const byCurrency = /* @__PURE__ */ new Map();
|
|
@@ -504,7 +520,7 @@ function createSupabaseFinancialProvider() {
|
|
|
504
520
|
const page = query.page ?? 1;
|
|
505
521
|
const pageSize = query.pageSize ?? 50;
|
|
506
522
|
qb = qb.range((page - 1) * pageSize, page * pageSize);
|
|
507
|
-
qb = query.sort === "recent" ? qb.order("created_at", { ascending: false }).order("due_date", { ascending: true }) : qb.order("due_date", { ascending:
|
|
523
|
+
qb = query.sort === "recent" ? qb.order("created_at", { ascending: false }).order("due_date", { ascending: true }) : qb.order("due_date", { ascending: false }).order("created_at", { ascending: false });
|
|
508
524
|
const { data, count, error } = await qb;
|
|
509
525
|
if (error) throw error;
|
|
510
526
|
const rows = data ?? [];
|
|
@@ -2333,32 +2349,38 @@ function createSupabaseFinancialProvider() {
|
|
|
2333
2349
|
const { pub } = getClients();
|
|
2334
2350
|
const { page, pageSize } = statementLinesPage(query);
|
|
2335
2351
|
const from = (page - 1) * pageSize;
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2352
|
+
const filtrar = (base) => {
|
|
2353
|
+
let qb = base.eq("provider_deleted", false);
|
|
2354
|
+
if (query?.bankAccountId) qb = qb.eq("bank_account_id", query.bankAccountId);
|
|
2355
|
+
if (query?.dateRange) qb = qb.gte("posted_on", query.dateRange.from).lte("posted_on", query.dateRange.to);
|
|
2356
|
+
if (query?.direction) qb = qb.eq("direction", query.direction);
|
|
2357
|
+
if (query?.status === "reconciled") qb = qb.not("reconciled_at", "is", null);
|
|
2358
|
+
else if (query?.status === "pending") qb = qb.is("reconciled_at", null);
|
|
2359
|
+
const term = (query?.search ?? "").trim();
|
|
2360
|
+
if (term) {
|
|
2361
|
+
const safe = term.replace(/[,()*%]/g, " ");
|
|
2362
|
+
qb = qb.or([
|
|
2363
|
+
`description.ilike.%${safe}%`,
|
|
2364
|
+
`counterparty_name.ilike.%${safe}%`,
|
|
2365
|
+
`counterparty_document.ilike.%${safe}%`,
|
|
2366
|
+
`document.ilike.%${safe}%`,
|
|
2367
|
+
`code.ilike.%${safe}%`,
|
|
2368
|
+
`category.ilike.%${safe}%`,
|
|
2369
|
+
`transaction_type.ilike.%${safe}%`,
|
|
2370
|
+
`external_id.ilike.%${safe}%`
|
|
2371
|
+
].join(","));
|
|
2372
|
+
}
|
|
2373
|
+
if (query?.hideInvestments) qb = qb.or(`code.is.null,code.not.in.(${INVESTMENT_CODES.join(",")})`);
|
|
2374
|
+
return qb;
|
|
2375
|
+
};
|
|
2376
|
+
const [{ data, error, count }, totals] = await Promise.all([
|
|
2377
|
+
filtrar(pub.from(T.statementLines).select("*", { count: "exact" })).order("posted_on", { ascending: false }).order("id", { ascending: false }).range(from, from + pageSize - 1),
|
|
2378
|
+
sumStatementLines(() => filtrar(pub.from(T.statementLines).select("id,direction,amount")))
|
|
2379
|
+
]);
|
|
2358
2380
|
if (error) throw error;
|
|
2359
2381
|
const rows = (data ?? []).map(toStatementLine);
|
|
2360
2382
|
await anexaContraparte(rows);
|
|
2361
|
-
return { rows, total: count ?? 0, page, pageSize, ...pageTotals(rows) };
|
|
2383
|
+
return { rows, total: count ?? 0, page, pageSize, ...pageTotals(rows), totals };
|
|
2362
2384
|
},
|
|
2363
2385
|
async getUnreconciled(query) {
|
|
2364
2386
|
const { pub } = getClients();
|
|
@@ -2853,5 +2875,5 @@ function createSupabaseFinancialProvider() {
|
|
|
2853
2875
|
}
|
|
2854
2876
|
|
|
2855
2877
|
export { createSupabaseFinancialProvider, invoiceLineOrFilter };
|
|
2856
|
-
//# sourceMappingURL=chunk-
|
|
2857
|
-
//# sourceMappingURL=chunk-
|
|
2878
|
+
//# sourceMappingURL=chunk-5FESQBPQ.js.map
|
|
2879
|
+
//# sourceMappingURL=chunk-5FESQBPQ.js.map
|