Tuesday, March 6, 2018

How to Create Purchase Order from Backend by using interface tables

declare
CURSOR c2 (v_po_number varchar2)
        IS
        select distinct po_num, po.line_num,po.item_id, po.po_header_id,po.promised_date, po.agent_id, po.type_lookup_code,
         po.attribute12, po.attribute14, po.terms_id, po.org_id, po.rate_date,
                    po.RATE_TYPE,  po.vendor_id, po.vendor_site_id, po.currency_code, po.need_by_date, po.shipment_num,
                    remaining_qty, po.unit_price, po.SHIP_TO_ORGANIZATION_ID, line_type_id,
                    po.DISTRIBUTION_NUM,  po.code_combination_id, po.DESTINATION_CONTEXT, po.po_line_id, req_distribution_id,
                      po.item_description, unit_meas_lookup_code
                     from xxbak_open_po_v po
                   
                     where
                          remaining_qty>0
                          and po.PO_NUM=v_po_number
                   
                          ;
                   




        l_user_emp_id NUMBER;
        l_item_account_id NUMBER;
        l_location_id NUMBER;
        l_user_id NUMBER;
        l_incident_number NUMBER;
        l_org_id NUMBER;
        l_sob_id NUMBER;
        l_sob_currency VARCHAR2 (15);
        l_line_no NUMBER;
        l_request_id NUMBER;
        l_doc_num NUMBER;
         l_organization_id NUMBER;




  BEGIN
            l_user_id := fnd_profile.VALUE ('USER_ID');
            l_org_id :=fnd_profile.VALUE ('ORG_ID');
            l_organization_id :=114; -- fnd_profile.VALUE ('GAA_ORGANIZATION_ID');
            l_sob_id := fnd_profile.VALUE ('GL_SET_OF_BKS_ID');   
             
         
          -- dbms_output.put_line(1);
         
     FOR h in (select distinct po_num,
                      po.po_header_id,
                      po.agent_id,
                      po.type_lookup_code,
                      po.attribute12,
                      po.attribute14,
                      po.terms_id,
                      po.org_id,
                      po.rate_date,
                      po.RATE_TYPE,
                      po.rate,
                      po.vendor_id,
                      po.vendor_site_id,
                      po.currency_code,
                      po.ship_to_location_id_h,
                      po.bill_to_location_id ,
                      po.fob_lookup_code,
                      po.note_to_authorizer,
                      po.note_to_vendor_h,
                      po.note_to_receiver,
                      po.comments,
                      po.attribute_category,
                      attribute4,
                          attribute5,
                          attribute7,
                          attribute9,
                          attribute10,
                          attribute13
                                       
                     from xxbak_open_po_v po
                      where remaining_qty>0                                 
                 
                           
                       ) loop
                             





           INSERT INTO po_headers_interface
                        (INTERFACE_HEADER_ID, --1
                          ACTION,--2
                          ORG_ID,--3
                          AGENT_ID,--4
                          DOCUMENT_TYPE_CODE, --5
                          DOCUMENT_NUM,--6
                          VENDOR_ID, --7
                          VENDOR_SITE_ID, ---8
                          LOAD_SOURCING_RULES_FLAG ,---9
                          COMMENTS, ---10
                          CURRENCY_CODE, --11
                          RATE_TYPE, --12
                          rate, ---13
                          RATE_DATE, ---14
                          attribute12, ---15 cost_center
                          attribute14, ---16  asr
                          ship_to_location_id,
                          bill_to_location_id,
                          terms_id,
                          fob,
                          note_to_vendor ,
                          note_to_receiver,
                          attribute_category,
                          attribute4,
                          attribute5,
                          attribute7,
                          attribute9,
                          attribute10,
                          attribute13
                          )
                    VALUES
                        (PO_HEADERS_INTERFACE_S.NEXTVAL, --1
                        'ORIGINAL', --2
                         h.org_id,---3
                         h.agent_id, --4
                         h.type_lookup_code, --5
                         'P-'||h.po_num, ---6
                         h.vendor_id, ---7
                         h.vendor_site_id,---8
                         'N', ----9                   
                         h.comments, --10
                         h.currency_code, --11
                         decode(h.RATE_TYPE,1000,'User',h.RATE_TYPE), --12
                         h.rate,---13
                         decode(h.CURRENCY_CODE,'AZN', null,h.rate_date), ---14
                         h.attribute12, --15
                         h.attribute14,
                         h.ship_to_location_id_h,
                         h.bill_to_location_id,
                         h.terms_id,
                         h.fob_lookup_code,
                         h.note_to_vendor_h,
                         h.note_to_receiver,
                         h.attribute_category,
                         h.attribute4,
                         h.attribute5,
                         h.attribute7,
                         h.attribute9,
                         h.attribute10,
                         h.attribute13
                         ); 




         for l in c2(h.po_num) loop   
         
                    INSERT INTO po_lines_interface
                    (interface_line_id, ---1
                    interface_header_id, ---2
                    line_type_id,---3
                    item_id, ---4
                    item_description,  ---5
                    unit_price, ---6
                    unit_of_measure, ---7
                    quantity,---8
                    note_to_vendor, ---9
                    shipment_num, ----10
                    line_num, ---11
                    NEED_BY_DATE,  ---12
                    PROMISED_DATE, ---13
                    SHIPMENT_TYPE, ---14
                    ship_to_organization_id)  ---15 
                    VALUES
                    ( PO_LINES_INTERFACE_S.NEXTVAL,---1
                     PO_HEADERS_INTERFACE_S.CURRVAL, ---2
                     l.line_type_id,---3
                     l.item_id, ---4
                     l.item_description, ---5
                     l.unit_price, ---6
                     l.unit_meas_lookup_code, ---7
                     l.remaining_qty, ---8
                     l.item_description,---9
                     l.shipment_num, ---10
                     l.line_num, ---11
                     l.need_by_date,---12
                     l.promised_date,---13
                     'STANDARD',---14
                     l.SHIP_TO_ORGANIZATION_ID);
                   
                   INSERT INTO po_distributions_interface
                        (interface_line_id,---1
                        interface_header_id, ---2
                        interface_distribution_id, ---3
                        ORG_ID, ---4
                        QUANTITY_ORDERED, ---5
                        DESTINATION_TYPE_CODE, ---6
                        CHARGE_ACCOUNT_ID, -----7
                        DISTRIBUTION_NUM, -----8
                        DESTINATION_ORGANIZATION_ID, --9
                        req_distribution_id)
                    VALUES
                        (PO_LINES_INTERFACE_S.CURRVAL, ---1
                         PO_HEADERS_INTERFACE_S.CURRVAL, ---2
                         PO_DISTRIBUTIONS_INTERFACE_S.NEXTVAL,----3
                         l.ORG_ID,  ---4
                         l.REMAINING_QTY, ----5
                         l.DESTINATION_CONTEXT, ----6
                         l.code_combination_id, ----7
                         l.DISTRIBUTION_NUM, ---8
                         l.SHIP_TO_ORGANIZATION_ID,
                         l.req_distribution_id);
                       
                     
             end loop;
     
   

    END LOOP;
    Commit;

                END;

3 comments:

  1. Casino Games - Jeopardy Casino - Jeopardy.com
    Casino Games. We've got some of the biggest and most anticipated video 나주 출장마사지 games 포항 출장샵 out 부천 출장마사지 there and 아산 출장안마 all this 강릉 출장샵 time! Come and play your favorite casino game,

    ReplyDelete
  2. Every business should invest in basic cybersecurity training. DigitalViking.tech

    ReplyDelete