| Aggregate (cost=584.10..584.11 rows=1 width=8) |
| -> Sort (cost=558.86..563.07 rows=1683 width=468) |
| Sort Key: (max(eso.created_at)) DESC NULLS LAST, epop.id DESC |
| -> HashAggregate (cost=451.85..468.68 rows=1683 width=468) |
| Group Key: epop.id |
| Filter: (((epop.number - COALESCE(max(outbound_count.outbound_number), '0'::numeric)) + COALESCE(max(return_count.return_number), '0'::numeric)) > '0'::numeric) |
| -> Hash Left Join (cost=343.11..435.02 rows=1683 width=80) |
| Hash Cond: (epop.id = return_count.erp_sales_order_product_id) |
| -> Hash Left Join (cost=325.89..413.37 rows=1683 width=48) |
| Hash Cond: (epop.id = outbound_count.erp_sales_order_product_id) |
| -> Hash Left Join (cost=290.07..373.13 rows=1683 width=16) |
| Hash Cond: (eso.client_id = client.id) |
| Filter: ((client.sales_rep = 1001) OR (eso.created_by = 1001) OR (rvr.user_id = 1001) OR (eso.created_by = ANY ('{1000,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,1022,1023,1025,1026,1027,1028,1029,1030,5015,5016,5022,5023,5024,5025,5026,5027,5028,5029,5030,5031,5032,5033,5037,5043,5044,5045,5047,5048,5049,5050,5062,5063,5064,5065,5066,5069,5070,5071,5072,5073,5074,5075,5076,5078,5079,5080,5081,5082,5083,5085,5086,5087,5088,5089,5093,5094,5095,5096,5101,5102,5104,5105,5123,5124,5125,5126,5128,5135,5203,5208,5209,5229,5230,5247,5248,5249,5250,5252,5258,5259,5293,5294,5295,5296,5297,5298,5299,5300,5301,5302,5303,5304,5305,5309,5311,5329,5332,5333,5351,5356,5357,5358,5359,5360,5364,5388,5393,5404,5409,5411,5412,5413,5419,5420,5440,5445,5446,5448,5449,5461,5467,5476,5497,5499,5500}'::integer[]))) |
| -> Hash Left Join (cost=156.12..234.52 rows=1693 width=28) |
| Hash Cond: (eso.id = rvr.erp_sales_order_id) |
| -> Hash Right Join (cost=151.86..220.37 rows=1693 width=28) |
| Hash Cond: (purchase_rel.project_id = eso.project_id) |
| -> Seq Scan on tbl_purchase_client_rels purchase_rel (cost=0.00..33.11 rows=2111 width=8) |
| -> Hash (cost=133.89..133.89 rows=1437 width=32) |
| -> Hash Join (cost=73.35..133.89 rows=1437 width=32) |
| Hash Cond: (epop.erp_sales_order_id = eso.id) |
| -> Seq Scan on tbl_erp_sales_order_products epop (cost=0.00..54.71 rows=2217 width=16) |
| Filter: (number > '0'::numeric) |
| -> Hash (cost=59.45..59.45 rows=1112 width=24) |
| -> Seq Scan on tbl_erp_sales_orders eso (cost=0.00..59.45 rows=1112 width=24) |
| Filter: ((NOT is_done) AND (status = 2)) |
| -> Hash (cost=2.45..2.45 rows=145 width=8) |
| -> Seq Scan on tbl_erp_sales_order_verify_rels rvr (cost=0.00..2.45 rows=145 width=8) |
| -> Hash (cost=108.98..108.98 rows=1998 width=8) |
| -> Seq Scan on tbl_clients client (cost=0.00..108.98 rows=1998 width=8) |
| -> Hash (cost=31.03..31.03 rows=383 width=36) |
| -> Subquery Scan on outbound_count (cost=22.41..31.03 rows=383 width=36) |
| -> HashAggregate (cost=22.41..27.20 rows=383 width=36) |
| Group Key: esop.erp_sales_order_product_id |
| -> Hash Join (cost=9.96..20.35 rows=412 width=9) |
| Hash Cond: (esop.erp_sales_outbound_id = esob.id) |
| -> Seq Scan on tbl_erp_sales_outbound_products esop (cost=0.00..9.25 rows=425 width=13) |
| -> Hash (cost=7.64..7.64 rows=186 width=4) |
| -> Seq Scan on tbl_erp_sales_outbounds esob (cost=0.00..7.64 rows=186 width=4) |
| Filter: (status = ANY ('{1,2,5}'::integer[])) |
| -> Hash (cost=17.16..17.16 rows=4 width=36) |
| -> Subquery Scan on return_count (cost=17.04..17.16 rows=4 width=36) |
| -> GroupAggregate (cost=17.04..17.12 rows=4 width=36) |
| Group Key: esop_1.erp_sales_order_product_id |
| -> Sort (cost=17.04..17.05 rows=4 width=9) |
| Sort Key: esop_1.erp_sales_order_product_id |
| -> Nested Loop (cost=2.68..17.00 rows=4 width=9) |
| -> Nested Loop (cost=2.53..16.07 rows=4 width=13) |
| -> Hash Join (cost=2.26..14.64 rows=4 width=9) |
| Hash Cond: (esosp.id = esrp.erp_sales_outbound_spent_product_id) |
| -> Seq Scan on tbl_erp_sales_outbound_spent_products esosp (cost=0.00..10.34 rows=534 width=8) |
| -> Hash (cost=2.21..2.21 rows=4 width=9) |
| -> Hash Join (cost=1.12..2.21 rows=4 width=9) |
| Hash Cond: (esrp.erp_sales_return_id = esr.id) |
| -> Seq Scan on tbl_erp_sales_return_products esrp (cost=0.00..1.06 rows=6 width=13) |
| -> Hash (cost=1.07..1.07 rows=4 width=4) |
| -> Seq Scan on tbl_erp_sales_returns esr (cost=0.00..1.07 rows=4 width=4) |
| Filter: (status = ANY ('{2,5}'::integer[])) |
| -> Index Scan using tbl_erp_sales_outbound_products_pkey on tbl_erp_sales_outbound_products esop_1 (cost=0.27..0.36 rows=1 width=12) |
| Index Cond: (id = esosp.erp_sales_outbound_product_id) |
| -> Index Scan using tbl_erp_sales_outbounds_pkey on tbl_erp_sales_outbounds esob_1 (cost=0.14..0.23 rows=1 width=4) |
| Index Cond: (id = esop_1.erp_sales_outbound_id) |
| Filter: (status = ANY ('{1,2,5}'::integer[])) |