| Aggregate (cost=894.54..894.55 rows=1 width=32) |
| -> Hash Left Join (cost=758.62..894.26 rows=56 width=42) |
| Hash Cond: (t.id = sub.contract_id) |
| Filter: (CASE WHEN (cancel.purchase_contract_id IS NULL) THEN t.amount ELSE '0'::numeric END < COALESCE(sub.amount, '0'::numeric)) |
| -> Hash Left Join (cost=115.80..250.99 rows=167 width=14) |
| Hash Cond: (t.id = cancel.purchase_contract_id) |
| -> Seq Scan on tbl_purchase_contracts t (cost=0.00..134.76 rows=167 width=10) |
| Filter: ((NOT is_draft) AND (NOT is_refuse) 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) AND (cost_type = 1)) |
| -> Hash (cost=115.78..115.78 rows=1 width=4) |
| -> Subquery Scan on cancel (cost=115.76..115.78 rows=1 width=4) |
| -> GroupAggregate (cost=115.76..115.77 rows=1 width=12) |
| Group Key: t_1.purchase_contract_id |
| -> Sort (cost=115.76..115.76 rows=1 width=4) |
| Sort Key: t_1.purchase_contract_id |
| -> Seq Scan on tbl_erp_purchase_orders t_1 (cost=0.00..115.75 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=640.32..640.32 rows=200 width=36) |
| -> Subquery Scan on sub (cost=635.82..640.32 rows=200 width=36) |
| -> HashAggregate (cost=635.82..638.32 rows=200 width=36) |
| Group Key: "*SELECT* 1".contract_id |
| -> Append (cost=111.47..634.16 rows=333 width=21) |
| -> Subquery Scan on "*SELECT* 1" (cost=111.47..160.92 rows=187 width=10) |
| -> Hash Join (cost=111.47..159.05 rows=187 width=106) |
| Hash Cond: (r.erp_payment_ticket_id = t_2.id) |
| -> Seq Scan on tbl_erp_payment_ticket_settles r (cost=0.00..41.01 rows=2501 width=14) |
| -> Hash (cost=109.27..109.27 rows=176 width=4) |
| -> Seq Scan on tbl_erp_payment_tickets t_2 (cost=0.00..109.27 rows=176 width=4) |
| 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* 2" (cost=1.18..3.97 rows=5 width=36) |
| -> Hash Join (cost=1.18..3.92 rows=5 width=132) |
| Hash Cond: (t_3.id = r_1.erp_other_income_ticket_id) |
| -> Seq Scan on tbl_erp_other_income_tickets t_3 (cost=0.00..2.60 rows=25 width=4) |
| Filter: ((bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=1.08..1.08 rows=8 width=40) |
| -> Seq Scan on tbl_erp_other_income_ticket_purchase_contract_settles r_1 (cost=0.00..1.08 rows=8 width=40) |
| -> Subquery Scan on "*SELECT* 3" (cost=0.29..323.34 rows=4 width=36) |
| -> Nested Loop (cost=0.29..323.30 rows=4 width=132) |
| -> Seq Scan on tbl_erp_cash_cost_ticket_purchase_contract_settles r_2 (cost=0.00..1.45 rows=45 width=40) |
| -> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets t_4 (cost=0.29..7.15 rows=1 width=4) |
| Index Cond: (id = r_2.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* 4" (cost=102.63..145.92 rows=137 width=36) |
| -> Hash Join (cost=102.63..144.55 rows=137 width=132) |
| Hash Cond: (r_3.erp_collect_ticket_id = t_5.id) |
| -> Seq Scan on tbl_erp_collect_ticket_settles r_3 (cost=0.00..35.83 rows=2183 width=14) |
| -> Hash (cost=100.91..100.91 rows=138 width=4) |
| -> Seq Scan on tbl_erp_collect_tickets t_5 (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)) |