Friday, January 9, 2015

SQL for AR Invoice Balance

-- SQL to Figure out the Invoice Balance.
SELECT rta.TRX_NUMBER ,xxfact.* ,ps.amount_due_remaining-- NVL (SUM (ps.amount_due_remaining), 0) invoice_balance
FROM ra_cust_trx_types_all rtt,
ra_customer_trx_all rta,
ra_cust_trx_line_gl_dist_all rgld,
gl_code_combinations cc,
hz_cust_accounts_all cust_acct,
ar_payment_schedules_all ps,
hz_cust_acct_sites_all acct_site,
hz_party_sites party_site,
hz_locations loc,
hz_cust_site_uses_all site_uses,
BOLINF.XX_MTSN_AR_FACTS_HDR_STG  xxfact
WHERE xxfact.PROCESS_STATUS='P'
and rta.TRX_NUMBER =xxfact.invoice_number
and rta.TRX_NUMBER in(
'9607549','9607549','9553904','9539375',
'8585991','8253017','7609696',
'7080387','6653404','5313598',
'4785453','3965052','3429136',
'3399680','2871815','2675303',
'2455262','2186174','1660375')
--TRUNC (ps.gl_date) <= :p_as_of_date
--AND cust_acct.account_number = :p_account_number
AND ps.customer_id = cust_acct.cust_account_id
AND ps.cust_trx_type_id = rtt.cust_trx_type_id
--AND ps.trx_date <= :p_as_of_date
AND ps.CLASS NOT IN ('CM', 'PMT')
AND site_uses.site_use_code = 'BILL_TO'
AND acct_site.party_site_id = party_site.party_site_id
AND loc.location_id = party_site.location_id
AND NVL (site_uses.status, 'A') = 'A'
AND cust_acct.cust_account_id = acct_site.cust_account_id
AND acct_site.cust_acct_site_id = site_uses.cust_acct_site_id
AND ps.customer_id = acct_site.cust_account_id
AND ps.customer_site_use_id = site_uses.site_use_id
AND rta.customer_trx_id = ps.customer_trx_id
AND rta.customer_trx_id = rgld.customer_trx_id
AND rgld.code_combination_id = cc.code_combination_id AND rgld.account_class = 'REV'

--------------------------------------------------
-- Query for Credit Memo Balance

SELECT NVL (SUM (ps.amount_due_remaining), 0) cr_memo_balance
FROM ra_cust_trx_types_all rtt,
ra_customer_trx_all rta,
ra_cust_trx_line_gl_dist_all rgld,
gl_code_combinations cc,
hz_cust_accounts_all cust_acct,
ar_payment_schedules_all ps,
hz_cust_acct_sites_all acct_site,
hz_party_sites party_site,
hz_locations loc,
hz_cust_site_uses_all site_uses
WHERE TRUNC (ps.gl_date) <= :p_as_of_date
AND cust_acct.account_number = :p_account_number
AND ps.customer_id = cust_acct.cust_account_id
AND ps.cust_trx_type_id = rtt.cust_trx_type_id
AND ps.trx_date <= :p_as_of_date
AND ps.CLASS = 'CM'
AND ps.status = 'OP'
AND site_uses.site_use_code = 'BILL_TO'
AND site_uses.cust_acct_site_id = acct_site.cust_acct_site_id
AND acct_site.party_site_id = party_site.party_site_id
AND loc.location_id = party_site.location_id
AND NVL (site_uses.status, 'A') = 'A'
AND cust_acct.cust_account_id = acct_site.cust_account_id
AND acct_site.cust_acct_site_id = site_uses.cust_acct_site_id
AND ps.customer_id = acct_site.cust_account_id
AND ps.customer_site_use_id = site_uses.site_use_id
AND rta.customer_trx_id = ps.customer_trx_id
AND rta.customer_trx_id = rgld.customer_trx_id
AND rgld.code_combination_id = cc.code_combination_id
AND rgld.account_class = 'REV'

Saturday, September 6, 2014

O2C

order to cash process steps can be listed as below
  • Enter the Sales Order
  • Book the Sales Order
  • Launch Pick Release
  • Ship Confirm
  • Create Invoice
  • Create the Receipts either manually or using Auto Lockbox ( In this article we will concentrate on Manual creation)
  • Transfer to General Ledger
  • Journal Import
  • Posting
  • O2C Query 
  • SELECT hp.party_name customer
  •       ,hca.account_number
          ,hp.party_number
          ,ooh.order_number
          ,ooh.flow_status_code Order_status
          ,rcta.trx_date Invoice_date
          ,rcta.trx_number Invoice_number
          ,rcta.status_trx Invoice_Status
          ,rcta.invoice_currency_code Invoice_currency
          ,rctla.line_number
          ,msi.segment1 Item_number
          ,rctla.description
          ,rctla.extended_amount line_amt
          ,arp.amount_due_original
          ,arp.amount_due_remaining
          ,rcta.org_id
          ,rcta.customer_trx_id
      FROM RA_CUSTOMER_TRX_ALL RCTA,
           RA_CUSTOMER_TRX_LINES_ALL RCTLA,
           RA_CUST_TRX_TYPES_ALL rctt,
           AR_PAYMENT_SCHEDULES_ALL arp,
           HZ_CUST_ACCOUNTS_ALL HCA,
           HZ_PARTIES HP,
           MTL_SYSTEM_ITEMS_B msi,
           OE_ORDER_LINES_ALL ool,
           OE_ORDER_HEADERS_ALL ooh
    WHERE rcta.customer_trx_id = rctla.customer_trx_id
      AND msi.inventory_item_id = rctla.inventory_item_id
      AND msi.organization_id = 116
      AND rcta.cust_trx_type_id = rctt.cust_trx_type_id
      AND arp.customer_trx_id = rcta.customer_trx_id
      AND rctla.line_type =  'LINE'
      AND rcta.org_id = rctla.org_id
      AND rcta.bill_to_customer_id = hca.cust_account_id
      AND hca.party_id = hp.party_id
      AND rctla.interface_line_attribute6 = ool.line_id
      AND ool.header_id = ooh.header_id
    --  AND ooh.order_number = '13904756'
    --  AND hp.party_name = 'BANQUE MAGNETIQUE'
    ORDER BY hp.party_name,rcta.trx_number,rctla.line_number;
  • Enter the Sales Order:
    Navigation: Order Management Super User Operations (USA)>Orders Returns >Sales Orders
    Enter the Customer details (Ship to and Bill to address), Order type.
