Search This Blog

Tuesday, April 18, 2023

API To Create Credit Note Apps R12

 


declare

l_return_status varchar2(1);

p_count  NUMBER;

l_msg_count number;

l_msg_data varchar2(2000);

l_batch_id number;

l_cnt number := 0;

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_customer_trx_id number;

cnt number; 

v_context varchar2(100);

trx_header_id            NUMBER  ;

trx_line_id              NUMBER  ;

trx_dist_id              NUMBER  ;

L_COUNT2 NUMBER;

LV_SQLERRM  varchar2(100);

L_ERRMSG   varchar2(100);

W_MESSAGE  varchar2(100);

W_STATUS  varchar2(100);

LN_MSG_INDEX_OUT  varchar2(100);


l_bill_to_customer_id number;

    

    CURSOR GET_RECORDS IS

          SELECT CUSTOMER_NUMBER, TRX_DATE, GL_DATE,TRX_REFERENCE,QUANTITY, UNIT_PRICE, CURRENCY

          FROM XX_AR_INV_INT_CN

         ;    

BEGIN

FOR I IN GET_RECORDS LOOP

DBMS_OUTPUT.PUT_LINE('1');


SELECT CUSTOMER_ID

INTO l_bill_to_customer_id

 FROM 

AR_CUSTOMERS

WHERE CUSTOMER_NUMBER = I.CUSTOMER_NUMBER

;


--1. Set applications context if not already set.

    /* Setting the oracle applications context for the particular session */

    fnd_global.apps_initialize ( user_id      => 1110

                                ,resp_id      => 50917

                                ,resp_appl_id => 222);

    /* Setting the org context for the particular session */

    mo_global.set_policy_context('S',121);


        BEGIN

            SELECT ra_customer_trx_s.NEXTVAL INTO trx_header_id FROM DUAL;

        END;

        BEGIN

            SELECT ra_customer_trx_lines_s.NEXTVAL INTO trx_line_id FROM DUAL;

        END;


        BEGIN

            SELECT ra_cust_trx_line_gl_dist_s.NEXTVAL

              INTO trx_dist_id

              FROM DUAL;

        END;

        

        DBMS_OUTPUT.PUT_LINE('TRX_HEADER_ID-'||ra_customer_trx_s.CURRVAL);


l_batch_source_rec.batch_source_id := 4002;

                l_trx_header_tbl(1).trx_header_id := trx_header_id;

                l_trx_header_tbl(1).trx_number := I.TRX_NUMBER;

                l_trx_header_tbl(1).bill_to_customer_id := l_bill_to_customer_id;

                l_trx_header_tbl(1).cust_trx_type_id := 6001; 

                l_trx_header_tbl(1).trx_date :=I.TRX_DATE;

                l_trx_header_tbl(1).gl_date :=TO_DATE('31-MAR-2023');

                l_trx_header_tbl(1).trx_currency  := I.CURRENCY;

--                l_trx_header_tbl(1).exchange_date := I.GL_DATE; --non functional currency

  --              l_trx_header_tbl(1).exchange_rate_type := 'Corporate'; --non functional currency

                l_trx_header_tbl(1).primary_salesrep_id := -3;

                l_trx_header_tbl(1).org_id := 121;

                l_trx_header_tbl(1).comments :=I.TRX_REFERENCE; 

                 l_trx_header_tbl(1).trx_class:='CM'; 

--                 l_trx_header_tbl(1).bill_to_site_use_id := 6051;

                 l_trx_header_tbl(1).term_id             :=  NULL;

                 l_trx_header_tbl(1).finance_charges        :=  null;

                l_trx_header_tbl(1).status_trx                     :=  'OP';

                l_trx_header_tbl(1).printing_option            :=  'PRI';

                

                

              ---Calling API 

                       BEGIN

                         SELECT

                         ra_customer_trx_lines_s.nextval

                         INTO

                         trx_line_id

                         FROM  dual;

                       END;

  

                       BEGIN

                           SELECT

                           ra_cust_trx_line_gl_dist_s.nextval

                           INTO  trx_dist_id

                       FROM  dual;

                       END; 

                       l_count2 := 1;

                        l_trx_lines_tbl(l_count2).trx_header_id := trx_header_id;

                        l_trx_lines_tbl(l_count2).trx_line_id := trx_line_id; 

                        l_trx_lines_tbl(l_count2).line_number := l_count2;

                        l_trx_lines_tbl(l_count2).DESCRIPTION := NVL(I.DESCRIPTION,I.TRX_REFERENCE);

                        l_trx_lines_tbl(l_count2).quantity_invoiced := 1;

                        l_trx_lines_tbl(l_count2).unit_selling_price :=I.UNIT_PRICE;--P_line_amt(i);

                        l_trx_lines_tbl(l_count2).line_type := TRIM('LINE');

                        l_trx_lines_tbl(l_count2).taxable_flag := NULL;

                      l_trx_dist_tbl(l_count2).trx_dist_id := trx_dist_id;

                      l_trx_dist_tbl(l_count2).trx_header_id := trx_header_id;

                      l_trx_dist_tbl(l_count2).trx_line_id := trx_line_id;

                      l_trx_dist_tbl(l_count2).account_class := 'REV';

                      l_trx_dist_tbl(l_count2).percent := 100;

                      l_trx_dist_tbl(l_count2).amount := I.UNIT_PRICE;--P_line_amt(i);

                       l_trx_dist_tbl(l_count2).code_combination_id := 27016; 

                  

 

              ----Call the invoice api 

                fnd_global.apps_initialize(1110,50917,222);

                      mo_global.set_policy_context('S',121);

                     

