| Aggregate (cost=730.74..730.75 rows=1 width=32) |
| -> Hash Left Join (cost=629.61..715.22 rows=2068 width=96) |
| Hash Cond: (t.id = settle.purchase_contract_id) |
| Filter: (((purchase.purchase_contract_id IS NOT NULL) OR (settle.purchase_contract_id IS NOT NULL)) AND ((((COALESCE(purchase.amount, '0'::numeric) - COALESCE(return.amount, '0'::numeric)) - COALESCE(settle.amount, '0'::numeric)) >= '0'::numeric) OR ord.is_done)) |
| -> Hash Left Join (cost=126.52..206.28 rows=2224 width=73) |
| Hash Cond: (t.id = return.purchase_contract_id) |
| -> Hash Left Join (cost=118.40..192.31 rows=2224 width=41) |
| Hash Cond: (t.id = purchase.purchase_contract_id) |
| -> Hash Right Join (cost=104.25..172.31 rows=2224 width=5) |
| Hash Cond: (ord.purchase_contract_id = t.id) |
| -> Seq Scan on tbl_erp_purchase_orders ord (cost=0.00..62.22 rows=2222 width=5) |
| -> Hash (cost=76.45..76.45 rows=2224 width=4) |
| -> Seq Scan on tbl_purchase_contracts t (cost=0.00..76.45 rows=2224 width=4) |
| Filter: (cost_type = 1) |
| -> Hash (cost=12.46..12.46 rows=135 width=36) |
| -> Subquery Scan on purchase (cost=9.42..12.46 rows=135 width=36) |
| -> HashAggregate (cost=9.42..11.11 rows=135 width=36) |
| Group Key: t_1.purchase_contract_id |
| -> Seq Scan on tbl_erp_purchase_inbounds t_1 (cost=0.00..8.73 rows=139 width=10) |
| Filter: ((created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (verify_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=8.11..8.11 rows=1 width=36) |
| -> Subquery Scan on return (cost=8.08..8.11 rows=1 width=36) |
| -> GroupAggregate (cost=8.08..8.10 rows=1 width=36) |
| Group Key: pi.purchase_contract_id |
| -> Sort (cost=8.08..8.08 rows=1 width=9) |
| Sort Key: pi.purchase_contract_id |
| -> Nested Loop Left Join (cost=1.53..8.07 rows=1 width=9) |
| -> Hash Join (cost=1.12..2.20 rows=1 width=9) |
| Hash Cond: (esrps.erp_purchase_return_id = t_2.id) |
| -> Seq Scan on tbl_erp_purchase_return_products esrps (cost=0.00..1.06 rows=6 width=13) |
| -> Hash (cost=1.10..1.10 rows=1 width=4) |
| -> Seq Scan on tbl_erp_purchase_returns t_2 (cost=0.00..1.10 rows=1 width=4) |
| Filter: ((created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (verify_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Nested Loop Left Join (cost=0.42..5.85 rows=1 width=8) |
| -> Index Scan using tbl_erp_purchase_inbound_products_pkey on tbl_erp_purchase_inbound_products esips (cost=0.27..5.62 rows=1 width=8) |
| Index Cond: (id = esrps.erp_purchase_inbound_product_id) |
| -> Index Scan using tbl_erp_purchase_inbounds_pkey on tbl_erp_purchase_inbounds pi (cost=0.14..0.23 rows=1 width=8) |
| Index Cond: (id = esips.erp_purchase_inbound_id) |
| -> Hash (cost=502.79..502.79 rows=24 width=36) |
| -> Subquery Scan on settle (cost=502.07..502.79 rows=24 width=36) |
| -> GroupAggregate (cost=502.07..502.55 rows=24 width=36) |
| Group Key: "*SELECT* 1".contract_id |
| -> Sort (cost=502.07..502.13 rows=24 width=11) |
| Sort Key: "*SELECT* 1".contract_id |
| -> Append (cost=80.47..501.52 rows=24 width=11) |
| -> Subquery Scan on "*SELECT* 1" (cost=80.47..126.37 rows=21 width=10) |
| -> Hash Join (cost=80.47..126.16 rows=21 width=106) |
| Hash Cond: (r.erp_payment_ticket_id = t_3.id) |
| -> Seq Scan on tbl_erp_payment_ticket_settles r (cost=0.00..39.65 rows=2295 width=14) |
| Filter: (purchase_contract_id IS NOT NULL) |
| -> Hash (cost=80.20..80.20 rows=22 width=4) |
| -> Seq Scan on tbl_erp_payment_tickets t_3 (cost=0.00..80.20 rows=22 width=4) |
| Filter: (is_payment_settle AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) 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.14..2.98 rows=1 width=10) |
| -> Hash Join (cost=1.14..2.97 rows=1 width=106) |
| Hash Cond: (t_4.id = r_1.erp_other_income_ticket_id) |
| -> Seq Scan on tbl_erp_other_income_tickets t_4 (cost=0.00..1.70 rows=25 width=4) |
| Filter: ((created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=1.11..1.11 rows=2 width=14) |
| -> Seq Scan on tbl_erp_other_income_ticket_purchase_contract_settles r_1 (cost=0.00..1.11 rows=2 width=14) |
| Filter: (purchase_contract_id IS NOT NULL) |
| -> Subquery Scan on "*SELECT* 3" (cost=0.29..310.07 rows=1 width=9) |
| -> Nested Loop (cost=0.29..310.06 rows=1 width=105) |
| -> Seq Scan on tbl_erp_cash_cost_ticket_purchase_contract_settles r_2 (cost=0.00..1.53 rows=53 width=13) |
| Filter: (purchase_contract_id IS NOT NULL) |
| -> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets t_5 (cost=0.29..5.82 rows=1 width=4) |
| Index Cond: (id = r_2.erp_cash_cost_ticket_id) |
| Filter: (is_payment_settle AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Subquery Scan on "*SELECT* 4" (cost=0.28..62.10 rows=1 width=36) |
| -> Nested Loop (cost=0.28..62.09 rows=1 width=132) |
| -> Seq Scan on tbl_erp_collect_ticket_settles r_3 (cost=0.00..35.94 rows=3 width=14) |
| Filter: (purchase_contract_id IS NOT NULL) |
| -> Index Scan using tbl_erp_collect_tickets_pkey on tbl_erp_collect_tickets t_6 (cost=0.28..8.30 rows=1 width=4) |
| Index Cond: (id = r_3.erp_collect_ticket_id) |
| Filter: ((created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |