private BusinessPartnerResponse SetCustomerData(string externalId, BusinessPartnerRequest businessPartner) { var response = new BusinessPartnerResponse(); response = _customerService.SetCustomerFromBusinessPartner(businessPartner, _billingCountry, externalId); if (response.Errors.Count > 0) { return(response); } AccountHierarchyResponse hierResponse = new AccountHierarchyResponse(); if (string.IsNullOrEmpty(businessPartner.BpDetails.Hierarchy.ParentId)) { hierResponse = _hierarchyService.SetAccountHierarchy(businessPartner.BpDetails.Hierarchy, externalId); } else { hierResponse = _hierarchyService.SetAccountToGroup(businessPartner.BpDetails.Hierarchy, externalId); } response.Errors = hierResponse.Errors; response.Warnings = hierResponse.Warnings; response.Note = hierResponse.Note; response.Hierarchy = hierResponse; return(response); }
public BusinessPartnerResponse SetBusinessPartner(BusinessPartnerRequest businessPartner) { var req = new BusinessPartnerBundleMaintainRequestMessage_sync(); //int bpCount = GetNumberOfBusinessPartners(businessPartner); req.BusinessPartner = new BusinessPartnerMaintainRequestBundleBusinessPartner[1]; var sapBp = SetAccountDetails(businessPartner.BpDetails); req.BusinessPartner[0] = sapBp; _billingCountry = businessPartner.Locations.First(x => x.LocationTypeExternalId.Contains("BILL_TO")).CountryExternalId; //if this is a new business partner, we need to create it with only one location first if (string.IsNullOrEmpty(businessPartner.BpDetails.ExternalID)) { //find the default and set the details var defaultLocation = businessPartner.Locations.First(x => x.LocationTypeExternalId.Contains("BILL_TO")); req.BusinessPartner[0].AddressInformation = SetDefaultLocation(defaultLocation, businessPartner.BpDetails.Email, businessPartner.BpDetails.Website); //var xml1 = SapXmlExtractor.GetXmlString(req); var defaultLocationResponse = ParseSapManageResponse(_manageClient.MaintainBundle(req)); //was the call successful? if (defaultLocationResponse.Errors.Count > 0) { return(defaultLocationResponse); } else { //we need to query the new business partner to get the UUID of the default location we just created var bpQueryResponse = GetBusinessPartner(defaultLocationResponse.BpExternalId, businessPartner); if (string.IsNullOrEmpty(bpQueryResponse.BpExternalId)) { return(bpQueryResponse); } //set the external ids so that we are now updating the business partner and the location that exists defaultLocation.ExternalId = bpQueryResponse.LocationExternalIds.First().ExternalId; req.BusinessPartner[0].InternalID = bpQueryResponse.BpExternalId; } } var sapLocations = SetLocationDetails(businessPartner.Locations, businessPartner.BpDetails.Email, businessPartner.BpDetails.Website); req.BusinessPartner[0].AddressInformation = sapLocations; var sapContacts = SetContactDetails(businessPartner.Contacts, businessPartner.BpDetails.Website, businessPartner.BpDetails.ExternalID); req.BusinessPartner[0].ContactPerson = sapContacts; //var xml2 = SapXmlExtractor.GetXmlString(req); var sapResponse = _manageClient.MaintainBundle(req); var sapResponseParsed = ParseSapManageResponse(sapResponse); return(sapResponseParsed); }
public BusinessPartnerQueryResponse GetBusinessPartner(string externalId, BusinessPartnerRequest bpRequest) { var sapResponse = CreateBusinessPartnerQuery(externalId); var sapParsedResponse = ParseSapQueryResponse(sapResponse, bpRequest); return(sapParsedResponse); }
private int GetNumberOfBusinessPartners(BusinessPartnerRequest businessPartner) { int accountCount = 1; int contactCount = businessPartner.Contacts.Count; int locationCount = businessPartner.Locations.Count; return(accountCount + contactCount + locationCount); }
public BusinessPartnerResponse ProcessBusinessPartnerRequest(BusinessPartnerRequest businessPartner) { var bpManageResponse = SetBusinessPartner(businessPartner); var response = new BusinessPartnerResponse(); if (bpManageResponse.Errors.Count > 0) { return(bpManageResponse); } var bpQueryResponse = GetBusinessPartner(bpManageResponse.BpExternalId, businessPartner); if (string.IsNullOrEmpty(bpQueryResponse.BpExternalId)) { return(bpQueryResponse); } if (businessPartner.BpDetails.AccountTypes.Contains("supplier", StringComparer.OrdinalIgnoreCase)) { var suppRequest = SetSupplierData(bpQueryResponse.BpExternalId); response.SupplierDetails = suppRequest.SupplierDetails; if (suppRequest.Errors.Count > 0) { return(suppRequest); } } if (businessPartner.BpDetails.AccountTypes.Contains("customer", StringComparer.OrdinalIgnoreCase)) { var custRequest = SetCustomerData(bpQueryResponse.BpExternalId, businessPartner); if (custRequest.Errors.Count > 0) { return(custRequest); } response.Hierarchy = custRequest.Hierarchy; response.Hierarchy.Id = businessPartner.BpDetails.Hierarchy.Id; response.CustomerDetails = custRequest.CustomerDetails; } response.BpExternalId = bpQueryResponse.BpExternalId; response.ExternalId = bpQueryResponse.BpExternalId; response.ContactExternalIds = bpQueryResponse.ContactExternalIds; response.LocationExternalIds = bpQueryResponse.LocationExternalIds; response.Status = bpQueryResponse.Status; response.Errors = bpQueryResponse.Errors; response.Warnings = bpQueryResponse.Warnings; response.Note = bpQueryResponse.Note; return(response); }
public BusinessPartnerIncomingResponse SetBusinessPartner(BusinessPartnerRequest bp) { return(_businessPartnerService.MapBusinessPartnerResponse(_businessPartnerService.ProcessBusinessPartnerRequest(bp))); }
public BusinessPartnerResponse SetLocationAndContactIds(BusinessPartnerResponseMessage_sync queryResponse, BusinessPartnerRequest bpRequest) { var response = new BusinessPartnerResponse(); if (queryResponse.BusinessPartner[0].AddressInformation != null) { response.LocationExternalIds = new List <PairedIdsResponse>(); foreach (var location in bpRequest.Locations) { var match = queryResponse.BusinessPartner[0].AddressInformation.FirstOrDefault(x => FindLocationMatch(x, location)); if (match != null) { response.LocationExternalIds.Add(new PairedIdsResponse { LocalId = location.LocationId, ExternalId = match.UUID.Value }); } } } if (queryResponse.BusinessPartner[0].ContactPerson != null) { response.ContactExternalIds = new List <PairedIdsResponse>(); foreach (var contact in bpRequest.Contacts) { try { var match = queryResponse.BusinessPartner[0].ContactPerson.First(x => FindContactMatch(x, contact)); response.ContactExternalIds.Add(new PairedIdsResponse { LocalId = contact.ContactId, ExternalId = match.BusinessPartnerContactInternalID }); } catch (Exception e) { response.Errors.Add(e.Message); return(response); } } } return(response); }
private BusinessPartnerQueryResponse ParseSapQueryResponse(BusinessPartnerResponseMessage_sync sapResponse, BusinessPartnerRequest bpRequest) { BusinessPartnerQueryResponse response = new BusinessPartnerQueryResponse(); BaseResponse tempRes = SapLogParser.ParseSapResponseLog(sapResponse.Log); response.Errors = tempRes.Errors; response.Warnings = tempRes.Warnings; if (sapResponse.BusinessPartner != null) { response.BpExternalId = sapResponse.BusinessPartner[0].InternalID; response.IsSupplier = sapResponse.BusinessPartner[0].SupplierIndicator; response.IsCustomer = sapResponse.BusinessPartner[0].CustomerIndicator; response.Status = sapResponse.BusinessPartner[0].LifeCycleStatusCode.GetEnumDescription(); } else { return(response); } BusinessPartnerResponse conAndLocData = SetLocationAndContactIds(sapResponse, bpRequest); response.LocationExternalIds = conAndLocData.LocationExternalIds; response.ContactExternalIds = conAndLocData.ContactExternalIds; return(response); }
public BusinessPartnerResponse SetCustomerFromBusinessPartner(BusinessPartnerRequest customer, string billingCountry, string externalId) { var query = new CustomerBundleMaintainRequestMessage_sync_V1(); CustomerMaintainRequestBundleCustomer_V1 sapCustomer = new CustomerMaintainRequestBundleCustomer_V1(); sapCustomer.InternalID = externalId; sapCustomer.CreateFromBusinessPartnerIndicator = true; sapCustomer.CreateFromBusinessPartnerIndicatorSpecified = true; sapCustomer.actionCode = ActionCode.Item02; sapCustomer.actionCodeSpecified = true; sapCustomer.directResponsibilityListCompleteTransmissionIndicator = true; sapCustomer.directResponsibilityListCompleteTransmissionIndicatorSpecified = true; sapCustomer.DirectResponsibility = new CustomerMaintainRequestBundleDirectResponsibility[1]; sapCustomer.DirectResponsibility[0] = new CustomerMaintainRequestBundleDirectResponsibility(); sapCustomer.DirectResponsibility[0].PartyRoleCode = "142"; sapCustomer.DirectResponsibility[0].EmployeeID = new AccountManageCustomerService.EmployeeID(); sapCustomer.DirectResponsibility[0].EmployeeID.Value = customer.BpDetails.Ownership.LeadOwner.ExternalId; _sapOrgs = _sapService.SetOrgsFromDb(); sapCustomer.salesArrangementListCompleteTransmissionIndicatorSpecified = true; sapCustomer.salesArrangementListCompleteTransmissionIndicator = true; sapCustomer.SalesArrangement = new CustomerMaintainRequestBundleSalesArrangement[_sapOrgs.Sales.Count]; //sapCustomer.PaymentData = new CustomerMaintainRequestBundlePaymentData[_sapOrgs.Sales.Count]; foreach (var sales in _sapOrgs.Sales) { int index = _sapOrgs.Sales.IndexOf(sales); //sales arrangement var salesArrangement = new CustomerMaintainRequestBundleSalesArrangement(); salesArrangement.SalesOrganisationID = sales; salesArrangement.DistributionChannelCode = new AccountManageCustomerService.DistributionChannelCode(); salesArrangement.DistributionChannelCode.Value = "01"; salesArrangement.CompleteDeliveryRequestedIndicator = false; salesArrangement.CompleteDeliveryRequestedIndicatorSpecified = true; //payment data //var paymentData = new CustomerMaintainRequestBundlePaymentData(); //paymentData.CompanyID = company.Company; //paymentData.AccountDeterminationDebtorGroupCode = new AccountManageCustomerService.AccountDeterminationDebtorGroupCode(); //paymentData.AccountDeterminationDebtorGroupCode.Value = company.CountryCode == billingCountry ? "4010" : "4020"; //paymentData.PaymentForm = new CustomerMaintainRequestBundlePaymentDataPaymentForm[1]; //paymentData.PaymentForm[0] = new CustomerMaintainRequestBundlePaymentDataPaymentForm(); //paymentData.PaymentForm[0].PaymentFormCode = "06"; //sapCustomer.PaymentData[index] = paymentData; sapCustomer.SalesArrangement[index] = salesArrangement; } sapCustomer.generalProductTaxExemptionListCompleteTransmissionIndicator = true; sapCustomer.generalProductTaxExemptionListCompleteTransmissionIndicatorSpecified = true; sapCustomer.GeneralProductTaxExemption = new CustomerMaintainRequestBundleGeneralProductTaxExemption[1]; sapCustomer.GeneralProductTaxExemption[0] = new CustomerMaintainRequestBundleGeneralProductTaxExemption(); sapCustomer.GeneralProductTaxExemption[0].CountryCode = "US"; sapCustomer.GeneralProductTaxExemption[0].TaxTypeCode = new AccountManageCustomerService.TaxTypeCode { listID = "US", Value = "1" }; sapCustomer.GeneralProductTaxExemption[0].ReasonCode = new AccountManageCustomerService.TaxExemptionReasonCode { listID = "US", Value = "O" }; //shipping instructions //sapCustomer.Text = new CustomerMaintainRequestBundleText[1]; //sapCustomer.Text[0] = new CustomerMaintainRequestBundleText(); //sapCustomer.textListCompleteTransmissionIndicator = true; //sapCustomer.textListCompleteTransmissionIndicatorSpecified = true; //sapCustomer.Text[0].ContentText = customer.BpDetails.ShippingInstructions; CustomerMaintainRequestBundleCustomer_V1[] customerArray = new CustomerMaintainRequestBundleCustomer_V1[1]; customerArray[0] = sapCustomer; query.Customer = customerArray; CustomerBundleMaintainConfirmationMessage_sync_V1 sapResponse = _manageClient.MaintainBundle_V1(query); return(CreateSetCustomerResponse(sapResponse)); }