begin

 AR_INVOICE_API_PUB.create_single_invoice(

                      p_api_version           => 1.0,

                      P_INIT_MSG_LIST         => FND_API.G_FALSE,

                      P_COMMIT                => FND_API.G_FALSE,

                      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_customer_trx_id       => l_customer_trx_id,

                      x_return_status         => l_return_status,

                      x_msg_count             => l_msg_count,

                      x_msg_data              => l_msg_data); 

                    commit;

                    exception when others then

                     W_Status:='E';

  W_Message:=sqlerrm;

end;                    

     

   END LOOP;

          

 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('FND_MSG_PUB.Count_Msg ');

        dbms_output.put_line(l_return_status||':'||sqlerrm);            

            

              FOR l_msg_count IN 1..FND_MSG_PUB.Count_Msg

      LOOP

      FND_MSG_PUB.Get(p_msg_index     => l_msg_count

                     ,p_encoded       => 'F'

                     ,p_data          => l_msg_data

                     ,p_msg_index_OUT => ln_msg_index_out

                     );

       lv_sqlerrm   := SUBSTR(lv_sqlerrm||REPLACE(l_msg_data,CHR(10),''),1,3998);

       W_Status := 'E';

       W_Message := lv_sqlerrm;

       dbms_output.put_line(l_return_status||':'||lv_sqlerrm);

     END LOOP;

    FND_MSG_PUB.Delete_Msg;

    ELSE   

         dbms_output.put_line('FND_MSG_PUB.Count_Msg else :'||FND_MSG_PUB.Count_Msg); 

    END IF;

              EXCEPTION WHEN OTHERS THEN

            l_ErrMsg :=SQLERRM;

            

          END ;



 --for any errors check the table

SELECT * FROM ar_trx_errors_gt;

--OPEN Issues

Not able to find CT_Reference field, so used comments field to pass the value.

API Create Debit Note Apps R12

 declare

l_return_status varchar2(1);

p_count  NUMBER;

l_msg_count number;

l_msg_data varchar2(2000);

l_batch_id number;

l_cnt number := 0;

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_customer_trx_id number;

cnt number; 

v_context varchar2(100);

trx_header_id            NUMBER  ;

trx_line_id              NUMBER  ;

trx_dist_id              NUMBER  ;

L_COUNT2 NUMBER;

LV_SQLERRM  varchar2(100);

L_ERRMSG   varchar2(100);

W_MESSAGE  varchar2(100);

W_STATUS  varchar2(100);

LN_MSG_INDEX_OUT  varchar2(100);


l_bill_to_customer_id number;

    

    CURSOR GET_RECORDS IS

        SELECT CUSTOMER_NUMBER, TRX_DATE, GL_DATE,TRX_REFERENCE,QUANTITY, UNIT_PRICE, CURRENCY

          FROM XX_AR_INV_INT_DN

         ;    

BEGIN

FOR I IN GET_RECORDS LOOP

DBMS_OUTPUT.PUT_LINE('1');


SELECT CUSTOMER_ID

INTO l_bill_to_customer_id

 FROM 

AR_CUSTOMERS

WHERE CUSTOMER_NUMBER = I.CUSTOMER_NUMBER

;


--1. Set applications context if not already set.

    /* Setting the oracle applications context for the particular session */

    fnd_global.apps_initialize ( user_id      => 1110

                                ,resp_id      => 50917

                                ,resp_appl_id => 222);

    /* Setting the org context for the particular session */

    mo_global.set_policy_context('S',121);


        BEGIN

            SELECT ra_customer_trx_s.NEXTVAL INTO trx_header_id FROM DUAL;

        END;

        BEGIN

            SELECT ra_customer_trx_lines_s.NEXTVAL INTO trx_line_id FROM DUAL;

        END;


        BEGIN

            SELECT ra_cust_trx_line_gl_dist_s.NEXTVAL

              INTO trx_dist_id

              FROM DUAL;

        END;

        

        DBMS_OUTPUT.PUT_LINE('TRX_HEADER_ID-'||ra_customer_trx_s.CURRVAL);


                l_batch_source_rec.batch_source_id := 4002;

                l_trx_header_tbl(1).trx_header_id := trx_header_id;

                l_trx_header_tbl(1).trx_number := I.TRX_NUMBER;

                l_trx_header_tbl(1).bill_to_customer_id := l_bill_to_customer_id;

                l_trx_header_tbl(1).cust_trx_type_id := 6002; 

                l_trx_header_tbl(1).trx_date :=I.TRX_DATE;

                l_trx_header_tbl(1).gl_date :=TO_DATE('31-MAR-2023');

               l_trx_header_tbl(1).trx_currency  := I.CURRENCY;

              --  l_trx_header_tbl(1).exchange_date := I.GL_DATE; --if other than functional curr

                -- l_trx_header_tbl(1).exchange_rate_type := 'Corporate';  --if other than functional curr

                l_trx_header_tbl(1).primary_salesrep_id := -3;

                l_trx_header_tbl(1).org_id := 121;

                l_trx_header_tbl(1).comments :=I.TRX_REFERENCE; 

                 l_trx_header_tbl(1).trx_class:='DM'; 

