Friday 10 January 2014

API - Creating Values in Independant and dependant Value Sets

API - Creating Values in Independant and dependant Value Sets
declare
x varchar2(200);
v_msg varchar2(2000);
begin

fnd_global.apps_initialize (1090, 51007, 401);

  FND_FLEX_VAL_API.create_independent_vset_value
 ('XX_IND_VSET','10','Inserted from API','Y',sysdate,NULL,'N',NULL,NULL,X);
    DBMS_OUTPUT.PUT_LINE(X);
exception
when others then
v_msg:=fnd_flex_val_api.message;
  DBMS_OUTPUT.PUT_LINE(v_msg);
end;
/

COMMIT


------    Inserting child dependent Value Set Values -------------------------------

declare
x varchar2(200);
v_msg varchar2(2000);
begin

fnd_global.apps_initialize (1090, 51007, 401);


 FND_FLEX_VAL_API.create_dependent_vset_value
  ('XX_DEP_VSET','10','10.1','Dependent Value inserted through API','Y',sysdate,NULL,NULL,x);
    DBMS_OUTPUT.PUT_LINE(X);
exception
when others then
v_msg:=fnd_flex_val_api.message;
  DBMS_OUTPUT.PUT_LINE(v_msg);
end;
/

COMMIT

API - Assign Inventory Items to Warehouse

API - Assign Inventory Items to Warehouse
l_api_version   NUMBER := 1.0;
l_init_msg_list VARCHAR2(2) := FND_API.G_TRUE;
l_commit        VARCHAR2(2) := FND_API.G_FALSE; 
SELECT inventory_item_id,
        segment1,
        primary_uom_code
 FROM   mtl_system_items_b
 WHERE  segment1 = v_segment1;  -- INVENTORY ITEM CODE


EGO_ITEM_PUB.ASSIGN_ITEM_TO_ORG(
   P_API_VERSION       =>  l_api_version
,  P_INIT_MSG_LIST     =>  l_INIT_MSG_LIST
,  P_COMMIT            =>  l_COMMIT
,  P_INVENTORY_ITEM_ID =>  itm.inventory_item_id --(item id from the above Query)           
,  P_ITEM_NUMBER       =>  itm.segment1          --(Item Code from the above Query)
,  P_ORGANIZATION_ID   =>  v_organization_id     --(Organization Id for assingment)
,  P_ORGANIZATION_CODE =>  NULL--v_organization_code
,  P_PRIMARY_UOM_CODE  =>  itm.primary_uom_code  --(UOM from the above Query)
,  X_RETURN_STATUS     =>  X_RETURN_STATUS
,  X_MSG_COUNT         =>  X_MSG_COUNT
 );

 

API - Assign Categries to Inventory Items

