Advertisement
tko_pb

mas charis permintaan roll.sql

Mar 10th, 2022
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. select "name",m_warehouse_id  from m_warehouse mw where m_warehouse_id in (1000002,1000011, 1000001)
  3.  
  4. select qtyordered, qtyentered,* from c_orderline co where
  5. c_orderline_id =4164919
  6.  
  7. qtyentered-> qty order
  8. qtyordered -> qty bom
  9.  
  10. -- header
  11.  
  12. select
  13.     cb.c_bpartner_id,
  14.     cb."name" as supplier_name,
  15.     ki.kst_packinglist  as no_packing_list,
  16.     ki.kst_invoicevendor as no_invoice,
  17.     ki.kst_resi as no_receipt,
  18.     ki.kst_invoicevendor_id as no_delivery_order,
  19.     ki.kst_ETDDate::date  as ex_factory_date,
  20.     kie.eta_date::date as eta_date,
  21.     kr.m_warehouse_id as erp_warehouse_id,
  22.     ki.created::date as created_at,
  23.     kr.kst_receipt_id
  24. from kst_invoicevendor ki
  25. join c_bpartner cb on ki.c_bpartner_id = cb.c_bpartner_id
  26. join kst_receipt kr on ki.kst_invoicevendor_id = kr.kst_invoicevendor_id
  27. join kst_invoicevendor_exim kie on ki.kst_invoicevendor_id = kie.kst_invoicevendor_id
  28. where kr.kst_receipt_id =1341040
  29.  
  30. -- line
  31. select
  32.     krl.m_product_id as item_id,
  33.     co.c_order_id, -- c_order_id asal bukan additional
  34.     mpc.isfabric,
  35.     cu.uomsymbol,
  36.     coalesce ((select sum(kst_receiptline.qtyentered) from kst_receiptline  
  37.             join c_orderline on kst_receiptline.c_orderline_id = c_orderline.c_orderline_id
  38.             join c_order on c_orderline.c_order_id = c_order.c_order_id
  39.             where kst_receiptline.kst_receipt_id = krl.kst_receipt_id and kst_receiptline.m_product_id = krl.m_product_id  
  40.             and kst_receiptline.ref_orderline_id is null
  41.             and c_order.c_order_id= co.c_order_id),0) as qty_delivered,
  42.     coalesce ((select sum(kst_receiptline.qtyentered) from kst_receiptline  
  43.             where kst_receiptline.kst_receipt_id = krl.kst_receipt_id and kst_receiptline.m_product_id = krl.m_product_id  
  44.             and kst_receiptline.isfockst = 'Y' ),0) as foc,
  45.     coalesce ((select sum(kst_receiptline.qtyentered) from kst_receiptline  
  46.             where kst_receiptline.kst_receipt_id = krl.kst_receipt_id and kst_receiptline.m_product_id = krl.m_product_id  
  47.             and kst_receiptline.isfockst = 'N' and kst_receiptline.ref_orderline_id > 0),0) as additional,
  48.     krl.kst_receipt_id
  49. from kst_receiptline krl
  50. join kst_receipt kr on krl.kst_receipt_id = kr.kst_receipt_id
  51. join kst_invoicevendor ki on kr.kst_invoicevendor_id = ki.kst_invoicevendor_id
  52. join c_orderline col on krl.c_orderline_id = col.c_orderline_id and (krl.ref_orderline_id is null or krl.ref_orderline_id <1)
  53. join c_order co on col.c_order_id = co.c_order_id
  54. join m_product mp on krl.m_product_id = mp.m_product_id
  55. join m_product_category mpc on mp.m_product_category_id = mpc.m_product_category_id
  56. join c_uom cu on krl.c_uom_id = cu.c_uom_id
  57. where krl.kst_receipt_id =1341040
  58. group by krl.kst_receipt_id,
  59.     krl.m_product_id,
  60.     co.c_order_id,
  61.     mpc.isfabric,
  62.     cu.uomsymbol
  63.  
  64. -- detail roll
  65. select
  66.     krl.kst_noroll as nomor_roll,
  67.     '-' as batch_number,
  68.     cu.uomsymbol as uom,
  69.     sum(qty),
  70.     krl.m_product_id,
  71.     col.c_order_id,
  72.     col.c_orderline_id ,
  73.     krl.kst_receipt_id
  74. from kst_receiptline krl
  75. join c_orderline col on krl.c_orderline_id = col.c_orderline_id
  76. join c_uom cu on krl.c_uom_id = cu.c_uom_id
  77. where krl.kst_receipt_id =1341040
  78. group by krl.m_product_id, krl.kst_receipt_id, krl.kst_noroll, cu.uomsymbol, col.c_orderline_id
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement