Ejemplo n.º 1
0
        public override InvoiceModel CalculateDistributorPriceOnCustomerSection(InvoiceModel invoice, string memberId,
                                                                                string locale,
                                                                                string countryCode)
        {
            var address = !invoice.InvoiceShipToAddress
                ? (invoice.MemberAddress != null && !string.IsNullOrEmpty(invoice.MemberAddress.City) &&
                   !string.IsNullOrEmpty(invoice.MemberAddress.State))
                    ? GetAddressFromInvoice(invoice.MemberAddress)
                    : DistributorOrderingProfileProvider.GetAddress(AddressType.Mailing, memberId, countryCode)
                : GetAddressFromInvoice(invoice.Address);
            var warehouseCode    = _invoiceShipping.GetWarehouseCode(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale);
            var shippingMethodId = _invoiceShipping.GetShippingMethodId(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale);

            var order = ConvertToDistributorrOrder(invoice, memberId, countryCode, address, warehouseCode,
                                                   shippingMethodId, invoice.InvoicePrice.DiscountPercentage);

            order.UseSlidingScale = true;
            var response = CallDistributorPricing(order, true);

            if (null == response)
            {
                LoggerHelper.Error("Invoice CalculateDistributorPriceOnCustomerSection Pricing error");
                return(invoice);
            }
            CalculateDiscountedAmount(invoice, response);
            CalculateShippingAmount(invoice, response);
            CalculateTaxAmount(invoice, response);
            CalculateTotalDue(invoice);
            CalculateProfit(invoice);
            return(invoice);
        }
Ejemplo n.º 2
0
        public override InvoiceModel CalculateCustomerPrice(InvoiceModel invoice, string memberId, string locale,
                                                            string countryCode)
        {
            if (null == invoice || string.IsNullOrEmpty(memberId))
            {
                return(invoice);
            }
            var address = !invoice.InvoiceShipToAddress
                ? (invoice.MemberAddress != null && !string.IsNullOrEmpty(invoice.MemberAddress.City) &&
                   !string.IsNullOrEmpty(invoice.MemberAddress.State))
                    ? GetAddressFromInvoice(invoice.MemberAddress)
                    : DistributorOrderingProfileProvider.GetAddress(AddressType.Mailing, memberId, countryCode)
                : GetAddressFromInvoice(invoice.Address);
            var warehouseCode    = _invoiceShipping.GetWarehouseCode(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale);
            var shippingMethodId = string.IsNullOrEmpty(invoice.ShippingMethod)
                ? _invoiceShipping.GetShippingMethodId(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale)
                : invoice.ShippingMethod;

            CalculateDiscountedAmount(invoice);
            CalculateShippingAmount(invoice);
            foreach (var invoiceLine in invoice.InvoiceLines)
            {
                CalculateLineDiscountedAmmount(invoiceLine, invoice.InvoicePrice);
                CaculateFreightCharge(invoice, invoiceLine);
            }
            CalculateTaxAmount(invoice, memberId, countryCode, address, warehouseCode,
                               shippingMethodId, locale);
            CalculateTotalDue(invoice);

            CalculateProfit(invoice);
            return(invoice);
        }
Ejemplo n.º 3
0
        public bool CanPurchase(string distributorID, string countryCode)
        {
            bool canPurchase = false;
            List <TaxIdentification> tins = DistributorOrderingProfileProvider.GetTinList(distributorID, true); //HMS made up the country code

            //Must have POTX TinCode to purchase
            foreach (TaxIdentification t in tins)
            {
                if (t.IDType.Key == "POTX")
                {
                    canPurchase = true;
                }
            }

            if (!canPurchase)
            {
                //If they don't have the TinCode, they can only purchase if their mailing address is not in Portugal.
                var mailingAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, distributorID, countryCode);
                if (null != mailingAddress)
                {
                    if (!string.IsNullOrEmpty(mailingAddress.Country) && mailingAddress.Country != "PT")
                    {
                        canPurchase = true;
                    }
                }
            }
            return(canPurchase);
        }
        private bool CheckDSMailingAddress(bool check, ShippingAddress_V01 address)
        {
            if (check)
            {
                //if (address.Address.Country != this.CountryCode)
                //{
                //    this.errDRFraud.Text = GetLocalResourceObject("MailingAddNotBR") as string;
                //    this.errDRFraud.Visible = true;
                //    return false;
                //}

                var mailingaddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing,
                                                                                   DistributorID,
                                                                                   CountryCode);
                if (mailingaddress != null)
                {
                    if (mailingaddress.Country != CountryCode)
                    {
                        errDRFraud.Text    = GetLocalResourceObject("MailingAddNotBR") as string;
                        errDRFraud.Visible = true;
                        return(false);
                    }
                }
            }
            errDRFraud.Visible = false;
            errDRFraud.Text    = string.Empty;
            return(true);
        }
