Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private BusinessPartnerIncomingResponse ParseSapQueryResponseForIncoming(BusinessPartnerResponseMessage_sync sapResponse)
        {
            BusinessPartnerIncomingResponse response = SetLocationAndContactIdsForIncoming(sapResponse);

            if (sapResponse.BusinessPartner != null)
            {
                var bp = sapResponse.BusinessPartner[0];
                response.AccountDetails            = new AccountDetailsIncoming();
                response.AccountDetails.ExternalID = bp.InternalID;
                response.AccountDetails.Status     = bp.LifeCycleStatusCode.GetEnumDescription();
                response.AccountDetails.Name       = bp.Organisation != null ? bp.Organisation.FirstLineName : null;

                var defaultLocation = response.Locations.Where(x => x.isDefault == true).FirstOrDefault();
                if (defaultLocation != null)
                {
                    response.AccountDetails.Website = defaultLocation.Website;
                    response.AccountDetails.Email   = defaultLocation.Email;
                }

                response.AccountDetails.VendorNum      = bp.ApprovedVendor1;
                response.AccountDetails.ApprovedVendor = bp.ApprovedVendor;
                response.AccountDetails.CompanyType    = bp.CompanyType;
                response.AccountDetails.AccountTypes   = new List <string>();

                if (sapResponse.BusinessPartner[0].CustomerIndicator)
                {
                    var custResponse = _customerService.GetCustomerDetails(bp.InternalID);
                    response.AccountDetails.CustomerDetails = custResponse.CustomerDetails != null ? custResponse.CustomerDetails : new AccountTypeDetails();
                    response.AccountDetails.AccountTypes.Add("customer");

                    //hierarchy
                    var hierarchy = _hierarchyService.IsAccountAssignedToHierarchy(bp.InternalID);
                    if (hierarchy.ParentId != null)
                    {
                        response.AccountDetails.Hierarchy = hierarchy;
                    }
                }

                if (sapResponse.BusinessPartner[0].SupplierIndicator)
                {
                    var suppResponse = _supplierService.GetSupplierDetails(bp.InternalID);
                    response.AccountDetails.SupplierDetails = suppResponse.SupplierDetails != null ? suppResponse.SupplierDetails : new AccountTypeDetails();
                    response.AccountDetails.AccountTypes.Add("supplier");
                }
            }

            BaseResponse tempRes = SapLogParser.ParseSapResponseLog(sapResponse.Log);

            response.Errors   = tempRes.Errors;
            response.Warnings = tempRes.Warnings;

            return(response);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private BusinessPartnerIncomingResponse SetLocationAndContactIdsForIncoming(BusinessPartnerResponseMessage_sync queryResponse)
        {
            var response = new BusinessPartnerIncomingResponse();

            response.Locations = new List <LocationDetails>();
            response.Contacts  = new List <ContactDetails>();

            if (queryResponse.BusinessPartner[0] != null)
            {
                if (queryResponse.BusinessPartner[0].AddressInformation != null)
                {
                    foreach (var addressInformation in queryResponse.BusinessPartner[0].AddressInformation)
                    {
                        var location = new LocationDetails();

                        if (addressInformation.Address != null && addressInformation.Address.PostalAddress != null)
                        {
                            var postalAddress = addressInformation.Address.PostalAddress;

                            location.Address1          = postalAddress.CareOfName;
                            location.Address2          = postalAddress.AdditionalStreetPrefixName;
                            location.Address4          = postalAddress.StreetSuffixName;
                            location.HouseNo           = postalAddress.HouseID;
                            location.Street            = postalAddress.StreetName;
                            location.City              = postalAddress.CityName;
                            location.StateExternalId   = postalAddress.RegionCode != null ? postalAddress.RegionCode.Value : null;
                            location.District          = postalAddress.DistrictName;
                            location.CountryExternalId = postalAddress.CountryCode;
                            location.Website           = addressInformation.Address.WebURI;
                            location.Email             = addressInformation.Address.EmailURI != null ? addressInformation.Address.EmailURI.Value : null;
                            location.PostalCode        = postalAddress.StreetPostalCode;
                        }

                        if (addressInformation.AddressUsage != null)
                        {
                            location.LocationTypeExternalId = new List <string>();

                            if (queryResponse.BusinessPartner[0].AddressInformation.Count() == 1)
                            {
                                location.isDefault = true;
                                location.LocationTypeExternalId.Add("BILL_TO");
                                location.LocationTypeExternalId.Add("SHIP_TO");
                            }
                            else
                            {
                                foreach (var addressUsage in addressInformation.AddressUsage)
                                {
                                    if (addressUsage.AddressUsageCode.Value == "BILL_TO")
                                    {
                                        if (addressUsage.DefaultIndicator == true)
                                        {
                                            location.LocationTypeExternalId.Add("BILL_TO");
                                        }
                                    }
                                    else
                                    {
                                        if (addressUsage.AddressUsageCode.Value == "XXDEFAULT")
                                        {
                                            location.isDefault = true;
                                        }
                                        if (addressUsage.AddressUsageCode.Value == "SHIP_TO")
                                        {
                                            location.LocationTypeExternalId.Add(addressUsage.AddressUsageCode.Value);
                                        }
                                    }
                                }
                            }
                        }

                        location.ExternalId = addressInformation.UUID != null ? addressInformation.UUID.Value : null;
                        response.Locations.Add(location);
                    }
                }

                if (queryResponse.BusinessPartner[0].ContactPerson != null)
                {
                    foreach (var sapContact in queryResponse.BusinessPartner[0].ContactPerson)
                    {
                        var contact = new ContactDetails();

                        contact.FirstName          = sapContact.GivenName;
                        contact.LastName           = sapContact.FamilyName;
                        contact.OfficePhone        = sapContact.WorkplaceTelephone[0] != null ? sapContact.WorkplaceTelephone[0].FormattedNumberDescription : null;
                        contact.Email              = sapContact.WorkplaceEmailURI != null ? sapContact.WorkplaceEmailURI.Value : null;
                        contact.LocationExternalId = sapContact.WorkplaceBusinessAddressUUID != null ? sapContact.WorkplaceBusinessAddressUUID.Value : null;
                        contact.ExternalId         = sapContact.BusinessPartnerContactInternalID;

                        response.Contacts.Add(contact);
                    }
                }
            }

            return(response);
        }