SPOOL C:\TEMP\texto12.
txt
SET TERMOUT OFF
SET ECHO OFF
SET VERIFY OFF
SET FEEDBACK OFF
SET SERVEROUTPUT OFF
SET LINESIZE 10000
SET PAGESIZE 50000
SET TRIMOUT ON
SET TRIMSPOOL ON
SET NEWPAGE NONE
--SET COLSEP " "
--SET HEADSEP " "
SET HEADING ON
COLUMN * JUSTIFY LEFT
select
pha.segment1 "Contrato",
pha.creation_date "Data Cria��o",
pha.currency_code "Moeda",
pha.AUTHORIZATION_STATUS "Status Contrato",
VENDOR_PRODUCT_NUM codigo_item_fornecedor,
( select distinct fu.LAST_NAME
from apps.per_all_people_f fu
where fu.person_id = pha.agent_id and rownum = 1 ) "Comprador
Contrato",
pla.global_attribute1 NCM,
vendor_name fornecedor,
pla.line_num "Linha Contrato",
(select sum(decode (pha.currency_code, 'BRL',price_override,price_override *
pha.rate) * (quantity - quantity_cancelled)) from po_line_locations_all
where
po_header_id = pha.po_header_id
and
po_line_id = pla.po_line_id) "Valor Liberado Linha",
(select count(*) from apps.po_line_locations_all ppra where po_header_id =
pha.po_header_id
and
po_line_id = pla.po_line_id
and
nvl(cancel_flag,'N')= 'N'
and
shipment_type = 'BLANKET' ) numero_libera��es,
pla.unit_price "Preco Item",
uNIT_MEAS_LOOKUP_CODE "Unidade de Medida",
mcb.segment1||'.'||mcb.segment2||'.'||mcb.segment3||'.'||mcb.segment4||'.'||
mcb.segment5 categoria,
pla.item_description descri��o,
decode((select count(*) from APPS.FND_ATTACHED_DOCUMENTS FAD where
FAD.ENTITY_NAME = 'PO_HEADERS'
AND FAD.PK1_VALUE = TO_CHAR(PHA.PO_HEADER_ID)), 0, 'N','Y') "Tem Anexo"
FROM
apps.po_lines_all pla,
apps.po_headers_all pha,
apps.mtl_categories_b mcb,
apps.po_vendors pv
where
pla.po_header_id = pha.po_header_id
and pha.AUTHORIZATION_STATUS = 'APPROVED'
and nvl(pha.closed_code, 'OPEN') = 'OPEN'
and nvl(pla.closed_code,'OPEN') = 'OPEN'
and pla.item_id is null
and pha.org_id = 90
and pha.TYPE_LOOKUP_CODE = 'BLANKET'
and trunc(pha.start_date) <= trunc(sysdate)
and trunc(pha.end_date) >= trunc(sysdate)
and pha.vendor_id = pv.vendor_id
and pla.category_id = mcb.category_id
and mcb.segment1 = 'SV'
and PHA.AGENT_ID in (
4217,
4316,
4872,
4876,
4877,
57294,
5549,
5595,
6187,
6349,
7181,
8857,
8863,
8994,
8996,
9019,
9388,
9592,
10013,
10212,
88015,
10945,
11678,
11823,
12097,
12311,
12392,
12394,
17141,
20045,
20663,
20723,
21591,
21933,
22617,
23027,
23324,
23596,
24293,
2816,
27651,
27766,
29207,
29938,
32168,
32297,
33180,
33346,
34015,
34134,
34394,
34543,
33346,
23324,
38212,
38527,
38637,
41021,
41021,
41284,
41286,
41234,
41376,
42068,
42223,
42966,
44598,
46191,
48109,
48326,
48718,
48807,
49073,
50456,
50592,
51278,
56540,
52132,
52134,
52139,
52140,
53950,
53952,
53997,
54037,
54121,
56810,
57294,
33180,
58305,
58481,
58587,
29207,
58907,
59844,
59355,
64739,
60065,
60568,
60596,
61044,
17141,
61515,
61515,
61705,
61740,
61741,
61809,
62431,
62789,
62916,
62917,
63111,
63585,
63601,
63873,
64053,
64054,
64055,
64194,
59355,
64298,
64382,
64402,
65584,
65841,
65987,
66453,
73371,
73372,
73570,
73687,
73954,
76245,
76246,
77686,
76947,
77180,
102356,
81680,
81898,
84369,
86163,
85429,
85433,
84640,
85035,
85078,
85091,
85147,
85616,
85847,
86194,
86504,
86517,
86875,
86897,
87817,
88015,
86875,
86897,
91800,
89512,
89308,
89444,
90078,
90112,
86504,
90368,
90903,
91389,
89989,
90003,
91788,
91328,
92594,
91855,
92923,
93378,
95609,
95712,
95970,
94623,
94626,
94638,
97845,
98939,
98469,
99231,
99320,
100374,
100379,
102327,
102006,
102031,
102356,
102301,
105503,
103151,
102840,
102497,
105060,
105783,
105134,
105606,
104847,
106489,
106553,
106553,
109512,
85091,
102301,
104847,
102327,
86517,
107458,
107569,
109118,
109146,
108974,
108635,
107012,
107015,
107053,
108720,
34015);
/