Click on Lines Tab. Enter the Item to be ordered and the quantity required.
Line is scheduled automatically when the Line Item is saved.
Scheduling/unscheduling can be done manually by selecting Schedule/Un schedule from the Actions Menu.
You can check if the item to be ordered is available in the Inventory by clicking on Availability Button.
Save the work.
Underlying Tables affected:
In Oracle, Order information is maintained at the header and line level.
The header information is stored in OE_ORDER_HEADERS_ALL and the line information in OE_ORDER_LINES_ALL when the order is entered. The column called FLOW_STATUS_CODE is available in both the headers and lines tables which tell us the status of the order at each stage.
At this stage, the FLOW_STATUS_CODE in OE_ORDER_HEADERS_ALL is ‘Entered’
Book the Sales Order:
Book the Order by clicking on the Book Order button.
Now that the Order is BOOKED, the status on the header is change accordingly.
Underlying tables affected:
At this stage:
The FLOW_STATUS_CODE in the table OE_ORDER_HEADERS_ALL would be
‘BOOKED’
The FLOW_STATUS_CODE in OE_ORDER_LINES_ALL will be
‘AWAITING_SHIPPING’.
Record(s) will be created in the table WSH_DELIVERY_DETAILS with
RELEASED_STATUS=’R’ (Ready to Release)
Also Record(s) will be inserted into WSH_DELIVERY_ASSIGNMENTS.
At the same time DEMAND INTERFACE PROGRAM runs in the background and inserts
into MTL_DEMAND
Launch Pick Release:
Navigation: Shipping > Release Sales Order > Release Sales Orders.
Key in Based on Rule and Order Number
In the Shipping Tab key in the below:
Auto Create Delivery: Yes
Auto Pick Confirm: Yes
Auto Pack Delivery: Yes
In the Inventory Tab:
Auto Allocate: Yes
Enter the Warehouse
Click on Execute Now Button.
On successful completion, the below message would pop up as shown below.
Pick Release process in turn will kick off several other requests like Pick Slip Report,
Shipping Exception Report and Auto Pack Report
Underlying Tables affected:
If Autocreate Delivery is set to ‘Yes’ then a new record is created in the table WSH_NEW_DELIVERIES.
DELIVERY_ID is populated in the table WSH_DELIVERY_ASSIGNMENTS.
The RELEASED_STATUS in WSH_DELIVERY_DETAILS would be now set to ‘Y’ (Pick Confirmed) if Auto Pick Confirm is set to Yes otherwise RELEASED_STATUS is ‘S’ (Release to Warehouse).
Pick Confirm the Order:
IF Auto Pick Confirm in the above step is set to NO, then the following should be done.
Navigation: Inventory Super User > Move Order> Transact Move Order
In the HEADER tab, enter the BATCH NUMBER (from the above step) of the order. Click FIND. Click on VIEW/UPDATE Allocation, then Click TRANSACT button. Then Transact button will be deactivated then just close it and go to next step.
Ship Confirm the Order:
Navigation: Order Management Super User>Shipping >Transactions.
Query with the Order Number.
Click On Delivery Tab
Click on Ship Confirm.
The Status in Shipping Transaction screen will now be closed.
This will kick off concurrent programs like.INTERFACE TRIP Stop, Commercial Invoice, Packing Slip Report, Bill of Lading
Underlying tables affected:
RELEASED_STATUS in WSH_DELIVERY_DETAILS would be ‘C’ (Ship Confirmed)
FLOW_STATUS_CODE in OE_ORDER_HEADERS_ALL would be “BOOKED”
FLOW_STATUS_CODE in OE_ORDER_LINES_ALL would be “SHIPPED”
Create Invoice:
Run workflow background Process.
Navigation: Order Management >view >Requests
Workflow Background Process inserts the records RA_INTERFACE_LINES_ALL with
INTERFACE_LINE_CONTEXT     =     ‘ORDER ENTRY’
INTERFACE_LINE_ATTRIBUTE1=     Order_number
INTERFACE_LINE_ATTRIBUTE3=     Delivery_id
and spawns Auto invoice Master Program and Auto invoice import program which creates Invoice for that particular Order.
The Invoice created can be seen using the Receivables responsibility
Navigation: Receivables Super User> Transactions> Transactions
Query with the Order Number as Reference.
Underlying tables:
RA_CUSTOMER_TRX_ALL will have the Invoice header information. The column INTERFACE_HEADER_ATTRIBUTE1 will have the Order Number.
RA_CUSTOMER_TRX_LINES_ALL will have the Invoice lines information. The column INTERFACE_LINE_ATTRIBUTE1 will have the Order Number.
Create receipt:
Navigation: Receivables> Receipts> Receipts
Enter the information.
Click on Apply Button to apply it to the Invoice.
Underlying tables:
AR_CASH_RECEIPTS_ALL
Transfer to General Ledger:
To transfer the Receivables accounting information to general ledger, run General Ledger Transfer Program.
Navigation: Receivables> View Requests
Parameters:
  • Give in the Start date and Post through date to specify the date range of the transactions to be transferred.
  • Specify the GL Posted Date, defaults to SYSDATE.
  • Post in summary: This controls how Receivables creates journal entries for your transactions in the interface table. If you select ‘No’, then the General Ledger Interface program creates at least one journal entry in the interface table for each transaction in your posting submission. If you select ‘Yes’, then the program creates one journal entry for each general ledger account.
  • If the Parameter Run Journal Import is set to ‘Yes’, the journal import program is kicked off automatically which transfers journal entries from the interface table to General Ledger, otherwise follow the topic Journal Import to import the journals to General Ledger manually.