Ejemplo n.º 5
0
        //protected void checkDSFraud()
        //{
        //    if (HLConfigManager.Configurations.AddressingConfiguration.ValidateDSFraud)
        //    {
        //        if (ShoppingCart.DeliveryInfo != null &&
        //            null != ShoppingCart.DeliveryInfo.Address &&
        //            null != ShoppingCart.DeliveryInfo.Address.Address)
        //        {
        //            ShoppingCart.DSFraudValidationError = ShoppingCartProvider.GetDSFraudResxKey(DistributorOrderingProfileProvider.CheckForDRFraud(
        //                ShoppingCart.DistributorID, ShoppingCart.CountryCode,
        //                ShoppingCart.DeliveryInfo.Address.Address.PostalCode));

        //            ShoppingCart.PassDSFraudValidation = string.IsNullOrEmpty(ShoppingCart.DSFraudValidationError);
        //        }
        //    }
        //}

        protected string getDSMailingAddressState()
        {
            var address = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, DistributorID, CountryCode);

            if (address != null)
            {
                return(address.StateProvinceTerritory);
            }
            return("SP");
        }
Ejemplo n.º 6
0
        public override InvoiceModel CalculateDistributorPrice(InvoiceModel invoice, string memberId, string locale,
                                                               string countryCode)
        {
            var distributorOrderingProfile = GetDistributorOrderingProfile(memberId, countryCode);
            var address = !invoice.InvoiceShipToAddress
                ? (invoice.MemberAddress != null && !string.IsNullOrEmpty(invoice.MemberAddress.City) &&
                   !string.IsNullOrEmpty(invoice.MemberAddress.State))
                    ? GetAddressFromInvoice(invoice.MemberAddress)
                    : DistributorOrderingProfileProvider.GetAddress(AddressType.Mailing, memberId, countryCode)
                : GetAddressFromInvoice(invoice.Address);
            var warehouseCode    = _invoiceShipping.GetWarehouseCode(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale);
            var shippingMethodId = string.IsNullOrEmpty(invoice.ShippingMethod)
                ? _invoiceShipping.GetShippingMethodId(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale)
                : invoice.ShippingMethod;

            invoice.InvoicePrice.MemberStaticDiscount = invoice.InvoicePrice.MemberStaticDiscount > 0
                ? invoice.InvoicePrice.MemberStaticDiscount
                : distributorOrderingProfile.StaticDiscount;
            var order = ConvertToDistributorrOrder(invoice, memberId, countryCode, address, warehouseCode,
                                                   shippingMethodId, invoice.InvoicePrice.MemberStaticDiscount);

            var response = CallDistributorPricing(order, true);

            if (null == response)
            {
                LoggerHelper.Error("Invoice CalculateDistributorPrice Pricing error");
                return(invoice);
            }

            invoice.InvoicePrice.MemberDiscount = response.DiscountPercentage;

            foreach (var invoiceLine in invoice.InvoiceLines)
            {
                CalculateYourPrice(invoiceLine, invoice.InvoicePrice, response,
                                   response.DiscountPercentage);
            }

            CalculateTotalYourPrice(invoice);
            CalculateMemberTax(response, invoice);
            CalculateMemberFreight(response, invoice);
            CalculateTotalMemberTax(invoice);


            return(invoice);
        }
Ejemplo n.º 7
0
        public void PerformTaxationRules(Order_V01 order, string locale)
        {
            const string SanAndres        = "SAN ANDRES";
            const string Amazonas         = "AMAZONAS";
            string       contributorClass = "NATIONAL";

            if (order.Messages == null)
            {
                order.Messages = new MessageCollection();
            }
            try
            {
                var legalAddress = DistributorOrderingProfileProvider.GetAddress(AddressType.PermanentLegal, order.DistributorID, Country);

                Address          shippingAddress = (order.Shipment as ShippingInfo_V01).Address;
                MyHLShoppingCart cart            = ShoppingCartProvider.GetShoppingCart(order.DistributorID, "es-CO");

                if (legalAddress != null && shippingAddress != null)
                {
                    string legalAddressState    = legalAddress.StateProvinceTerritory.ToUpper();
                    string shippingAddressState = shippingAddress.StateProvinceTerritory.ToUpper();
                    if (legalAddressState == SanAndres || legalAddressState == Amazonas)
                    {
                        if (shippingAddressState == SanAndres || shippingAddressState == Amazonas)
                        {
                            contributorClass = "NATIONAL EXEMPT";
                        }
                    }
                }

                Message message = new Message();
                message.MessageType  = "ContributorClass";
                message.MessageValue = contributorClass;
                order.Messages.Add(message);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(
                    string.Format("CO Taxation Rules failed for Distributor {0}. Exception details \r\n{1}",
                                  order.DistributorID, ex.Message));
            }
        }
