Ejemplo n.º 1
0
 public abstract ITaxStructured DoCalc(
     TaxSession session,
     IAddress fromAddress,
     IAddress toAddress,
     Amount amount,
     Amount shipping);
Ejemplo n.º 2
0
        public ITaxCalculation Calc(
            TaxSession session,
            IAddress wholesellerAddress,
            string[] wholesellerNexusStates,
            IAddress retailerAddress,
            string[] retailerNexusStates,
            string[] retailerCertificateStates,
            IAddress shippingAddress,
            Amount wholesalePrice,
            Amount retailPrice,
            Amount shipping)
        {
            if (!wholesalePrice.CurrencyISO.EqualsOrdIgnoreCase(retailPrice.CurrencyISO) ||
                !wholesalePrice.CurrencyISO.EqualsOrdIgnoreCase(shipping.CurrencyISO) ||
                !retailPrice.CurrencyISO.EqualsOrdIgnoreCase(shipping.CurrencyISO))
            {
                throw new TaxException(GetType().FullName + StringConsts.TAX_CALC_DIFFERENT_CURRENCIES_ERROR +
                                       ".Calc(wholesalePrice='{0}', retailPrice='{1}', shipping='{2}')".Args(wholesalePrice, retailPrice, shipping));
            }

            var currencyISO = retailPrice.CurrencyISO;

            var wholesellerHasNexus    = wholesellerNexusStates.Any(s => s.EqualsOrdIgnoreCase(shippingAddress.Region));
            var retailerHasNexus       = retailerNexusStates.Any(s => s.EqualsOrdIgnoreCase(shippingAddress.Region));
            var retailerHasCertificate = retailerCertificateStates.Any(cs => cs.EqualsOrdIgnoreCase(shippingAddress.Region));

            if (wholesellerHasNexus)
            {
                if (retailerHasNexus)
                {
                    if (retailerHasCertificate)
                    {
                        var retailerTax = DoCalc(session, retailerAddress, shippingAddress, retailPrice, shipping);
                        return(new TaxCalculation()
                        {
                            CurrencyISO = currencyISO, Recipient = shippingAddress.Region, RetailerTax = retailerTax
                        });
                    }
                    else
                    {
                        var wholesellerTax = DoCalc(session, wholesellerAddress, shippingAddress, wholesalePrice, shipping);
                        var retailerTax    = DoCalc(session, retailerAddress, shippingAddress, retailPrice, shipping);
                        return(new TaxCalculation()
                        {
                            CurrencyISO = currencyISO, Recipient = shippingAddress.Region, WholesellerTax = wholesellerTax, RetailerTax = retailerTax
                        });
                    }
                }
                else
                {
                    if (retailerHasCertificate)
                    {
                        return(TaxCalculation.NoneInstance);
                    }
                    else
                    {
                        var wholesellerTax = DoCalc(session, wholesellerAddress, shippingAddress, wholesalePrice, shipping);
                        return(new TaxCalculation()
                        {
                            CurrencyISO = currencyISO, Recipient = shippingAddress.Region, WholesellerTax = wholesellerTax
                        });
                    }
                }
            }
            else
            {
                if (retailerHasNexus)
                {
                    var retailerTax = DoCalc(session, retailerAddress, shippingAddress, retailPrice, shipping);
                    return(new TaxCalculation()
                    {
                        CurrencyISO = currencyISO, Recipient = shippingAddress.Region, RetailerTax = retailerTax
                    });
                }
                else
                {
                    return(TaxCalculation.NoneInstance);
                }
            }
        }