Gutirez
R12 Studing

PO Study -- PO常用SQL

1,输入税后金额,得到税前金额。(知道line id&line location id)
必须保存产生line id后才可以得到税的信息。
参考文件:http://etrm.oracle.com/pls/trm120/etrm_fndnav.show_file?n_file_id=148
SQL:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  1. SELECT zx.tax_rate
  2. FROM zx_lines zx,
  3. po_headers_all ph,
  4. po_lines_all pl,
  5. po_line_locations_all pll
  6. WHERE pl.po_header_id = ph.po_header_id
  7. AND pll.po_line_id = pl.po_line_id
  8. AND pll.po_header_id = ph.po_header_id
  9. AND zx.trx_line_id = pll.line_location_id
  10. AND zx.application_id = ''
  11. AND ph.segment1 = ''
  12. AND pl.line_num = ''
  13. AND ph.org_id = ''

2,修改purchase order&requisition 的Document number.要求每月重新初始化sequence。格式:YYYYMM+9999 2010041800001

SQL:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  1. PROCEDURE update_document_number(p_table_name IN VARCHAR2, p_seq IN NUMBER) IS
  2. BEGIN
  3. UPDATE po.po_unique_identifier_cont_all
  4. SET current_max_unique_identifier = p_seq,
  5. last_update_date = SYSDATE,
  6. last_updated_by = fnd_global.user_id
  7. WHERE table_name = p_table_name
  8. AND org_id = fnd_profile.VALUE('ORG_ID')
  9. END
  10. PROCEDURE create_document_number IS
  11. BEGIN
  12. update_document_number('PO_REQUISITION_HEADERS',
  13. to_char(SYSDATE, 'yyyymm') '0000')
  14. update_document_number('PO_HEADERS',
  15. to_char(SYSDATE, 'yyyymm') '0000')
  16. END

3,获得供应商的料号。
在requisition中,根据line中的ASL,自动带出供应商的料号。
SQL:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  1. FUNCTION get_vendor_product_num(p_item_id IN NUMBER,
  2. p_vendor_id IN NUMBER,
  3. p_vendor_site_id IN NUMBER,
  4. p_using_organization_id IN NUMBER)
  5. RETURN VARCHAR2 IS
  6. x_using_organization_id NUMBER := p_using_organization_id
  7. x_asl_id NUMBER
  8. x_vendor_product_num VARCHAR2(240) := ''
  9. x_purchasing_uom VARCHAR2(240) := ''
  10. BEGIN
  11. po_autosource_sv.get_asl_info(p_item_id,
  12. p_vendor_id,
  13. p_vendor_site_id,
  14. x_using_organization_id,
  15. x_asl_id,
  16. x_vendor_product_num,
  17. x_purchasing_uom)
  18. RETURN x_vendor_product_num
  19. END

4,看requisition line的料号sql:

  1. 1
  2. 2
  3. 3
  4. 4
  1. SELECT mst.segment1 ' ' mst.description  item_number
  2. FROM po.po_requisition_lines_all b, mtl_system_items_vl mst
  3. WHERE b.item_id = mst.inventory_item_id
  4. AND mst.organization_id = b.destination_organization_id

列出没有销售订单的内部采购订单

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  1. ---used to list all Internal Requisitions that do not have an associated Internal Sales order
  2. SELECT rqh.segment1 req_num,
  3. rql.line_num,
  4. rql.requisition_header_id,
  5. rql.requisition_line_id,
  6. rql.item_id,
  7. rql.unit_meas_lookup_code,
  8. rql.unit_price,
  9. rql.quantity,
  10. rql.quantity_cancelled,
  11. rql.quantity_delivered,
  12. rql.cancel_flag,
  13. rql.source_type_code,
  14. rql.source_organization_id,
  15. rql.destination_organization_id,
  16. rqh.transferred_to_oe_flag
  17. FROM po_requisition_lines_all rql, po_requisition_headers_all rqh
  18. WHERE rql.requisition_header_id = rqh.requisition_header_id
  19. AND rql.source_type_code = 'INVENTORY'
  20. AND rql.source_organization_id IS NOT NULL
  21. AND NOT EXISTS
  22. (SELECT 'existing internal order'
  23. FROM oe_order_lines_all lin
  24. WHERE lin.source_document_line_id = rql.requisition_line_id
  25. AND lin.source_document_type_id = 10)
  26. ORDER BY rqh.requisition_header_id, rql.line_num

