Advertisement
henikseptiana15

review query terkait jen-6

Jan 19th, 2022
1,617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SET SEARCH_PATH TO jenindo;
  2.  
  3. SELECT * FROM pu_po
  4. WHERE doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031') AND doc_type_id = 160;
  5. -- 5 rows
  6.  
  7. SELECT * FROM pu_po_balance_invoice
  8. WHERE ref_doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031')
  9. AND ref_doc_type_id = 160;
  10. -- 9 rows
  11.  
  12. SELECT * FROM in_product_price_balance  
  13. WHERE doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031')
  14. AND doc_type_id = 160;
  15. -- 9 rows
  16.  
  17. SELECT * FROM in_log_product_balance_stock
  18. WHERE doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031')
  19. AND doc_type_id = 160;
  20. -- 9 rows
  21.  
  22. SELECT * FROM in_log_product_price_balance_stock
  23. WHERE doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031')
  24. AND doc_type_id = 160;
  25. -- 9 rows
  26.  
  27. SELECT * FROM in_balance_receive_goods_item A  
  28. WHERE EXISTS (SELECT 1 FROM pu_po B
  29.               WHERE A.po_id = B.po_id
  30.               AND A.po_no = B.doc_no
  31.               AND B.doc_type_id = 160
  32.               AND B.doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031'));
  33. -- 9 rows
  34.  
  35. SELECT *
  36. FROM  pu_monthly_price_product
  37. WHERE ref_doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031')
  38. AND ref_doc_type_id = 160;
  39. -- 5 rows
  40.  
  41. SELECT * FROM pu_log_monthly_price_product  
  42. WHERE ref_doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031')
  43. AND ref_doc_type_id = 160;
  44. -- 9 rows
  45.  
  46. SELECT * FROM fi_invoice_ap_balance
  47. WHERE doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031')
  48. AND doc_type_id = 160;
  49. -- 5 rows
  50.  
  51. SELECT * FROM gl_journal_trx A
  52. WHERE EXISTS (SELECT 1 FROM pu_po B
  53.               WHERE A.doc_id = B.po_id
  54.               AND A.doc_no = B.doc_no
  55.               AND B.doc_type_id = 160
  56.               AND B.doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031'));
  57. -- 10 rows
  58.  
  59.  
  60.  
  61. SELECT A.tenant_id, A.ou_bu_id, A.journal_type, LEFT(A.doc_date,6) AS journal_year_month,
  62.        COUNT(A.journal_trx_id) AS total_journal
  63. FROM gl_journal_trx A  
  64. WHERE EXISTS (SELECT 1 FROM pu_po B
  65.               WHERE A.doc_id = B.po_id
  66.               AND A.doc_no = B.doc_no
  67.               AND B.doc_type_id = 160
  68.               AND B.doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031'))
  69. GROUP BY A.tenant_id, A.ou_bu_id, A.journal_type, journal_year_month;
  70.  
  71. WITH temp_data_admin_journal AS (
  72.     SELECT A.tenant_id, A.ou_bu_id, A.journal_type, LEFT(A.doc_date,6) AS journal_year_month,
  73.            COUNT(A.journal_trx_id) AS total_journal
  74.     FROM gl_journal_trx A  
  75.     WHERE EXISTS (SELECT 1 FROM pu_po B
  76.                   WHERE A.doc_id = B.po_id
  77.                   AND A.doc_no = B.doc_no
  78.                   AND B.doc_type_id = 160
  79.                   AND B.doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031'))
  80.     GROUP BY A.tenant_id, A.ou_bu_id, A.journal_type, journal_year_month
  81. )
  82. UPDATE gl_admin_journal_trx A
  83. SET journal_counter = A.journal_counter - B.total_journal
  84. FROM temp_data_admin_journal B
  85. WHERE A.tenant_id = B.tenant_id
  86. AND A.ou_id = B.ou_bu_id
  87. AND A.journal_type = B.journal_type
  88. AND A.journal_year_month = B.journal_year_month;
  89.  
  90. WITH temp_data_admin_journal AS (
  91.     SELECT A.tenant_id, A.ou_bu_id, A.journal_type, LEFT(A.doc_date,6) AS journal_year_month,
  92.            COUNT(A.journal_trx_id) AS total_journal
  93.     FROM gl_journal_trx A  
  94.     WHERE EXISTS (SELECT 1 FROM pu_po B
  95.                   WHERE A.doc_id = B.po_id
  96.                   AND A.doc_no = B.doc_no
  97.                   AND B.doc_type_id = 160
  98.                   AND B.doc_no IN ('HGP-2108-00027','HGP-2108-00028','HGP-2108-00029','HGP-2108-00030','HGP-2108-00031'))
  99.     GROUP BY A.tenant_id, A.ou_bu_id, A.journal_type, journal_year_month
  100. )
  101. UPDATE gl_admin_journal_trx A
  102. SET journal_counter = A.journal_counter + B.total_journal
  103. FROM temp_data_admin_journal B
  104. WHERE A.tenant_id = B.tenant_id
  105. AND A.ou_id = 10
  106. AND A.journal_type = B.journal_type
  107. AND A.journal_year_month = B.journal_year_month;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement