示例#1
0
        static void Main(string[] args)
        {
            BAPISDLS LOGIC_SWITCH = new BAPISDLS();

            //Build object and value to Object
            BAPISDHD1 ORDER_HEADER_IN = new BAPISDHD1();

            ORDER_HEADER_IN.DOC_TYPE = "";
            ORDER_HEADER_IN.SALES_ORG = "";
            ORDER_HEADER_IN.DISTR_CHAN = "";
            ORDER_HEADER_IN.DIVISION = "";
            ORDER_HEADER_IN.REF_DOC_L = "";
            //---------------------------------------------------------

            //Build object and value to Object
            BAPISDHD1X ORDER_HEADER_INX = new BAPISDHD1X();

            ORDER_HEADER_INX.DOC_TYPE = "";
            ORDER_HEADER_INX.SALES_ORG = "";
            ORDER_HEADER_INX.DISTR_CHAN = "";
            ORDER_HEADER_INX.DIVISION = "";
            ORDER_HEADER_INX.REF_DOC_L = "";
            //---------------------------------------------------------

            BAPI_SENDER SENDER = new BAPI_SENDER();

            BAPIPAREX[] EXTENSIONIN = new BAPIPAREX[1];
            BAPICCARD[] ORDER_CCARD = new BAPICCARD[1];
            BAPICUBLB[] ORDER_CFGS_BLOB = new BAPICUBLB[1];
            BAPICUINS[] ORDER_CFGS_INST = new BAPICUINS[1];
            BAPICUPRT[] ORDER_CFGS_PART_OF = new BAPICUPRT[1];
            BAPICUCFG[] ORDER_CFGS_REF = new BAPICUCFG[1];
            BAPICUREF[] ORDER_CFGS_REFINST = new BAPICUREF[1];
            BAPICUVAL[] ORDER_CFGS_VALUE = new BAPICUVAL[1];
            BAPICUVK[] ORDER_CFGS_VK = new BAPICUVK[1];
            BAPICOND[] ORDER_CONDITIONS_IN = new BAPICOND[1];
            BAPICONDX[] ORDER_CONDITIONS_INX = new BAPICONDX[1];

            //Build object and value to []
            BAPISDITM[] ORDER_ITEMS_IN = new BAPISDITM[1];

            BAPISDITM item = new BAPISDITM();

            item.ITM_NUMBER = "";
            item.MATERIAL = "";
            item.TARGET_QTY = 5;

            ORDER_ITEMS_IN.SetValue(item, 0);
            //---------------------------------------------------------
            //Build object and value to []
            BAPISDITMX[] ORDER_ITEMS_INX = new BAPISDITMX[1];

            BAPISDITMX itemx = new BAPISDITMX();

            itemx.ITM_NUMBER = "";
            itemx.MATERIAL = "";
            itemx.TARGET_QTY = "";

            ORDER_ITEMS_INX.SetValue(itemx, 0);
            //---------------------------------------------------------
            BAPISDKEY[] ORDER_KEYS = new BAPISDKEY[1];
            BAPIPARNR[] ORDER_PARTNERS = new BAPIPARNR[1];

            //Build object and value to []
            BAPIPARNR ordPartn = new BAPIPARNR();

            ordPartn.PARTN_ROLE = "";
            ordPartn.PARTN_NUMB = "";

            ORDER_PARTNERS.SetValue(ordPartn, 0);
            //---------------------------------------------------------
            //Build object and value to []
            BAPISCHDL[] ORDER_SCHEDULES_IN = new BAPISCHDL[1];

            BAPISCHDL OrdSchedIn = new BAPISCHDL();

            OrdSchedIn.ITM_NUMBER = "";
            OrdSchedIn.REQ_QTY = 4;

            ORDER_SCHEDULES_IN.SetValue(OrdSchedIn, 0);
            //---------------------------------------------------------
            //Build object and value to []
            BAPISCHDLX[] ORDER_SCHEDULES_INX = new BAPISCHDLX[1];

            BAPISCHDLX OrdSchedInX = new BAPISCHDLX();

            OrdSchedInX.ITM_NUMBER = "";
            OrdSchedInX.REQ_QTY = "";

            //---------------------------------------------------------

            BAPISDTEXT[] ORDER_TEXT = new BAPISDTEXT[1];
            BAPIADDR1[] PARTNERADDRESSES = new BAPIADDR1[1];
            BAPIRET2[] RETURN = new BAPIRET2[1];

            CreateSalesOrderServiceReference.SalesOrderCreateFromDat2_Outbound_AsyncClient client = new CreateSalesOrderServiceReference.SalesOrderCreateFromDat2_Outbound_AsyncClient();
            client.SalesOrderCreateFromDat2_Outbound_AsyncAsync("adsf", "adf", "adsf", "asdf", LOGIC_SWITCH,
                ORDER_HEADER_IN, ORDER_HEADER_INX, "", SENDER, "", EXTENSIONIN, ORDER_CCARD,
                ORDER_CFGS_BLOB, ORDER_CFGS_INST, ORDER_CFGS_PART_OF, ORDER_CFGS_REF, ORDER_CFGS_REFINST,
                ORDER_CFGS_VALUE, ORDER_CFGS_VK, ORDER_CONDITIONS_IN, ORDER_CONDITIONS_INX,
                ORDER_ITEMS_IN, ORDER_ITEMS_INX, ORDER_KEYS, ORDER_PARTNERS, ORDER_SCHEDULES_IN,
                ORDER_SCHEDULES_INX, ORDER_TEXT, PARTNERADDRESSES, RETURN);
        }