DECLARE

 X_RETURN_STATUS  VARCHAR2(1000);
 X_ERRORCODE         NUMBER;
 X_MSG_COUNT        NUMBER;
 X_MSG_DATA          VARCHAR2(1000);
 X_MSG_INDEX_OUT VARCHAR2(2000);
 L_ERROR_MESSAGE VARCHAR2(2000);

 BEGIN

   --Apps Initialization is available in another section. Use the below link to know in detail
    --     Apps_Initialize;

 INV_ITEM_CATEGORY_PUB.CREATE_CATEGORY_ASSIGNMENT
                                                 (  P_API_VERSION           => 1.0,
                                                    P_INIT_MSG_LIST         => FND_API.G_FALSE,
                                                    P_COMMIT                => FND_API.G_FALSE,
                                                    X_RETURN_STATUS         => X_RETURN_STATUS,
                                                    X_ERRORCODE             => X_ERRORCODE,
                                                    X_MSG_COUNT             => X_MSG_COUNT,
                                                    X_MSG_DATA              => X_MSG_DATA,
                                                    P_CATEGORY_ID           => 1355,                                          -- Category id to be assigned
                                                    P_CATEGORY_SET_ID       => 1100000043,                            -- Category Set id
                                                    P_INVENTORY_ITEM_ID     => 25803,                                    -- Inventory Item Id
                                                    P_ORGANIZATION_ID       => 755);                                       -- Warehouse

    IF x_return_status = fnd_api.g_ret_sts_success
    THEN
       COMMIT;
       DBMS_OUTPUT.put_line ('Item Category Assignment using API is Successful');
  
    ELSE
       BEGIN
          IF (fnd_msg_pub.count_msg > 1)
          THEN
             FOR k IN 1 .. fnd_msg_pub.count_msg
             LOOP
                fnd_msg_pub.get (p_msg_index            => k,
                                              p_encoded            => 'F',
                                              p_data                 => x_msg_data,
                                              p_msg_index_out   => x_msg_index_out
                                             );

                DBMS_OUTPUT.PUT_LINE('x_msg_data:= ' || x_msg_data);
                IF x_msg_data IS NOT NULL
                THEN
                   l_error_message := l_error_message || '-' || x_msg_data;
                END IF;
             END LOOP;
          ELSE
             --Only one error
             fnd_msg_pub.get (p_msg_index             => 1,
                                            p_encoded            => 'F',
                                            p_data                 => x_msg_data,
                                            p_msg_index_out   => x_msg_index_out
                                          );
             l_error_message := x_msg_data;
          END IF;

          DBMS_OUTPUT.put_line (   'Error encountered by the API is '
                                || l_error_message
                               );
          ROLLBACK;
       EXCEPTION
          WHEN OTHERS
          THEN
             l_error_message := SQLERRM;
             DBMS_OUTPUT.put_line (   'Error encountered by the API is '
                                   || l_error_message
                                  );
       END;
    END IF;

 EXCEPTION
   WHEN OTHERS THEN
       DBMS_OUTPUT.put_line('Error in Assigning Category to an Item and error is '||SUBSTR(SQLERRM,1,200));
 END;

API - AR Invoice (Transaction) Creation

API - AR Invoice (Transaction) Creation
CREATE OR REPLACE procedure APPS.xx_ar_invoice_api
is
        l_return_status         varchar2(1);
        l_msg_count             number;
        l_msg_data              varchar2(2000);
        l_batch_source_rec      ar_invoice_api_pub.batch_source_rec_type;
        l_trx_header_tbl        ar_invoice_api_pub.trx_header_tbl_type;
        l_trx_lines_tbl         ar_invoice_api_pub.trx_line_tbl_type;
        l_trx_dist_tbl          ar_invoice_api_pub.trx_dist_tbl_type;
        l_trx_salescredits_tbl  ar_invoice_api_pub.trx_salescredits_tbl_type;
        l_cust_trx_id           number;

BEGIN
       
        begin
            MO_GLOBAL.SET_POLICY_CONTEXT('S',82);
        end;
       
        fnd_global.apps_initialize(1090,20678,222);

        l_batch_source_rec.batch_source_id          :=  1001;
        l_trx_header_tbl(1).trx_header_id           :=  9898;
        l_trx_header_tbl(1).trx_date                :=  sysdate;
        l_trx_header_tbl(1).trx_currency            :=  'AED';
        l_trx_header_tbl(1).cust_trx_type_id        :=  1000;
        l_trx_header_tbl(1).bill_to_customer_id     :=  1139;
        l_trx_header_tbl(1).term_id                 :=  1000;
        l_trx_header_tbl(1).finance_charges         :=  'N';
        l_trx_header_tbl(1).status_trx              :=  'OP';
        l_trx_header_tbl(1).printing_option         :=  'NOT';
        --l_trx_header_tbl(1).reference_number            :=  '1111';
        l_trx_lines_tbl(1).trx_header_id            :=  9898;
        l_trx_lines_tbl(1).trx_line_id              :=  101;
        l_trx_lines_tbl(1).line_number              :=  1;
        l_trx_lines_tbl(1).inventory_item_id        :=  1185;
       -- l_trx_lines_tbl(1).description              :=  'CAST IRON GRILL-325*485MM';
        l_trx_lines_tbl(1).quantity_invoiced        :=  3;
        l_trx_lines_tbl(1).unit_selling_price       :=  525;          --Price
        l_trx_lines_tbl(1).uom_code                 :=  'EAC';
        l_trx_lines_tbl(1).line_type                :=  'LINE';
        l_trx_dist_tbl(1).trx_dist_id               :=  101;
        l_trx_dist_tbl(1).trx_line_id               :=  101;
        l_trx_dist_tbl(1).ACCOUNT_CLASS             := 'REV';
        l_trx_dist_tbl(1).percent                   := 100;
        l_trx_dist_tbl(1).CODE_COMBINATION_ID       := 1012;
       
