SELECT *
FROM ( SELECT mkv.CONCATENATED_SEGMENTS category,
gjb.NAME batch_name,
gjh.NAME journal_name,
DECODE (:P_GROUP_BY,
'Item', '''' || msib.segment1 || '''',
'Category', NULL,
NULL)
item_code,
SUM (mmt.TRANSACTION_QUANTITY) TRANSACTION_QUANTITY,
-- DECODE ( :P_GROUP_BY , 'Item' ,SUM ( mmt.TRANSACTION_QUANTITY ) , 'Category' , NULL , NULL ) TRANSACTION_QUANTITY,
SUM (xal.accounted_dr) accounted_dr,
SUM (xal.accounted_cr) accounted_cr
FROM apps.gl_je_headers gjh,
apps.gl_je_lines gjl,
apps.gl_je_batches gjb,
apps.gl_import_references gir,
xla.xla_ae_lines xal,
xla.xla_ae_headers xah,
xla.xla_transaction_entities xte,
apps.mtl_material_transactions mmt,
apps.mtl_system_items_b msib,
apps.gl_code_combinations_kfv gcc,
apps.mtl_parameters mp,
mtl_categories_kfv mkv,
mtl_item_categories mic,
apps.mtl_transaction_types mtt --, GL_JE_BATCHES_HEADERS_V gjv
WHERE gjh.je_header_id = gjl.je_header_id
AND gjh.je_header_id = gir.je_header_id
AND gir.je_header_id = gjl.je_header_id
AND gir.je_line_num = gjl.je_line_num
AND gjb.je_batch_id = gir.je_batch_id
-- AND gjl.period_name = 'AUG-12-13'
AND gir.gl_sl_link_id = xal.gl_sl_link_id
AND xal.ae_header_id = xah.ae_header_id
AND xal.application_id = '707'
AND xah.application_id = '707'
AND xte.application_id = '707'
AND xal.ACCOUNTING_CLASS_CODE = 'INVENTORY_VALUATION'
AND xah.entity_id = xte.entity_id
AND xte.source_id_int_1 = mmt.transaction_id
AND mtt.transaction_type_id = mmt.transaction_type_id
AND mmt.inventory_item_id = msib.inventory_item_id
AND mmt.organization_id = msib.organization_id
AND mp.organization_id = mmt.organization_id
AND mp.ORGANIZATION_CODE = 'UAE'
AND gcc.segment3 IN (100510)
AND gjl.code_combination_id = gcc.code_combination_id
AND gjh.JE_SOURCE = 'Cost Management'
AND mic.inventory_item_id = msib.inventory_item_id
AND mic.category_id = mkv.category_id
AND mic.organization_id = mmt.organization_id
AND TRUNC (mmt.TRANSACTION_DATE) BETWEEN --NVL (
TO_DATE (
:P_DATE_FROM,
'YYYY/MM/DD HH24:MI:SS') -- ,TO_DATE ( '01/01/2000', 'DD/MM/YYYY' ) )
AND --NVL (
TO_DATE (
:P_DATE_TO,
'YYYY/MM/DD HH24:MI:SS') -- ,TO_DATE ( '01/01/2050', 'DD/MM/YYYY' ) )
-- AND TRUNC ( mmt.TRANSACTION_DATE ) BETWEEN :P_DATE_FROM AND :P_DATE_TO
-- AND gjh.NAME = 'Jan-15 Inventory EUR'
-- AND gjb.NAME = 'Cost Management A 32432 3878403'
-- AND mkv.CONCATENATED_SEGMENTS = 'Children.Accessories.Default'
-- AND gjh.je_header_id =26
GROUP BY gjb.NAME,
gjh.NAME,
mkv.CONCATENATED_SEGMENTS,
DECODE (:P_GROUP_BY,
'Item', '''' || msib.segment1 || '''',
'Category', NULL,
NULL))
UNION ALL
SELECT 'Manual',
gjb.NAME batch_name,
gjh.NAME journal_name,
NULL Item_code,
NULL TRANSACTION_QUANTITY,
SUM (gjl.ACCOUNTED_DR) gl_line_debit,
SUM (gjl.ACCOUNTED_CR) gl_line_credit
FROM apps.gl_je_headers gjh,
apps.gl_je_lines gjl,
apps.gl_je_batches gjb,
apps.gl_code_combinations_kfv gcc
WHERE gjh.je_header_id = gjl.je_header_id
AND gjb.je_batch_id = gjh.je_batch_id
AND gjl.code_combination_id = gcc.code_combination_id
AND gcc.segment3 IN (100510)
AND gcc.segment1 IN (002)
AND gjh.je_source = 'Manual'
AND gjh.status = 'P'
AND gjl.status = 'P'
-- AND gjh.period_name = 'Jan-15'
AND gjh.period_name IN
(SELECT PERIOD_NAME
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME = 'Accounting'
AND ADJUSTMENT_PERIOD_FLAG = 'N'
AND PERIOD_YEAR BETWEEN (SELECT PERIOD_YEAR
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_FROM)
AND (SELECT PERIOD_YEAR
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_TO)
AND PERIOD_NUM BETWEEN (SELECT PERIOD_NUM
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_FROM)
AND (SELECT PERIOD_NUM
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_TO))
GROUP BY gjb.NAME, gjh.NAME
FROM ( SELECT mkv.CONCATENATED_SEGMENTS category,
gjb.NAME batch_name,
gjh.NAME journal_name,
DECODE (:P_GROUP_BY,
'Item', '''' || msib.segment1 || '''',
'Category', NULL,
NULL)
item_code,
SUM (mmt.TRANSACTION_QUANTITY) TRANSACTION_QUANTITY,
-- DECODE ( :P_GROUP_BY , 'Item' ,SUM ( mmt.TRANSACTION_QUANTITY ) , 'Category' , NULL , NULL ) TRANSACTION_QUANTITY,
SUM (xal.accounted_dr) accounted_dr,
SUM (xal.accounted_cr) accounted_cr
FROM apps.gl_je_headers gjh,
apps.gl_je_lines gjl,
apps.gl_je_batches gjb,
apps.gl_import_references gir,
xla.xla_ae_lines xal,
xla.xla_ae_headers xah,
xla.xla_transaction_entities xte,
apps.mtl_material_transactions mmt,
apps.mtl_system_items_b msib,
apps.gl_code_combinations_kfv gcc,
apps.mtl_parameters mp,
mtl_categories_kfv mkv,
mtl_item_categories mic,
apps.mtl_transaction_types mtt --, GL_JE_BATCHES_HEADERS_V gjv
WHERE gjh.je_header_id = gjl.je_header_id
AND gjh.je_header_id = gir.je_header_id
AND gir.je_header_id = gjl.je_header_id
AND gir.je_line_num = gjl.je_line_num
AND gjb.je_batch_id = gir.je_batch_id
-- AND gjl.period_name = 'AUG-12-13'
AND gir.gl_sl_link_id = xal.gl_sl_link_id
AND xal.ae_header_id = xah.ae_header_id
AND xal.application_id = '707'
AND xah.application_id = '707'
AND xte.application_id = '707'
AND xal.ACCOUNTING_CLASS_CODE = 'INVENTORY_VALUATION'
AND xah.entity_id = xte.entity_id
AND xte.source_id_int_1 = mmt.transaction_id
AND mtt.transaction_type_id = mmt.transaction_type_id
AND mmt.inventory_item_id = msib.inventory_item_id
AND mmt.organization_id = msib.organization_id
AND mp.organization_id = mmt.organization_id
AND mp.ORGANIZATION_CODE = 'UAE'
AND gcc.segment3 IN (100510)
AND gjl.code_combination_id = gcc.code_combination_id
AND gjh.JE_SOURCE = 'Cost Management'
AND mic.inventory_item_id = msib.inventory_item_id
AND mic.category_id = mkv.category_id
AND mic.organization_id = mmt.organization_id
AND TRUNC (mmt.TRANSACTION_DATE) BETWEEN --NVL (
TO_DATE (
:P_DATE_FROM,
'YYYY/MM/DD HH24:MI:SS') -- ,TO_DATE ( '01/01/2000', 'DD/MM/YYYY' ) )
AND --NVL (
TO_DATE (
:P_DATE_TO,
'YYYY/MM/DD HH24:MI:SS') -- ,TO_DATE ( '01/01/2050', 'DD/MM/YYYY' ) )
-- AND TRUNC ( mmt.TRANSACTION_DATE ) BETWEEN :P_DATE_FROM AND :P_DATE_TO
-- AND gjh.NAME = 'Jan-15 Inventory EUR'
-- AND gjb.NAME = 'Cost Management A 32432 3878403'
-- AND mkv.CONCATENATED_SEGMENTS = 'Children.Accessories.Default'
-- AND gjh.je_header_id =26
GROUP BY gjb.NAME,
gjh.NAME,
mkv.CONCATENATED_SEGMENTS,
DECODE (:P_GROUP_BY,
'Item', '''' || msib.segment1 || '''',
'Category', NULL,
NULL))
UNION ALL
SELECT 'Manual',
gjb.NAME batch_name,
gjh.NAME journal_name,
NULL Item_code,
NULL TRANSACTION_QUANTITY,
SUM (gjl.ACCOUNTED_DR) gl_line_debit,
SUM (gjl.ACCOUNTED_CR) gl_line_credit
FROM apps.gl_je_headers gjh,
apps.gl_je_lines gjl,
apps.gl_je_batches gjb,
apps.gl_code_combinations_kfv gcc
WHERE gjh.je_header_id = gjl.je_header_id
AND gjb.je_batch_id = gjh.je_batch_id
AND gjl.code_combination_id = gcc.code_combination_id
AND gcc.segment3 IN (100510)
AND gcc.segment1 IN (002)
AND gjh.je_source = 'Manual'
AND gjh.status = 'P'
AND gjl.status = 'P'
-- AND gjh.period_name = 'Jan-15'
AND gjh.period_name IN
(SELECT PERIOD_NAME
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME = 'Accounting'
AND ADJUSTMENT_PERIOD_FLAG = 'N'
AND PERIOD_YEAR BETWEEN (SELECT PERIOD_YEAR
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_FROM)
AND (SELECT PERIOD_YEAR
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_TO)
AND PERIOD_NUM BETWEEN (SELECT PERIOD_NUM
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_FROM)
AND (SELECT PERIOD_NUM
FROM GL_PERIODS gl
WHERE PERIOD_SET_NAME =
'Accounting'
AND ADJUSTMENT_PERIOD_FLAG =
'N'
AND PERIOD_NAME =
:P_PERIOD_TO))
GROUP BY gjb.NAME, gjh.NAME
No comments:
Post a Comment