Underlying tables:
This transfers data about your adjustments, chargeback, credit memos, commitments, debit memos, invoices, and receipts to the GL_INTERFACE table.
Journal Import:
To transfer the data from General Ledger Interface table to General Ledger, run the Journal Import program from Oracle General Ledger.
Navigation: General Ledger > Journal> Import> Run
Parameters:
  • Select the appropriate Source.
  • Enter one of the following Selection Criteria:
    No Group ID: To import all data for that source that has no group ID. Use this option if you specified a NULL group ID for this source.
    All Group IDs: To import all data for that source that has a group ID. Use this option to import multiple journal batches for the same source with varying group IDs.
    Specific Group ID: To import data for a specific source/group ID combination. Choose a specific group ID from the List of Values for the Specific Value field.
    If you do not specify a Group ID, General Ledger imports all data from the specified journal entry source, where the Group_ID is null.
  • Define the Journal Import Run Options (optional)
    Choose Post Errors to Suspense if you have suspense posting enabled for your set of books to post the difference resulting from any unbalanced journals to your suspense account.
    Choose Create Summary Journals to have journal import create the following:
    • one journal line for all transactions that share the same account, period, and currency and that has a debit balance
    • one journal line for all transactions that share the same account, period, and currency and that has a credit balance.
  • Enter a Date Range to have General Ledger import only journals with accounting dates in that range. If you do not specify a date range, General Ledger imports all journals data.
  • Choose whether to Import Descriptive Flexfields, and whether to import them with validation.
Click on Import button.
Underlying tables:
GL_JE_BATCHES, GL_JE_HEADERS, GL_JE_LINES
Posting:
We have to Post journal batches that we have imported previously to update the account balances in General Ledger.
Navigation: General Ledger> Journals > Enter
Query for the unposted journals for a specific period as shown below.
From the list of unposted journals displayed, select one journal at a time and click on Post button to post the journal.
If you know the batch name to be posted you can directly post using the Post window
Navigation: General Ledger> Journals> Post

GL Important Concepts and Questions

1. Which process push the data into which tables?
Create Accounting : Subledger tables and xla_events -> xla_ae_headers, xla_ae_lines and xla_distribution_links
Transfer to GL: xla_ae_headers and xla_ae_lines -> gl_je_headers and gl_je_lines
Post to GL : gl_je_headers and gl_je_lines -> gl_balances
Subledger Accounting Balances Update : xla_ae_headers and xla_ae_lines -> xla_control_balances

2. Which tables store segment values and descriptions?

The tables are:
- FND_FLEX_VALUES_TL
- FND_FLEX_VALUES.
3. Why is the Field still protected against update, even after unfreezing the structure?
Most probably another flexfield that uses this value set is still frozen.
You can find the other flexfields with the following sql which shows the frozen structures containing the value set:
select vs.flex_value_set_name, st.id_flex_structure_code
from fnd_id_flex_structures st, fnd_flex_value_sets vs, fnd_id_flex_segments sg
where st.id_flex_num = sg.id_flex_num
and vs.flex_value_set_id = sg.flex_value_set_id
and st.freeze_flex_definition_flag = 'Y'
and st.application_id = 101
and st.id_flex_code = 'GL#'
order by 1,2


Monday, July 28, 2014

Inventory Pending material transaction -Period close issue

Pending transactions for inventory period close can be viewed from Inventory Accounting Periods form

Select Open period and click on Pending button.
Transactions under Resolution Required and Unprocessed Shipping Transactions zones must be resolved before an accounting period can be closed.