--                 l_trx_header_tbl(1).bill_to_site_use_id := 6051;

                 l_trx_header_tbl(1).term_id             :=  NULL;

                 l_trx_header_tbl(1).finance_charges        :=  null;

                l_trx_header_tbl(1).status_trx                     :=  'OP';

                l_trx_header_tbl(1).printing_option            :=  'PRI';

                

                

              ---Calling API 

                       BEGIN

                         SELECT

                         ra_customer_trx_lines_s.nextval

                         INTO

                         trx_line_id

                         FROM  dual;

                       END;

  

                       BEGIN

                           SELECT

                           ra_cust_trx_line_gl_dist_s.nextval

                           INTO  trx_dist_id

                       FROM  dual;

                       END; 

                       l_count2 := 1;

                        l_trx_lines_tbl(l_count2).trx_header_id := trx_header_id;

                        l_trx_lines_tbl(l_count2).trx_line_id := trx_line_id; 

                        l_trx_lines_tbl(l_count2).line_number := l_count2;

                        l_trx_lines_tbl(l_count2).DESCRIPTION := NVL(I.DESCRIPTION,I.TRX_REFERENCE);

                        l_trx_lines_tbl(l_count2).quantity_invoiced := 1;

                        l_trx_lines_tbl(l_count2).unit_selling_price :=I.UNIT_PRICE;--P_line_amt(i);

                        l_trx_lines_tbl(l_count2).line_type := TRIM('LINE');

                        l_trx_lines_tbl(l_count2).taxable_flag := NULL;

                      l_trx_dist_tbl(l_count2).trx_dist_id := trx_dist_id;

                      l_trx_dist_tbl(l_count2).trx_header_id := trx_header_id;

                      l_trx_dist_tbl(l_count2).trx_line_id := trx_line_id;

                      l_trx_dist_tbl(l_count2).account_class := 'REV';

                      l_trx_dist_tbl(l_count2).percent := 100;

                      l_trx_dist_tbl(l_count2).amount := I.UNIT_PRICE;--P_line_amt(i);

                       l_trx_dist_tbl(l_count2).code_combination_id := 27016; 

                  

 

              ----Call the invoice api 

                fnd_global.apps_initialize(1110,50917,222);

                      mo_global.set_policy_context('S',121);

                     

begin

 AR_INVOICE_API_PUB.create_single_invoice(

                      p_api_version           => 1.0,

                      P_INIT_MSG_LIST         => FND_API.G_FALSE,

                      P_COMMIT                => FND_API.G_FALSE,

                      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_customer_trx_id       => l_customer_trx_id,

                      x_return_status         => l_return_status,

                      x_msg_count             => l_msg_count,

                      x_msg_data              => l_msg_data); 

                    commit;

                    exception when others then

                     W_Status:='E';

  W_Message:=sqlerrm;

end;                    

     

   END LOOP;

          

 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('FND_MSG_PUB.Count_Msg ');

        dbms_output.put_line(l_return_status||':'||sqlerrm);            

            

              FOR l_msg_count IN 1..FND_MSG_PUB.Count_Msg

      LOOP

      FND_MSG_PUB.Get(p_msg_index     => l_msg_count

                     ,p_encoded       => 'F'

                     ,p_data          => l_msg_data

                     ,p_msg_index_OUT => ln_msg_index_out

                     );

       lv_sqlerrm   := SUBSTR(lv_sqlerrm||REPLACE(l_msg_data,CHR(10),''),1,3998);

       W_Status := 'E';

       W_Message := lv_sqlerrm;

       dbms_output.put_line(l_return_status||':'||lv_sqlerrm);

     END LOOP;

    FND_MSG_PUB.Delete_Msg;

    ELSE   

         dbms_output.put_line('FND_MSG_PUB.Count_Msg else :'||FND_MSG_PUB.Count_Msg); 

    END IF;

              EXCEPTION WHEN OTHERS THEN

            l_ErrMsg :=SQLERRM;

            

          END ;


--for any issues check the table

SELECT * FROM ar_trx_errors_gt;


--OPEN Issues

Not able to find CT_Reference field, so used comments field to pass the value.

Friday, April 14, 2023

Apps R12 create Sales Order with status Booked

 Step1: Create SO

Step2: Process SO status to Booked


Step1: 

--SET SERVEROUTPUT ON;

DECLARE

v_api_version_number           NUMBER    := 1;

v_return_status                VARCHAR2(2000);

v_msg_count                    NUMBER;

v_msg_data                     VARCHAR2(2000);

-- IN Variables --

v_header_rec                   oe_order_pub.header_rec_type;

v_line_tbl                     oe_order_pub.line_tbl_type;

v_action_request_tbl           oe_order_pub.request_tbl_type;

v_line_adj_tbl                 oe_order_pub.line_adj_tbl_type;

-- OUT Variables --

v_header_rec_out               oe_order_pub.header_rec_type;

v_header_val_rec_out           oe_order_pub.header_val_rec_type;

v_header_adj_tbl_out           oe_order_pub.header_adj_tbl_type;

v_header_adj_val_tbl_out       oe_order_pub.header_adj_val_tbl_type;