示例#2
0
        /// <summary>
        /// Call to ZSDI3003_CONTRACT_CREATE.
        /// </summary>
        /// <param name="contract"></param>
        /// <returns></returns>
        private IEnumerable <Result> WebServiceInvocator(NormalContract contract)
        {
            List <Result> result = new List <Result>();

            // Import tab in ZSDI3003_CONTRACT_CREATE.
            BAPISDHD1  contract_header_in  = new BAPISDHD1();
            BAPISDHD1X contract_header_inx = new BAPISDHD1X();
            BAPISDLS   logic_switch        = new BAPISDLS();

            // Tables tab in ZSDI3003_CONTRACT_CREATE.
            BAPICUBLB[]  contract_cfgs_blob      = new BAPICUBLB[1];
            BAPICUINS[]  contract_cfgs_inst      = new BAPICUINS[1];
            BAPICUPRT[]  contract_cfgs_part_of   = new BAPICUPRT[1];
            BAPICUCFG[]  contract_cfgs_ref       = new BAPICUCFG[1];
            BAPICUREF[]  contract_cfgs_refinst   = new BAPICUREF[1];
            BAPICUVAL[]  contract_cfgs_value     = new BAPICUVAL[1];
            BAPICUVK[]   contract_cfgs_vk        = new BAPICUVK[1];
            BAPICONDX[]  contract_conditions_inx = new BAPICONDX[1];
            BAPICTR[]    contract_data_in        = new BAPICTR[1];
            BAPICTRX[]   contract_data_inx       = new BAPICTRX[1];
            BAPISDITMX[] contract_items_inx      = new BAPISDITMX[1];
            BAPISDKEY[]  contract_keys           = new BAPISDKEY[1];
            BAPIPARNR[]  contract_partners       = new BAPIPARNR[2];
            BAPIPAREX[]  extensionin             = null;
            BAPIADDR1[]  partneraddresses        = new BAPIADDR1[1];
            BAPIRET2[]   breturn                = new BAPIRET2[1];
            BAPISDTEXT[] contract_text          = null;
            BAPICOND[]   contract_conditions_in = null;
            BAPISDITM[]  contract_items_in      = new BAPISDITM[contract.NormalContractItems.Count];

            //// HEADER ----------------------------------------------------------------------
            contract_header_in.DOC_TYPE   = contract.DocumentType.Id;
            contract_header_in.SALES_ORG  = contract.SalesOrganization.Id;
            contract_header_in.DISTR_CHAN = contract.DistributionChannel.Id;
            contract_header_in.DIVISION   = contract.SalesDivision.Id;
            contract_header_in.CT_VALID_F = contract.StartDate.Value.ToString("yyyy-MM-dd");
            contract_header_in.CT_VALID_T = contract.EndDate.Value.ToString("yyyy-MM-dd");
            contract_header_in.PURCH_NO_C = contract.PONumber.ToString();
            contract_header_in.SALES_GRP  = contract.SalesSupervisor.Code;
            contract_header_in.SALES_OFF  = contract.SalesSupervisor.Superior.Code;

            //// ITEMS ----------------------------------------------------------------------
            int itemsIndex = 0;

            foreach (NormalContractItem item in contract.NormalContractItems)
            {
                BAPISDITM bapisditm = new BAPISDITM();
                bapisditm.ITM_NUMBER          = string.Format("{0,6:000000}", item.Id);
                bapisditm.MATERIAL            = item.Material.Id;
                bapisditm.TARGET_QTY          = item.Quantity;
                bapisditm.TARGET_QTYSpecified = true;
                bapisditm.TARGET_QU           = "MTN";
                bapisditm.INCOTERMS1          = item.Incoterms.Id;
                bapisditm.INCOTERMS2          = item.Region.Name;

                contract_items_in[itemsIndex] = bapisditm;
                itemsIndex++;
            }

            // CUSTOMER ----------------------------------------------------------------------

            /*
             * AG = SP - EMISSOR DA ORDEM
             * PY = RG - PAGADOR
             * SH = WE - RECEBEDOR
             * ZW = ZW - RECEBEDOR'
             * ZA = ZA - AGENTE DE VENDAS
             */
            BAPIPARNR contract_partners_SoldTo = new BAPIPARNR();

            contract_partners_SoldTo.PARTN_ROLE = "SP";
            contract_partners_SoldTo.PARTN_NUMB = contract.Customer.Id;
            contract_partners[0] = contract_partners_SoldTo;

            //// SEND THE CONTRACT ----------------------------------------------------------------------
            NetworkCredential lNetCredentials = new NetworkCredential();

            lNetCredentials.UserName = ConfigurationManager.AppSettings["SI_CREATE_CONTRACT_OB_USER"];
            lNetCredentials.Password = ConfigurationManager.AppSettings["SI_CREATE_CONTRACT_OB_PWD"];

            SI_CREATE_CONTRACT_OB_BrazilMOService service = new SI_CREATE_CONTRACT_OB_BrazilMOService();

            service.Credentials = lNetCredentials;
            service.Timeout     = int.MaxValue;

            try
            {
                string res = service.SI_CREATE_CONTRACT_OB_BrazilMO(
                    null,
                    null,
                    contract_header_in,
                    contract_header_inx,
                    "X",
                    string.Empty, //IM_ZZREPCC (NU_CONTRATO_SUBSTITUI),
                    "X",
                    logic_switch,
                    "",
                    null,
                    string.Empty, //TESTRUN
                    ref contract_cfgs_blob,
                    ref contract_cfgs_inst,
                    ref contract_cfgs_part_of,
                    ref contract_cfgs_ref,
                    ref contract_cfgs_refinst,
                    ref contract_cfgs_value,
                    ref contract_cfgs_vk,
                    ref contract_conditions_in,
                    ref contract_conditions_inx,
                    ref contract_data_in,
                    ref contract_data_inx,
                    ref contract_items_in,
                    ref contract_items_inx,
                    ref contract_keys,
                    ref contract_partners,
                    ref contract_text,
                    ref extensionin,
                    ref partneraddresses,
                    ref breturn
                    );

                if (breturn != null)
                {
                    for (int i = 0; i <= breturn.Length - 1; i++)
                    {
                        if ((breturn[i].TYPE.ToUpper() == "S") && (breturn[i].NUMBER == "311"))
                        {
                            result.Add(new Result
                                       (
                                           success: true,
                                           message: "CONTRACT_NUMBER",
                                           payload: breturn[i].MESSAGE_V2
                                       ));
                        }
                        else
                        {
                            result.Add(new Result
                                       (
                                           success: (breturn[i].TYPE == "S"),
                                           message: breturn[i].MESSAGE
                                       ));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Add(new Result
                           (
                               success: false,
                               message: ex.Message
                           ));
                if (ex.InnerException != null)
                {
                    result.Add(new Result
                               (
                                   success: false,
                                   message: ex.InnerException.Message
                               ));
                }
            }

            return(result);
        }