Ejemplo n.º 8
0
        private bool ShouldAddAPFPT(MyHLShoppingCart cart)
        {
            //APF rules for PT
            bool shouldAddAPF = true;

            // Verify TIN is valid and non expired
            var  tins  = DistributorOrderingProfileProvider.GetTinList(cart.DistributorID, true);
            var  ptTIN = tins.Find(p => p.IDType.Key == "POTX");
            var  now   = DateUtils.GetCurrentLocalTime("PT");
            bool hasForeignMailingAddress = false;

            var mailingAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, this.DistributorProfileModel.Id, "PT");

            if (mailingAddress != null)
            {
                if (!string.IsNullOrEmpty(mailingAddress.Country) && mailingAddress.Country != "PT")
                {
                    hasForeignMailingAddress = true;
                }
            }

            if (ptTIN != null)
            {
                if (ptTIN.IDType.ExpirationDate < now)
                {
                    shouldAddAPF = false;   //if TIN is not active, APF shouldn't be added
                }
            }
            else  //no POTX TIN found
            {
                if (!hasForeignMailingAddress)
                {
                    shouldAddAPF = false;   //Adding APF is not allowed since mailing address is still PT and member doens't have TIN
                }
            }

            return(shouldAddAPF);
        }
Ejemplo n.º 9
0
        public override InvoiceModel CalculateModifiedPriceOnCustomerSection(InvoiceModel invoice, string memberId,
                                                                             string locale,
                                                                             string countryCode)
        {
            var address = !invoice.InvoiceShipToAddress
                ? DistributorOrderingProfileProvider.GetAddress(AddressType.Mailing, memberId, countryCode)
                : GetAddressFromInvoice(invoice.Address);
            var warehouseCode    = _invoiceShipping.GetWarehouseCode(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale);
            var shippingMethodId = string.IsNullOrEmpty(invoice.ShippingMethod)
                ? _invoiceShipping.GetShippingMethodId(ObjectMappingHelper.Instance.GetToShipping(address as Address_V01), locale)
                : invoice.ShippingMethod;

            CalculateDiscountedAmount(invoice);
            CalculateShippingAmount(invoice);
            foreach (var invoiceLine in invoice.InvoiceLines)
            {
                CalculateLineDiscountedAmmount(invoiceLine, invoice.InvoicePrice);
                CaculateFreightCharge(invoice, invoiceLine);
            }
            CalculateTaxAmountForModifiedPricing(invoice, memberId, countryCode, address, warehouseCode,
                                                 shippingMethodId);
            CalculateTotalDue(invoice);
            return(invoice);
        }
        public override Address_V01 GetHFFDefaultAddress(ShippingAddress_V01 address)
        {
            var         member        = (MembershipUser <DistributorProfileModel>)Membership.GetUser();
            string      distributorId = (member != null) ? member.Value.Id : "";
            Address_V01 hffAddress    = new Address_V01();

            if (!string.IsNullOrEmpty(distributorId))
            {
                if (IsMemberTaxRegistered(distributorId))
                {
                    hffAddress = ObjectMappingHelper.Instance.GetToShipping(DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.PermanentLegalLocal, distributorId, "GR"));
                }
                else
                {
                    hffAddress = ObjectMappingHelper.Instance.GetToShipping(DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.MailingLocal, distributorId, "GR"));
                }
            }
            else  //if unable to retrieve DistributorId, do the default process
            {
                if (address != null && address.Address != null)
                {
                    hffAddress = new Address_V01
                    {
                        Country = address.Address.Country,
                        StateProvinceTerritory = address.Address.StateProvinceTerritory,
                        City       = address.Address.City,
                        Line1      = address.Address.Line1,
                        PostalCode = address.Address.PostalCode,
                    };
                }

                hffAddress = base.GetHFFDefaultAddress(address);
            }

            return(hffAddress);
        }