v_header_price_att_tbl_out     oe_order_pub.header_price_att_tbl_type;

v_header_adj_att_tbl_out       oe_order_pub.header_adj_att_tbl_type;

v_header_adj_assoc_tbl_out     oe_order_pub.header_adj_assoc_tbl_type;

v_header_scredit_tbl_out       oe_order_pub.header_scredit_tbl_type;

v_header_scredit_val_tbl_out   oe_order_pub.header_scredit_val_tbl_type;

v_line_tbl_out                 oe_order_pub.line_tbl_type;

v_line_val_tbl_out             oe_order_pub.line_val_tbl_type;

v_line_adj_tbl_out             oe_order_pub.line_adj_tbl_type;

v_line_adj_val_tbl_out         oe_order_pub.line_adj_val_tbl_type;

v_line_price_att_tbl_out       oe_order_pub.line_price_att_tbl_type;

v_line_adj_att_tbl_out         oe_order_pub.line_adj_att_tbl_type;

v_line_adj_assoc_tbl_out       oe_order_pub.line_adj_assoc_tbl_type;

v_line_scredit_tbl_out         oe_order_pub.line_scredit_tbl_type;

v_line_scredit_val_tbl_out     oe_order_pub.line_scredit_val_tbl_type;

v_lot_serial_tbl_out           oe_order_pub.lot_serial_tbl_type;

v_lot_serial_val_tbl_out       oe_order_pub.lot_serial_val_tbl_type;

v_action_request_tbl_out       oe_order_pub.request_tbl_type;

BEGIN

DBMS_OUTPUT.PUT_LINE('Starting of script');

-- Setting the Enviroment --

mo_global.init('ONT');

fnd_global.apps_initialize ( user_id      => 1170

                            ,resp_id      => 50957

                            ,resp_appl_id => 660);

mo_global.set_policy_context('S',121);

-- Header Record --

v_header_rec                        := oe_order_pub.g_miss_header_rec;

v_header_rec.operation              := oe_globals.g_opr_create;

v_header_rec.order_type_id          := 1261;   

v_header_rec.sold_to_org_id         := 8318; --CUSTOMER_ID/VENDOR_ID

v_header_rec.ship_to_org_id         := 8588; --SHIP_TO  hz_cust_site_uses_all

v_header_rec.invoice_to_org_id      := 8589; --BILL_TO  hz_cust_site_uses_all

v_header_rec.order_source_id        := 0;

v_header_rec.booked_flag            := 'N';

v_header_rec.price_list_id          := 9007;

v_header_rec.pricing_date           := SYSDATE;

v_header_rec.flow_status_code       := 'ENTERED'; --'BOOKED';-- NOT WORKING 

--v_header_rec.cust_po_number         := '99478222532';

v_header_rec.sold_from_org_id       := 121;

v_header_rec.salesrep_id            := 100000051;

v_header_rec.transactional_curr_code:= 'AED';

v_action_request_tbl (1) := oe_order_pub.g_miss_request_rec;

-- Line Record --

v_line_tbl (1)                      := oe_order_pub.g_miss_line_rec;

v_line_tbl (1).operation            := oe_globals.g_opr_create;

v_line_tbl (1).inventory_item_id    := 15322;

v_line_tbl (1).ordered_quantity     := 1;

v_line_tbl (1).unit_selling_price   := 2200;

v_line_tbl (1).calculate_price_flag := 'Y';

DBMS_OUTPUT.PUT_LINE('Starting of API');

-- Calling the API to create an Order --

OE_ORDER_PUB.PROCESS_ORDER (

p_api_version_number            => v_api_version_number

, p_header_rec                  => v_header_rec

, p_line_tbl                    => v_line_tbl

, p_action_request_tbl          => v_action_request_tbl

, p_line_adj_tbl                => v_line_adj_tbl

-- OUT variables

, x_header_rec                  => v_header_rec_out

, x_header_val_rec              => v_header_val_rec_out

, x_header_adj_tbl              => v_header_adj_tbl_out

, x_header_adj_val_tbl          => v_header_adj_val_tbl_out

, x_header_price_att_tbl        => v_header_price_att_tbl_out

, x_header_adj_att_tbl          => v_header_adj_att_tbl_out

, x_header_adj_assoc_tbl        => v_header_adj_assoc_tbl_out

, x_header_scredit_tbl          => v_header_scredit_tbl_out

, x_header_scredit_val_tbl      => v_header_scredit_val_tbl_out

, x_line_tbl                    => v_line_tbl_out

, x_line_val_tbl                => v_line_val_tbl_out

, x_line_adj_tbl                => v_line_adj_tbl_out

, x_line_adj_val_tbl            => v_line_adj_val_tbl_out

, x_line_price_att_tbl          => v_line_price_att_tbl_out

, x_line_adj_att_tbl            => v_line_adj_att_tbl_out

, x_line_adj_assoc_tbl          => v_line_adj_assoc_tbl_out

, x_line_scredit_tbl            => v_line_scredit_tbl_out

, x_line_scredit_val_tbl        => v_line_scredit_val_tbl_out

, x_lot_serial_tbl              => v_lot_serial_tbl_out

, x_lot_serial_val_tbl          => v_lot_serial_val_tbl_out

, x_action_request_tbl          => v_action_request_tbl_out

, x_return_status               => v_return_status

, x_msg_count                   => v_msg_count

, x_msg_data                    => v_msg_data

);