--Here we call the API to create Invoice with the stored values


    AR_INVOICE_API_PUB.create_invoice
    (p_api_version          => 1.0
    --,p_commit               => 'T'
    ,p_batch_source_rec     => l_batch_source_rec
    ,p_trx_header_tbl       => l_trx_header_tbl
    ,p_trx_lines_tbl        => l_trx_lines_tbl
    ,p_trx_dist_tbl         => l_trx_dist_tbl
    ,p_trx_salescredits_tbl => l_trx_salescredits_tbl
    ,x_return_status        => l_return_status
    ,x_msg_count            => l_msg_count
    ,x_msg_data             => l_msg_data
    );
   
    dbms_output.put_line('Created:'||l_msg_data||l_return_status);

    IF l_return_status = fnd_api.g_ret_sts_error OR
       l_return_status = fnd_api.g_ret_sts_unexp_error THEN

        dbms_output.put_line(l_return_status||':'||sqlerrm);
    Else
        dbms_output.put_line(l_return_status||':'||sqlerrm);
        If (ar_invoice_api_pub.g_api_outputs.batch_id IS NOT NULL) Then
            Dbms_output.put_line('Invoice(s) suceessfully created!') ;
            Dbms_output.put_line('Batch ID: ' || ar_invoice_api_pub.g_api_outputs.batch_id);
            Dbms_output.put_line('customer_trx_id: ' || l_cust_trx_id);
        Else
            Dbms_output.put_line(sqlerrm);
        End If;
    end if;
    commit;
End;
/

API - AR Cash Receipt