Ejemplo n.º 11
0
        public void PerformTaxationRules(Order_V01 order, string locale)
        {
            bool IsNewArgentinaTaxStructure = Settings.GetRequiredAppSetting <bool>("EnableNewArgentinaTaxStructure", false);

            if (IsNewArgentinaTaxStructure)
            {
                NewTaxationRules(order, locale);
            }
            else
            {
                #region Old Tax Structure

                Message message = new Message();
                message.MessageType = "ContributorClass";
                string contributorClass = string.Empty;

                order.Messages = new MessageCollection();

                //Step 1
                //if DS is not AR COP then we're done!
                if (DistributorProfileModel.ProcessingCountryCode != "AR")
                {
                    message.MessageValue = "F";
                    order.Messages.Add(message);
                    return;
                }
                try
                {
                    //continue with calc
                    //step 1.2
                    int legalProvince    = 0;
                    int shippingProvince = 0;

                    var legalAddress      = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.PermanentLegal, order.DistributorID, Country);
                    var locallegalAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.PermanentLegalLocal, order.DistributorID, Country);

                    var shippingAddress = (order.Shipment as ShippingInfo_V01).Address;
                    if (null != legalAddress)
                    {
                        if (!Int32.TryParse(legalAddress.StateProvinceTerritory.Trim(), out legalProvince))
                        {
                            LoggerHelper.Error(
                                string.Format(
                                    "AR Taxation Rules failed for Distributor {0}. legalAddress.StateProvinceTerritory value is invalid: {1}",
                                    order.DistributorID, legalAddress.StateProvinceTerritory.Trim()));
                        }
                    }
                    if (null != shippingAddress)
                    {
                        if (!Int32.TryParse(shippingAddress.StateProvinceTerritory.Trim(), out shippingProvince))
                        {
                            LoggerHelper.Error(
                                string.Format(
                                    "AR Taxation Rules failed for Distributor {0}. shippingAddress.StateProvinceTerritory value is invalid: {1}",
                                    order.DistributorID, shippingAddress.StateProvinceTerritory.Trim()));
                        }
                    }

                    List <TaxIdentification> tinList = DistributorOrderingProfileProvider.GetTinList(order.DistributorID, true);
                    if (23 == legalProvince && 23 == shippingProvince) //TIERA DEL FUEGO
                    {
                        contributorClass = "X";
                    }
                    else
                    {
                        if (null != tinList && null != order)
                        {
                            bool hasARTX = (tinList.Find(t => t.IDType.Key == "ARTX") != null);
                            bool hasARVT = (tinList.Find(t => t.IDType.Key == "ARVT") != null);
                            bool hasCUIT = (tinList.Find(t => t.IDType.Key == "CUIT") != null);
                            //step 1.5
                            if (hasARTX && hasCUIT)
                            {
                                contributorClass = "M";
                            }
                            //step 1.7
                            else if (hasARVT && hasCUIT)
                            {
                                contributorClass = "I";
                            }
                            //step 1.8
                            else if (!hasARVT && !hasARTX)
                            {
                                contributorClass = "N";
                            }
                        }
                    }

                    //Step 2
                    //step 2.1 and 2.3
                    if (tinList.Find(t1 => t1.IDType.Key == "IBBA") != null ||
                        tinList.Find(t2 => t2.IDType.Key.Substring(0, 2) == "IB") == null || 2 == shippingProvince)
                    //2 == BEUNOS AIRES
                    {
                        contributorClass += "BA";
                    }
                    //step 2.4
                    if (tinList.Find(t => t.IDType.Key == "IBSF") != null || 20 == shippingProvince) //SANTA FE
                    {
                        contributorClass += "SF";
                    }
                    //step 2.5
                    if (tinList.Find(t => t.IDType.Key == "IBER") != null || 24 == shippingProvince) //ENTRE RIOS
                    {
                        contributorClass += "ER";
                    }
                    //step 2.6
                    if (tinList.Find(t => t.IDType.Key == "IBJJ") != null || 9 == shippingProvince) //JUJUY
                    {
                        contributorClass += "JJ";
                    }
                    //step 2.7
                    if (tinList.Find(t => t.IDType.Key == "IBSL") != null || 18 == shippingProvince) //SAN LUIS
                    {
                        contributorClass += "SL";
                    }
                    //step 2.8
                    if (tinList.Find(t => t.IDType.Key == "IBTU") != null || 22 == shippingProvince) //TUCUMAN
                    {
                        contributorClass += "TU";
                    }
                    //step 2.9
                    if (tinList.Find(t => t.IDType.Key == "IBCF") != null || 1 == shippingProvince) //CAPITAL FEDERAL
                    {
                        contributorClass += "CF";
                    }

                    message.MessageValue = contributorClass;
                    order.Messages.Add(message);
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(
                        string.Format("AR Taxation Rules failed for Distributor {0}. Exception details \r\n{1}",
                                      order.DistributorID, ex.Message));
                }

                #endregion
            }
        }