DBMS_OUTPUT.PUT_LINE('Completion of API');

IF v_return_status = fnd_api.g_ret_sts_success THEN

    COMMIT;

    DBMS_OUTPUT.put_line ('Order Import Success : '||v_header_rec_out.header_id);

ELSE

    DBMS_OUTPUT.put_line ('Order Import failed:'||v_msg_data);

    ROLLBACK;

    FOR i IN 1 .. v_msg_count

    LOOP

      v_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');

      dbms_output.put_line( i|| ') '|| v_msg_data);

    END LOOP;

END IF;

END;

/


Step2:

DECLARE

v_api_version_number           NUMBER  := 1;

v_return_status                VARCHAR2 (2000);

v_msg_count                    NUMBER;

v_msg_data                     VARCHAR2 (2000);


-- IN Variables --

v_header_rec                   oe_order_pub.header_rec_type;

v_line_tbl                     oe_order_pub.line_tbl_type;

v_action_request_tbl           oe_order_pub.request_tbl_type;

v_line_adj_tbl                 oe_order_pub.line_adj_tbl_type;


-- OUT Variables --

v_header_rec_out               oe_order_pub.header_rec_type;

v_header_val_rec_out           oe_order_pub.header_val_rec_type;

v_header_adj_tbl_out           oe_order_pub.header_adj_tbl_type;

v_header_adj_val_tbl_out       oe_order_pub.header_adj_val_tbl_type;

v_header_price_att_tbl_out     oe_order_pub.header_price_att_tbl_type;

v_header_adj_att_tbl_out       oe_order_pub.header_adj_att_tbl_type;

v_header_adj_assoc_tbl_out     oe_order_pub.header_adj_assoc_tbl_type;

v_header_scredit_tbl_out       oe_order_pub.header_scredit_tbl_type;

v_header_scredit_val_tbl_out   oe_order_pub.header_scredit_val_tbl_type;

v_line_tbl_out                 oe_order_pub.line_tbl_type;

v_line_val_tbl_out             oe_order_pub.line_val_tbl_type;

v_line_adj_tbl_out             oe_order_pub.line_adj_tbl_type;

v_line_adj_val_tbl_out         oe_order_pub.line_adj_val_tbl_type;

v_line_price_att_tbl_out       oe_order_pub.line_price_att_tbl_type;

v_line_adj_att_tbl_out         oe_order_pub.line_adj_att_tbl_type;

v_line_adj_assoc_tbl_out       oe_order_pub.line_adj_assoc_tbl_type;

v_line_scredit_tbl_out         oe_order_pub.line_scredit_tbl_type;

v_line_scredit_val_tbl_out     oe_order_pub.line_scredit_val_tbl_type;

v_lot_serial_tbl_out           oe_order_pub.lot_serial_tbl_type;

v_lot_serial_val_tbl_out       oe_order_pub.lot_serial_val_tbl_type;

v_action_request_tbl_out       oe_order_pub.request_tbl_type;



BEGIN


DBMS_OUTPUT.PUT_LINE('Starting of script');


-- Setting the Enviroment --


mo_global.init('ONT');

fnd_global.apps_initialize ( user_id      => 1170

                            ,resp_id      => 50957

                            ,resp_appl_id => 660);

mo_global.set_policy_context('S',121);


v_action_request_tbl (1)             := oe_order_pub.g_miss_request_rec;

v_action_request_tbl(1).request_type := OE_GLOBALS.G_BOOK_ORDER;

v_action_request_tbl(1).entity_code  := OE_GLOBALS.G_ENTITY_HEADER;

v_action_request_tbl(1).entity_id    := 43001; --pass header_id here


DBMS_OUTPUT.PUT_LINE('Starting of API');


-- Calling the API to to Book an Existing Order --


OE_ORDER_PUB.PROCESS_ORDER (

p_api_version_number            => v_api_version_number

, p_header_rec                  => v_header_rec

, p_line_tbl                    => v_line_tbl

, p_action_request_tbl          => v_action_request_tbl

, p_line_adj_tbl                => v_line_adj_tbl

-- OUT variables

, x_header_rec                  => v_header_rec_out

, x_header_val_rec              => v_header_val_rec_out

, x_header_adj_tbl              => v_header_adj_tbl_out

, x_header_adj_val_tbl          => v_header_adj_val_tbl_out

, x_header_price_att_tbl        => v_header_price_att_tbl_out

, x_header_adj_att_tbl          => v_header_adj_att_tbl_out

, x_header_adj_assoc_tbl        => v_header_adj_assoc_tbl_out

, x_header_scredit_tbl          => v_header_scredit_tbl_out

, x_header_scredit_val_tbl      => v_header_scredit_val_tbl_out

, x_line_tbl                    => v_line_tbl_out

, x_line_val_tbl                => v_line_val_tbl_out

, x_line_adj_tbl                => v_line_adj_tbl_out

, x_line_adj_val_tbl            => v_line_adj_val_tbl_out

, x_line_price_att_tbl          => v_line_price_att_tbl_out

, x_line_adj_att_tbl            => v_line_adj_att_tbl_out

, x_line_adj_assoc_tbl          => v_line_adj_assoc_tbl_out

, x_line_scredit_tbl            => v_line_scredit_tbl_out

, x_line_scredit_val_tbl        => v_line_scredit_val_tbl_out

, x_lot_serial_tbl              => v_lot_serial_tbl_out

, x_lot_serial_val_tbl          => v_lot_serial_val_tbl_out

, x_action_request_tbl          => v_action_request_tbl_out

, x_return_status               => v_return_status

, x_msg_count                   => v_msg_count

, x_msg_data                    => v_msg_data

);


