| Aggregate (cost=467.67..467.68 rows=1 width=8) |
| -> Sort (cost=467.58..467.60 rows=6 width=1306) |
| Sort Key: sc.signed_at DESC, sc.created_at DESC |
| -> Group (cost=467.33..467.51 rows=6 width=1306) |
| Group Key: sc.id, t0_1.erp_settle_amount, (CASE WHEN t0.including_tax THEN COALESCE(sum(t1.amount), '0'::numeric) ELSE t0.amount END), (sum(scpcrd.amount)), (sum(COALESCE(scpcrd.paid_amount, '0'::numeric))), (max(scpcrd.remind_date)), (CASE WHEN ((sc.amount - t0_1.erp_settle_amount) > '0'::numeric) THEN CASE WHEN (((sum(scpcrd.amount)) - (sum(COALESCE(scpcrd.paid_amount, '0'::numeric)))) > '0'::numeric) THEN (max(scpcrd.remind_date)) ELSE mind.min_date END ELSE NULL::date END) |
| -> Sort (cost=467.33..467.34 rows=6 width=126) |
| Sort Key: sc.id, t0_1.erp_settle_amount, (CASE WHEN t0.including_tax THEN COALESCE(sum(t1.amount), '0'::numeric) ELSE t0.amount END), (sum(scpcrd.amount)), (sum(COALESCE(scpcrd.paid_amount, '0'::numeric))), (max(scpcrd.remind_date)), (CASE WHEN ((sc.amount - t0_1.erp_settle_amount) > '0'::numeric) THEN CASE WHEN (((sum(scpcrd.amount)) - (sum(COALESCE(scpcrd.paid_amount, '0'::numeric)))) > '0'::numeric) THEN (max(scpcrd.remind_date)) ELSE mind.min_date END ELSE NULL::date END) |
| -> Hash Left Join (cost=413.88..467.25 rows=6 width=126) |
| Hash Cond: (sc.id = mind.id) |
| -> Hash Left Join (cost=383.78..437.08 rows=6 width=132) |
| Hash Cond: (c.sales_rep = sgr.sales_id) |
| -> Nested Loop (cost=381.64..434.88 rows=6 width=136) |
| -> Index Scan using tbl_clients_pkey on tbl_clients c (cost=0.28..8.38 rows=1 width=8) |
| Index Cond: (id = 982) |
| Filter: ((sales_rep = ANY ('{1001,5049,5500,5301,5499,5022,5209,5026,5293,5309,5356,5329,5299,5303,5302,5332,5047,1026,5096,5070,5448,5420,1029,5037,5087,1008,5048,5043,5045,5230,5031,5088,5208,1003,5467,5294,5357,5044,1030,5076,5300,5027,5089,5311,5066,5069,5364,1009,5295,1013,5128,5203,1025,5032,5075,5476,1004,5072,5033,5359,5412,5409,5229,1005,5304,5449,5358,1006,5093}'::integer[])) OR (sales_rep IS NULL)) |
| -> Hash Right Join (cost=381.36..426.44 rows=6 width=136) |
| Hash Cond: (t0.id = sc.id) |
| -> HashAggregate (cost=149.84..171.27 rows=1715 width=36) |
| Group Key: t0.id |
| -> Hash Right Join (cost=89.76..139.68 rows=2032 width=17) |
| Hash Cond: (t1.contract_id = t0.id) |
| -> Seq Scan on tbl_sales_contract_invoices t1 (cost=0.00..44.52 rows=2052 width=10) |
| -> Hash (cost=68.32..68.32 rows=1715 width=11) |
| -> Seq Scan on tbl_sales_contracts t0 (cost=0.00..68.32 rows=1715 width=11) |
| Filter: need_analysis |
| -> Hash (cost=231.45..231.45 rows=6 width=104) |
| -> Hash Right Join (cost=190.66..231.45 rows=6 width=104) |
| Hash Cond: (t0_1.id = sc.id) |
| -> HashAggregate (cost=72.61..89.76 rows=1715 width=10) |
| Group Key: t0_1.id |
| -> Seq Scan on tbl_sales_contracts t0_1 (cost=0.00..68.32 rows=1715 width=10) |
| Filter: need_analysis |
| -> Hash (cost=117.97..117.97 rows=6 width=98) |
| -> Hash Right Join (cost=107.53..117.97 rows=6 width=98) |
| Hash Cond: (scpcrd.contract_id = sc.id) |
| -> HashAggregate (cost=34.81..40.48 rows=378 width=76) |
| Group Key: scpcrd.contract_id |
| -> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrd (cost=0.00..29.89 rows=393 width=20) |
| Filter: ((remind_date <= '2026-07-01'::date) AND (COALESCE(paid_amount, '0'::numeric) < amount)) |
| -> Hash (cost=72.65..72.65 rows=6 width=30) |
| -> Seq Scan on tbl_sales_contracts sc (cost=0.00..72.65 rows=6 width=30) |
| Filter: (need_analysis AND (client_id = 982)) |
| -> Hash (cost=1.51..1.51 rows=51 width=4) |
| -> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.51 rows=51 width=4) |
| -> Hash (cost=30.05..30.05 rows=4 width=8) |
| -> Subquery Scan on mind (cost=29.93..30.05 rows=4 width=8) |
| -> GroupAggregate (cost=29.93..30.01 rows=4 width=8) |
| Group Key: scpcrd_1.contract_id |
| -> Sort (cost=29.93..29.95 rows=4 width=8) |
| Sort Key: scpcrd_1.contract_id |
| -> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrd_1 (cost=0.00..29.89 rows=4 width=8) |
| Filter: ((remind_date > '2026-07-01'::date) AND (COALESCE(paid_amount, '0'::numeric) >= amount)) |