Transactions under Resolution Recommended will not prevent the closing of a period but these transactions cannot be resolved after an accounting period is closed.


Below are the queries to check for the pending transactions.

Nav :Accounting Close Cycle > Inventory Accounting Periods


--Unprocessed Material Transactions

SELECT COUNT(*)
  FROM MTL_MATERIAL_TRANSACTIONS_TEMP
WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = 'ORG_CODE' AND
       TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')
  AND NVL(TRANSACTION_STATUS, 0) <> 2

--Uncosted Material Transactions

SELECT /*+ INDEX (MMT MTL_MATERIAL_TRANSACTIONS_N10) */
 COUNT(*)
  FROM MTL_MATERIAL_TRANSACTIONS MMT
 WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = '')
   AND TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')
   AND COSTED_FLAG IS NOT NULL

--Pending WIP Costing Transactions

SELECT COUNT(*)
  FROM WIP_COST_TXN_INTERFACE
 WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = '')
   AND TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')

--Uncosted WSM Transactions
      
SELECT COUNT(*)
  FROM WSM_SPLIT_MERGE_TRANSACTIONS
 WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = '')
   AND TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')

--Uncosted WSM Interface

SELECT COUNT(*)
  FROM WSM_SPLIT_MERGE_TXN_INTERFACE
 WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = '')
   AND TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')

--Pending Receiving Transactions

SELECT COUNT(*)
  FROM RCV_TRANSACTIONS_INTERFACE
 WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = '')
   AND TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')
   AND DESTINATION_TYPE_CODE = 'INVENTORY'

--Pending Material Transactions

SELECT COUNT(*)
  FROM MTL_TRANSACTIONS_INTERFACE
 WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = '')
   AND TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')
   AND PROCESS_FLAG <> 9


--Pending Shop Floor Move Transactions

SELECT COUNT(*)
  FROM WIP_MOVE_TXN_INTERFACE
 WHERE ORGANIZATION_ID =
       (SELECT ORGANIZATION_ID
          FROM APPS.ORG_ORGANIZATION_DEFINITIONS
         WHERE ORGANIZATION_CODE = '')
   AND TRANSACTION_DATE <
       (SELECT SCHEDULE_CLOSE_DATE + 1
          FROM APPS.ORG_ACCT_PERIODS
         WHERE ORGANIZATION_ID =
               (SELECT ORGANIZATION_ID
                  FROM APPS.ORG_ORGANIZATION_DEFINITIONS
                 WHERE ORGANIZATION_CODE = '')
           AND PERIOD_NAME = '')

--Unprocessed Shipping Transactions


SELECT COUNT(*)
  FROM WSH_DELIVERY_DETAILS     WDD,
       WSH_DELIVERY_ASSIGNMENTS WDA,
       WSH_NEW_DELIVERIES       WND,
       WSH_DELIVERY_LEGS        WDL,
       WSH_TRIP_STOPS           WTS
 WHERE WDD.SOURCE_CODE = 'OE'
   AND WDD.RELEASED_STATUS = 'C'
   AND WDD.INV_INTERFACED_FLAG IN ('N', 'P')
   AND WDD.ORGANIZATION_ID = 86
   AND WDA.DELIVERY_DETAIL_ID = WDD.DELIVERY_DETAIL_ID
   AND WND.DELIVERY_ID = WDA.DELIVERY_ID
   AND WND.STATUS_CODE IN ('CL', 'IT')
   AND WDL.DELIVERY_ID = WND.DELIVERY_ID
   AND WTS.PENDING_INTERFACE_FLAG IN ('Y', 'P')
   AND TRUNC(WTS.ACTUAL_DEPARTURE_DATE) BETWEEN
       TO_DATE('27-OCT-2012 00:00:00', 'DD-MON-YYYY HH24:MI:SS') AND
       TO_DATE('23-NOV-2012 23:59:59', 'DD-MON-YYYY HH24:MI:SS')
   AND WDL.PICK_UP_STOP_ID = WTS.STOP_ID