DBMS_OUTPUT.PUT_LINE('Completion of API');



IF v_return_status = fnd_api.g_ret_sts_success THEN

    COMMIT;

    DBMS_OUTPUT.put_line ('Booking of an Existing Order is Success ');

ELSE

    DBMS_OUTPUT.put_line ('Booking of an Existing Order failed:'||v_msg_data);

    ROLLBACK;

    FOR i IN 1 .. v_msg_count

    LOOP

      v_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');

      dbms_output.put_line( i|| ') '|| v_msg_data);

    END LOOP;

END IF;


END;

Apps r12 PO Approve from Backend (From Incomplete to Approved)

 /* Formatted on 4/14/2023 10:41:12 AM (QP5 v5.336) */

DECLARE

    l_return_status   VARCHAR2 (1000);


    l_msg_data        VARCHAR2 (1000);


    CURSOR c1 IS

        (SELECT *

           FROM po_headers_all

          WHERE     segment1 IN ('22729')

                AND type_lookup_code = 'STANDARD'

                AND (   authorization_status != 'APPROVED'

                     OR authorization_status IS NULL));

BEGIN

    mo_global.init ('PO');

    fnd_global.apps_initialize (1337, 51017, 201);


    FOR i IN c1

    LOOP

        po_document_action_pvt.do_approve (

            p_document_id        => i.po_header_id,

            p_document_type      => 'PO',

            p_document_subtype   => 'STANDARD',

            p_note               => '', --– Your comments that need to be displayed in action History,

            p_approval_path_id   => 0,  --SELECT * FROM po_action_history where creation_date like sysdate;

            x_return_status      => l_return_status,

            x_exception_msg      => l_msg_data);


        DBMS_OUTPUT.put_line (l_return_status);


        COMMIT;

    END LOOP;

END;


Thursday, March 16, 2023

Oracle Apps R12 AR Deposit API

 declare


l_return_status VARCHAR2(1);

l_msg_count NUMBER;

l_msg_data VARCHAR2(240);

l_new_trx_number ra_customer_trx.trx_number%type;

l_new_customer_trx_id ra_customer_trx.customer_trx_id%type;

l_new_customer_trx_line_id ra_customer_trx_lines.customer_trx_line_id%type;

l_new_rowid VARCHAR2(240);

l_new_status VARCHAR2(240);


begin


/*------------------------------+

| Setting global initialization |

+-------------------------------*/

FND_GLOBAL.apps_initialize(2605, 52695, 222);

MO_GLOBAL.init('AR');



ar_deposit_api_pub.CREATE_DEPOSIT(

  p_api_version => 1.0,

  p_init_msg_list => FND_API.G_TRUE,

  p_deposit_date => trunc(sysdate),

  p_currency_code => 'AED',

  p_amount => 200,

  p_term_id => 5,

  p_cust_trx_type_id => 9507,

  p_bill_to_customer_id =>  9745106,

  p_description => 'Generic Commitment',

  p_batch_source_id => -1,

  p_class => 'DEP',

  p_start_date_commitment => sysdate,

  p_commit => FND_API.G_TRUE,

  X_new_trx_number =>l_new_trx_number,

  X_new_customer_trx_id =>l_new_customer_trx_id,

  X_new_customer_trx_line_id =>l_new_customer_trx_line_id,

  X_new_rowid =>l_new_rowid,

  x_return_status => l_return_status,

  x_msg_count => l_msg_count,

  x_msg_data => l_msg_data ) ;


FND_MSG_PUB.count_and_get (

   p_encoded => FND_API.g_false,

   p_count => l_msg_count,

   p_data => l_msg_data );


dbms_output.put_line('Return Status ==> '||l_return_status);

dbms_output.put_line('Deposit customer_trx_id ==> '||l_new_customer_trx_id);

dbms_output.put_line('l_msg_count ==> '||l_msg_count);


-- display messages from the message stack

FOR I IN 1..L_MSG_COUNT LOOP

    DBMS_OUTPUT.PUT_LINE(SUBSTR(FND_MSG_PUB.GET(P_MSG_INDEX => I, P_ENCODED => 'F'), 1, 254));

END LOOP;


END;



Error: Deposit Creation Failed The customer location site number is invalid.

Solution: Add 

(R) Receivable Manager (M) Setup - Print - Remit-to Addresses - Section "Receipts From"

1.. Go to the "Receipts From" section of the form.

2. Put the cursor in the Country field and click on the LOV.

3. Select the value "Default value"

4. Put cursor in the State field and click on LOV.

5. Select the value "Default value"

6. Save.

"Default value" comes up in the LOV of Country and state, then retest  

Monday, February 27, 2023

Oracle HRMS Hierarchy Query (upward, down wards)

 Upward:

SELECT ORGANIZATION_ID_PARENT

  FROM (    SELECT LEVEL LEVEL_ID, ORGANIZATION_ID_PARENT

              FROM per_org_structure_elements org

             WHERE ORGANIZATION_ID_PARENT <> 81

        START WITH ORGANIZATION_ID_CHILD =  :p_org_id

        CONNECT BY PRIOR ORGANIZATION_ID_PARENT = ORGANIZATION_ID_CHILD)

 WHERE LEVEL_ID =

       (SELECT MAX (LEVEL_ID)

          FROM (    SELECT LEVEL LEVEL_ID, ORGANIZATION_ID_PARENT

                      FROM per_org_structure_elements org

                     WHERE ORGANIZATION_ID_PARENT <> 81

                START WITH ORGANIZATION_ID_CHILD = :p_org_id

                CONNECT BY PRIOR ORGANIZATION_ID_PARENT =

                           ORGANIZATION_ID_CHILD))



down wards:
           SELECT LPAD (' ', 10 * (LEVEL - 1)) || org.name hierarchy,
                  org.organization_id
             FROM hr_all_organization_units org, per_org_structure_elements pose
            WHERE 1 = 1 AND org.organization_id = pose.organization_id_child
       --and org.name like 'org name'
       START WITH pose.organization_id_parent = :p_org_id-- Orgnization of parent id -- provide the id from which level the downward hierarchy should be displayed
       CONNECT BY PRIOR pose.organization_id_child = pose.organization_id_parent
ORDER SIBLINGS BY org.location_id, pose.organization_id_child

Wednesday, February 8, 2023

EBS R12 API to Update Supervisor Assignment using loop for future assignment actions if available

 --begin

--fnd_global.apps_initialize(8952,52032,800);

--end;



DECLARE

P_NEW_SUPERVISOR_ID NUMBER := 1130;

P_PERSON_ID NUMBER := 211716;

P_DATE DATE := TO_DATE('01-FEB-2023');

V_OBJECT_VERSION_NUMBER NUMBER;

V_DATE DATE;

V_ERROR_MSG                          VARCHAR2(2500) := NULL;

V_API_ERROR                          VARCHAR2(500); 

--p_person_id number;

   -- Local Variables

   -- -----------------------

   lc_dt_ud_mode           VARCHAR2(100)    := NULL;

  -- ln_assignment_id       NUMBER                  := 37392;

   --ln_supervisor_id        NUMBER                  := 4485;

   ln_object_number       NUMBER                  ;

   --ln_people_group_id  NUMBER                  := 105;

 

   -- Out Variables for Find Date Track Mode API

   -- -----------------------------------------------------------------

   lb_correction                           BOOLEAN;

   lb_update                                 BOOLEAN;

   lb_update_override              BOOLEAN;

   lb_update_change_insert   BOOLEAN;

  

   -- Out Variables for Update Employee Assignment API

   -- ----------------------------------------------------------------------------

   ln_soft_coding_keyflex_id       HR_SOFT_CODING_KEYFLEX.SOFT_CODING_KEYFLEX_ID%TYPE;

   lc_concatenated_segments       VARCHAR2(2000);

   ln_comment_id                             PER_ALL_ASSIGNMENTS_F.COMMENT_ID%TYPE;

   lb_no_managers_warning        BOOLEAN;


 -- Out Variables for Update Employee Assgment Criteria

 -- -------------------------------------------------------------------------------

 ln_special_ceiling_step_id                    PER_ALL_ASSIGNMENTS_F.SPECIAL_CEILING_STEP_ID%TYPE;

 lc_group_name                                          VARCHAR2(30);

 ld_effective_start_date                             PER_ALL_ASSIGNMENTS_F.EFFECTIVE_START_DATE%TYPE;

 ld_effective_end_date                              PER_ALL_ASSIGNMENTS_F.EFFECTIVE_END_DATE%TYPE;

 lb_org_now_no_manager_warning   BOOLEAN;

 lb_other_manager_warning                  BOOLEAN;

 lb_spp_delete_warning                          BOOLEAN;

 lc_entries_changed_warning                VARCHAR2(30);

 lb_tax_district_changed_warn             BOOLEAN;

 p_cagr_grade_def_id NUMBER;

 p_cagr_concatenated_segments number;

 


 cursor C1 is

 

SELECT PAAF.ASSIGNMENT_ID,PAAF.EFFECTIVE_START_DATE, PAAF.EFFECTIVE_END_DATE

,PAAF.ASSIGNMENT_NUMBER

FROM PER_ALL_ASSIGNMENTS_F PAAF

WHERE PAAF.PERSON_ID = P_PERSON_ID

AND (P_DATE BETWEEN PAAF.EFFECTIVE_START_DATE AND  PAAF.EFFECTIVE_END_DATE

OR PAAF.EFFECTIVE_START_DATE  >= P_DATE  )

AND P_NEW_SUPERVISOR_ID IS NOT NULL

AND SUPERVISOR_ID <> P_NEW_SUPERVISOR_ID

ORDER BY effective_start_date

;



    

BEGIN

 DBMS_OUTPUT.PUT_LINE('hi1' );

FOR I IN C1 LOOP

 

V_DATE := GREATEST(P_DATE , I.EFFECTIVE_START_DATE);


   V_OBJECT_VERSION_NUMBER := 0;

   V_OBJECT_VERSION_NUMBER := XXPY_UPDATE_EMP_ASSIGNMENT.GET_OVN_F(I.ASSIGNMENT_ID,V_DATE);

