| Aggregate (cost=710.06..710.07 rows=1 width=32) |
| -> Hash Left Join (cost=597.47..702.76 rows=973 width=96) |
| Hash Cond: (t.id = settle.sales_contract_id) |
| Filter: (((sales.sales_contract_id IS NOT NULL) OR (settle.sales_contract_id IS NOT NULL)) AND ((((COALESCE(sales.amount, '0'::numeric) - COALESCE(return.amount, '0'::numeric)) - COALESCE(settle.amount, '0'::numeric)) >= '0'::numeric) OR ord.is_done)) |
| -> Hash Left Join (cost=380.55..481.29 rows=1725 width=73) |
| Hash Cond: (t.id = return.sales_contract_id) |
| -> Hash Left Join (cost=245.16..341.36 rows=1725 width=41) |
| Hash Cond: (t.id = sales.sales_contract_id) |
| -> Hash Right Join (cost=99.72..191.38 rows=1725 width=5) |
| Hash Cond: (ord.sales_contract_id = t.id) |
| -> Seq Scan on tbl_erp_sales_orders ord (cost=0.00..87.15 rows=1715 width=5) |
| -> Hash (cost=78.15..78.15 rows=1725 width=4) |
| -> Index Only Scan using tbl_sales_contracts_pkey on tbl_sales_contracts t (cost=0.28..78.15 rows=1725 width=4) |
| -> Hash (cost=144.09..144.09 rows=108 width=36) |
| -> Subquery Scan on sales (cost=141.66..144.09 rows=108 width=36) |
| -> HashAggregate (cost=141.66..143.01 rows=108 width=36) |
| Group Key: sc.id |
| -> Hash Right Join (cost=11.01..141.12 rows=108 width=10) |
| Hash Cond: (sc.from_project = t_1.project_id) |
| -> Seq Scan on tbl_sales_contracts sc (cost=0.00..118.25 rows=1725 width=8) |
| -> Hash (cost=9.66..9.66 rows=108 width=10) |
| -> Seq Scan on tbl_erp_sales_outbounds t_1 (cost=0.00..9.66 rows=108 width=10) |
| Filter: ((verify_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=135.38..135.38 rows=1 width=36) |
| -> Subquery Scan on return (cost=135.35..135.38 rows=1 width=36) |
| -> GroupAggregate (cost=135.35..135.37 rows=1 width=36) |
| Group Key: sc_1.id |
| -> Sort (cost=135.35..135.36 rows=1 width=36) |
| Sort Key: sc_1.id |
| -> Nested Loop (cost=0.54..135.34 rows=1 width=36) |
| Join Filter: (esrps.erp_sales_return_id = t_2.id) |
| -> Nested Loop Left Join (cost=0.54..134.31 rows=1 width=40) |
| -> Seq Scan on tbl_erp_sales_return_products esrps (cost=0.00..1.01 rows=1 width=40) |
| -> Nested Loop Left Join (cost=0.54..133.29 rows=1 width=8) |
| -> Index Scan using tbl_erp_sales_outbound_spent_products_pkey on tbl_erp_sales_outbound_spent_products esips (cost=0.27..8.29 rows=1 width=8) |
| Index Cond: (id = esrps.erp_sales_outbound_spent_product_id) |
| -> Hash Right Join (cost=0.26..124.99 rows=1 width=8) |
| Hash Cond: (sc_1.from_project = pi.project_id) |
| -> Seq Scan on tbl_sales_contracts sc_1 (cost=0.00..118.25 rows=1725 width=8) |
| -> Hash (cost=0.25..0.25 rows=1 width=8) |
| -> Index Scan using tbl_erp_sales_outbounds_pkey on tbl_erp_sales_outbounds pi (cost=0.14..0.25 rows=1 width=8) |
| Index Cond: (id = esips.erp_sales_outbound_id) |
| -> Seq Scan on tbl_erp_sales_returns t_2 (cost=0.00..1.02 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)) |
| -> Hash (cost=216.73..216.73 rows=15 width=36) |
| -> Subquery Scan on settle (cost=216.28..216.73 rows=15 width=36) |
| -> GroupAggregate (cost=216.28..216.58 rows=15 width=36) |
| Group Key: "*SELECT* 1".contract_id |
| -> Sort (cost=216.28..216.32 rows=15 width=13) |
| Sort Key: "*SELECT* 1".contract_id |
| -> Append (cost=106.56..215.99 rows=15 width=13) |
| -> Subquery Scan on "*SELECT* 1" (cost=106.56..148.18 rows=13 width=10) |
| -> Hash Join (cost=106.56..148.05 rows=13 width=106) |
| Hash Cond: (r.erp_collect_ticket_id = t_3.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=106.40..106.40 rows=13 width=4) |
| -> Seq Scan on tbl_erp_collect_tickets t_3 (cost=0.00..106.40 rows=13 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)) |
| -> Subquery Scan on "*SELECT* 2" (cost=0.29..9.47 rows=1 width=36) |
| -> Nested Loop (cost=0.29..9.46 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_4 (cost=0.29..8.31 rows=1 width=4) |
| Index Cond: (id = r_1.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* 3" (cost=0.28..58.33 rows=1 width=36) |
| -> Nested Loop (cost=0.28..58.32 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_5 (cost=0.28..8.30 rows=1 width=4) |
| Index Cond: (id = r_2.erp_payment_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)) |