API - AR Cash Receipt
CREATE OR REPLACE PROCEDURE APPS.XX_CREATE_CASH_RECEIPT_APPLY(errbuf  out NOCOPY varchar2,
                                                         retcode out NOCOPY varchar2)
  IS
      L_RETURN_STATUS   VARCHAR2(240);
      L_MSG_COUNT       NUMBER;
      L_MSG_DATA        VARCHAR2(240);
      L_CASH_RECEIPT_ID NUMBER;
      v_customer_number VARCHAR2(240);
      v_cust_name       VARCHAR(240);
      v_amount          NUMBER;
      v_receipt_number  NUMBER;
     
     
      CURSOR C1
      IS
      SELECT * FROM XX_AR_RECEIPTS_GMC;
 
  BEGIN
           
 
            BEGIN
                   MO_GLOBAL.SET_POLICY_CONTEXT('S',150);
            END;

            FOR I IN C1 LOOP
           
                    BEGIN
            
                    v_cust_name := I.customer_name;      --substr(I.CUSTOMER_NAME,1,length(I.CUSTOMER_NAME)-1);
                       
                    SELECT  DISTINCT ARC.CUSTOMER_NUMBER
                    INTO    v_customer_number
                    FROM    AR_CUSTOMERS ARC
                           ,HZ_CUST_ACCOUNTS_ALL   HCA
                           ,HZ_CUST_ACCT_SITES_ALL HCAS
                    WHERE  HCA.CUST_ACCOUNT_ID = HCAS.CUST_ACCOUNT_ID
                    AND    HCA.CUST_ACCOUNT_ID = ARC.CUSTOMER_ID
                    AND    HCAS.ORG_ID = 150        
                    AND    LTRIM(RTRIM(UPPER(ARC.CUSTOMER_NAME))) = LTRIM(RTRIM(UPPER(v_cust_name)));     
                       
                    DBMS_OUTPUT.PUT_LINE ('Customer Id - '||v_customer_number);  
          
                    EXCEPTION
                    WHEN NO_DATA_FOUNd THEN
                         DBMS_OUTPUT.PUT_LINE(I.CUSTOMER_NAME||' Customer Error: '||SUBSTR(SQLERRM,1,150));
                    END;

                    v_amount:= to_number(substr(I.AMOUNT,1,length(I.AMOUNT)-1));
                    --v_amount := to_number(I.AMOUNT);
                    v_receipt_number := to_number(I.RECEIPT_NUMBER);
                   
                           AR_RECEIPT_API_PUB.create_cash
                            ( p_api_version       => '1.0',
                              p_init_msg_list     => FND_API.G_TRUE,
                              p_commit            => FND_API.G_TRUE,
                              p_validation_level  => FND_API.G_VALID_LEVEL_FULL,
                              x_return_status     => l_return_status,
                              x_msg_count         => l_msg_count,
                              x_msg_data          => l_msg_data,
                              p_currency_code     => 'AED',
                              p_amount            => v_amount,
                              p_receipt_number    => v_receipt_number,
                              p_receipt_date      => sysdate,
                              p_gl_date           => to_date('31-dec-2008'),
                              p_customer_number   => v_customer_number,
                              p_org_id            =>  150,
                              p_receipt_method_id => '2007',
                              p_cr_id             => l_cash_receipt_id);
                             
                            
                             
                           /*  AR_RECEIPT_API_PUB.create_and_apply
                            (   p_api_version        => 1.0,
                                p_init_msg_list      => FND_API.G_TRUE,
                                p_commit             => FND_API.G_TRUE,
                                p_validation_level   => FND_API.G_VALID_LEVEL_FULL,
                                x_return_status      => l_return_status,
                                x_msg_count          => l_msg_count,
                                x_msg_data           => l_msg_data,
                                p_amount             => v_amount,
                                p_receipt_number     => v_receipt_number,
                                p_receipt_date       => sysdate,
                                p_gl_date            => to_date('31-dec-2008'),
                                p_customer_number    => v_customer_number,
                                p_location           => 'Abu Dhabi',
                                p_receipt_method_id  => '2007',
                                p_trx_number         => '500001',
                                p_cr_id              => l_cash_receipt_id
                             );
                              */
                             

           
            END LOOP;
         
            DBMS_OUTPUT.PUT_LINE('Cash Receipt Created & Applied'||'-'||l_cash_receipt_id||'- Comments : '||l_msg_data||l_return_status);
         
           COMMIT;

  EXCEPTION
      WHEN OTHERS THEN

      DBMS_OUTPUT.PUT_LINE(SUBSTR(SQLERRM,1,150)||'-'||l_msg_data);

  END;
/

Monday 9 December 2013

API - Allocate and Transact Orders (Transact Move Orders)

create or replace procedure XX_ALOCATE_TRANSACT_MOVE_ORDER (P_REQUEST_NUMBER VARCHAR2 ,P_ORGANIZATION_ID NUMBER,P_TRANSACTION_DATE varchar2)
as

----------------- ALLOCATE MOVE ORDER API REQUIREMENTS -------------------------

l_api_version NUMBER := 1.0;
l_init_msg_list VARCHAR2 (2) := fnd_api.g_true;
l_return_values VARCHAR2 (2) := fnd_api.g_false;
l_commit VARCHAR2 (2) := fnd_api.g_false;
x_return_status VARCHAR2 (2);
x_msg_count NUMBER := 0;
x_msg_data VARCHAR2 (255);
l_user_id NUMBER ;
l_resp_id NUMBER ;
l_appl_id NUMBER ;
l_row_cnt NUMBER := 1;
l_trohdr_rec inv_move_order_pub.trohdr_rec_type;
l_trohdr_val_rec inv_move_order_pub.trohdr_val_rec_type;
x_trohdr_rec inv_move_order_pub.trohdr_rec_type;
x_trohdr_val_rec inv_move_order_pub.trohdr_val_rec_type;
l_validation_flag VARCHAR2 (2) := inv_move_order_pub.g_validation_yes;
l_trolin_tbl inv_move_order_pub.trolin_tbl_type;
l_trolin_val_tbl inv_move_order_pub.trolin_val_tbl_type;
x_trolin_tbl inv_move_order_pub.trolin_tbl_type;
x_trolin_val_tbl inv_move_order_pub.trolin_val_tbl_type;
x_number_of_rows NUMBER ;
x_transfer_to_location NUMBER ;
x_expiration_date DATE;
x_transaction_temp_id NUMBER ;