DBMS_OUTPUT.PUT_LINE('V_DATE is '||V_DATE);

begin

  -- Update Employee Assignment

  -- ---------------------------------------------

 hr_assignment_api.update_emp_asg

 ( -- Input data elements

  -- ------------------------------

  p_effective_date                              =>V_DATE,

  p_datetrack_update_mode         => XXPY_UPDATE_EMP_ASSIGNMENT.GET_MODE_ASSGINMENT_F(I.ASSIGNMENT_ID,V_DATE),

  p_assignment_id                            => TO_NUMBER(I.assignment_id),

  p_supervisor_id                              => TO_NUMBER(P_NEW_SUPERVISOR_ID),

  p_change_reason                           => NULL,

--  p_manager_flag                              => 'N',

  p_bargaining_unit_code              => NULL,

  p_labour_union_member_flag   => NULL,

--  p_segment1                                       => TO_NUMBER(HIRING.LEGAL_EMP),--108,

--  p_normal_hours                              => 35,

--  p_time_normal_start                         => '07:30',

--  p_time_normal_finish                         => '14:30',

--  p_frequency                                       => 'W',

--  p_employee_category                               => HIRING.employee_category,--'EMP',

  -- Output data elements

  -- -------------------------------

  p_cagr_grade_def_id             => p_cagr_grade_def_id,-- bug 2359997

  p_cagr_concatenated_segments   => p_cagr_concatenated_segments,

  p_object_version_number             => V_OBJECT_VERSION_NUMBER,

  p_soft_coding_keyflex_id              => ln_soft_coding_keyflex_id,

  p_concatenated_segments             => lc_concatenated_segments,

  p_comment_id                                   => ln_comment_id,

  p_effective_start_date                      => ld_effective_start_date,

  p_effective_end_date                        => ld_effective_end_date,

  p_no_managers_warning               => lb_no_managers_warning,

  p_other_manager_warning            => lb_other_manager_warning

 );

 commit;

 EXCEPTION WHEN OTHERS THEN

 DBMS_OUTPUT.PUT_LINE(SQLERRM );--||'-'||I.ASSIGNMENT_NUMBER);

END;

END LOOP;

EXCEPTION WHEN OTHERS THEN

 DBMS_OUTPUT.PUT_LINE(SQLERRM );

END;


------------------------------------------------------------------------------------------------------------


FUNCTION GET_MODE_ASSGINMENT_F(P_ASSIGNMENT_ID NUMBER, P_DATE DATE)

RETURN VARCHAR2 AS

   lb_correction                  BOOLEAN;

   lb_update                      BOOLEAN;

   lb_update_override             BOOLEAN;

   lb_update_change_insert        BOOLEAN;

   lc_dt_ud_mode varchar2(200); 

   L_ERROR varchar2(2000); 

   BEGIN

dt_api.find_dt_upd_modes

   (    p_effective_date                  => P_DATE,

        p_base_table_name            => 'PER_ALL_ASSIGNMENTS_F',

        p_base_key_column            => 'ASSIGNMENT_ID',

        p_base_key_value                => P_ASSIGNMENT_ID,

         -- Output data elements

         -- --------------------------------

         p_correction                   => lb_correction,

         p_update                       => lb_update,

         p_update_override              => lb_update_override,

         p_update_change_insert    => lb_update_change_insert  ); 

 

   IF ( lb_correction = TRUE )

   THEN lc_dt_ud_mode := 'CORRECTION';

   end if;

   IF ( lb_update = TRUE )

   THEN lc_dt_ud_mode := 'UPDATE';

   END IF; 

   IF ( lb_update_override = TRUE  )

   THEN lc_dt_ud_mode := 'UPDATE_OVERRIDE';

   end if;

   IF (lb_update_change_insert = TRUE)

   THEN lc_dt_ud_mode := 'UPDATE_CHANGE_INSERT';

   end if;

   --INSERT INTO GET_MODE_ASSGINMENT_F_T(ASSIGNMENT_ID,P_DATE,ERROR_MSG,CREATION_DATE) VALUES(P_ASSIGNMENT_ID, SYSDATE,lc_dt_ud_mode,SYSDATE);

   RETURN lc_dt_ud_mode;

   EXCEPTION WHEN OTHERS THEN 

   L_ERROR := SQLERRM;

   --INSERT INTO GET_MODE_ASSGINMENT_F_T(ASSIGNMENT_ID,P_DATE,ERROR_MSG,CREATION_DATE) VALUES(P_ASSIGNMENT_ID, SYSDATE,L_ERROR,SYSDATE);

END;




FUNCTION GET_OVN_F (P_ASSIGNMENT_ID NUMBER, P_DATE DATE) RETURN NUMBER IS

L_RETURN NUMBER;

BEGIN

SELECT OBJECT_VERSION_NUMBER 

INTO L_RETURN

FROM PER_ALL_ASSIGNMENTS_F PAAF

WHERE ASSIGNMENT_ID = P_ASSIGNMENT_ID

AND P_DATE BETWEEN EFFECTIVE_START_DATE AND EFFECTIVE_END_DATE

AND PRIMARY_FLAG = 'Y'

;

RETURN L_RETURN;

EXCEPTION WHEN OTHERS THEN RETURN 0;

END;