--采購到入庫所經歷的表
--0.請購單
--創建請購單方式有
--a.從外掛系統導入請購的接口表PO_REQUISITIONS_INTERFACE_ALL,並允許請求(名稱:導入申請)
SELECT * FROM PO_REQUISITIONS_INTERFACE_ALL WHERE INTERFACE_SOURCE_CODE = 'TEST KHJ'
--b.在系統中創建請購單(路徑:PO/申請/申請)
--請購單頭信息
SELECT prh.requisition_header_id ,prh.authorization_status--未審批時為INCOMPLETE,審批完后為 from PO_REQUISITION_HEADERS_ALL PRH where prh.segment1= '600000' and prh.type_lookup_code='PURCHASE'
--請購單行信息
SELECT prL.Requisition_Line_Id ,prL.* from PO_REQUISITION_LINES_ALL PRL where PRL.REQUISITION_HEADER_ID IN( SELECT prh.requisition_header_id from PO_REQUISITION_HEADERS_ALL PRH where prh.segment1= '600000' and prh.type_lookup_code='PURCHASE')
--請購單分配行
select * from Po_Req_Distributions_All prda where prda.requisition_line_id in (SELECT prL.Requisition_Line_Id from PO_REQUISITION_LINES_ALL PRL where PRL.REQUISITION_HEADER_ID IN (SELECT prh.requisition_header_id from PO_REQUISITION_HEADERS_ALL PRH where prh.segment1 = '600000' and prh.type_lookup_code = 'PURCHASE'))
--1.采購訂單的創建(路徑:PO/采購訂單/采購訂單)
--po_headers_all 采購訂單頭表 select pha.po_header_id, pha.segment1, pha.agent_id, pha.type_lookup_code,--標准采購單為STANDARD,一攬子協議為BLANKET decode(pha.approved_flag,'R', pha.approved_flag, nvl(pha.authorization_status,'INCOMPLETE')),--審批,未審批時為INCOMPLETE,審批后為APPROVED PO_HEADERS_SV3.GET_PO_STATUS(pha.po_header_id)--剛下完采購單,未審批時,po狀態為未完成,審批后,狀態為批准 from po_headers_all pha where segment1 = 300446--采購單號碼 --po_lines_all 采購訂單行表 select pla.po_line_id, pla.line_type_id from po_lines_all pla where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446); /*
取已審批銷售訂單頭和行的數據:
涉及表: Po_headers_all,Po_lines_all
邏輯如下:
限制頭表的如下屬性,並通過Po_header_id把頭、行表關聯起來
APPROVED_FLAG=Y
*/
--po_line_locations_all 采購訂單行的發送表(路徑:PO/采購訂單/采購訂單/發運(T))
--po_line_id=po_lines_all.po_line_id
--當點擊發運按鈕時,系統會自動創建第一行發運行,可根據需要手工創建新的發運行
--(例如同一采購訂單行的物料可能會發往不同的地點,此表記錄物料發送情況)
--下面為取訂單與其發運的關系(可能存在多次發運)
select * from po_line_locations_all plla where plla.po_line_id =(select pla.po_line_id from po_lines_all pla where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446)); --或者 select * from po_line_locations_all plla where plla.po_header_id=(select po_header_id from po_headers_all where segment1 = 300446);
--4、po_distributions_all 采購訂單發送行的分配表(路徑:PO/采購訂單/采購訂單/發運(T)/分配(T))
--line_location_id=po_line_location_all.line_location_id
--發往同一地點的物料也可能放在不同的子庫存,此表記錄物料分配情況
SELECT * FROM po_distributions_all pda WHERE pda.line_location_id in( select plla.Line_Location_Id from po_line_locations_all plla where plla.po_line_id =(select pla.po_line_id from po_lines_all pla where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446))) --或者 select * from po_distributions_all where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446) --或者 select * from po_distributions_all pda where pda.po_line_id= (select pla.po_line_id from po_lines_all pla where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446))
--對於po_distribution_all 表而言,如果其SOURCE_DISTRIBUTION_ID 有值, 其對應於計划采購單發放
/*以上各表從上到下是一對多關系的 */
--po_releases_all 訂單發放
--該表包含一攬子協議以及計划采購單的release,對於每一張發放的一攬子協議或者計划采購單都有相關行與之對應
--其包含采購員,日期,釋放狀態,釋放號碼,每一個釋放行都有至少一條的采購單的發運信息與之對應(PO_LINE_LOCATIONS_ALL).
--每做一次Realese,PO_distributions_all就會新增一條記錄。這是計划訂單的特性。
--
SELECT * FROM po_releases_all WHERE po_header_id =<po_header_id>;;
--接收(路徑:INV/事務處理/接收/接收)
--1.rcv_shipment_headers 接收發送頭表
--記錄采購訂單的接收情況的頭表
select * from rcv_shipment_headers rsh where rsh.shipment_header_id in (select shipment_header_id from rcv_shipment_lines where po_header_id = 4105);
--2.rcv_shipment_lines 接收發送行表
--記錄采購訂單的發送的行的接收情況
select * from rcv_shipment_lines where po_header_id = 4105
--3.rcv_transactions 接收事務處理表
--記錄采購訂單的發送行的RECEIVE的信息
select RT.TRANSACTION_ID, rt.transaction_type, rt.destination_type_code, rt.* from rcv_transactions rt where rt.interface_source_code = 'RCV' and rt.source_document_code = 'PO' and ( rt.po_header_id = (select pha.po_header_id from po_headers_all pha where segment1 = 300446 ) or RT.PO_LINE_ID IN(select pla.po_line_id from po_lines_all pla where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446)) or RT.SHIPMENT_HEADER_ID = (select RSH.SHIPMENT_HEADER_ID from rcv_shipment_headers rsh where shipment_header_id in (select shipment_header_id from rcv_shipment_lines where po_header_id = 4105)) or rt.shipment_line_id in(select shipment_line_id from rcv_shipment_lines where po_header_id = 4105) )
--4.rcv_receiving_sub_ledger 暫記應付表
--記錄采購訂單接收后,產生的暫記應付信息(接收事務處理產生的分配行)
select * from rcv_receiving_sub_ledger where rcv_transaction_id in (select transaction_id from rcv_transactions where po_header_id = 4105);
--接受(路徑:INV/事務處理/接收/接收事務處理)
--接收事務處理:接收之后,其實現在還並沒有入庫。
--rcv_transactions 接收事務處理表
--記錄采購訂單的發送行的ACCEPT的信息
select RT.TRANSACTION_ID,rt.transaction_type,rt.destination_type_code,rt.* from rcv_transactions rt where rt.interface_source_code = 'RCV' --做接收的條件 and rt.source_document_code = 'PO' --做接收的條件 and rt.TRANSACTION_TYPE = 'RECEIVE'--做接收的條件 and rt.DESTINATION_TYPE_CODE = 'RECEIVE'--做接收的條件 and ( rt.po_header_id = (select pha.po_header_id from po_headers_all pha where segment1 = 300446 ) or RT.PO_LINE_ID IN(select pla.po_line_id from po_lines_all pla where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446)) or RT.SHIPMENT_HEADER_ID = (select RSH.SHIPMENT_HEADER_ID from rcv_shipment_headers rsh where shipment_header_id in (select shipment_header_id from rcv_shipment_lines where po_header_id = 4105)) or rt.shipment_line_id in(select shipment_line_id from rcv_shipment_lines where po_header_id = 4105) )
-- 入庫
--因為涉及入庫操作,所以,在庫存事務處理表中會留下相應的記錄。
--即在Mtl_material_transactions表中,會存在相應的兩條入庫記錄。
SELECT mmt.* FROM mtl_material_transactions mmt where mmt.transaction_type_id =18 --po接收 and mmt.transaction_action_id =27 --接收至庫存 and mmt.transaction_source_type_id=1 --采購訂單 and ( mmt.transaction_source_id= 4105 --po_header_id or mmt.rcv_transaction_id in (select RT.TRANSACTION_ID from rcv_transactions rt where rt.interface_source_code = 'RCV' and rt.source_document_code = 'PO' and (rt.po_header_id = (select pha.po_header_id from po_headers_all pha where segment1 = 300446)))) --此時,rcv_transactions的狀態變為 select RT.TRANSACTION_ID,rt.transaction_type,rt.destination_type_code,rt.* from rcv_transactions rt where rt.interface_source_code = 'RCV' --做入庫的條件 and rt.source_document_code = 'PO' --做入庫的條件 and rt.TRANSACTION_TYPE = 'DELIVER'--做入庫的條件 and rt.DESTINATION_TYPE_CODE = 'INVENTORY'--做入庫的條件 and ( rt.po_header_id = (select pha.po_header_id from po_headers_all pha where segment1 = 300446 ) or RT.PO_LINE_ID IN(select pla.po_line_id from po_lines_all pla where po_header_id = (select po_header_id from po_headers_all where segment1 = 300446)) or RT.SHIPMENT_HEADER_ID = (select RSH.SHIPMENT_HEADER_ID from rcv_shipment_headers rsh where shipment_header_id in (select shipment_header_id from rcv_shipment_lines where po_header_id = 4105)) or rt.shipment_line_id in(select shipment_line_id from rcv_shipment_lines where po_header_id = 4105) )
--退貨
--說明:
--退貨至接收時,產生一條記錄,退貨至供應商時,產生兩條數據。 可見退貨的實際順序為: 庫存----> 接收----> 供應商
--不管是退貨至接收還是退貨至供應商,在事務處理中,都會產生兩條記錄。
--而且,數量符號與接收的數據正好相反。而且產生的記錄都是RETURN TO RECEIVING。
--1.庫存退貨至接受
SELECT rt.DESTINATION_TYPE_CODE,rt.INTERFACE_SOURCE_CODE,rt.* FROM rcv_transactions rt WHERE rt.interface_source_code IS NULL and rt.transaction_type ='RETURN TO RECEIVING'--退貨至接受 and rt.source_document_code='PO' AND RT.DESTINATION_TYPE_CODE='RECEIVING' AND po_header_id = 4105 AND po_line_id = 9938 SELECT MMT.* FROM mtl_material_transactions MMT WHERE MMT.TRANSACTION_SOURCE_ID=4105 AND MMT.TRANSACTION_TYPE_ID =36 AND MMT.TRANSACTION_ACTION_ID=1 AND MMT.TRANSACTION_SOURCE_TYPE_ID=1
--2.庫存退貨至供應商(產生兩條數據。順序為: 庫存----> 接收----> 供應商)
--a.庫存退貨至接收
SELECT rt.DESTINATION_TYPE_CODE,rt.INTERFACE_SOURCE_CODE,rt.* FROM rcv_transactions rt WHERE rt.interface_source_code IS NULL and rt.transaction_type ='RETURN TO RECEIVING'--先退貨至接收 and rt.source_document_code='PO' AND RT.DESTINATION_TYPE_CODE='INVENTORY' AND po_header_id = 4105
--b.接收退貨至供應商
SELECT rt.DESTINATION_TYPE_CODE,rt.INTERFACE_SOURCE_CODE,rt.* FROM rcv_transactions rt WHERE rt.interface_source_code IS NULL and rt.transaction_type ='RETURN TO VENDOR'--退貨至供應商 and rt.source_document_code='PO' AND RT.DESTINATION_TYPE_CODE='RECEIVING' AND po_header_id = 4105
SELECT MMT.* FROM mtl_material_transactions MMT WHERE MMT.TRANSACTION_SOURCE_ID=4105 AND MMT.TRANSACTION_TYPE_ID =36--向供應商退貨 AND MMT.TRANSACTION_ACTION_ID=1--從庫存發放 AND MMT.TRANSACTION_SOURCE_TYPE_ID=1--采購訂單