----------------- TRANSACT MOVE ORDER API REQUIREMENTS -------------------------

a_l_api_version NUMBER := 1.0;
a_l_init_msg_list VARCHAR2 (2) := fnd_api.g_true;
a_l_commit VARCHAR2 (2) := fnd_api.g_false;
a_x_return_status VARCHAR2 (2);
a_x_msg_count NUMBER := 0;
a_x_msg_data VARCHAR2 (255);
a_l_move_order_type NUMBER := 3;
a_l_transaction_mode NUMBER := 1;
a_l_trolin_tbl inv_move_order_pub.trolin_tbl_type;
a_l_mold_tbl inv_mo_line_detail_util.g_mmtt_tbl_type;
a_x_mmtt_tbl inv_mo_line_detail_util.g_mmtt_tbl_type;
a_x_trolin_tbl inv_move_order_pub.trolin_tbl_type;
a_l_transaction_date DATE := SYSDATE;
a_l_user_id NUMBER;
a_l_resp_id NUMBER;
a_l_appl_id NUMBER;
v_transaction_date date;


CURSOR c_mo_details IS

SELECT mtrh.header_id,
mtrh.request_number,
mtrh.move_order_type,
mtrh.organization_id,
mtrl.line_id,
mtrl.line_number,
mtrl.inventory_item_id,
mtrl.lot_number,
mtrl.quantity,
revision,mtrl.from_locator_id,
(select distinct operating_unit from org_organization_definitions
where organization_id = mtrh.organization_id) org_id
FROM mtl_txn_request_headers mtrh, mtl_txn_request_lines mtrl
WHERE mtrh.header_id = mtrl.header_id
AND (mtrh.request_number = P_REQUEST_NUMBER OR P_REQUEST_NUMBER IS NULL )--'8007'
AND (mtrh.organization_id = P_ORGANIZATION_ID OR P_ORGANIZATION_ID IS NULL ); -- 755;

BEGIN

FND_GLOBAL.APPS_INITIALIZE(1130, 50632, 401);

FOR i IN c_mo_details

LOOP

mo_global.set_policy_context ('S', i.org_id);
inv_globals.set_org_id (NVL(i.organization_id,P_ORGANIZATION_ID));
-- mo_global.init ('INV');

SELECT COUNT (*)
INTO x_number_of_rows
FROM mtl_txn_request_lines
WHERE header_id = i.header_id;

DBMS_OUTPUT.put_line ('Calling INV_REPLENISH_DETAIL_PUB to Allocate MO');
-- Allocate each line of the Move Order

inv_replenish_detail_pub.line_details_pub(
p_line_id => i.line_id,
x_number_of_rows => x_number_of_rows,
x_detailed_qty => i.quantity,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data,
x_revision => i.revision,
x_locator_id => i.from_locator_id,
x_transfer_to_location => x_transfer_to_location,
x_lot_number => i.lot_number,
x_expiration_date => x_expiration_date,
x_transaction_temp_id => x_transaction_temp_id,
p_transaction_header_id => NULL,
p_transaction_mode => NULL,
p_move_order_type => i.move_order_type,
p_serial_flag => fnd_api.g_false,
p_plan_tasks => FALSE,
p_auto_pick_confirm => FALSE,
p_commit => FALSE
);

DBMS_OUTPUT.put_line('==========================================================');
DBMS_OUTPUT.put_line (x_return_status);
DBMS_OUTPUT.put_line (x_msg_data);
DBMS_OUTPUT.put_line (x_msg_count);

IF (x_return_status <> fnd_api.g_ret_sts_success) THEN

DBMS_OUTPUT.put_line (x_msg_data);

END IF;

IF (x_return_status = fnd_api.g_ret_sts_success) THEN

DBMS_OUTPUT.put_line ('ALLOCATE API SUCCESSFUL WITH - Trx temp ID: ');
DBMS_OUTPUT.put_line (x_transaction_temp_id);

END IF;

