| Aggregate (cost=445.61..445.62 rows=1 width=32) |
| -> Hash Left Join (cost=318.09..445.46 rows=31 width=42) |
| Hash Cond: (t.id = sub.contract_id) |
| Filter: (CASE WHEN (cancel.sales_contract_id IS NULL) THEN t.amount ELSE '0'::numeric END < COALESCE(sub.amount, '0'::numeric)) |
| -> Hash Left Join (cost=100.06..227.18 rows=94 width=14) |
| Hash Cond: (t.id = cancel.sales_contract_id) |
| -> Seq Scan on tbl_sales_contracts t (cost=0.00..126.88 rows=94 width=10) |
| Filter: (build_by_project AND (id IS NOT NULL) AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (created_at <= '2025-12-31 23:59:59+08'::timestamp with time zone)) |
| -> Hash (cost=100.05..100.05 rows=1 width=4) |
| -> Subquery Scan on cancel (cost=100.02..100.05 rows=1 width=4) |
| -> GroupAggregate (cost=100.02..100.04 rows=1 width=12) |
| Group Key: t_1.sales_contract_id |
| -> Sort (cost=100.02..100.03 rows=1 width=4) |
| Sort Key: t_1.sales_contract_id |
| -> Seq Scan on tbl_erp_sales_orders t_1 (cost=0.00..100.01 rows=1 width=4) |
| Filter: ((cancel_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (cancel_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 8)) |
| -> Hash (cost=216.31..216.31 rows=137 width=36) |
| -> Subquery Scan on sub (cost=213.23..216.31 rows=137 width=36) |
| -> HashAggregate (cost=213.23..214.94 rows=137 width=36) |
| Group Key: "*SELECT* 1".contract_id |
| -> Append (cost=102.63..212.55 rows=137 width=10) |
| -> Subquery Scan on "*SELECT* 1" (cost=102.63..145.48 rows=135 width=10) |
| -> Hash Join (cost=102.63..144.13 rows=135 width=106) |
| Hash Cond: (r.erp_collect_ticket_id = t_2.id) |
| -> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..35.83 rows=2154 width=14) |
| Filter: (sales_contract_id IS NOT NULL) |
| -> Hash (cost=100.91..100.91 rows=138 width=4) |
| -> Seq Scan on tbl_erp_collect_tickets t_2 (cost=0.00..100.91 rows=138 width=4) |
| Filter: ((bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 2" (cost=0.29..9.35 rows=1 width=36) |
| -> Nested Loop (cost=0.29..9.34 rows=1 width=132) |
| -> Seq Scan on tbl_erp_cash_cost_ticket_sales_contract_settles r_1 (cost=0.00..1.01 rows=1 width=40) |
| Filter: (sales_contract_id IS NOT NULL) |
| -> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets t_3 (cost=0.29..8.31 rows=1 width=4) |
| Index Cond: (id = r_1.erp_cash_cost_ticket_id) |
| Filter: (is_payment_settle AND (bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 3" (cost=0.28..57.72 rows=1 width=36) |
| -> Nested Loop (cost=0.28..57.71 rows=1 width=132) |
| -> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..41.01 rows=2 width=14) |
| Filter: (sales_contract_id IS NOT NULL) |
| -> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets t_4 (cost=0.28..8.30 rows=1 width=4) |
| Index Cond: (id = r_2.erp_payment_ticket_id) |
| Filter: (is_payment_settle AND (bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |