採購至庫存所經歷的表

weixin_30924079發表於2020-04-04
select * from PO_REQUISITIONS_INTERFACE_ALL;--請購介面表
select * from PO_REQUISITION_HEADERS_ALL;--請購單頭資訊
select * from PO_REQUISITION_LINES_ALL;--請購單行資訊
select * from PO_REQ_DISTRIBUTIONS_ALL;--請購單分配資訊
select * from po_headers_all;--採購訂單頭資訊
select * from po_lines_all;--採購訂單行資訊
select * from po_line_locations_all;--採購訂單行的傳送表
select * from po_distributions_all;--採購訂單
select * from po_releases_all;-- 訂單發放
select * from RCV_TRANSACTIONS;--接收事務處理

 

--採購到入庫所經歷的表



--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_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 =供應商)
--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 --採購訂單;

 

轉載於:https://www.cnblogs.com/lizicheng/p/8962476.html

相關文章