Advertisement
henikseptiana15

script update tax no

Aug 12th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- A. Sehubungan 5 tax_no yg di email
  2.     -- 1. Cek apakah dari daftar tax no yg di email sudah dipakai di invoice
  3.     SELECT * FROM m_gen_tax_number
  4.     WHERE tax_no IN ('017-17.89289593', '017-17.89289592', '017-17.89289594', '017-17.89289591', '017-17.89289595')
  5.  
  6.     -- 2. update m_gen_tax_number dengan info dari invoice yg terkait
  7.     --    a. '017-17.89289593': 19589/17/AI-CL/YM/KM
  8.           SELECT * FROM sl_invoice WHERE doc_no = '19589/17/AI-CL/YM/KM' AND doc_type_id = 321;
  9.          
  10.           UPDATE m_gen_tax_number  A SET
  11.             invoice_id = B.invoice_id,
  12.             invoice_doc_type_id = B.doc_type_id,
  13.             invoice_doc_no = B.doc_no,
  14.             invoice_doc_date = B.doc_date,
  15.             update_user_id = -3,
  16.             update_datetime = '20170812152500',
  17.             version = A.version + 1
  18.           FROM sl_invoice B
  19.           WHERE A.tenant_id = 10
  20.             AND A.tax_no = '017-17.89289593'
  21.             AND B.doc_no = '19589/17/AI-CL/YM/KM'
  22.             AND B.doc_type_id = 321;
  23.        
  24.     --    b. '017-17.89289592': 19647/17/AI-CL/YM/KM
  25.           SELECT * FROM sl_invoice WHERE doc_no = '19647/17/AI-CL/YM/KM' AND doc_type_id = 321;
  26.          
  27.           UPDATE m_gen_tax_number  A SET
  28.             invoice_id = B.invoice_id,
  29.             invoice_doc_type_id = B.doc_type_id,
  30.             invoice_doc_no = B.doc_no,
  31.             invoice_doc_date = B.doc_date,
  32.             update_user_id = -3,
  33.             update_datetime = '20170812152500',
  34.             version = A.version + 1
  35.           FROM sl_invoice B
  36.           WHERE A.tenant_id = 10
  37.             AND A.tax_no = '017-17.89289592'
  38.             AND B.doc_no = '19647/17/AI-CL/YM/KM'
  39.             AND B.doc_type_id = 321;
  40.        
  41.     --    c. '017-17.89289594': 19686/17/AI-CL/YM/KM
  42.           SELECT * FROM sl_invoice WHERE doc_no = '19686/17/AI-CL/YM/KM' AND doc_type_id = 321;
  43.          
  44.           UPDATE m_gen_tax_number  A SET
  45.             invoice_id = B.invoice_id,
  46.             invoice_doc_type_id = B.doc_type_id,
  47.             invoice_doc_no = B.doc_no,
  48.             invoice_doc_date = B.doc_date,
  49.             update_user_id = -3,
  50.             update_datetime = '20170812152500',
  51.             version = A.version + 1
  52.           FROM sl_invoice B
  53.           WHERE A.tenant_id = 10
  54.             AND A.tax_no = '017-17.89289594'
  55.             AND B.doc_no = '19686/17/AI-CL/YM/KM'
  56.             AND B.doc_type_id = 321;
  57.                  
  58.     --    d. '017-17.89289591': 21456/17/AI-CL/IL/KM
  59.           SELECT * FROM sl_invoice WHERE doc_no = '21456/17/AI-CL/IL/KM' AND doc_type_id = 321;
  60.          
  61.           UPDATE m_gen_tax_number  A SET
  62.             invoice_id = B.invoice_id,
  63.             invoice_doc_type_id = B.doc_type_id,
  64.             invoice_doc_no = B.doc_no,
  65.             invoice_doc_date = B.doc_date,
  66.             update_user_id = -3,
  67.             update_datetime = '20170812152500',
  68.             version = A.version + 1
  69.           FROM sl_invoice B
  70.           WHERE A.tenant_id = 10
  71.             AND A.tax_no = '017-17.89289591'
  72.             AND B.doc_no = '21456/17/AI-CL/IL/KM'
  73.             AND B.doc_type_id = 321;
  74.                  
  75.     --    e. '017-17.89289595': 21446/17/AI-CL/IL/KM
  76.           SELECT * FROM sl_invoice WHERE doc_no = '21446/17/AI-CL/IL/KM' AND doc_type_id = 321;
  77.          
  78.           UPDATE m_gen_tax_number  A SET
  79.             invoice_id = B.invoice_id,
  80.             invoice_doc_type_id = B.doc_type_id,
  81.             invoice_doc_no = B.doc_no,
  82.             invoice_doc_date = B.doc_date,
  83.             update_user_id = -3,
  84.             update_datetime = '20170812152500',
  85.             version = A.version + 1
  86.           FROM sl_invoice B
  87.           WHERE A.tenant_id = 10
  88.             AND A.tax_no = '017-17.89289595'
  89.             AND B.doc_no = '21446/17/AI-CL/IL/KM'
  90.             AND B.doc_type_id = 321;
  91.  
  92.     -- 3. update m_gen_tax_number dengan info dari invoice yg terkait
  93.         UPDATE sl_invoice_tax A SET
  94.             tax_no = '010.'||C.tax_no,
  95.             update_user_id = -3,
  96.             update_datetime = '20170812152500',
  97.             version = A.version + 1
  98.         FROM sl_invoice B, m_gen_tax_number C
  99.         WHERE A.invoice_id = B.invoice_id
  100.             AND B.doc_type_id = 321
  101.             AND B.tenant_id = C.tenant_id
  102.             AND B.invoice_id = C.invoice_id
  103.             AND B.doc_type_id = C.invoice_doc_type_id
  104.             AND C.tax_no IN ('017-17.89289593', '017-17.89289592', '017-17.89289594', '017-17.89289591', '017-17.89289595');
  105.    
  106.    
  107. -----------------------------------------------------------------------------------------------------------------------------------------
  108. -- B. Sehubungan 6 partner yg di issue KAT-168   
  109.     -- 1. Get data invoice 6 partner tsb
  110.         SELECT f_get_partner_code(partner_id) AS partner_code, f_get_partner_name(partner_id) AS partner_name,
  111.             A.invoice_id, A.invoice_tax_id, A.tax_no, A.tax_date,
  112.             ROW_NUMBER() OVER (ORDER BY f_get_partner_code(partner_id), A.tax_date) AS nomor_data_invoice, A.*
  113.         FROM sl_invoice_tax A
  114.         INNER JOIN sl_invoice B ON A.invoice_id = B.invoice_id
  115.         WHERE B.doc_type_id = 321
  116.             AND B.doc_date BETWEEN '20170701' and '20170731'
  117.             AND B.partner_id IN (300646,300244,302212,300200,300184,302199)
  118.         ORDER BY partner_code, A.tax_date;
  119.        
  120.     -- 2. Update data m_gen_tax_number , untuk booked invoice-invoice yg ingin diupdate
  121.        
  122.         WITH data_gen_tax_number AS (
  123.             -- get data tax_no yg belum dipakai
  124.             SELECT ROW_NUMBER() OVER (ORDER BY tax_no) AS nomor_tax_number,
  125.                 tenant_id, gen_tax_number_id, tax_no
  126.             FROM m_gen_tax_number
  127.             WHERE invoice_id = -99
  128.                 AND year::text = '2017'
  129.                 AND tenant_id = 10
  130.             ORDER BY tax_no
  131.         ), data_invoice AS (
  132.             -- get data invoice dari partner-partner yg dilaporkan untuk bulan juli 2017
  133.             SELECT f_get_partner_code(partner_id) AS partner_code, f_get_partner_name(partner_id) AS partner_name,
  134.                 A.tenant_id, A.invoice_id, B.doc_type_id, B.doc_no, B.doc_date,
  135.                 A.invoice_tax_id, A.tax_no, A.tax_date,
  136.                 ROW_NUMBER() OVER (ORDER BY f_get_partner_code(partner_id), A.tax_date) AS nomor_data_invoice
  137.             FROM sl_invoice_tax A
  138.             INNER JOIN sl_invoice B ON A.invoice_id = B.invoice_id
  139.             WHERE B.doc_type_id = 321
  140.                 AND B.doc_date BETWEEN '20170701' and '20170731'
  141.                 AND B.partner_id IN (300646,300244,302212,300200,300184,302199)
  142.             ORDER BY partner_code, A.tax_date
  143.         )
  144.             -- update m_gen_tax_number
  145.             UPDATE m_gen_tax_number A SET
  146.                 invoice_id = C.invoice_id,
  147.                 invoice_doc_type_id = C.doc_type_id,
  148.                 invoice_doc_no = C.doc_no,
  149.                 invoice_doc_date = C.doc_date,
  150.                 update_user_id = -3,
  151.                 update_datetime = '20170812152500',
  152.                 version = A.version + 1
  153.             FROM data_gen_tax_number B, data_invoice C
  154.             WHERE A.gen_tax_number_id = B.gen_tax_number_id
  155.                 AND B.tenant_id = C.tenant_id
  156.                 AND B.nomor_tax_number = C.nomor_data_invoice;
  157.  
  158.     -- 3. Update tax_no di sl_invoice_tax berdasarkan tax_no yg sudah di booking sebelumnya di m_gen_tax_number
  159.         UPDATE sl_invoice_tax A SET
  160.             tax_no = '010.'||C.tax_no,
  161.             update_user_id = -3,
  162.             update_datetime = '20170812152500',
  163.             version = A.version + 1
  164.         FROM sl_invoice B, m_gen_tax_number C
  165.         WHERE A.invoice_id = B.invoice_id
  166.             AND B.doc_type_id = 321
  167.             AND B.tenant_id = C.tenant_id
  168.             AND B.invoice_id = C.invoice_id
  169.             AND B.doc_type_id = C.invoice_doc_type_id
  170.             AND B.partner_id IN (300646,300244,302212,300200,300184,302199)
  171.             AND B.doc_date BETWEEN '20170701' and '20170731'
  172.             AND C.update_user_id = -3
  173.             AND C.update_datetime = '20170812152500';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement