Queries · q223 · Chief Financial Officer · week 2, night 2
“What do the actual ledger entries look like for the refunded and anomalous payments flagged in the transaction walkthrough, and does the accounting treatment of refunds make sense?”
Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told
Week 2
The external auditors start the 2025 year-end audit in two weeks. They will want to see that the money adds up across the whole chain: what shoppers paid, what was refunded or credited, what merchants received in payouts, what Tidewick kept, and that invoices agree with all of it. They will also trace sample transactions end to end.
The manager, at the start of week 2
Subject: Good progress — but the audit clock is now the priority
Kofi,
Thanks — this is useful, and I appreciate you flagging the caveats rather than smoothing them over. A few reactions and then where I want to focus next week.
What stood out:
The big new driver: external audit starts in two weeks. They'll want to walk the full money trail — what a shopper paid, what was refunded or credited back, what the merchant was paid out, what we kept as our fee, and that it all agrees with the invoices and accounts — and they'll pick sample transactions and trace them start to finish. I'd rather we got ahead of that than react to it.
Questions for this week, in priority order:
Audit readiness (#1) is the one I most need — please make that the lead request even if it means FX and B2B receivables slip another week.
Thanks, Tobias
The analyst · week 2, night 2, request 1 of 3
Report 1's ledger columns are the big finding. For every refunded payment, ledger_credit_total exactly equals payment_amount + amount_refunded, not net_amount: e.g. OfficeHub Nordic SO-100363 (265,275.15 paid, fully refunded) shows ledger_credit_total = 530,550.30 = 2x the payment, and Fell & Fjell #1179 shows 69,408.75 = 34,885.85 + 34,522.90 exactly. My ledger_debit_credit_diff column is useless for catching this (it's 0 everywhere by construction, since any balanced journal entry nets to zero regardless of which accounts are touched) — I designed that check too naively. Before I tell Tobias "the ledger balances," I need to see the actual account-level entries for a few of these to confirm this is just a normal (and explainable) refund-accounting pattern — e.g. a reversing entry on a different account — rather than revenue being double-booked.
Two more things in Report 1 don't fit any pattern and need chasing at scale rather than left as anecdotes: Castell Fasteners' SO-100233 (no refund, not yet paid out) has ledger_credit_total of 805.56 against a payment_amount of 752.91 — an unexplained ~7% gap; and Marrowby & Vane's #3307 (a tiny $20 payment) has NULL ledger_credit_total, meaning no ledger entries exist for it at all. Given this week's pattern across other teams (CISO: deletions and role changes with zero audit trail), an "orphan payment with no ledger entry" is exactly the kind of gap auditors will zero in on, so I want to know if that's a one-off or systemic before Friday.
Tonight's three slots: (1) pull the actual ledger line items for the flagged refunded + anomalous sample payments to explain the credit-total pattern; (2) run the same credit-total-vs-payment reconciliation across ALL of 2025's payments (not just the 25-sample) to see if the "+refund" pattern is universal/explainable and how big the "other mismatch" and "no ledger entries" buckets really are; (3) quantify the no-ledger-entry gap by merchant to see if it's concentrated or spread thin.
The engineer · 1 dry run on the empty schema, then the submission
with flagged_pairs (merchant_name, order_number) as ( values ('OfficeHub Nordic', 'SO-100363'), ('Fell & Fjell', '#1179'), ('Courtside Collective', 'CC-100015'), ('Ampfeld Elektronik', '#1727'), ('Ballycorran Industrial Supply', 'SO-100835'), ('Ballycorran Industrial Supply', 'SO-100608'), ('Midland Safety Wear', 'SO-100307'), ('Halden Boots', '#1004'), ('Castell Fasteners', 'SO-100233') ), matched_orders as ( select o.id as order_id, o.order_number, t.name as merchant_name from orders o join tenants t on t.id = o.tenant_id join flagged_pairs fp on fp.merchant_name = t.name and fp.order_number = o.order_number ), matched_payments as ( select p.id as payment_id, mo.order_id, mo.order_number, mo.merchant_name from payments p join matched_orders mo on mo.order_id = p.order_id ), ledger_detail as ( select mp.merchant_name, mp.order_number, la.name as ledger_account_name, la.account_type, le.direction, le.amount, le.currency_code, le.description, le.entry_group, le.occurred_at from ledger_entries le join matched_payments mp on mp.payment_id = le.payment_id join ledger_accounts la on la.id = le.ledger_account_id ) select merchant_name, order_number, ledger_account_name, account_type, direction, amount, currency_code, description, entry_group, occurred_at from ledger_detail order by merchant_name, order_number, occurred_at, entry_group
“Query compiles and returns the expected columns. Submitting now.”
“Submitted. The query resolves each of the 9 flagged (merchant, order_number) pairs to its order(s) via tenants.name + orders.order_number, finds the associated payment(s), and returns every ledger_entries row for those payments at full grain (joined to ledger_accounts for name/account_type), ordered by merchant, order number, timestamp, and entry group so paired debit/credit lines sit together for the CFO's accounting review.”
As Kofi Mensah saw it, from the small dataset the agents worked on
merchant_name | order_number | ledger_account_name | account_type | direction | amount | currency_code | description | entry_group | occurred_at ------------------------------+--------------+--------------------------+----------------+-----------+-------------+---------------+-------------------------------+--------------------------------------+--------------------------- Ampfeld Elektronik | #1727 | VAT / sales tax payable | liability | credit | 2653.6100 | EUR | Order payment captured | c257c88c-e5ae-4799-9e45-53cd2615e382 | 2025-05-02 21:24:26.731706 Ampfeld Elektronik | #1727 | Payment gateway clearing | asset | debit | 16619.9900 | EUR | Order payment captured | c257c88c-e5ae-4799-9e45-53cd2615e382 | 2025-05-02 21:24:26.731706 Ampfeld Elektronik | #1727 | Sales revenue | revenue | credit | 13966.3800 | EUR | Order payment captured | c257c88c-e5ae-4799-9e45-53cd2615e382 | 2025-05-02 21:24:26.731706 Ampfeld Elektronik | #1727 | Payment gateway clearing | asset | credit | 16619.9900 | EUR | Return refund | d3174af8-215a-47ee-9c5d-f4917168ab8c | 2025-05-22 23:58:15.251402 Ampfeld Elektronik | #1727 | VAT / sales tax payable | liability | debit | 2653.6100 | EUR | Return refund | d3174af8-215a-47ee-9c5d-f4917168ab8c | 2025-05-22 23:58:15.251402 Ampfeld Elektronik | #1727 | Refunds and returns | contra_revenue | debit | 13966.3800 | EUR | Return refund | d3174af8-215a-47ee-9c5d-f4917168ab8c | 2025-05-22 23:58:15.251402 Ballycorran Industrial Supply | SO-100608 | Sales revenue | revenue | credit | 7439.3800 | EUR | Order payment captured | 8ccce0f3-00e2-4dcd-8512-e47c0b44ecb4 | 2025-04-09 09:30:06.184013 Ballycorran Industrial Supply | SO-100608 | VAT / sales tax payable | liability | credit | 1711.0600 | EUR | Order payment captured | 8ccce0f3-00e2-4dcd-8512-e47c0b44ecb4 | 2025-04-09 09:30:06.184013 Ballycorran Industrial Supply | SO-100608 | Payment gateway clearing | asset | debit | 9150.4400 | EUR | Order payment captured | 8ccce0f3-00e2-4dcd-8512-e47c0b44ecb4 | 2025-04-09 09:30:06.184013 Ballycorran Industrial Supply | SO-100608 | Payment gateway clearing | asset | credit | 8402.4600 | EUR | Return refund | eb6ed774-6bb5-407a-93b2-9a4335da04f4 | 2025-04-22 19:29:57.126354 Ballycorran Industrial Supply | SO-100608 | VAT / sales tax payable | liability | debit | 1511.7900 | EUR | Return refund | eb6ed774-6bb5-407a-93b2-9a4335da04f4 | 2025-04-22 19:29:57.126354 Ballycorran Industrial Supply | SO-100608 | Refunds and returns | contra_revenue | debit | 6890.6700 | EUR | Return refund | eb6ed774-6bb5-407a-93b2-9a4335da04f4 | 2025-04-22 19:29:57.126354 Ballycorran Industrial Supply | SO-100835 | VAT / sales tax payable | liability | credit | 2837.5100 | EUR | Order payment captured | a3269ea7-b9d0-46ab-a5b1-40c7f45e23a8 | 2025-12-08 09:04:33.468947 Ballycorran Industrial Supply | SO-100835 | Payment gateway clearing | asset | debit | 15174.5200 | EUR | Order payment captured | a3269ea7-b9d0-46ab-a5b1-40c7f45e23a8 | 2025-12-08 09:04:33.468947 Ballycorran Industrial Supply | SO-100835 | Sales revenue | revenue | credit | 12337.0100 | EUR | Order payment captured | a3269ea7-b9d0-46ab-a5b1-40c7f45e23a8 | 2025-12-08 09:04:33.468947 Ballycorran Industrial Supply | SO-100835 | VAT / sales tax payable | liability | debit | 2837.5100 | EUR | Order cancelled: refund | 87e31b59-7a20-40f6-b7b8-f6b0399a44ea | 2025-12-08 18:34:03.468947 Ballycorran Industrial Supply | SO-100835 | Payment gateway clearing | asset | credit | 15174.5200 | EUR | Order cancelled: refund | 87e31b59-7a20-40f6-b7b8-f6b0399a44ea | 2025-12-08 18:34:03.468947 Ballycorran Industrial Supply | SO-100835 | Refunds and returns | contra_revenue | debit | 12337.0100 | EUR | Order cancelled: refund | 87e31b59-7a20-40f6-b7b8-f6b0399a44ea | 2025-12-08 18:34:03.468947 Castell Fasteners | SO-100233 | Bank | asset | debit | 752.9100 | USD | Invoice paid by bank transfer | 8eb000d0-e4bd-4dbb-9e03-d32359d27bec | 2025-02-13 06:29:52.262559 Castell Fasteners | SO-100233 | VAT / sales tax payable | liability | credit | 52.7000 | USD | Invoice paid by bank transfer | 8eb000d0-e4bd-4dbb-9e03-d32359d27bec | 2025-02-13 06:29:52.262559 Castell Fasteners | SO-100233 | Sales revenue | revenue | credit | 752.8600 | USD | Invoice paid by bank transfer | 8eb000d0-e4bd-4dbb-9e03-d32359d27bec | 2025-02-13 06:29:52.262559 Castell Fasteners | SO-100233 | Refunds and returns | contra_revenue | debit | 52.6500 | USD | Invoice paid by bank transfer | 8eb000d0-e4bd-4dbb-9e03-d32359d27bec | 2025-02-13 06:29:52.262559 Courtside Collective | CC-100015 | VAT / sales tax payable | liability | credit | 3431.7000 | NOK | Order payment captured | d0e7c47b-a04a-4da6-bce7-7569daa30a22 | 2025-04-14 13:53:39.65033 Courtside Collective | CC-100015 | Sales revenue | revenue | credit | 13726.8000 | NOK | Order payment captured | d0e7c47b-a04a-4da6-bce7-7569daa30a22 | 2025-04-14 13:53:39.65033 Courtside Collective | CC-100015 | Payment gateway clearing | asset | debit | 17158.5000 | NOK | Order payment captured | d0e7c47b-a04a-4da6-bce7-7569daa30a22 | 2025-04-14 13:53:39.65033 Courtside Collective | CC-100015 | Payment gateway clearing | asset | credit | 17158.5000 | NOK | Return refund | c6463d0c-47ac-4844-be3a-c3a92355da63 | 2025-04-23 08:41:26.737694 Courtside Collective | CC-100015 | Refunds and returns | contra_revenue | debit | 14006.9400 | NOK | Return refund | c6463d0c-47ac-4844-be3a-c3a92355da63 | 2025-04-23 08:41:26.737694 Courtside Collective | CC-100015 | VAT / sales tax payable | liability | debit | 3151.5600 | NOK | Return refund | c6463d0c-47ac-4844-be3a-c3a92355da63 | 2025-04-23 08:41:26.737694 Fell & Fjell | #1179 | Sales revenue | revenue | credit | 27908.6800 | DKK | Order payment captured | 5ab2780b-ba4c-45a9-a5ea-1d4ade360a6a | 2025-09-07 14:09:33.306149 Fell & Fjell | #1179 | Payment gateway clearing | asset | debit | 34885.8500 | DKK | Order payment captured | 5ab2780b-ba4c-45a9-a5ea-1d4ade360a6a | 2025-09-07 14:09:33.306149 Fell & Fjell | #1179 | VAT / sales tax payable | liability | credit | 6977.1700 | DKK | Order payment captured | 5ab2780b-ba4c-45a9-a5ea-1d4ade360a6a | 2025-09-07 14:09:33.306149 Fell & Fjell | #1179 | Payment gateway clearing | asset | credit | 34522.9000 | DKK | Return refund | 13a0efcc-0308-4726-b45a-e3bc20bf000a | 2025-10-05 19:28:01.89952 Fell & Fjell | #1179 | VAT / sales tax payable | liability | debit | 6904.5800 | DKK | Return refund | 13a0efcc-0308-4726-b45a-e3bc20bf000a | 2025-10-05 19:28:01.89952 Fell & Fjell | #1179 | Refunds and returns | contra_revenue | debit | 27618.3200 | DKK | Return refund | 13a0efcc-0308-4726-b45a-e3bc20bf000a | 2025-10-05 19:28:01.89952 Halden Boots | #1004 | Sales revenue | revenue | credit | 5248.0000 | SEK | Order payment captured | 3dc00aae-2b7f-4477-951d-d2b6bf190949 | 2025-02-16 12:28:39.238233 Halden Boots | #1004 | VAT / sales tax payable | liability | credit | 1312.0000 | SEK | Order payment captured | 3dc00aae-2b7f-4477-951d-d2b6bf190949 | 2025-02-16 12:28:39.238233 Halden Boots | #1004 | Payment gateway clearing | asset | debit | 6560.0000 | SEK | Order payment captured | 3dc00aae-2b7f-4477-951d-d2b6bf190949 | 2025-02-16 12:28:39.238233 Halden Boots | #1004 | Payment gateway clearing | asset | credit | 4102.0000 | SEK | Return refund | 214c6ead-b835-4164-bdc9-01671edc1d15 | 2025-03-09 11:10:49.504052 Halden Boots | #1004 | VAT / sales tax payable | liability | debit | 820.4000 | SEK | Return refund | 214c6ead-b835-4164-bdc9-01671edc1d15 | 2025-03-09 11:10:49.504052 Halden Boots | #1004 | Refunds and returns | contra_revenue | debit | 3281.6000 | SEK | Return refund | 214c6ead-b835-4164-bdc9-01671edc1d15 | 2025-03-09 11:10:49.504052 Midland Safety Wear | SO-100307 | Shipping income | revenue | credit | 9.9500 | EUR | Order payment captured | 94034aa4-12b8-472f-ae12-4be498ec6786 | 2025-09-04 10:54:31.532927 Midland Safety Wear | SO-100307 | Payment gateway clearing | asset | debit | 7702.3700 | EUR | Order payment captured | 94034aa4-12b8-472f-ae12-4be498ec6786 | 2025-09-04 10:54:31.532927 Midland Safety Wear | SO-100307 | VAT / sales tax payable | liability | credit | 1335.0500 | EUR | Order payment captured | 94034aa4-12b8-472f-ae12-4be498ec6786 | 2025-09-04 10:54:31.532927 Midland Safety Wear | SO-100307 | Sales revenue | revenue | credit | 6357.3700 | EUR | Order payment captured | 94034aa4-12b8-472f-ae12-4be498ec6786 | 2025-09-04 10:54:31.532927 Midland Safety Wear | SO-100307 | Payment gateway clearing | asset | credit | 4122.4400 | EUR | Return refund | 35317b3b-1bca-4efb-a6ef-983f49e0b259 | 2025-09-29 14:14:56.463681 Midland Safety Wear | SO-100307 | VAT / sales tax payable | liability | debit | 677.2800 | EUR | Return refund | 35317b3b-1bca-4efb-a6ef-983f49e0b259 | 2025-09-29 14:14:56.463681 Midland Safety Wear | SO-100307 | Refunds and returns | contra_revenue | debit | 3445.1600 | EUR | Return refund | 35317b3b-1bca-4efb-a6ef-983f49e0b259 | 2025-09-29 14:14:56.463681 OfficeHub Nordic | SO-100363 | Payment gateway clearing | asset | debit | 265275.1500 | NOK | Order payment captured | ecd97210-c8ce-418b-bae1-3b6a08ccf862 | 2025-08-08 09:36:02.238519 OfficeHub Nordic | SO-100363 | VAT / sales tax payable | liability | credit | 53055.0300 | NOK | Order payment captured | ecd97210-c8ce-418b-bae1-3b6a08ccf862 | 2025-08-08 09:36:02.238519 OfficeHub Nordic | SO-100363 | Sales revenue | revenue | credit | 212220.1200 | NOK | Order payment captured | ecd97210-c8ce-418b-bae1-3b6a08ccf862 | 2025-08-08 09:36:02.238519 (53 rows, first 50 printed)
The memo and the queries that followed; links found by title, so inferred
Later queries that build on this report:
It builds on:
Changed only where the benchmark needs the same result on every system
with flagged_pairs (merchant_name, order_number) as ( values ('OfficeHub Nordic', 'SO-100363'), ('Fell & Fjell', '#1179'), ('Courtside Collective', 'CC-100015'), ('Ampfeld Elektronik', '#1727'), ('Ballycorran Industrial Supply', 'SO-100835'), ('Ballycorran Industrial Supply', 'SO-100608'), ('Midland Safety Wear', 'SO-100307'), ('Halden Boots', '#1004'), ('Castell Fasteners', 'SO-100233')),matched_orders as ( select o.id as order_id, o.order_number, o.order_number AS order_number, t.name as merchant_name from orders o join tenants t on t.id = o.tenant_id join flagged_pairs fp on fp.merchant_name = t.name and fp.order_number = o.order_number),matched_payments as ( select p.id as payment_id, mo.order_id, mo.order_number, mo.merchant_name mo.order_id AS order_id, mo.order_number AS order_number, mo.merchant_name AS merchant_name from payments p join matched_orders mo on mo.order_id = p.order_id),ledger_detail as ( select mp.merchant_name, mp.order_number, mp.merchant_name AS merchant_name, mp.order_number AS order_number, la.name as ledger_account_name, la.account_type, le.direction, le.amount, le.currency_code, le.description, le.entry_group, le.occurred_at la.account_type AS account_type, le.direction AS direction, le.amount AS amount, le.currency_code AS currency_code, le.description AS description, le.entry_group AS entry_group, le.occurred_at AS occurred_at from ledger_entries le join matched_payments mp on mp.payment_id = le.payment_id join ledger_accounts la on la.id = le.ledger_account_id)select merchant_name, order_number, ledger_account_name, account_type, direction, amount, currency_code, description, entry_group, occurred_atfrom ledger_detailorder by merchant_name, order_number, occurred_at, entry_grouporder by merchant_name NULLS LAST, order_number NULLS LAST, occurred_at NULLS LAST, entry_group NULLS LAST, ledger_account_name NULLS LAST, account_type NULLS LAST, direction NULLS LAST, amount NULLS LAST, currency_code NULLS LAST, description NULLS LAST
with flagged_pairs (merchant_name, order_number) as ( values ('OfficeHub Nordic', 'SO-100363'), ('Fell & Fjell', '#1179'), ('Courtside Collective', 'CC-100015'), ('Ampfeld Elektronik', '#1727'), ('Ballycorran Industrial Supply', 'SO-100835'), ('Ballycorran Industrial Supply', 'SO-100608'), ('Midland Safety Wear', 'SO-100307'), ('Halden Boots', '#1004'), ('Castell Fasteners', 'SO-100233') ), matched_orders as ( select o.id as order_id, o.order_number AS order_number, t.name as merchant_name from orders o join tenants t on t.id = o.tenant_id join flagged_pairs fp on fp.merchant_name = t.name and fp.order_number = o.order_number ), matched_payments as ( select p.id as payment_id, mo.order_id AS order_id, mo.order_number AS order_number, mo.merchant_name AS merchant_name from payments p join matched_orders mo on mo.order_id = p.order_id ), ledger_detail as ( select mp.merchant_name AS merchant_name, mp.order_number AS order_number, la.name as ledger_account_name, la.account_type AS account_type, le.direction AS direction, le.amount AS amount, le.currency_code AS currency_code, le.description AS description, le.entry_group AS entry_group, le.occurred_at AS occurred_at from ledger_entries le join matched_payments mp on mp.payment_id = le.payment_id join ledger_accounts la on la.id = le.ledger_account_id ) select merchant_name, order_number, ledger_account_name, account_type, direction, amount, currency_code, description, entry_group, occurred_at from ledger_detail order by merchant_name NULLS LAST, order_number NULLS LAST, occurred_at NULLS LAST, entry_group NULLS LAST, ledger_account_name NULLS LAST, account_type NULLS LAST, direction NULLS LAST, amount NULLS LAST, currency_code NULLS LAST, description NULLS LAST
The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted
Report request from Kofi Mensah (analyst for the Chief Financial Officer): Title: Ledger Line-Item Detail for Flagged Sample Payments, 2025 Question: What do the actual ledger entries look like for the refunded and anomalous payments flagged in the transaction walkthrough, and does the accounting treatment of refunds make sense? Grain: one ledger_entries row, for a fixed list of flagged payments Columns: - merchant_name - order_number - ledger_account_name - account_type - direction - amount - currency_code - description - entry_group - occurred_at Details: Source: ledger_entries joined to ledger_accounts (for name/account_type), joined to payments via ledger_entries.payment_id, joined to orders (for order_number) and tenants (for merchant_name). Restrict to the ledger entries for exactly these 9 (merchant, order_number) pairs from last night's walkthrough sample: (OfficeHub Nordic, SO-100363), (Fell & Fjell, #1179), (Courtside Collective, CC-100015), (Ampfeld Elektronik, #1727), (Ballycorran Industrial Supply, SO-100835), (Ballycorran Industrial Supply, SO-100608), (Midland Safety Wear, SO-100307), (Halden Boots, #1004), (Castell Fasteners, SO-100233) — match each pair to its order then its payment(s). Show every ledger_entries row tied to those payment_id(s), not aggregated. Order by merchant_name, order_number, occurred_at, entry_group. Check your query with the warehouse's dry_run tool, then hand it in with submit.
dry_runwith flagged_pairs (merchant_name, order_number) as ( values ('OfficeHub Nordic', 'SO-100363'), ('Fell & Fjell', '#1179'), ('Courtside Collective', 'CC-100015'), ('Ampfeld Elektronik', '#1727'), ('Ballycorran Industrial Supply', 'SO-100835'), ('Ballycorran Industrial Supply', 'SO-100608'), ('Midland Safety Wear', 'SO-100307'), ('Halden Boots', '#1004'), ('Castell Fasteners', 'SO-100233') ), matched_orders as ( select o.id as order_id, o.order_number, t.name as merchant_name from orders o join tenants t on t.id = o.tenant_id join flagged_pairs fp on fp.merchant_name = t.name and fp.order_number = o.order_number ), matched_payments as ( select p.id as payment_id, mo.order_id, mo.order_number, mo.merchant_name from payments p join matched_orders mo on mo.order_id = p.order_id ), ledger_detail as ( select mp.merchant_name, mp.order_number, la.name as ledger_account_name, la.account_type, le.direction, le.amount, le.currency_code, le.description, le.entry_group, le.occurred_at from ledger_entries le join matched_payments mp on mp.payment_id = le.payment_id join ledger_accounts la on la.id = le.ledger_account_id ) select merchant_name, order_number, ledger_account_name, account_type, direction, amount, currency_code, description, entry_group, occurred_at from ledger_detail order by merchant_name, order_number, occurred_at, entry_group
STATUS: COMPILES (dry run on the empty schema, no data read) COLUMNS: merchant_name, order_number, ledger_account_name, account_type, direction, amount, currency_code, description, entry_group, occurred_at
submitwith flagged_pairs (merchant_name, order_number) as ( values ('OfficeHub Nordic', 'SO-100363'), ('Fell & Fjell', '#1179'), ('Courtside Collective', 'CC-100015'), ('Ampfeld Elektronik', '#1727'), ('Ballycorran Industrial Supply', 'SO-100835'), ('Ballycorran Industrial Supply', 'SO-100608'), ('Midland Safety Wear', 'SO-100307'), ('Halden Boots', '#1004'), ('Castell Fasteners', 'SO-100233') ), matched_orders as ( select o.id as order_id, o.order_number, t.name as merchant_name from orders o join tenants t on t.id = o.tenant_id join flagged_pairs fp on fp.merchant_name = t.name and fp.order_number = o.order_number ), matched_payments as ( select p.id as payment_id, mo.order_id, mo.order_number, mo.merchant_name from payments p join matched_orders mo on mo.order_id = p.order_id ), ledger_detail as ( select mp.merchant_name, mp.order_number, la.name as ledger_account_name, la.account_type, le.direction, le.amount, le.currency_code, le.description, le.entry_group, le.occurred_at from ledger_entries le join matched_payments mp on mp.payment_id = le.payment_id join ledger_accounts la on la.id = le.ledger_account_id ) select merchant_name, order_number, ledger_account_name, account_type, direction, amount, currency_code, description, entry_group, occurred_at from ledger_detail order by merchant_name, order_number, occurred_at, entry_group
Submitted to tonight's batch. Your work on this request is done.