You are on page 1of 4

with hr_uo as (

SELECT distinct hrl.country,


lep.legal_entity_id,
lep.NAME legal_entity,
hroutl_ou.NAME ou_name,
hroutl_ou.organization_id org_id,
hrl.location_id
FROM xle_entity_profiles lep,
xle_registrations reg,
hz_locations hrl,
hr_operating_units hro,
hr_all_organization_units_tl hroutl_ou
WHERE 1=1
AND lep.transacting_entity_flag = 'Y'
AND lep.legal_entity_id = reg.source_id
AND reg.source_table = 'XLE_ENTITY_PROFILES'
AND hrl.location_id = reg.location_id
AND reg.identifying_flag = 'Y'
AND lep.legal_entity_id = hro.default_legal_context_id
AND hroutl_ou.organization_id = hro.organization_id
),
CONVERSION AS (
select intraconv.inventory_item_id inventory_item_id,
intraconv.uom_code from_uom_code,
uom.uom_code to_base_uom,
intraconv.conversion_rate conversion_rate,
intraconv.uom_class uom_class,
intraconv.disable_date conversion_expiry_date,
uom.disable_date baseuom_expiry_date
from fusion.inv_uom_conversions intraconv,
fusion.inv_units_of_measure_b uom
where intraconv.inventory_item_id > 0
and uom.uom_class = intraconv.uom_class
-- and uom.base_uom_flag = 'Y'
-- and uom.uom_code='kg'
)
Select x.delivery_id,
x.inventory_item_id,
x.item_number,
x.Desc_item,
x.primary_uom_code,
x.requested_quantity_uom,
x.business_unit_name,
x.delivery_name,
x.request_ship_date,
x.submitted_date,
x.bill_party_name,
x.sold_to_party_name,
x.ship_to_party_name,
x.puerto_embarque,
x.puerto_destino,
x.country_from,
x.country_to,
x.net_weight,
x.gross_weight,
x.volume,
x.requested_quantity,
x.shipped_quantity,
x.converted_quantity,
x.volume_line,
x.net_weight_line,
x.gross_weight_line,
x.total_cajas,
x.factor_cajas,
x.factor_unidad,
case
when nvl(x.factor_cajas,0) >0 then
x.requested_quantity/ nvl(x.factor_cajas,1)
else
0
end Unidad_empaque,
case
when nvl(x.factor_unidad,0) >0 and nvl(x.factor_cajas,0) >0 then
-- ((x.requested_quantity*x.factor_unidad)/ nvl(x.factor_cajas,1))
(x.requested_quantity* nvl(x.factor_unidad,1))/(x.requested_quantity/
nvl(x.factor_cajas,1))
else
0
end content_cja,
case
when nvl(x.factor_unidad,0) >0 then
x.requested_quantity* nvl(x.factor_unidad,0)
else
0
end Cantidad_und

from (
SELECT del.delivery_id,
del.delivery_name,
iodv.organization_code,
iodv.organization_name,
iodv.business_unit_id,
iodv.legal_entity,
iodv.business_unit_name,
del.organization_id,
TO_CHAR(dha.request_ship_date,'YYY-MM-DD') request_ship_date, --fecha solicitud
dha.ordered_date ,
dha.request_arrival_date,
TO_CHAR(dha.submitted_date,'YYY-MM-DD') submitted_date, --fecha envio
dhe.attribute_char9 puerto_embarque,
dhe.attribute_char13 puerto_destino,
ship_from_loc.country country_from,
ship_loc.country country_to,
del.net_weight,
del.gross_weight,
del.weight_uom_code,
del.VOLUME,
del.VOLUME_UOM_CODE,
deldet.VOLUME Volume_line,
to_number(deldet.attribute5) peso_neto,
to_number(deldet.attribute6) peso_bruto,
deldet.attribute7 total_cajas,
(del.gross_weight - NVL(del.net_weight, 0)) tara,
deldet.gross_weight + ((deldet.gross_weight - NVL(deldet.net_weight, 0)))
net_weight_line,
deldet.gross_weight gross_weight_line,
deldet.SRC_REQUESTED_QUANTITY_UOM,
deldet.requested_quantity_uom,
deldet.converted_quantity,
deldet.shipped_quantity,
deldet.requested_quantity,
deldet.original_item_uom,
deldet.original_item_converted_qty,
deldet.sp_picked_quantity,
deldet.spq_uom,
itm.primary_uom_code,
case
when deldet.requested_quantity_uom <>'cja' then
(select conv.conversion_rate
from CONVERSION conv
where conv.inventory_item_id=itm.inventory_item_id
and conv.from_uom_code=deldet.requested_quantity_uom
and to_base_uom='cja'
and rownum=1
)
else
1
end factor_cajas,
case
when requested_quantity_uom <>'und' then
(select conv.conversion_rate
from CONVERSION conv
where conv.inventory_item_id=itm.inventory_item_id
and conv.from_uom_code=deldet.requested_quantity_uom
and to_base_uom='und'
and rownum=1
)
else
1
end factor_unidad,
del.confirm_date,
del.delivered_date,
del.tp_shipment_number,
bill_of_lading_number,
packing_slip_number,
ship_party.party_name ship_to_party_name,
sold_party.party_name sold_to_party_name,
bill_party.party_name bill_party_name,
deldet.source_shipment_id,
dfla.header_id,
deldet.source_header_id,
deldet.source_line_type,
deldet.sales_order_number,
deldet.sales_order_line_number,
deldet.sales_order_shipment_number,
deldet.source_shipment_number,
itm.inventory_item_id,
itm.item_number,
esit.description Desc_item,
deldet.lot_number,
deldet.shipping_instructions ,
ship_party.party_id ship_party_id,
bill_party.party_id bill_party_id,
sold_party.party_id sold_party_id

FROM wsh_new_deliveries del,


wsh_carriers_v car ,
wsh_delivery_assignments DelAssgn,
wsh_delivery_details DelDet,
doo_fulfill_lines_all dfla,
doo_headers_all dha,
doo_headers_eff_b dhe,
egp_system_items_b itm ,
egp_system_items_tl esit,
inv_org_parameters iop,
hz_parties ship_party,
hz_parties sold_party,
hz_parties bill_party,
hz_locations ship_loc,
hr_locations ship_from_loc,
inv_organization_definitions_v iodv,
hr_uo uo
WHERE 1=1
AND car.carrier_id(+) = del.carrier_id
AND DelAssgn.DELIVERY_ID = Del.DELIVERY_ID
and del.organization_id=iodv.organization_id
AND DelDet.delivery_detail_id = delassgn.delivery_detail_id
and DelDet.source_shipment_id=dfla.fulfill_line_id
and dfla.header_id=dha.header_id
AND itm.inventory_item_id = DelDet.Inventory_item_id
and itm.inventory_item_id=esit.inventory_item_id
and itm.organization_id=esit.organization_id
and esit.language = userenv('LANG')
AND iop.organization_id = itm.organization_id
AND iop.organization_id = iop.master_organization_id
AND deldet.ship_to_party_id = ship_party.party_id
AND deldet.sold_to_party_id = sold_party.party_id
AND deldet.bill_to_party_id = bill_party.party_id
and iodv.legal_entity=uo.legal_entity_id
and deldet.ship_to_location_id=ship_loc.location_id(+)
and deldet.ship_from_location_id=ship_from_loc.location_id(+)
and dha.header_id=dhe.header_id(+)
-- and del.delivery_name='26006'
and del.organization_id =:p_organization
and del.delivery_name= :p_delivery
)x
where 1=1

You might also like