关联PR的PO

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  1. -----Relation with Requistion and PO
  2. SELECT r.segment1 "Req Num", p.segment1 "PO Num"
  3. FROM po_headers_all p,
  4. po_distributions_all d,
  5. po_req_distributions_all rd,
  6. po_requisition_lines_all rl,
  7. po_requisition_headers_all r
  8. WHERE p.po_header_id = d.po_header_id
  9. AND d.req_distribution_id = rd.distribution_id
  10. AND rd.requisition_line_id = rl.requisition_line_id
  11. AND rl.requisition_header_id = r.requisition_header_id

所有取消的PR

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  1.  
  2. -----list My cancel Requistion
  3. SELECT prh.requisition_header_id,
  4. prh.preparer_id,
  5. prh.segment1 "REQ NUM",
  6. trunc(prh.creation_date),
  7. prh.description,
  8. prh.note_to_authorizer
  9. FROM apps.po_requisition_headers_all prh, apps.po_action_history pah
  10. WHERE action_code = 'CANCEL'
  11. AND pah.object_type_code = 'REQUISITION'
  12. AND pah.object_id = prh.requisition_header_id

没有PO的Pr

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  1.  
  2.  
  3. -----list all Purchase Requisition without a Purchase order that means a PR has not been autocreated to PO.
  4. SELECT prh.segment1 "PR NUM",
  5. trunc(prh.creation_date) "CreateD ON",
  6. trunc(prl.creation_date) "Line Creation Date",
  7. prl.line_num "Seq #",
  8. msi.segment1 "Item Num",
  9. prl.item_description "Description",
  10. prl.quantity "Qty",
  11. trunc(prl.need_by_date) "Required By",
  12. ppf1.full_name "REQUESTOR",
  13. ppf2.agent_name "BUYER"
  14. FROM po.po_requisition_headers_all prh,
  15. po.po_requisition_lines_all prl,
  16. apps.per_people_f ppf1,
  17. (SELECT DISTINCT agent_id, agent_name FROM apps.po_agents_v) ppf2,
  18. po.po_req_distributions_all prd,
  19. inv.mtl_system_items_b msi,
  20. po.po_line_locations_all pll,
  21. po.po_lines_all pl,
  22. po.po_headers_all ph
  23. WHERE prh.requisition_header_id = prl.requisition_header_id
  24. AND prl.requisition_line_id = prd.requisition_line_id
  25. AND ppf1.person_id = prh.preparer_id
  26. AND prh.creation_date BETWEEN ppf1.effective_start_date AND
  27. ppf1.effective_end_date
  28. AND ppf2.agent_id(+) = msi.buyer_id
  29. AND msi.inventory_item_id = prl.item_id
  30. AND msi.organization_id = prl.destination_organization_id
  31. AND pll.line_location_id(+) = prl.line_location_id
  32. AND pll.po_header_id = ph.po_header_id(+)
  33. AND pll.po_line_id = pl.po_line_id(+)
  34. AND prh.authorization_status = 'APPROVED'
  35. AND pll.line_location_id IS NULL
  36. AND prl.closed_code IS NULL
  37. AND nvl(prl.cancel_flag, 'N') 'Y'
  38. ORDER BY 1, 2

