CREATE OR REPLACE TRIGGER PO_APPROVED_AUTO_RECEIVE_sx
after UPDATE OF APPROVED_FLAG on po_line_locations_all
REFERENCING
for each row
WHEN (OLD.ship_to_organization_id = 1934
and new.approved_flag ='Y')
declare
v_sysdate DATE := SYSDATE;
v_vendor_id NUMBER;
v_vendor_site_id NUMBER;
--v_vendor_name varchar2(200);
--v_user_id NUMBER;
v_employee_id NUMBER;
v_expected_receipt_date DATE :=SYSDATE;
v_comments varchar2(1000):='XUAN.SHA test';
c_validation_flag VARCHAR2 (1) := 'Y';
v_quantity NUMBER; --:=10;
v_unit_of_measure varchar2(10);
v_item_id NUMBER; --:=38023;
v_po_header_id NUMBER; --:=542;
v_po_line_id NUMBER; --:=523;
v_po_line_location_id NUMBER; --:=474;
--v_org_id NUMBER; --:=104;
v_ship_to_location_id NUMBER; --:=142;
v_deliver_to_location_id NUMBER; --:=142;
V_CREATED_BY NUMBER;
V_LAST_UPDATED_BY NUMBER;
V_SHIP_TO_ORG_ID NUMBER;
V_VENDOR_NAME VARCHAR2(200);
V_ORG_CODE VARCHAR2(20);
V_PO_NO VARCHAR2(20);
v_po_distribution_id NUMBER;
V_GROUP_ID NUMBER;
V_HEADER_INTERFACE_ID NUMBER;
v_transaction_interface_id NUMBER;
v_ITEM_REVISION varchar2(10);
v_item_desc varchar2(200);
v_tax_name varchar2(20);
c_processing_status_code rcv_headers_interface.processing_status_code%TYPE := 'PENDING';
c_receipt_source_code rcv_headers_interface.receipt_source_code%TYPE := 'VENDOR';
c_head_transaction_type rcv_headers_interface.transaction_type%TYPE := 'NEW';
c_line_transaction_type rcv_headers_interface.transaction_type%TYPE := 'RECEIVE';
--c_h_auto_transact_code rcv_headers_interface.auto_transact_code%TYPE := 'RECEIVE';
c_l_auto_transact_code rcv_headers_interface.auto_transact_code%TYPE := 'RECEIVE';
c_processing_mode_code rcv_transactions_interface.processing_mode_code%TYPE := 'BATCH';
c_source_document_code rcv_transactions_interface.source_document_code%TYPE := 'PO';
c_transaction_status_code rcv_transactions_interface.transaction_status_code%TYPE := 'PENDING';
c_destination_type_code rcv_transactions_interface.destination_type_code%TYPE := 'RECEIVING'; --'EXPENSE';
v_interface_source_code varchar2(50):='RCV';
-- local variables here
begin
select item_id,
UNIT_MEAS_LOOKUP_CODE,
ITEM_REVISION,
item_description into v_item_id,v_unit_of_measure,v_ITEM_REVISION,v_item_desc
from po_lines_all
where po_line_id = :new.po_line_id;
--if v_item_id in (391716,392294) then
--v_user_id = fnd_global.user_id;
v_quantity :=:new.quantity;
v_po_header_id :=:new.po_header_id;
v_po_line_id := :new.po_line_id;
v_po_line_location_id := :new.line_location_id;
--v_org_id := :new.org_id;
v_ship_to_location_id := :new.ship_to_location_id;
v_deliver_to_location_id := :new.ship_to_location_id;
V_CREATED_BY :=:NEW.CREATED_BY;
V_LAST_UPDATED_BY :=:NEW.LAST_UPDATED_BY;
V_SHIP_TO_ORG_ID :=:NEW.SHIP_TO_ORGANIZATION_ID;
SELECT PO_DISTRIBUTION_ID INTO v_po_distribution_id
FROM PO_DISTRIBUTIONS_ALL
WHERE LINE_LOCATION_ID =:NEW.LINE_LOCATION_ID;
SELECT rcv_headers_interface_s.NEXTVAL INTO V_HEADER_INTERFACE_ID FROM DUAL;
SELECT rcv_interface_groups_s.NEXTVAL INTO V_GROUP_ID FROM DUAL;
SELECT RCV_TRANSACTIONS_INTERFACE_S.NEXTVAL INTO v_transaction_interface_id FROM DUAL;
--------------------取PO_HEADER資料-----------
select vendor_id,
vendor_site_id,
agent_id,
CREATED_BY,
SEGMENT1
into
v_vendor_id,
v_vendor_site_id,
v_employee_id,
V_CREATED_BY,
V_PO_NO
from po_headers_all
where po_header_id = :new.po_header_id;
SELECT ORGANIZATION_CODE INTO V_ORG_CODE FROM MTL_PARAMETERS
WHERE ORGANIZATION_ID = V_SHIP_TO_ORG_ID;
select name into v_tax_name from ap_tax_codes_all
where tax_id = :new.tax_code_id;
--------------------取PO_LINE資料-----------
------------------取VENDOR NAME-------
SELECT VENDOR_NAME INTO V_VENDOR_NAME FROM PO_VENDORS
WHERE VENDOR_ID = v_vendor_id;
if :new.APPROVED_FLAG <>
CREATE OR REPLACE TRIGGER po_receive_auto_delivery_sx
after insert on rcv_transactions
for each row
WHEN ( new.organization_id = 1934
and new.transaction_type ='ACCEPT')
Declare
v_interface_transaction_id number;
v_group_id number;
v_shipment_header_id number;
v_shipment_line_id number;
v_line_location_id number;
v_po_distribution_id number;
--v_header_interface_id number;
v_deliver_to_person_id number;
l_request_id number;
l_request_id2 number;
v_destination_type_code varchar2(100);
v_expected_receipt_date date;
v_country_of_origin_code varchar2(100);
v_lot_control number;
v_use_mtl_serial number;
v_rcv_qty number;
--v_trans_qty number;
l_phase varchar2(10);
l_status varchar2(10);
l_dev_phase varchar2(10);
l_dev_status varchar2(10);
l_message varchar2(10);
l_request_lauch1_status boolean;
v_interface_id number;
v_item_id number;
v_UNIT_OF_MEASURE varchar2(20);
v_po_no varchar2(20);
v_location_id number;
Begin
select item_id,unit_meas_lookup_code into v_item_id,v_UNIT_OF_MEASURE from po_lines_all
where po_line_id =:new.po_line_id;
--if v_item_id = 391716 then --------42.52J03GA01測試此料自動入庫
select segment1 into v_po_no from po_headers_all where po_header_id = :new.po_header_id;
Select rcv_transactions_interface_s.nextval into v_interface_transaction_id from dual;
Select RCV_INTERFACE_GROUPS_S.nextval into v_group_id from dual;
select rcv_shipment_headers_s.nextval into v_shipment_header_id from dual;
select rcv_shipment_lines_s.nextval into v_shipment_line_id from dual;
--select rcv_headers_interface_s.nextval into v_header_interface_id from dual;
select MTL_MATERIAL_TRANSACTIONS_S.NEXTVAL into v_interface_id from dual;
select item_id,unit_meas_lookup_code into v_item_id,v_UNIT_OF_MEASURE from po_lines_all
where po_line_id =:new.po_line_id;
select location_id into v_location_id from hr_locations_all
where inventory_ORGANIZATION_id = :new.organization_id;
Begin
select msib.lot_control_code
into v_lot_control
from mtl_system_items_b msib
where msib.inventory_item_id = v_item_id
and msib.organization_id = :new.organization_id;--HUTS
Exception when others then
v_lot_control := null;
End;
If v_lot_control is null then
v_use_mtl_serial := null;
else
v_use_mtl_serial := 1;
End if;
--Get po line location informations
Begin
select plla.line_location_id,
plla.need_by_date,
plla.country_of_origin_code
into v_line_location_id,
v_expected_receipt_date,
v_country_of_origin_code
from po_line_locations_all plla
where plla.po_header_id = :new.po_header_id
and plla.po_line_id = :new.po_line_id
and rownum = 1;
Exception when others then
v_line_location_id := null;
v_expected_receipt_date := null;
v_country_of_origin_code := null;
End;
--Get po_distribution_id
Begin
select pda.po_distribution_id ,
pda.destination_type_code,
pda.deliver_to_person_id
into v_po_distribution_id ,
v_destination_type_code,
v_deliver_to_person_id
from po_distributions_all pda
where pda.po_header_id = :new.po_header_id
and pda.po_line_id = :new.po_line_id
and rownum = 1;
Exception when others then
v_po_distribution_id := null;
v_destination_type_code := null;
End;
If :new.quantity > 0 then
INSERT INTO RCV_TRANSACTIONS_INTERFACE
(INTERFACE_TRANSACTION_ID,
GROUP_ID,
LAST_UPDATE_DATE,
LAST_UPDATED_BY,
CREATION_DATE,
CREATED_BY,
LAST_UPDATE_LOGIN,
TRANSACTION_TYPE,
TRANSACTION_DATE,
PROCESSING_STATUS_CODE,
PROCESSING_MODE_CODE,
TRANSACTION_STATUS_CODE,
QUANTITY,
UNIT_OF_MEASURE,
ITEM_ID,
EMPLOYEE_ID,
AUTO_TRANSACT_CODE,
SHIP_TO_LOCATION_ID,
RECEIPT_SOURCE_CODE,
VENDOR_ID,
SOURCE_DOCUMENT_CODE,
PO_HEADER_ID,
PO_LINE_ID,
PO_LINE_LOCATION_ID,
DESTINATION_TYPE_CODE,
DELIVER_TO_PERSON_ID,
LOCATION_ID,
DELIVER_TO_LOCATION_ID,
SUBINVENTORY,
locator_id,
--HEADER_INTERFACE_ID,
DOCUMENT_NUM,
TO_ORGANIZATION_ID,
VALIDATION_FLAG,
SHIPMENT_HEADER_ID,
SHIPMENT_LINE_ID,
parent_transaction_id
)
Values
(
v_interface_transaction_id,--INTERFACE_TRANSACTION_ID,
v_group_id,--GROUP_ID,
sysdate,--LAST_UPDATE_DATE,
:new.last_updated_by,--LAST_UPDATED_BY,
sysdate,--CREATION_DATE,
:new.created_by,--CREATED_BY,
:new.last_update_login,--LAST_UPDATE_LOGIN,
'DELIVER',--TRANSACTION_TYPE,
sysdate,--TRANSACTION_DATE,
'PENDING',--PROCESSING_STATUS_CODE,
'BATCH',--PROCESSING_MODE_CODE,
'PENDING',--TRANSACTION_STATUS_CODE,
:new.quantity,--QUANTITY,
v_UNIT_OF_MEASURE,--UNIT_OF_MEASURE,
v_item_id,--ITEM_ID,
:new.employee_id,--EMPLOYEE_ID,
'DELIVER',--AUTO_TRANSACT_CODE,
:new.location_id,--SHIP_TO_LOCATION_ID,
'VENDOR',--RECEIPT_SOURCE_CODE,
:new.vendor_id,--VENDOR_ID,
'PO',--SOURCE_DOCUMENT_CODE,
:new.po_header_id,--PO_HEADER_ID,
:new.PO_LINE_ID,--PO_LINE_ID,
v_line_location_id,--PO_LINE_LOCATION_ID,
v_destination_type_code,--DESTINATION_TYPE_CODE,
v_DELIVER_TO_PERSON_ID,--DELIVER_TO_PERSON_ID,
v_location_id,--LOCATION_ID,
v_location_id,--DELIVER_TO_LOCATION_ID,
'3MR1',--SUBINVENTORY,
206535,--locator_id,
--:new.header_interface_id,--HEADER_INTERFACE_ID,
v_po_no,--DOCUMENT_NUM,
:NEW.ORGANIZATION_ID,--TO_ORGANIZATION_ID,
'Y',--VALIDATION_FLAG
:new.SHIPMENT_header_ID,
:new.SHIPMENT_LINE_ID,
:new.transaction_id
);
INSERT INTO mtl_transaction_lots_interface
(
TRANSACTION_INTERFACE_ID,
source_code,
LAST_UPDATE_DATE,
LAST_UPDATED_BY,
CREATION_DATE,
CREATED_BY,
LAST_UPDATE_LOGIN,
LOT_NUMBER,
TRANSACTION_QUANTITY,
PRIMARY_QUANTITY,
--SERIAL_TRANSACTION_TEMP_ID,
PRODUCT_CODE,
PRODUCT_TRANSACTION_ID,
process_flag,
source_line_id
)
VALUES
(v_interface_id,--TRANSACTION_INTERFACE_ID
'PO',--ORIGINATION_TYPE
SYSDATE, --LAST_UPDATE_DATE
:new.LAST_UPDATED_BY, --LAST_UPDATED_BY
SYSDATE, --CREATION_DATE
:new.created_by, --CREATED_BY
:new.last_update_login, --LAST_UPDATE_LOGIN
'0', --LOT_NUMBER
:new.quantity, --TRANSACTION_QUANTITY
:new.primary_quantity, --PRIMARY_QUANTITY
--0,--MTL_MATERIAL_TRANSACTIONS_S.NEXTVAL, --SERIAL_TRANSACTION_TEMP_ID
'RCV', --PRODUCT_CODE
v_interface_transaction_id, --PRODUCT_TRANSACTION_ID
1,
-1
);
--End if;
end if;
End;