| Limit (cost=4292.71..4292.74 rows=10 width=278) |
| -> Sort (cost=4292.71..4297.75 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=3997.88..4249.21 rows=2013 width=278) |
| Hash Cond: (c.client_class = cc.id) |
| -> Hash Left Join (cost=3996.79..4148.88 rows=2013 width=202) |
| Hash Cond: (c.id = wl.client_id) |
| -> Hash Left Join (cost=2052.44..2199.24 rows=2013 width=194) |
| Hash Cond: (c.sales_rep = sr.id) |
| -> Hash Left Join (cost=2034.20..2175.64 rows=2013 width=189) |
| Hash Cond: (c.id = prev.client_id) |
| -> Hash Join (cost=1107.26..1243.40 rows=2013 width=125) |
| Hash Cond: (c_1.id = c.id) |
| -> HashAggregate (cost=971.96..1082.68 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=759.35..906.54 rows=2013 width=260) |
| Hash Cond: (c_1.id = esgs.client_id) |
| -> Hash Left Join (cost=731.15..873.05 rows=2013 width=228) |
| Hash Cond: (c_1.id = eccrt.client_id) |
| -> Hash Left Join (cost=729.94..866.54 rows=2013 width=196) |
| Hash Cond: (c_1.id = ecct.client_id) |
| -> Hash Left Join (cost=224.56..355.87 rows=2013 width=164) |
| Hash Cond: (c_1.id = ect2.client_id) |
| -> Hash Left Join (cost=37.73..163.74 rows=2013 width=132) |
| Hash Cond: (c_1.id = ect.client_id) |
| -> Hash Left Join (cost=33.23..153.95 rows=2013 width=100) |
| Hash Cond: (c_1.id = eoi.client_id) |
| -> Hash Left Join (cost=30.47..145.90 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=29.61..29.61 rows=69 width=68) |
| -> Subquery Scan on o (cost=27.89..29.61 rows=69 width=68) |
| -> HashAggregate (cost=27.89..28.92 rows=69 width=68) |
| Group Key: t.client_id |
| -> Hash Right Join (cost=11.00..24.98 rows=388 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=107 width=8) |
| -> Seq Scan on tbl_erp_sales_outbounds t (cost=0.00..9.66 rows=107 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-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=2.75..2.75 rows=1 width=36) |
| -> Subquery Scan on eoi (cost=2.71..2.75 rows=1 width=36) |
| -> GroupAggregate (cost=2.71..2.74 rows=1 width=36) |
| Group Key: t_1.client_id |
| -> Sort (cost=2.71..2.71 rows=2 width=10) |
| Sort Key: t_1.client_id |
| -> Seq Scan on tbl_erp_other_income_tickets t_1 (cost=0.00..2.70 rows=2 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-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=2 width=9) |
| Sort Key: t_2.client_id |
| -> Seq Scan on tbl_erp_cost_tickets t_2 (cost=0.00..4.44 rows=2 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-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=186.29..186.29 rows=43 width=36) |
| -> Subquery Scan on ect2 (cost=185.00..186.29 rows=43 width=36) |
| -> GroupAggregate (cost=185.00..185.86 rows=43 width=36) |
| Group Key: con.client_id |
| -> Sort (cost=185.00..185.11 rows=43 width=9) |
| Sort Key: con.client_id |
| -> Hash Join (cost=5.19..183.84 rows=43 width=9) |
| Hash Cond: (con.id = t_3.contact_id) |
| -> Seq Scan on tbl_contacts con (cost=0.00..139.84 rows=3416 width=8) |
| Filter: (client_id IS NOT NULL) |
| -> Hash (cost=4.44..4.44 rows=60 width=9) |
| -> Seq Scan on tbl_erp_cost_tickets t_3 (cost=0.00..4.44 rows=60 width=9) |
| Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2)) |
| -> Hash (cost=500.53..500.53 rows=388 width=36) |
| -> Subquery Scan on ecct (cost=491.80..500.53 rows=388 width=36) |
| -> HashAggregate (cost=491.80..496.65 rows=388 width=36) |
| Group Key: t_4.client_id |
| -> Seq Scan on tbl_erp_cash_cost_tickets t_4 (cost=0.00..487.21 rows=918 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-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 >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-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=901.78..901.78 rows=2013 width=68) |
| -> Subquery Scan on prev (cost=781.00..901.78 rows=2013 width=68) |
| -> HashAggregate (cost=781.00..881.65 rows=2013 width=68) |
| Group Key: c_2.id |
| -> Hash Left Join (cost=578.45..725.64 rows=2013 width=260) |
| Hash Cond: (c_2.id = esgs_1.client_id) |
| -> Hash Left Join (cost=550.25..692.15 rows=2013 width=228) |
| Hash Cond: (c_2.id = eccrt_1.client_id) |
| -> Hash Left Join (cost=549.04..685.64 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 >= '2024-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2024-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_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 >= '2024-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2024-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_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 >= '2024-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2024-12-31 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 >= '2024-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2024-12-31 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=500.40..500.40 rows=386 width=36) |
| -> Subquery Scan on ecct_1 (cost=491.72..500.40 rows=386 width=36) |
| -> HashAggregate (cost=491.72..496.54 rows=386 width=36) |
| Group Key: t_11.client_id |
| -> Seq Scan on tbl_erp_cash_cost_tickets t_11 (cost=0.00..487.21 rows=902 width=9) |
| Filter: ((client_id IS NOT NULL) AND (created_at >= '2024-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2024-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_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 >= '2024-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2024-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_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) |