5.在PR转PO过程中的(应该是自动创建里面的数据吧)

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  1.  
  2. ----- List and all data entry from PR till PO
  3.  
  4. SELECT DISTINCT u.description "Requestor",
  5. porh.segment1 AS "Req Number",
  6. trunc(porh.creation_date) "Created On",
  7. pord.last_updated_by,
  8. porh.authorization_status "Status",
  9. porh.description "Description",
  10. poh.segment1 "PO Number",
  11. trunc(poh.creation_date) "PO Creation Date",
  12. poh.authorization_status "PO Status",
  13. trunc(poh.approved_date) "Approved Date"
  14. FROM apps.po_headers_all poh,
  15. apps.po_distributions_all pod,
  16. apps.po_req_distributions_all pord,
  17. apps.po_requisition_lines_all porl,
  18. apps.po_requisition_headers_all porh,
  19. apps.fnd_user u
  20. WHERE porh.requisition_header_id = porl.requisition_header_id
  21. AND porl.requisition_line_id = pord.requisition_line_id
  22. AND pord.distribution_id = pod.req_distribution_id(+)
  23. AND pod.po_header_id = poh.po_header_id(+)
  24. AND porh.created_by = u.user_id
  25. ORDER BY 2

没有自动创建PO成功的PR

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  1. -----list all Purchase Requisition without a Purchase order that means a PR has not been autocreated to PO.
  2. SELECT prh.segment1 "PR NUM",
  3. trunc(prh.creation_date) "CreateD ON",
  4. trunc(prl.creation_date) "Line Creation Date",
  5. prl.line_num "Seq #",
  6. msi.segment1 "Item Num",
  7. prl.item_description "Description",
  8. prl.quantity "Qty",
  9. trunc(prl.need_by_date) "Required By",
  10. ppf1.full_name "REQUESTOR",
  11. ppf2.agent_name "BUYER"
  12. FROM po.po_requisition_headers_all prh,
  13. po.po_requisition_lines_all prl,
  14. apps.per_people_f ppf1,
  15. (SELECT DISTINCT agent_id, agent_name FROM apps.po_agents_v) ppf2,
  16. po.po_req_distributions_all prd,
  17. inv.mtl_system_items_b msi,
  18. po.po_line_locations_all pll,
  19. po.po_lines_all pl,
  20. po.po_headers_all ph
  21. WHERE prh.requisition_header_id = prl.requisition_header_id
  22. AND prl.requisition_line_id = prd.requisition_line_id
  23. AND ppf1.person_id = prh.preparer_id
  24. AND prh.creation_date BETWEEN ppf1.effective_start_date AND
  25. ppf1.effective_end_date
  26. AND ppf2.agent_id(+) = msi.buyer_id
  27. AND msi.inventory_item_id = prl.item_id
  28. AND msi.organization_id = prl.destination_organization_id
  29. AND pll.line_location_id(+) = prl.line_location_id
  30. AND pll.po_header_id = ph.po_header_id(+)
  31. AND pll.po_line_id = pl.po_line_id(+)
  32. AND prh.authorization_status = 'APPROVED'
  33. AND pll.line_location_id IS NULL
  34. AND prl.closed_code IS NULL
  35. AND nvl(prl.cancel_flag, 'N') 'Y'
  36. ORDER BY 1, 2

PR与PO的关联表

PO_DISTRIBUTIONS_ALL =>PO_HEADER_ID, REQ_DISTRIBUTION_ID
PO_HEADERS_ALL=>PO_HEADER_ID, SEGMENT1
PO_REQ_DISTRIBUTIONS_ALL =>DISTRIBUTION_ID, REQUISITION_LINE_ID
PO_REQUISITION_LINES_ALL =>REQUISITION_LINE_ID)
PO_REQUISITION_HEADERS_ALL =>REQUISITION_HEADER_ID, REQUISITION_LINE_ID, SEGMENT1

What you have to make a join on PO_DISTRIBUTIONS_ALL (REQ_DISTRIBUTION_ID) and PO_REQ_DISTRIBUTIONS_ALL (DISTRIBUTION_ID) to see if there is a PO for the req.

你要做的就是将PO_DISTRIBUTIONS_ALL的REQ_DISTRIBUTION_ID与PO_REQ_DISTRIBUTIONS_ALL中的DISTRIBUTION_ID关联,查看看PR是否有对应的PO

