From df8623ff9f04bd8ec1a63b412fdbb6e9bd9d4bf8 Mon Sep 17 00:00:00 2001 From: renee-png Date: Fri, 12 Jun 2026 19:52:21 -0400 Subject: [PATCH] buildium-gl-sync: include inactive bank-account GL ids from /v1/bankaccounts /v1/glaccounts omits some inactive accounts (e.g. prior-management bank accounts) whose ledgers still hold one side of historical transactions, making checks/deposits come back unbalanced on backfills (found during the Casuarina Club GL import). Co-Authored-By: Claude Opus 4.8 --- supabase/functions/buildium-gl-sync/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/supabase/functions/buildium-gl-sync/index.ts b/supabase/functions/buildium-gl-sync/index.ts index 14d16b6..7f525ef 100644 --- a/supabase/functions/buildium-gl-sync/index.ts +++ b/supabase/functions/buildium-gl-sync/index.ts @@ -189,6 +189,24 @@ Deno.serve(async (req) => { if (Array.isArray(g.SubAccounts)) for (const s of g.SubAccounts) addGl(s); }; for (const g of glAccounts) addGl(g); + + // /v1/glaccounts omits some inactive accounts (e.g. prior-management bank + // accounts) whose ledgers still hold one side of historical transactions — + // without them, checks/deposits come back unbalanced. /v1/bankaccounts + // returns inactive banks too, so merge their GL ids in. + const bankAccts = await buildiumFetchAll("/v1/bankaccounts", clientId, clientSecret); + for (const b of bankAccts) { + const gid = String(b.GLAccount?.Id ?? b.Id ?? ""); + if (gid && !bGlById.has(gid)) { + bGlById.set(gid, { + Id: gid, + Name: b.GLAccount?.Name ?? b.Name, + AccountNumber: b.GLAccount?.AccountNumber ?? null, + Type: b.GLAccount?.Type ?? "Asset", + IsActive: b.IsActive, + }); + } + } const allGlIds = [...bGlById.keys()]; const today = isoDate(new Date());