Ejemplo n.º 12
0
        private void NewTaxationRules(Order_V01 order, string locale)
        {
            Message message = new Message();

            message.MessageType = "ContributorClass";
            Message addionalMsg = new Message();

            addionalMsg.MessageType = "AdditionalClass";
            string contributorClass = string.Empty;
            string additionalClass  = string.Empty;

            order.Messages = new MessageCollection();

            //Step 1
            //if DS is not AR COP then we're done!
            //Immaterial of Country of Processing we need to make DS flow thorugh step1 and step2,So commenting the return code.
            //if (DistributorProfileModel.ProcessingCountryCode != "AR")
            //{
            //    message.MessageValue = "F";
            //    order.Messages.Add(message);
            //    return;
            //}
            try
            {
                //continue with calc
                //step 1.2
                int legalProvince    = 0;
                int shippingProvince = 0;

                var legalAddress      = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.PermanentLegal, order.DistributorID, Country);
                var locallegalAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.PermanentLegalLocal, order.DistributorID, Country);

                var shippingAddress = (order.Shipment as ShippingInfo_V01).Address;
                if (null != legalAddress)
                {
                    if (!Int32.TryParse(legalAddress.StateProvinceTerritory.Trim(), out legalProvince))
                    {
                        LoggerHelper.Error(
                            string.Format(
                                "AR Taxation Rules failed for Distributor {0}. legalAddress.StateProvinceTerritory value is invalid: {1}",
                                order.DistributorID, legalAddress.StateProvinceTerritory.Trim()));
                    }
                }
                if (null != shippingAddress)
                {
                    if (!Int32.TryParse(shippingAddress.StateProvinceTerritory.Trim(), out shippingProvince))
                    {
                        LoggerHelper.Error(
                            string.Format(
                                "AR Taxation Rules failed for Distributor {0}. shippingAddress.StateProvinceTerritory value is invalid: {1}",
                                order.DistributorID, shippingAddress.StateProvinceTerritory.Trim()));
                    }
                }

                //This Fix is only For iKiosk - We do not receive statecode.GDO UI sends statecode so GDO works.
                if (HLConfigManager.Platform == "iKiosk" && shippingProvince == 0)
                {
                    IShippingProvider provider = ShippingProvider.GetShippingProvider(shippingAddress.Country);
                    if (provider != null)
                    {
                        var lookupResults = provider.GetStatesForCountry(shippingAddress.Country);
                        if (lookupResults != null && lookupResults.Count > 0)
                        {
                            foreach (var province in lookupResults)
                            {
                                string[] state = province.Split('-');
                                if (state[0] == shippingAddress.StateProvinceTerritory.Trim())
                                {
                                    shippingProvince = Convert.ToInt32(state[1]);
                                    break;
                                }
                            }
                        }
                    }
                }



                List <TaxIdentification> tinList = DistributorOrderingProfileProvider.GetTinList(order.DistributorID, true);
                bool hasARTX = (tinList.Find(t => t.IDType.Key == "ARTX") != null);
                bool hasARVT = (tinList.Find(t => t.IDType.Key == "ARVT") != null);
                bool hasCUIT = (tinList.Find(t => t.IDType.Key == "CUIT") != null);
                bool hasARCM = (tinList.Find(t => t.IDType.Key == "ARCM") != null);
                bool hasARRS = (tinList.Find(t => t.IDType.Key == "ARRS") != null);
                bool hasARID = (tinList.Find(t => t.IDType.Key == "ARID") != null);
                bool ISAR    = DistributorProfileModel.ProcessingCountryCode == "AR";


                if (23 == shippingProvince) //TIERA DEL FUEGO
                {
                    if (null != tinList && null != order)
                    {
                        if (hasCUIT && hasARTX)
                        {
                            contributorClass = "Y";
                        }
                        if (hasARVT && hasCUIT)
                        {
                            contributorClass = "X";
                        }
                        if ((hasARID && !hasARTX && !hasARVT) || (!hasARID && !hasARTX && !hasARVT && !ISAR))
                        {
                            contributorClass = "Z";
                        }
                    }
                }
                else
                {
                    if (null != tinList && null != order)
                    {
                        //step 1.5
                        if (hasARTX && hasCUIT)
                        {
                            contributorClass = "M";
                        }
                        //step 1.7
                        else if (hasARVT && hasCUIT)
                        {
                            contributorClass = "I";
                        }

                        //step 1.8
                        else if (!hasARVT && !hasARTX && !hasCUIT)
                        {
                            contributorClass = "N";
                        }
                    }
                }

                //Step-2 New Implementation

                if (hasARCM)
                {
                    contributorClass += "C";
                }
                else
                {
                    if (hasARRS)
                    {
                        contributorClass += "S";
                    }
                }

                //Call Create Contributor Class String
                string concatentionClass = string.Empty;
                CreateContributorClass(hasARCM, hasARVT, hasARTX, hasARRS, shippingProvince, tinList, out additionalClass, out concatentionClass);
                contributorClass += concatentionClass;

                message.MessageValue = contributorClass;
                order.Messages.Add(message);
                addionalMsg.MessageValue = additionalClass;
                order.Messages.Add(addionalMsg);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(
                    string.Format("AR Taxation Rules failed for Distributor {0}. Exception details \r\n{1}",
                                  order.DistributorID, ex.Message));
            }
        }
        public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, Shipment shippment)
        {
            if (shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Address != null &&
                shoppingCart.DeliveryInfo.Address.Address != null &&
                shoppingCart.DeliveryOption == ServiceProvider.CatalogSvc.DeliveryOptionType.Shipping)
            {
                if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
                {
                    shippment.WarehouseCode    = HLConfigManager.Configurations.APFConfiguration.APFwarehouse;
                    shippment.ShippingMethodID = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
                }
                else
                {
                    shoppingCart.CheckShippingForNonStandAloneAPF();

                    SessionInfo sessionInfo = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                    if (sessionInfo.IsEventTicketMode && shoppingCart.DeliveryInfo != null)
                    {
                        shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketWarehouseCode;
                        shoppingCart.DeliveryInfo.FreightCode   = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
                        shippment.WarehouseCode    = shoppingCart.DeliveryInfo.WarehouseCode;
                        shippment.ShippingMethodID = shoppingCart.DeliveryInfo.FreightCode;

                        // Take address from DB in the ShoppingCart.
                        var deliveryOptions = base.GetDeliveryOptions(shoppingCart.Locale);
                        var addressETO      = deliveryOptions.Find(d =>
                                                                   d.Option == ServiceProvider.ShippingSvc.DeliveryOptionType.Shipping &&
                                                                   d.OrderCategory == ServiceProvider.ShippingSvc.OrderCategoryType.ETO);

                        if (addressETO != null)
                        {
                            shoppingCart.DeliveryInfo.Address.Address = addressETO.Address;
                        }

                        // Take mailing address for HMS
                        var mailingAddress = DistributorOrderingProfileProvider.GetAddress(
                            ServiceProvider.OrderSvc.AddressType.Mailing, shoppingCart.DistributorID,
                            shoppingCart.CountryCode);

                        if (mailingAddress != null)
                        {
                            shippment.Address.Line1 = mailingAddress.Line1;
                            shippment.Address.Line2 = mailingAddress.Line2;
                            shippment.Address.Line3 = mailingAddress.Line3;
                            shippment.Address.Line4 = mailingAddress.Line4;
                            shippment.Address.City  = mailingAddress.City;
                            shippment.Address.StateProvinceTerritory = mailingAddress.StateProvinceTerritory;
                            shippment.Address.PostalCode             = mailingAddress.PostalCode;
                            shippment.Address.CountyDistrict         = mailingAddress.CountyDistrict;
                            shippment.Address.Country = mailingAddress.Country;
                        }

                        // Set MB's Name in the Recipient name
                        var loader      = new Core.DistributorProvider.DistributorLoader();
                        var distributor = loader.Load(shoppingCart.DistributorID, shoppingCart.CountryCode);

                        if (distributor != null && distributor.EnglishName != null)
                        {
                            shoppingCart.DeliveryInfo.Address.Recipient = string.Format("{0} {1}{2}",
                                                                                        distributor.EnglishName.First,
                                                                                        !string.IsNullOrEmpty(distributor.EnglishName.Middle) ? distributor.EnglishName.Middle + " " : string.Empty,
                                                                                        distributor.EnglishName.Last);
                        }
                    }
                }
            }
            return(true);
        }
        protected override void handleDeliveryTypeChanged(DropDownList DeliveryType, DropDownList DropdownNickName)
        {
            CheckDSMailingAddress(false, null);
            DeliveryOptionType deliveryType = getDeliveryOptionTypeFromDropdown(DeliveryType);

            if (null != DropdownNickName)
            {
                DropdownNickName.Attributes.Remove("style");
            }
            ShoppingCart.DeliveryInfo = null;
            if (deliveryType == DeliveryOptionType.Shipping || deliveryType == DeliveryOptionType.ShipToCourier)
            {
                populateShipping();
                setAddressByNickName(ShoppingCart.DeliveryInfo == null
                                         ? null
                                         : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping
                                                ? ShoppingCart.DeliveryInfo.Address
                                                : null));
            }
            else if (deliveryType == DeliveryOptionType.PickupFromCourier)
            {
                populatePickupPreference();
                setAddressByNickName(ShoppingCart.DeliveryInfo == null
                                         ? null
                                         : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.PickupFromCourier
                                                ? ShoppingCart.DeliveryInfo.Address
                                                : null));
            }
            else
            {
                if (CountryCode == "BR")
                {
                    var mailingAdd = new ShippingAddress_V01(1, DistributorProfileModelHelper.DistributorName(DistributorProfileModel),
                                                             ObjectMappingHelper.Instance.GetToShipping(DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, DistributorID, CountryCode)),
                                                             string.Empty, string.Empty, false, string.Empty,
                                                             DateTime.Now);
                    if (CheckDSMailingAddress(true, mailingAdd))
                    {
                        populatePickup();
                        setAddressByNickName(ShoppingCart.DeliveryInfo == null
                                                 ? null
                                                 : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup
                                                        ? ShoppingCart.DeliveryInfo.Address
                                                        : null));
                    }
                }
                else
                {
                    populatePickup();
                    setAddressByNickName(ShoppingCart.DeliveryInfo == null
                                             ? null
                                             : (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup
                                                    ? ShoppingCart.DeliveryInfo.Address
                                                    : null));
                }
            }
            showShiptoOrPickup(IsStatic);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// if DS can purchase on site
        /// </summary>
        /// <param name="tins"></param>
        /// <param name="CountryOfProcessing"></param>
        /// <param name="CountyCode"></param>
        /// <returns></returns>
        public override bool CanPurchase(List <TaxIdentification> tins, string CountryOfProcessing, string CountyCode)
        {
            bool canPurchase = true;

            //Check for override rule whether this DS is exempted.
            if (CatalogProvider.IsDistributorExempted(this.DistributorProfileModel.Id))
            {
                return(true);
            }

            var countryCodes = new List <string>();

            switch (CountyCode)
            {
            case "SG":
            {
                countryCodes.AddRange(CountryType.SG.HmsCountryCodes);
                countryCodes.Add(CountryType.SG.Key);
                if (countryCodes.Contains(CountryOfProcessing))
                {
                    canPurchase = !(tins.Count == 0 || !tins.Any(t => t.IDType.Key.Equals("SNID")));
                }
            }
            break;

            case "CL":
            {
                countryCodes.AddRange(CountryType.CL.HmsCountryCodes);
                countryCodes.Add(CountryType.CL.Key);
                if (countryCodes.Contains(CountryOfProcessing))
                {
                    var tin = (from t in tins where t.IDType.Key == "CIID" select t).FirstOrDefault();
                    if (tin == null)
                    {
                        canPurchase = false;
                    }
                }
            }
            break;

            //case "EC":
            //    {
            //        countryCodes.AddRange(CountryType.EC.HmsCountryCodes);
            //        countryCodes.Add(CountryType.EC.Key);
            //        if (countryCodes.Contains(CountryOfProcessing))
            //        {
            //            if (tins.Count > 0)
            //            {
            //                var tin = (from t in tins from r in (new[] { "ECID", "ECTX" }) where t.IDType.Key == r select t).ToList();
            //                if (tin == null || tin.Count == 0)
            //                {
            //                    canPurchase = false;
            //                }
            //            }
            //        }
            //    }
            //    break;
            case "VE":
            {
                countryCodes.AddRange(CountryType.VE.HmsCountryCodes);
                countryCodes.Add(CountryType.VE.Key);
                if (countryCodes.Contains(CountryOfProcessing))
                {
                    canPurchase = false;
                    //VRIF TinCode required to purchase
                    foreach (TaxIdentification t in tins)
                    {
                        if (t.IDType.Key == "VRIF")
                        {
                            canPurchase = true;
                        }
                    }
                }
                else if (CountryOfProcessing == "BR" || CountryOfProcessing == "CO")
                {
                    //foreign DS, Not in whitelist, can't purchase
                    canPurchase = CatalogProvider.IsDistributorExempted(this.DistributorProfileModel.Id);
                }
            }
            break;

            case "BE":
            {
                if (HLConfigManager.Configurations.DOConfiguration.PurchasingLimitRestrictionType == PurchasingLimitRestrictionType.MarketingPlan)
                {
                    countryCodes.AddRange(CountryType.BE.HmsCountryCodes);
                    countryCodes.Add(CountryType.BE.Key);
                    if (countryCodes.Contains(CountryOfProcessing))
                    {
                        if (tins.Count > 0)
                        {
                            var beTins =
                                (from t in tins
                                 from r in (new[] { "BEDI", "BENO", "BEVT" })
                                 where t.IDType.Key == r
                                 select t.IDType.Key).ToList();
                            if (beTins.Contains("BEDI") && (beTins.Contains("BENO") || beTins.Contains("BEVT")))
                            {
                                canPurchase = false;
                            }
                        }
                    }
                }
            }
            break;

            case "KR":
            {
                // only KR distributor
                if (!(new List <string>(CountryType.KR.HmsCountryCodes)).Union(new List <string>()
                    {
                        CountryType.KR.Key
                    }).Contains(DistributorProfileModel.ProcessingCountryCode))
                {
                    canPurchase = false;
                }
                else if (tins.Count > 0 && tins.Any(t => t.IDType.Key.Equals("KSID")))
                {
                    var tin = tins.Find(t => t.IDType.Key.Equals("KSID"));
                    if (tin.IDType.ExpirationDate != null && tin.IDType.ExpirationDate < DateUtils.GetCurrentLocalTime("KR"))
                    {
                        canPurchase = false;
                    }
                }
            }
            break;

            case "BR":
            {
                canPurchase = !(tins.Count == 0 || !tins.Any(t => t.IDType.Key.Equals("BRPF")));
            }
            break;

            case "PT":
            {
                canPurchase = !(tins.Count == 0 || !tins.Any(t => t.IDType.Key.Equals("POTX")));
                if (!canPurchase)
                {
                    //If they don't have the TinCode, they can only purchase if their mailing address is not in Portugal.
                    var mailingAddress = DistributorOrderingProfileProvider.GetAddress(ServiceProvider.OrderSvc.AddressType.Mailing, this.DistributorProfileModel.Id, CountyCode);
                    if (null != mailingAddress)
                    {
                        if (!string.IsNullOrEmpty(mailingAddress.Country) && mailingAddress.Country != "PT")
                        {
                            canPurchase = true;
                        }
                    }
                }
            }
            break;
            //case "TH":
            //    {
            //        countryCodes.AddRange(CountryType.TH.HmsCountryCodes);
            //        countryCodes.Add(CountryType.TH.Key);

            //        var tid = tins == null ? null : tins.Find(t => t.IDType.Key == "THID");

            //        if (countryCodes.Contains(CountryOfProcessing))
            //        {
            //            canPurchase = tid != null;
            //        }
            //        else
            //        {
            //            canPurchase = tins != null && tins.Find(p => p.ID == "TH00000000000") != null;
            //        }
            //    }
            //    break;
            case "VN":
            {
                canPurchase = false;
                countryCodes.AddRange(CountryType.VN.HmsCountryCodes);
                countryCodes.Add(CountryType.VN.Key);
                if (countryCodes.Contains(CountryOfProcessing))
                {
                    canPurchase = tins != null && tins.Find(p => p.IDType.Key == "VNID") != null;
                }
            }
            break;

            case "MO":
            {
                countryCodes.AddRange(CountryType.MO.HmsCountryCodes);
                countryCodes.Add(CountryType.MO.Key);
                if (countryCodes.Contains(CountryOfProcessing))
                {
                    canPurchase = tins != null && tins.Find(p => p.IDType.Key == "MCID") != null;
                }
            }
            break;
            }

            return(canPurchase);
        }