未结PO

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  1. ----- List all open PO'S
  2. SELECT h.segment1 "PO NUM",
  3. h.authorization_status "STATUS",
  4. l.line_num "SEQ NUM",
  5. ll.line_location_id,
  6. d.po_distribution_id,
  7. h.type_lookup_code "TYPE"
  8. FROM po.po_headers_all h,
  9. po.po_lines_all l,
  10. po.po_line_locations_all ll,
  11. po.po_distributions_all d
  12. WHERE h.po_header_id = l.po_header_id
  13. AND ll.po_line_id = l.po_line_id
  14. AND ll.line_location_id = d.line_location_id
  15. AND h.closed_date IS NULL
  16. AND h.type_lookup_code NOT IN ('QUOTATION')

List and PO With there approval , invoice and payment details

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  1. ----- List and PO With there approval , invoice and payment details
  2. SELECT a.org_id "ORG ID",
  3. e.segment1 "VENDOR NUM",
  4. e.vendor_name "SUPPLIER NAME",
  5. upper(e.vendor_type_lookup_code) "VENDOR TYPE",
  6. f.vendor_site_code "VENDOR SITE CODE",
  7. f.address_line1 "ADDRESS",
  8. f.city "CITY",
  9. f.country "COUNTRY",
  10. to_char(trunc(d.creation_date)) "PO Date",
  11. d.segment1 "PO NUM",
  12. d.type_lookup_code "PO Type",
  13. c.quantity_ordered "QTY orDERED",
  14. c.quantity_cancelled "QTY CANCELLED",
  15. g.item_id "ITEM ID",
  16. g.item_description "ITEM DESCRIPTION",
  17. g.unit_price "UNIT PRICE",
  18. (nvl(c.quantity_ordered, 0) - nvl(c.quantity_cancelled, 0)) *
  19. nvl(g.unit_price, 0) "PO Line Amount",
  20. (SELECT decode(ph.approved_flag, 'Y', 'Approved')
  21. FROM po.po_headers_all ph
  22. WHERE ph.po_header_id = d.po_header_id) "PO Approved?",
  23. a.invoice_type_lookup_code "INVOICE TYPE",
  24. a.invoice_amount "INVOICE AMOUNT",
  25. to_char(trunc(a.invoice_date)) "INVOICE DATE",
  26. a.invoice_num "INVOICE NUMBER",
  27. (SELECT decode(x.match_status_flag, 'A', 'Approved')
  28. FROM ap.ap_invoice_distributions_all x
  29. WHERE x.invoice_distribution_id = b.invoice_distribution_id) "Invoice Approved?",
  30. a.amount_paid,
  31. h.amount,
  32. h.check_id,
  33. h.invoice_payment_id "Payment Id",
  34. i.check_number "Cheque Number",
  35. to_char(trunc(i.check_date)) "PAYMENT DATE"
  36.  
  37. FROM ap.ap_invoices_all a,
  38. ap.ap_invoice_distributions_all b,
  39. po.po_distributions_all c,
  40. po.po_headers_all d,
  41. po.po_vendors e,
  42. po.po_vendor_sites_all f,
  43. po.po_lines_all g,
  44. ap.ap_invoice_payments_all h,
  45. ap.ap_checks_all i
  46. WHERE a.invoice_id = b.invoice_id
  47. AND b.po_distribution_id = c.
  48. po_distribution_id(+)
  49. AND c.po_header_id = d.po_header_id(+)
  50. AND e.vendor_id(+) = d.vendor_id
  51. AND f.vendor_site_id(+) = d.vendor_site_id
  52. AND d.po_header_id = g.po_header_id
  53. AND c.po_line_id = g.po_line_id
  54. AND a.invoice_id = h.invoice_id
  55. AND h.check_id = i.check_id
  56. AND f.vendor_site_id = i.vendor_site_id
  57. AND c.po_header_id IS NOT NULL
  58. AND a.payment_status_flag = 'Y'
  59. AND d.type_lookup_code != 'BLANKET'
posted on 2011-05-10 22:28  Gutirez  阅读(920)  评论(0)    收藏  举报