DBMS_OUTPUT.put_line('==========================================================');


IF x_transaction_temp_id IS NOT NULL OR x_transaction_temp_id <> 0 THEN


mo_global.set_policy_context ('S', i.org_id);
inv_globals.set_org_id (i.organization_id);
mo_global.init ('INV');

a_l_trolin_tbl (1).line_id := i.line_id;


select to_date (P_TRANSACTION_DATE) --('31-AUG-2010')
into v_transaction_date
from dual;

FND_GLOBAL.APPS_INITIALIZE(1130, 50632, 401);

inv_pick_wave_pick_confirm_pub.pick_confirm
(p_api_version_number => a_l_api_version,
p_init_msg_list => a_l_init_msg_list,
p_commit => a_l_commit,
x_return_status => a_x_return_status,
x_msg_count => a_x_msg_count,
x_msg_data => a_x_msg_data,
p_move_order_type => i.move_order_type,
p_transaction_mode => a_l_transaction_mode,
p_trolin_tbl => a_l_trolin_tbl,
p_mold_tbl => a_l_mold_tbl,
x_mmtt_tbl => a_x_mmtt_tbl,
x_trolin_tbl => a_x_trolin_tbl,
p_transaction_date => v_transaction_date -- l_transaction_date
);

DBMS_OUTPUT.put_line('=======================================================');
DBMS_OUTPUT.put_line ('Return Status - '||a_x_return_status||' '||sqlerrm);
DBMS_OUTPUT.put_line ('Return Message - '||a_x_msg_data);
DBMS_OUTPUT.put_line (a_x_msg_count);

IF (a_x_return_status <> fnd_api.g_ret_sts_success) THEN

DBMS_OUTPUT.put_line (a_x_msg_data);

END IF;

IF (a_x_return_status = fnd_api.g_ret_sts_success) THEN

DBMS_OUTPUT.put_line ('TRANSACT API SUCCESSFULLY PROCESSED');

END IF;
DBMS_OUTPUT.put_line('=======================================================');

END IF;

END LOOP;

EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('OUTER Exception Occured :');
DBMS_OUTPUT.put_line (SQLCODE||':'||SQLERRM);
DBMS_OUTPUT.put_line ('=======================================================');
END;
END;




begin
XX_ALOCATE_TRANSACT_MOVE_ORDER('',763,'31-AUG-2010');
end;

Display All Subinventories Setup

select msi.secondary_inventory_name, MSI.SECONDARY_INVENTORY_NAME "Subinventory", MSI.DESCRIPTION "Description",
MSI.DISABLE_DATE "Disable Date", msi.PICKING_ORDER "Picking Order",
gcc1.concatenated_segments "Material Account",
gcc2.concatenated_segments "Material Overhead Account",
gcc3.concatenated_segments "Resource Account",
gcc4.concatenated_segments "Overhead Account",
gcc5.concatenated_segments "Outside Processing Account",
gcc6.concatenated_segments "Expense Account",
gcc7.concatenated_segments "Encumbrance Account",
msi.material_overhead_account,
msi.resource_account,
msi.overhead_account,
msi.outside_processing_account,
msi.expense_account,
msi.encumbrance_account
from mtl_secondary_inventories msi,
gl_code_combinations_kfv gcc1,
gl_code_combinations_kfv gcc2,
gl_code_combinations_kfv gcc3,
gl_code_combinations_kfv gcc4,
gl_code_combinations_kfv gcc5,
gl_code_combinations_kfv gcc6,
gl_code_combinations_kfv gcc7
where msi.material_account = gcc1.CODE_COMBINATION_ID(+)
and msi.material_overhead_account = gcc2.CODE_COMBINATION_ID(+)
and msi.resource_account = gcc3.CODE_COMBINATION_ID(+)
and msi.overhead_account = gcc4.CODE_COMBINATION_ID(+)
and msi.outside_processing_account = gcc5.CODE_COMBINATION_ID(+)
and msi.expense_account = gcc6.CODE_COMBINATION_ID(+)
and msi.encumbrance_account = gcc7.CODE_COMBINATION_ID(+)
order by msi.secondary_inventory_name