| Limit (cost=4182.17..4182.20 rows=10 width=278) |
| -> Sort (cost=4182.17..4187.21 rows=2013 width=278) |
| Sort Key: (COALESCE(((COALESCE(sum(o.outbound_amount), '0'::numeric) + COALESCE(sum(eoi.amount), '0'::numeric))), '0'::numeric)) DESC NULLS LAST |
| -> Hash Left Join (cost=3887.34..4138.67 rows=2013 width=278) |
| Hash Cond: (c.client_class = cc.id) |
| -> Hash Left Join (cost=3886.25..4038.34 rows=2013 width=202) |
| Hash Cond: (c.id = wl.client_id) |
| -> Hash Left Join (cost=1941.90..2088.70 rows=2013 width=194) |
| Hash Cond: (c.sales_rep = sr.id) |
| -> Hash Left Join (cost=1923.66..2065.10 rows=2013 width=189) |
| Hash Cond: (c.id = prev.client_id) |
| -> Hash Join (cost=1005.53..1141.67 rows=2013 width=125) |
| Hash Cond: (c_1.id = c.id) |
| -> HashAggregate (cost=870.23..980.95 rows=2013 width=68) |
| Group Key: c_1.id |
| Filter: ((COALESCE(sum(o.outbound_amount), '0'::numeric) + COALESCE(sum(eoi.amount), '0'::numeric)) > '0'::numeric) |
| -> Hash Left Join (cost=657.62..804.81 rows=2013 width=260) |
| Hash Cond: (c_1.id = esgs.client_id) |
| -> Hash Left Join (cost=629.42..771.32 rows=2013 width=228) |
| Hash Cond: (c_1.id = eccrt.client_id) |
| -> Hash Left Join (cost=628.21..764.81 rows=2013 width=196) |
| Hash Cond: (c_1.id = ecct.client_id) |
| -> Hash Left Join (cost=134.37..265.68 rows=2013 width=164) |
| Hash Cond: (c_1.id = ect2.client_id) |
| -> Hash Left Join (cost=33.51..159.52 rows=2013 width=132) |
| Hash Cond: (c_1.id = ect.client_id) |
| -> Hash Left Join (cost=29.02..149.74 rows=2013 width=100) |
| Hash Cond: (c_1.id = eoi.client_id) |
| -> Hash Left Join (cost=26.26..141.69 rows=2013 width=68) |
| Hash Cond: (c_1.id = o.client_id) |
| -> Seq Scan on tbl_clients c_1 (cost=0.00..110.13 rows=2013 width=4) |
| Filter: (NOT deleted) |
| -> Hash (cost=25.86..25.86 rows=32 width=68) |
| -> Subquery Scan on o (cost=25.06..25.86 rows=32 width=68) |
| -> HashAggregate (cost=25.06..25.54 rows=32 width=68) |
| Group Key: t.client_id |
| -> Hash Right Join (cost=10.11..24.09 rows=130 width=13) |
| Hash Cond: (eipss.erp_sales_outbound_id = t.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss (cost=0.00..12.51 rows=551 width=13) |
| -> Hash (cost=9.66..9.66 rows=36 width=8) |
| -> Seq Scan on tbl_erp_sales_outbounds t (cost=0.00..9.66 rows=36 width=8) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=2.74..2.74 rows=1 width=36) |
| -> Subquery Scan on eoi (cost=2.71..2.74 rows=1 width=36) |
| -> GroupAggregate (cost=2.71..2.73 rows=1 width=36) |
| Group Key: t_1.client_id |
| -> Sort (cost=2.71..2.71 rows=1 width=10) |
| Sort Key: t_1.client_id |
| -> Seq Scan on tbl_erp_other_income_tickets t_1 (cost=0.00..2.70 rows=1 width=10) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=4.48..4.48 rows=1 width=36) |
| -> Subquery Scan on ect (cost=4.45..4.48 rows=1 width=36) |
| -> GroupAggregate (cost=4.45..4.47 rows=1 width=36) |
| Group Key: t_2.client_id |
| -> Sort (cost=4.45..4.45 rows=1 width=9) |
| Sort Key: t_2.client_id |
| -> Seq Scan on tbl_erp_cost_tickets t_2 (cost=0.00..4.44 rows=1 width=9) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=100.75..100.75 rows=9 width=36) |
| -> Subquery Scan on ect2 (cost=100.48..100.75 rows=9 width=36) |
| -> GroupAggregate (cost=100.48..100.66 rows=9 width=36) |
| Group Key: con.client_id |
| -> Sort (cost=100.48..100.50 rows=9 width=9) |
| Sort Key: con.client_id |
| -> Nested Loop (cost=0.28..100.34 rows=9 width=9) |
| -> Seq Scan on tbl_erp_cost_tickets t_3 (cost=0.00..4.44 rows=13 width=9) |
| Filter: ((created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Index Scan using tbl_contacts_pkey on tbl_contacts con (cost=0.28..7.38 rows=1 width=8) |
| Index Cond: (id = t_3.contact_id) |
| Filter: (client_id IS NOT NULL) |
| -> Hash (cost=491.82..491.82 rows=161 width=36) |
| -> Subquery Scan on ecct (cost=488.20..491.82 rows=161 width=36) |
| -> HashAggregate (cost=488.20..490.21 rows=161 width=36) |
| Group Key: t_4.client_id |
| -> Seq Scan on tbl_erp_cash_cost_tickets t_4 (cost=0.00..487.21 rows=198 width=9) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=1.20..1.20 rows=1 width=36) |
| -> Subquery Scan on eccrt (cost=1.18..1.20 rows=1 width=36) |
| -> HashAggregate (cost=1.18..1.19 rows=1 width=36) |
| Group Key: t_5.client_id |
| -> Seq Scan on tbl_erp_cost_convert_tickets t_5 (cost=0.00..1.18 rows=1 width=36) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2026-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=27.63..27.63 rows=45 width=36) |
| -> Subquery Scan on esgs (cost=26.62..27.63 rows=45 width=36) |
| -> HashAggregate (cost=26.62..27.18 rows=45 width=36) |
| Group Key: t_6.client_id |
| -> Hash Right Join (cost=8.93..22.89 rows=497 width=13) |
| Hash Cond: (eipss_1.erp_sales_gift_id = t_6.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss_1 (cost=0.00..12.51 rows=551 width=13) |
| -> Hash (cost=7.54..7.54 rows=111 width=8) |
| -> Seq Scan on tbl_erp_sales_gifts t_6 (cost=0.00..7.54 rows=111 width=8) |
| Filter: ((client_id IS NOT NULL) AND (status = 2)) |
| -> Hash (cost=110.13..110.13 rows=2013 width=61) |
| -> Seq Scan on tbl_clients c (cost=0.00..110.13 rows=2013 width=61) |
| Filter: (NOT deleted) |
| -> Hash (cost=892.97..892.97 rows=2013 width=68) |
| -> Subquery Scan on prev (cost=772.19..892.97 rows=2013 width=68) |
| -> HashAggregate (cost=772.19..872.84 rows=2013 width=68) |
| Group Key: c_2.id |
| -> Hash Left Join (cost=569.64..716.83 rows=2013 width=260) |
| Hash Cond: (c_2.id = esgs_1.client_id) |
| -> Hash Left Join (cost=541.44..683.34 rows=2013 width=228) |
| Hash Cond: (c_2.id = eccrt_1.client_id) |
| -> Hash Left Join (cost=540.23..676.83 rows=2013 width=196) |
| Hash Cond: (c_2.id = ecct_1.client_id) |
| -> Hash Left Join (cost=43.81..175.12 rows=2013 width=164) |
| Hash Cond: (c_2.id = ect2_1.client_id) |
| -> Hash Left Join (cost=31.01..157.03 rows=2013 width=132) |
| Hash Cond: (c_2.id = ect_1.client_id) |
| -> Hash Left Join (cost=26.52..147.24 rows=2013 width=100) |
| Hash Cond: (c_2.id = eoi_1.client_id) |
| -> Hash Left Join (cost=23.77..139.19 rows=2013 width=68) |
| Hash Cond: (c_2.id = o_1.client_id) |
| -> Seq Scan on tbl_clients c_2 (cost=0.00..110.13 rows=2013 width=4) |
| Filter: (NOT deleted) |
| -> Hash (cost=23.76..23.76 rows=1 width=68) |
| -> Subquery Scan on o_1 (cost=23.69..23.76 rows=1 width=68) |
| -> GroupAggregate (cost=23.69..23.75 rows=1 width=68) |
| Group Key: t_7.client_id |
| -> Sort (cost=23.69..23.70 rows=4 width=13) |
| Sort Key: t_7.client_id |
| -> Hash Right Join (cost=9.67..23.65 rows=4 width=13) |
| Hash Cond: (eipss_2.erp_sales_outbound_id = t_7.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss_2 (cost=0.00..12.51 rows=551 width=13) |
| -> Hash (cost=9.66..9.66 rows=1 width=8) |
| -> Seq Scan on tbl_erp_sales_outbounds t_7 (cost=0.00..9.66 rows=1 width=8) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-05-29 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=2.74..2.74 rows=1 width=36) |
| -> Subquery Scan on eoi_1 (cost=2.71..2.74 rows=1 width=36) |
| -> GroupAggregate (cost=2.71..2.73 rows=1 width=36) |
| Group Key: t_8.client_id |
| -> Sort (cost=2.71..2.71 rows=1 width=10) |
| Sort Key: t_8.client_id |
| -> Seq Scan on tbl_erp_other_income_tickets t_8 (cost=0.00..2.70 rows=1 width=10) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-05-29 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=4.48..4.48 rows=1 width=36) |
| -> Subquery Scan on ect_1 (cost=4.45..4.48 rows=1 width=36) |
| -> GroupAggregate (cost=4.45..4.47 rows=1 width=36) |
| Group Key: t_9.client_id |
| -> Sort (cost=4.45..4.45 rows=1 width=9) |
| Sort Key: t_9.client_id |
| -> Seq Scan on tbl_erp_cost_tickets t_9 (cost=0.00..4.44 rows=1 width=9) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-05-29 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=12.78..12.78 rows=1 width=36) |
| -> Subquery Scan on ect2_1 (cost=12.75..12.78 rows=1 width=36) |
| -> GroupAggregate (cost=12.75..12.77 rows=1 width=36) |
| Group Key: con_1.client_id |
| -> Sort (cost=12.75..12.75 rows=1 width=9) |
| Sort Key: con_1.client_id |
| -> Nested Loop (cost=0.28..12.74 rows=1 width=9) |
| -> Seq Scan on tbl_erp_cost_tickets t_10 (cost=0.00..4.44 rows=1 width=9) |
| Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-05-29 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Index Scan using tbl_contacts_pkey on tbl_contacts con_1 (cost=0.28..8.30 rows=1 width=8) |
| Index Cond: (id = t_10.contact_id) |
| Filter: (client_id IS NOT NULL) |
| -> Hash (cost=493.67..493.67 rows=220 width=36) |
| -> Subquery Scan on ecct_1 (cost=488.72..493.67 rows=220 width=36) |
| -> HashAggregate (cost=488.72..491.47 rows=220 width=36) |
| Group Key: t_11.client_id |
| -> Seq Scan on tbl_erp_cash_cost_tickets t_11 (cost=0.00..487.21 rows=302 width=9) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-05-29 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=1.20..1.20 rows=1 width=36) |
| -> Subquery Scan on eccrt_1 (cost=1.18..1.20 rows=1 width=36) |
| -> HashAggregate (cost=1.18..1.19 rows=1 width=36) |
| Group Key: t_12.client_id |
| -> Seq Scan on tbl_erp_cost_convert_tickets t_12 (cost=0.00..1.18 rows=1 width=36) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-05-29 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=27.63..27.63 rows=45 width=36) |
| -> Subquery Scan on esgs_1 (cost=26.62..27.63 rows=45 width=36) |
| -> HashAggregate (cost=26.62..27.18 rows=45 width=36) |
| Group Key: t_13.client_id |
| -> Hash Right Join (cost=8.93..22.89 rows=497 width=13) |
| Hash Cond: (eipss_3.erp_sales_gift_id = t_13.id) |
| -> Seq Scan on tbl_erp_inventory_product_spents eipss_3 (cost=0.00..12.51 rows=551 width=13) |
| -> Hash (cost=7.54..7.54 rows=111 width=8) |
| -> Seq Scan on tbl_erp_sales_gifts t_13 (cost=0.00..7.54 rows=111 width=8) |
| Filter: ((client_id IS NOT NULL) AND (status = 2)) |
| -> Hash (cost=16.44..16.44 rows=144 width=13) |
| -> Seq Scan on tbl_users sr (cost=0.00..16.44 rows=144 width=13) |
| -> Hash (cost=1928.88..1928.88 rows=1238 width=12) |
| -> Subquery Scan on wl (cost=1891.74..1928.88 rows=1238 width=12) |
| -> HashAggregate (cost=1891.74..1916.50 rows=1238 width=12) |
| Group Key: tbl_work_logs.client_id |
| -> Seq Scan on tbl_work_logs (cost=0.00..1713.31 rows=35685 width=12) |
| Filter: (NOT is_draft) |
| -> Hash (cost=1.04..1.04 rows=4 width=6) |
| -> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=6) |