Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. select x.io
  2. , x.subinventory
  3. , x.subinv_desc
  4. , x.item_code
  5. , x.item_desc
  6. , x.item_cost
  7. , x.primary_uom
  8. , sum(case when x.transaction_type = 'S-1 Scrap' then x.quantity end) scrap_quantity
  9. , sum(case when x.transaction_type = 'S-1 Scrap' then x.amount end) scrap_amount
  10. , sum(case when x.transaction_type in ('E-1 Expense Another', 'E-4 Sample Expense') then x.quantity end) expense_quantity
  11. , sum(case when x.transaction_type in ('E-1 Expense Another', 'E-4 Sample Expense') then x.amount end) expense_amount
  12. , x.period_monyy period
  13. from
  14. (select ood.organization_code io
  15. , mmt.subinventory_code subinventory
  16. , ms.description subinv_desc
  17. , msi.segment1 item_code
  18. , msi.description item_desc
  19. , mmt.new_cost item_cost
  20. , msi.primary_uom_code primary_uom
  21. , mtt.transaction_type_name transaction_type
  22. , mmt.transaction_quantity quantity
  23. , mmt.new_cost * mmt.transaction_quantity amount
  24. , mmt.transaction_date
  25. , to_char(mmt.transaction_date, 'YYYY-MM') period_yyyymm
  26. , to_char(mmt.transaction_date, 'MON-YY') period_monyy
  27. from apps.mtl_material_transactions mmt
  28. , apps.org_organization_definitions ood
  29. , apps.mtl_system_items msi
  30. , apps.mtl_secondary_inventories ms
  31. , apps.mtl_transaction_types mtt
  32. where 1=1
  33. and ood.organization_id = mmt.organization_id
  34. and ood.operating_unit = 85
  35. and ood.organization_code <> 'GM0'
  36. and msi.organization_id = mmt.organization_id
  37. and msi.inventory_item_id = mmt.inventory_item_id
  38. and ms.organization_id = mmt.organization_id
  39. and ms.secondary_inventory_name = mmt.subinventory_code
  40. and mtt.transaction_type_id = mmt.transaction_type_id
  41. and mtt.transaction_type_name in (
  42. 'S-1 Scrap'
  43. , 'E-1 Expense Another'
  44. , 'E-4 Sample Expense'
  45. )
  46. and (ood.organization_code = :io_code or :io_code is null)
  47. and (msi.segment1 = :item_code or :item_code is null)
  48. and (mmt.subinventory_code = :subinventory or : subinventory is null)
  49. and (trunc(mmt.transaction_date) >= to_date(:txn_date_from, 'DD/MM/YYYY') or :txn_date_from is null)
  50. and (trunc(mmt.transaction_date) <= to_date(:txn_date_to, 'DD/MM/YYYY') or :txn_date_to is null)
  51. and (to_char(mmt.transaction_date, 'MON-YY') = :period or :period is null)
  52. ) x
  53. group by x.io
  54. , x.subinventory
  55. , x.subinv_desc
  56. , x.item_code
  57. , x.item_desc
  58. , x.item_cost
  59. , x.primary_uom
  60. , x.period_yyyymm
  61. , x.period_monyy
  62. order by x.io
  63. , x.subinventory
  64. , x.item_code
  65. , x.period_yyyymm desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement