总账追朔各模块SQL
SELECT gjh.set_of_books_id, gjl.je_line_num, mta.organization_id, ood.organization_code, ood.organization_name, mtt.transaction_type_name, NULL trx_number, to_char(ooh.order_number) trx_source, trunc(mmt.transaction_date) transaction_date, gcc.concatenated_segments account, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0, 0, NULL)) entered_dr1, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), -1, (-1 * nvl(mta.transaction_value, mta.base_transaction_value)), NULL)) entered_cr1, SUM(decode(sign(mta.base_transaction_value), 1, mta.base_transaction_value, 0, 0, NULL)) accounted_dr1, SUM(decode(sign(mta.base_transaction_value), -1, (-1 * mta.base_transaction_value), NULL)) accounted_cr1, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_cr, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, mta.base_transaction_value, 0)) accounted_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * mta.base_transaction_value, 0)) accounted_cr FROM gl_je_lines gjl, gl_je_headers gjh, gl_code_combinations_kfv gcc, gl_import_references gir, gl_period_statuses gps, mtl_transaction_accounts mta, mtl_material_transactions mmt, mtl_transaction_types mtt, org_organization_definitions ood, oe_order_lines_all ool, oe_order_headers_all ooh WHERE gjl.je_header_id = gjh.je_header_id AND gjl.code_combination_id = gcc.code_combination_id AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.set_of_books_id = gps.set_of_books_id AND gjh.period_name = gps.period_name AND gps.application_id = 401 AND gir.reference_1 = mta.gl_batch_id AND gjl.code_combination_id = mta.reference_account AND mta.transaction_date BETWEEN gps.start_date AND gps.end_date AND mta.transaction_id = mmt.transaction_id AND mmt.transaction_type_id = mtt.transaction_type_id AND mmt.organization_id = ood.organization_id AND -- mtt.transaction_type_name = 'Sales Order Pick' AND ooh.header_id = ool.header_id AND ool.line_id = mmt.trx_source_line_id AND -- gjh.je_source = 'Inventory' AND gjh.je_category = 'MTL' AND -- gjh.period_name = '06-2004' AND gjh.set_of_books_id = 1 AND gjh.je_header_id = 3148 GROUP BY gjh.set_of_books_id, mta.organization_id, ood.organization_code, ood.organization_name, gjl.je_line_num, trunc(mmt.transaction_date), ooh.order_number, mtt.transaction_type_name, gcc.concatenated_segments UNION ALL SELECT gjh.set_of_books_id, gjl.je_line_num, mta.organization_id, ood.organization_code, ood.organization_name, mtt.transaction_type_name, wnd.NAME trx_number, to_char(ooh.order_number) trx_source, trunc(mmt.transaction_date) transaction_date, gcc.concatenated_segments account, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0, 0, NULL)) entered_dr1, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), -1, (-1 * nvl(mta.transaction_value, mta.base_transaction_value)), NULL)) entered_cr1, SUM(decode(sign(mta.base_transaction_value), 1, mta.base_transaction_value, 0, 0, NULL)) accounted_dr1, SUM(decode(sign(mta.base_transaction_value), -1, (-1 * mta.base_transaction_value), NULL)) accounted_cr1, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_cr, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, mta.base_transaction_value, 0)) accounted_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * mta.base_transaction_value, 0)) accounted_cr FROM gl_je_lines gjl, gl_je_headers gjh, gl_code_combinations_kfv gcc, gl_import_references gir, gl_period_statuses gps, mtl_transaction_accounts mta, mtl_material_transactions mmt, mtl_transaction_types mtt, org_organization_definitions ood, oe_order_lines_all ool, wsh_new_deliveries wnd, oe_order_headers_all ooh WHERE gjl.je_header_id = gjh.je_header_id AND gjl.code_combination_id = gcc.code_combination_id AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.set_of_books_id = gps.set_of_books_id AND gjh.period_name = gps.period_name AND gps.application_id = 401 AND gir.reference_1 = mta.gl_batch_id AND gjl.code_combination_id = mta.reference_account AND mta.transaction_date BETWEEN gps.start_date AND gps.end_date AND mta.transaction_id = mmt.transaction_id AND mmt.transaction_type_id = mtt.transaction_type_id AND mmt.organization_id = ood.organization_id AND -- mtt.transaction_type_name = 'Sales order issue' AND mmt.shipment_number = wnd.delivery_id AND ooh.header_id = ool.header_id AND ool.line_id = mmt.trx_source_line_id AND -- gjh.je_source = 'Inventory' AND gjh.je_category = 'MTL' AND -- gjh.period_name = '06-2004' AND gjh.set_of_books_id = 1 AND gjh.je_header_id = 3148 GROUP BY gjh.set_of_books_id, mta.organization_id, ood.organization_code, ood.organization_name, gjl.je_line_num, trunc(mmt.transaction_date), ooh.order_number, wnd.NAME, mtt.transaction_type_name, gcc.concatenated_segments UNION ALL SELECT gjh.set_of_books_id, gjl.je_line_num, mta.organization_id, ood.organization_code, ood.organization_name, mtt.transaction_type_name, rsh.receipt_num trx_number, pha.segment1 trx_source, trunc(mmt.transaction_date) transaction_date, gcc.concatenated_segments account, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0, 0, NULL)) entered_dr1, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), -1, (-1 * nvl(mta.transaction_value, mta.base_transaction_value)), NULL)) entered_cr1, SUM(decode(sign(mta.base_transaction_value), 1, mta.base_transaction_value, 0, 0, NULL)) accounted_dr1, SUM(decode(sign(mta.base_transaction_value), -1, (-1 * mta.base_transaction_value), NULL)) accounted_cr1, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_cr, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, mta.base_transaction_value, 0)) accounted_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * mta.base_transaction_value, 0)) accounted_cr FROM gl_je_lines gjl, gl_je_headers gjh, gl_code_combinations_kfv gcc, gl_import_references gir, gl_period_statuses gps, mtl_transaction_accounts mta, mtl_material_transactions mmt, mtl_transaction_types mtt, org_organization_definitions ood, rcv_transactions rt, rcv_shipment_headers rsh, po_headers_all pha WHERE gjl.je_header_id = gjh.je_header_id AND gjl.code_combination_id = gcc.code_combination_id AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.set_of_books_id = gps.set_of_books_id AND gjh.period_name = gps.period_name AND gps.application_id = 401 AND gir.reference_1 = mta.gl_batch_id AND gjl.code_combination_id = mta.reference_account AND mta.transaction_date BETWEEN gps.start_date AND gps.end_date AND mta.transaction_id = mmt.transaction_id AND mmt.transaction_type_id = mtt.transaction_type_id AND mmt.organization_id = ood.organization_id AND -- mtt.transaction_type_name IN ('PO Receipt', 'PO Rcpt Adjust') AND rt.transaction_id = mmt.rcv_transaction_id AND rt.shipment_header_id = rsh.shipment_header_id AND rt.po_header_id = pha.po_header_id AND -- gjh.je_source = 'Inventory' AND gjh.je_category = 'MTL' AND -- gjh.period_name = '06-2004' AND gjh.set_of_books_id = 1 AND gjh.je_header_id = 3148 GROUP BY gjh.set_of_books_id, mta.organization_id, ood.organization_code, ood.organization_name, gjl.je_line_num, trunc(mmt.transaction_date), rsh.receipt_num, pha.segment1, mtt.transaction_type_name, gcc.concatenated_segments UNION ALL SELECT gjh.set_of_books_id, gjl.je_line_num, mta.organization_id, ood.organization_code, ood.organization_name, mtt.transaction_type_name, to_char(mmt.transaction_set_id) trx_number, mmt.subinventory_code trx_source, trunc(mmt.transaction_date) transaction_date, gcc.concatenated_segments account, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0, 0, NULL)) entered_dr1, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), -1, (-1 * nvl(mta.transaction_value, mta.base_transaction_value)), NULL)) entered_cr1, SUM(decode(sign(mta.base_transaction_value), 1, mta.base_transaction_value, 0, 0, NULL)) accounted_dr1, SUM(decode(sign(mta.base_transaction_value), -1, (-1 * mta.base_transaction_value), NULL)) accounted_cr1, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_cr, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, mta.base_transaction_value, 0)) accounted_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * mta.base_transaction_value, 0)) accounted_cr FROM gl_je_lines gjl, gl_je_headers gjh, gl_code_combinations_kfv gcc, gl_import_references gir, gl_period_statuses gps, mtl_transaction_accounts mta, mtl_material_transactions mmt, mtl_transaction_types mtt, org_organization_definitions ood WHERE gjl.je_header_id = gjh.je_header_id AND gjl.code_combination_id = gcc.code_combination_id AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.set_of_books_id = gps.set_of_books_id AND gjh.period_name = gps.period_name AND gps.application_id = 401 AND gir.reference_1 = mta.gl_batch_id AND gjl.code_combination_id = mta.reference_account AND mta.transaction_date BETWEEN gps.start_date AND gps.end_date AND mta.transaction_id = mmt.transaction_id AND mmt.transaction_type_id = mtt.transaction_type_id AND mmt.organization_id = ood.organization_id AND -- mtt.transaction_type_name IN ('Subinventory Transfer', 'Move Order Transfer', 'Physical Inv Adjust', '富通子库存转移') AND -- gjh.je_source = 'Inventory' AND gjh.je_category = 'MTL' AND -- gjh.period_name = '06-2004' AND gjh.set_of_books_id = 1 AND gjh.je_header_id = 3148 GROUP BY gjh.set_of_books_id, mta.organization_id, ood.organization_code, ood.organization_name, gjl.je_line_num, mmt.transaction_set_id, mmt.subinventory_code, trunc(mmt.transaction_date), mtt.transaction_type_name, gcc.concatenated_segments UNION ALL SELECT gjh.set_of_books_id, gjl.je_line_num, mta.organization_id, ood.organization_code, ood.organization_name, mtt.transaction_type_name, NULL trx_number, mmt.transaction_source_name trx_source, trunc(mmt.transaction_date) transaction_date, gcc.concatenated_segments account, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0, 0, NULL)) entered_dr1, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), -1, (-1 * nvl(mta.transaction_value, mta.base_transaction_value)), NULL)) entered_cr1, SUM(decode(sign(mta.base_transaction_value), 1, mta.base_transaction_value, 0, 0, NULL)) accounted_dr1, SUM(decode(sign(mta.base_transaction_value), -1, (-1 * mta.base_transaction_value), NULL)) accounted_cr1, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_cr, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, mta.base_transaction_value, 0)) accounted_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * mta.base_transaction_value, 0)) accounted_cr FROM gl_je_lines gjl, gl_je_headers gjh, gl_code_combinations_kfv gcc, gl_import_references gir, gl_period_statuses gps, mtl_transaction_accounts mta, mtl_material_transactions mmt, mtl_transaction_types mtt, org_organization_definitions ood WHERE gjl.je_header_id = gjh.je_header_id AND gjl.code_combination_id = gcc.code_combination_id AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.set_of_books_id = gps.set_of_books_id AND gjh.period_name = gps.period_name AND gps.application_id = 401 AND gir.reference_1 = mta.gl_batch_id AND gjl.code_combination_id = mta.reference_account AND mta.transaction_date BETWEEN gps.start_date AND gps.end_date AND mta.transaction_id = mmt.transaction_id AND mmt.transaction_type_id = mtt.transaction_type_id AND mmt.organization_id = ood.organization_id AND -- mtt.transaction_type_name = 'Average cost update' AND -- gjh.je_source = 'Inventory' AND gjh.je_category = 'MTL' AND -- gjh.period_name = '06-2004' AND gjh.set_of_books_id = 1 AND gjh.je_header_id = 3148 GROUP BY gjh.set_of_books_id, mta.organization_id, ood.organization_code, ood.organization_name, gjl.je_line_num, mmt.transaction_source_name, mmt.subinventory_code, trunc(mmt.transaction_date), mtt.transaction_type_name, gcc.concatenated_segments UNION ALL SELECT gjh.set_of_books_id, gjl.je_line_num, mta.organization_id, ood.organization_code, ood.organization_name, mtt.transaction_type_name, rsh.receipt_num trx_number, to_char(ooh.order_number) trx_source, trunc(mmt.transaction_date) transaction_date, gcc.concatenated_segments account, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0, 0, NULL)) entered_dr1, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), -1, (-1 * nvl(mta.transaction_value, mta.base_transaction_value)), NULL)) entered_cr1, SUM(decode(sign(mta.base_transaction_value), 1, mta.base_transaction_value, 0, 0, NULL)) accounted_dr1, SUM(decode(sign(mta.base_transaction_value), -1, (-1 * mta.base_transaction_value), NULL)) accounted_cr1, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_cr, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, mta.base_transaction_value, 0)) accounted_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * mta.base_transaction_value, 0)) accounted_cr FROM gl_je_lines gjl, gl_je_headers gjh, gl_code_combinations_kfv gcc, gl_import_references gir, gl_period_statuses gps, mtl_transaction_accounts mta, mtl_material_transactions mmt, mtl_transaction_types mtt, rcv_transactions rt, rcv_shipment_headers rsh, oe_order_headers_all ooh, org_organization_definitions ood WHERE gjl.je_header_id = gjh.je_header_id AND gjl.code_combination_id = gcc.code_combination_id AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.set_of_books_id = gps.set_of_books_id AND gjh.period_name = gps.period_name AND gps.application_id = 401 AND gir.reference_1 = mta.gl_batch_id AND gjl.code_combination_id = mta.reference_account AND mta.transaction_date BETWEEN gps.start_date AND gps.end_date AND mta.transaction_id = mmt.transaction_id AND mmt.transaction_type_id = mtt.transaction_type_id AND mmt.organization_id = ood.organization_id AND -- mtt.transaction_type_name = 'RMA Receipt' AND rt.transaction_id = mmt.rcv_transaction_id AND rt.shipment_header_id = rsh.shipment_header_id AND rt.oe_order_header_id = ooh.header_id AND -- gjh.je_source = 'Inventory' AND gjh.je_category = 'MTL' AND -- gjh.period_name = '06-2004' AND gjh.set_of_books_id = 1 AND gjh.je_header_id = 3148 GROUP BY gjh.set_of_books_id, mta.organization_id, ood.organization_code, ood.organization_name, gjl.je_line_num, rsh.receipt_num, ooh.order_number, mmt.subinventory_code, trunc(mmt.transaction_date), mtt.transaction_type_name, gcc.concatenated_segments UNION ALL SELECT gjh.set_of_books_id, gjl.je_line_num, mta.organization_id, ood.organization_code, ood.organization_name, mtt.transaction_type_name, to_char(mmt.transaction_set_id) trx_number, mgd.segment1 trx_source, trunc(mmt.transaction_date) transaction_date, gcc.concatenated_segments account, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0, 0, NULL)) entered_dr1, SUM(decode(sign(nvl(mta.transaction_value, mta.base_transaction_value)), -1, (-1 * nvl(mta.transaction_value, mta.base_transaction_value)), NULL)) entered_cr1, SUM(decode(sign(mta.base_transaction_value), 1, mta.base_transaction_value, 0, 0, NULL)) accounted_dr1, SUM(decode(sign(mta.base_transaction_value), -1, (-1 * mta.base_transaction_value), NULL)) accounted_cr1, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * nvl(mta.transaction_value, mta.base_transaction_value), 0)) entered_cr, SUM(decode(sign(nvl(gjl.accounted_dr, 0)), 1, mta.base_transaction_value, 0)) accounted_dr, SUM(decode(sign(nvl(gjl.accounted_cr, 0)), 1, -1 * mta.base_transaction_value, 0)) accounted_cr FROM gl_je_lines gjl, gl_je_headers gjh, gl_code_combinations_kfv gcc, gl_import_references gir, gl_period_statuses gps, mtl_transaction_accounts mta, mtl_material_transactions mmt, mtl_transaction_types mtt, org_organization_definitions ood, MTL_GENERIC_DISPOSITIONS mgd WHERE gjl.je_header_id = gjh.je_header_id AND gjl.code_combination_id = gcc.code_combination_id AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.set_of_books_id = gps.set_of_books_id AND gjh.period_name = gps.period_name AND gps.application_id = 401 AND gir.reference_1 = mta.gl_batch_id AND gjl.code_combination_id = mta.reference_account AND mta.transaction_date BETWEEN gps.start_date AND gps.end_date AND mta.transaction_id = mmt.transaction_id AND mmt.transaction_type_id = mtt.transaction_type_id AND mmt.organization_id = ood.organization_id AND -- mtt.transaction_type_name NOT IN ('Sales Order Pick', 'Sales order issue', 'PO Receipt', 'PO Rcpt Adjust', 'Subinventory Transfer', 'Move Order Transfer', 'Physical Inv Adjust', '富通子库存转移', 'Average cost update', 'RMA Receipt') AND mmt.transaction_source_id = mgd.disposition_id AND mgd.organization_id = mmt.organization_id AND -- gjh.je_source = 'Inventory' AND gjh.je_category = 'MTL' AND -- gjh.period_name = '06-2004' AND gjh.set_of_books_id = 1 AND gjh.je_header_id = 3148 GROUP BY gjh.set_of_books_id, mta.organization_id, ood.organization_code, ood.organization_name, gjl.je_line_num, mmt.transaction_set_id, mgd.segment1, trunc(mmt.transaction_date), mtt.transaction_type_name, gcc.concatenated_segments ORDER BY 2
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。