Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 7

CREATE OR REPLACE PROCEDURE APPS.

XXJIL_RECEIPT_DATA(P_ORG_ID IN
VARCHAR2,P_FROM_DATE DATE,P_TO_DATE DATE) IS
CURSOR C1 IS
select * from XXJIL_RECEIPT_DATA_SAN;
CURSOR C2 IS
select * from XXJIL_RECEIPT_DATA_SAN;
begin
delete from XXJIL_RECEIPT_DATA_SAN;
insert into XXJIL_RECEIPT_DATA_SAN
select --rcvt.transaction_id,
decode(rcvh.ship_to_org_id,'83','LIQUOR','163','FOOD','167','SANITIZER','169','MILK
','170','ETHANOL',NULL) DIVISION,
DECODE((SELECT attribute1 FROM mtl_system_items_b WHERE
INVENTORY_ITEM_ID=rcvl.item_id AND
organization_id=rcvh.ship_to_org_id),'SER','SERVICE','MATERIALS') ITEMTYPE,
rcvt.transaction_type,
rcvh.RECEIPT_NUM,
rcvh.CREATION_DATE Receipt_date,
(SELECT SEGMENT1 FROM PO_HEADERS_ALL
WHERE PO_HEADER_ID=rcvt.po_header_id) PO_NO,
(SELECT creation_date FROM PO_HEADERS_ALL
WHERE PO_HEADER_ID=rcvt.po_header_id) PO_date,
(SELECT APPROVED_date FROM PO_HEADERS_ALL
WHERE PO_HEADER_ID=rcvt.po_header_id) PO_APPROVAL_DATE,
((SELECT DISTINCT rha.segment1
FROM po_requisition_headers_all rha,po_requisition_lines_all rla,
po_req_distributions_all rda,po_distributions_all pda,po_headers_all pha
WHERE 1=1
AND rha.requisition_header_id=rla.requisition_header_id
AND rla.requisition_line_id=rda.requisition_line_id
AND rda.distribution_id=pda.req_distribution_id
AND pda.po_header_id=pha.po_header_id
--AND pha.segment1=:P_PO_NUMBER;
--order by pda.po_header_id desc
and pda.po_header_id=rcvt.po_header_id
and pha.org_id=rcvh.ship_to_org_id))REQUISITION_NO,
((SELECT DISTINCT trunc(rha.creation_date)
FROM po_requisition_headers_all rha,po_requisition_lines_all rla,
po_req_distributions_all rda,po_distributions_all pda,po_headers_all pha
WHERE 1=1
AND rha.requisition_header_id=rla.requisition_header_id
AND rla.requisition_line_id=rda.requisition_line_id
AND rda.distribution_id=pda.req_distribution_id
AND pda.po_header_id=pha.po_header_id
--AND pha.segment1=:P_PO_NUMBER;
--order by pda.po_header_id desc
and pda.po_header_id=rcvt.po_header_id
and pha.org_id=rcvh.ship_to_org_id))REQUISITION_DATE,
((SELECT DISTINCT rha.APPROVED_DATE
FROM po_requisition_headers_all rha,po_requisition_lines_all rla,
po_req_distributions_all rda,po_distributions_all pda,po_headers_all pha
WHERE 1=1
AND rha.requisition_header_id=rla.requisition_header_id
AND rla.requisition_line_id=rda.requisition_line_id
AND rda.distribution_id=pda.req_distribution_id
AND pda.po_header_id=pha.po_header_id
--AND pha.segment1=:P_PO_NUMBER;
--order by pda.po_header_id desc
and pda.po_header_id=rcvt.po_header_id
and pha.org_id=rcvh.ship_to_org_id))REQUISITION_APPROVAL_DATE,
(select vendor_name from ap_suppliers where
vendor_id=rcvh.vendor_id )vendor_name
-- ,rcvt.po_distribution_id
-- ,rcvt.po_header_id
--,rcvt.po_line_id
--,rcvt.po_line_location_id
--,rcvt.po_release_id
,rcvh.shipment_header_id
,rcvl.shipment_line_id
--,rcvt.transaction_date
,(SELECT SEGMENT1 FROM mtl_system_items_b WHERE
INVENTORY_ITEM_ID=rcvl.item_id AND organization_id=rcvh.ship_to_org_id) ITEMCODE
,rcvl.item_description
,(SELECT PRIMARY_UOM_CODE FROM mtl_system_items_b WHERE
INVENTORY_ITEM_ID=rcvl.item_id AND organization_id=rcvh.ship_to_org_id)
PRIMARY_UNIT
,(SELECT SECONDARY_UOM_CODE FROM mtl_system_items_b WHERE
INVENTORY_ITEM_ID=rcvl.item_id AND organization_id=rcvh.ship_to_org_id)
SECONDARY_UNIT
,round(nvl(rcvl.quantity_shipped,0),3) QUANTITY_ORDERED
,round(nvl(rcvl.quantity_received,0),3) QUANTITY_RECEIVED
,rcvl.shipment_line_status_code QUANTITY_STATUS
-- ,rcvl.destination_type_code
--,rcvh.receipt_source_code
-- ,rcvh.vendor_id
--,rcvl.to_subinventory
--,rcvh.shipment_header_id
--,rcvh.receipt_num
--,(select distinct vendor_site_code from ap_supplier_sites_all where
vendor_id=rcvh.vendor_id) vendor_site
--,rcvh.vendor_site_id
,round(nvl(rcvt.QUANTITY_BILLED,0),3) QUANTITY
,rcvt.PO_UNIT_PRICE price
,rcvt.AMOUNT_BILLED AMOUNT
/* ,(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type='ACCEPT'
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id) TAX_AMOUNT_AFTER_GST_INCLD_FRT,
*/
,((select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id)) Tax,
(select nvl(sum(NVL(a.QUANTITY,0)),0) from rcv_transactions A
where A.shipment_line_id=rcvl.shipment_line_id
AND A.shipment_header_id = rcvh.shipment_header_id
AND (A.transaction_type in('RETURN TO RECEIVING') OR A.transaction_type in('RETURN
TO VENDOR'))
AND A.ORGANIZATION_ID=rcvl.TO_ORGANIZATION_ID) RTV_QUANTITY,
0 RTV_VALUE,
/*(select nvl(sum(NVL(a.QUANTITY,0)),0)*SUM(NVL(PO_UNIT_PRICE,0)) from
rcv_transactions A
where A.shipment_line_id=rcvl.shipment_line_id
AND A.shipment_header_id = rcvh.shipment_header_id
AND (A.transaction_type in('RETURN TO RECEIVING') OR A.transaction_type in('RETURN
TO VENDOR'))
AND A.ORGANIZATION_ID=rcvl.TO_ORGANIZATION_ID) RTV_BASIC_AMOUNT,*/
((select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and (trx_type ='RETURN TO RECEIVING' or trx_type ='RETURN TO VENDOR')
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id)) RTV_TAX,
0 RTV_TAX_VALUE,
(select nvl(sum(NVL(a.QUANTITY,0)),0)from rcv_transactions A
where A.shipment_line_id=rcvl.shipment_line_id
AND A.shipment_header_id = rcvh.shipment_header_id
AND (A.transaction_type in( 'REJECT'))
AND A.ORGANIZATION_ID=rcvl.TO_ORGANIZATION_ID) REJECTED_QUANTITY,
0 REJECTED_VALUE,
((select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and (trx_type='REJECT')
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id)) REJECTED_TAX,
0 REJECTED_TAX_VALUE,
(select nvl(sum(NVL(a.QUANTITY,0)),0) from rcv_transactions A
where A.shipment_line_id=rcvl.shipment_line_id
AND A.shipment_header_id = rcvh.shipment_header_id
AND A.transaction_type in('DELIVER')
AND A.ORGANIZATION_ID=rcvl.TO_ORGANIZATION_ID) DELIVERED_QUNATITY,
((select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
AND TAX_REGIME_CODE='IN-GST')+
(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
AND TAX_REGIME_CODE='IN-EXCISE')+
(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
and tax_rate_id='10342')+
(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
AND TAX_REGIME_CODE='IN-TCS')+
(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
AND TAX_REGIME_CODE='IN-VAT')+
(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) TAX from
JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
--and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
AND TAX_REGIME_CODE='IN-CST')+
(select nvl(sum(nvl(tax_amount,0)),0) TAX from JAI_RCV_LINE_TAXES c
where c.shipment_header_id=rcvh.shipment_header_id
and c.shipment_line_id=rcvl.shipment_line_id
and c.transaction_id=rcvt.transaction_id)) New_tax,
((select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) from JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
-- and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
and tax_regime_code='Other Tax'
--and tax_rate_code='Freight New'
AND tax_rate_id in('10386','10769','10564','10519','10389','10526','10525'))
+
(select nvl(sum(nvl(tax_amount,0)),0) from JAI_RCV_LINE_TAXES c
where c.shipment_header_id=rcvh.shipment_header_id
and c.shipment_line_id=rcvl.shipment_line_id
and c.transaction_id=rcvt.transaction_id
and c.Tax_name='Freight'
and c.Tax_type='Freight')) FREIGHT,
((select nvl(sum(nvl(tax_amount,0)),0) from JAI_RCV_LINE_TAXES c
where c.shipment_header_id=rcvh.shipment_header_id
and c.shipment_line_id=rcvl.shipment_line_id
and c.transaction_id=rcvt.transaction_id
--and c.Tax_name='Freight'
and c.Tax_type='Service')+
(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) from JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
-- and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
and tax_regime_code='Other Tax'
--and tax_rate_code='Freight New'
AND tax_rate_id
in('10678','10521','10522','10316','10862','10520','10524','10317','10801','10523',
'10773','10322')
)+
(select nvl(sum(nvl(UNROUND_TAX_AMT_TRX_CURR,0)),0) from JAI_TAX_LINES_ALL
where event_class_code='RECEIVING'
and trx_type ='ACCEPT'
-- and ((trx_type <>'RETURN TO RECEIVING') or (trx_type <>'REJECT') or
(trx_type<>'RETURN TO VENDOR'))
and trx_number=rcvh.RECEIPT_NUM
and item_id=d.inventory_item_id
AND TRX_ID=rcvh.shipment_header_id
and trx_line_id=rcvl.shipment_line_id
AND ORG_ID=rcvl.TO_organization_id
AND ORG_ID=rcvh.ship_to_org_id
and tax_regime_code='Other Tax'
--and tax_rate_code='Freight New'
AND tax_rate_id in('10679' ,'10861')
)) PKG_FRWD_COMM_SER_CHARGES,
-- ,rcvh.EMPLOYEE_ID,
(select ATTRIBUTE1 from per_all_people_f
where person_id=rcvh.employee_id) Deptid,
(select UPPER(DESCRIPTION) from fnd_flex_values_vl
where flex_value_set_id='1016208'
and flex_value_meaning=(select ATTRIBUTE1 from per_all_people_f
where person_id=rcvh.employee_id)) deptname
from rcv_shipment_headers rcvh
,rcv_shipment_lines rcvl
,rcv_transactions rcvt
, mtl_system_items_b d
where 1 = 1
AND rcvh.shipment_header_id = rcvl.shipment_header_id
AND rcvl.shipment_line_id = rcvt.shipment_line_id
AND rcvh.shipment_header_id = rcvt.shipment_header_id
AND rcvt.transaction_type = 'RECEIVE'
and rcvh.ship_to_org_id=rcvl.TO_ORGANIZATION_ID
and rcvh.ship_to_org_id=rcvt.ORGANIZATION_ID
and rcvl.TO_ORGANIZATION_ID=rcvt.ORGANIZATION_ID
and rcvh.ship_to_org_id =P_org_id
--and rcvl.shipment_line_status_code<>'EXPECTED'
-- and trunc(rcvt.transaction_date) between '01-APR-2018' AND '31-MAR-2019'
AND TRUNC(rcvh.CREATION_DATE) between p_from_date and P_to_date
AND rcvh.RECEIPT_SOURCE_CODE='VENDOR'
and rcvl.item_id=d.INVENTORY_ITEM_ID
and rcvl.TO_ORGANIZATION_Id=d.ORGANIZATION_ID
and rcvh.ship_to_org_id=d.ORGANIZATION_ID
and rcvt.ORGANIZATION_ID=d.ORGANIZATION_ID
and d.ATTRIBUTE1 NOT IN('FG')
--and d.ATTRIBUTE1 IN('SER')
/*
AND((SELECT SEGMENT1 FROM PO_HEADERS_ALL
WHERE PO_HEADER_ID=rcvt.po_header_id))like '%HFLSER170593%' --LIKE '%SER%'
-- */
--and rcvh.RECEIPT_NUM= '218302650'
--AND rcvt.po_header_id='187578';
order by rcvh.ship_to_org_id ,Receipt_date ASC,receipt_num;
FOR i in c1
loop
update XXJIL_RECEIPT_DATA_SAN
set rtv_value=i.rtv_quantity*i.Price
where receipt_num=i.receipt_num
and itemcode=i.itemcode
and shipment_header_id=i.shipment_header_id
and shipment_line_id=i.shipment_line_id;

update XXJIL_RECEIPT_DATA_SAN
set rejected_value=i.rejected_quantity*i.Price
where receipt_num=i.receipt_num
and itemcode=i.itemcode
and shipment_header_id=i.shipment_header_id
and shipment_line_id=i.shipment_line_id;
commit;

end loop;
for j in c2
loop
if j.rtv_value>0 or j.rejected_value>0 or j.rtv_tax>0 or j.rejected_tax>0
then
update XXJIL_RECEIPT_DATA_SAN
set rejected_value=-abs(j.rejected_value),rtv_value=-
abs(j.rtv_value),rtv_tax=-abs(j.rtv_tax),rejected_tax=-abs(j.rejected_tax)
where receipt_num=j.receipt_num
and itemcode=j.itemcode
and shipment_header_id=j.shipment_header_id
and shipment_line_id=j.shipment_line_id;

end if;
end loop;
commit;
End;
/

You might also like