예제 #1
0
            /// <summary>
            /// Calculates tax for this code for the line item.
            /// Updates the line item by adding a new Tax Item.
            /// </summary>
            /// <param name="codes">The collection of tax codes.</param>
            /// <param name="taxCodeAmountRounder">The current, accrued totals for this tax code.</param>
            /// <returns>
            /// The calculated amount of tax.
            /// </returns>
            public virtual decimal CalculateTaxAmount(ReadOnlyCollection <TaxCode> codes, TaxCodeAmountRounder taxCodeAmountRounder)
            {
                decimal taxAmount = decimal.Zero;

                this.TaxableEntity.ItemTaxGroupId = this.TaxGroup;
                var taxAmountNonRounded = this.TaxIncludedInPrice ? this.CalculateTaxIncluded(codes) : this.CalculateTaxExcluded(codes);

                string groupRoundingKey = string.Empty;

                if (this.TaxGroupRounding)
                {
                    // tax codes already sorted for this taxable item.
                    foreach (var code in codes)
                    {
                        groupRoundingKey += code.Code + "@:$";
                    }
                }
                else if (this.TaxLimitBase == TaxLimitBase.InvoiceWithoutVat)
                {
                    // total tax required for whole invoice by this tax code only.
                    groupRoundingKey = this.Code;
                }

                // rounding required when tax is not zero (not exempted).
                if (taxAmountNonRounded != decimal.Zero)
                {
                    // Round per tax code or adjust tax code amount.
                    taxAmount = taxCodeAmountRounder.Round(this.TaxContext, this, groupRoundingKey, taxAmountNonRounded);
                }

                // record amounts on line item
                TaxLine taxLine = new TaxLine
                {
                    Amount            = taxAmount,
                    Percentage        = this.Value,
                    TaxCode           = this.Code,
                    TaxGroup          = this.TaxGroup,
                    IsExempt          = this.Exempt,
                    IsIncludedInPrice = this.TaxIncludedInPrice,
                    TaxBasis          = this.TaxBasis
                };

                this.TaxableEntity.TaxLines.Add(taxLine);

                return(taxAmount);
            }
예제 #2
0
            /// <summary>
            /// Calculates tax for this code for the line item.
            /// Updates the line item by adding a new Tax Item.
            /// </summary>
            /// <param name="codes">The tax codes collection.</param>
            /// <param name="taxCodeAmountRounder">The current, accrued totals for this tax code.</param>
            /// <returns>The calculated amount of tax.</returns>
            public override decimal CalculateTaxAmount(ReadOnlyCollection <TaxCode> codes, TaxCodeAmountRounder taxCodeAmountRounder)
            {
                if (codes == null)
                {
                    return(decimal.Zero);
                }

                decimal taxAmount = decimal.Zero;

                this.TaxableEntity.ItemTaxGroupId = this.TaxGroup;
                taxAmount = this.TaxIncludedInPrice ? this.CalculateTaxIncluded(codes) : this.CalculateTaxExcluded(codes);

                string groupRoundingKey = string.Empty;

                if (this.TaxGroupRounding)
                {
                    // tax codes already sorted for this taxable item.
                    foreach (var code in codes)
                    {
                        groupRoundingKey += code.Code + "@:$";
                    }
                }
                else if (this.TaxLimitBase == TaxLimitBase.InvoiceWithoutVat)
                {
                    // total tax required for whole invoice by this tax code only.
                    groupRoundingKey = this.Code;
                }

                // rounding required for above cases and when tax is not zero (not exempted).
                if (taxAmount != decimal.Zero)
                {
                    // Adjust tax code amount.
                    taxAmount = taxCodeAmountRounder.Round(this.TaxContext, this, groupRoundingKey, taxAmount);
                }

                // Record amounts on line item
                TaxLineIndia taxLine = new TaxLineIndia();

                taxLine.Amount            = taxAmount;
                taxLine.Percentage        = this.Value;
                taxLine.TaxCode           = this.Code;
                taxLine.TaxGroup          = this.TaxGroup;
                taxLine.IsExempt          = this.Exempt;
                taxLine.IsIncludedInPrice = this.TaxIncludedInPrice;
                taxLine.TaxComponent      = this.GetTaxComponent();
                taxLine.IsTaxOnTax        = this.IsTaxOnTax;

                foreach (string codeInFormula in this.TaxCodesInFormula)
                {
                    if (!taxLine.TaxCodesInFormula.Contains(codeInFormula))
                    {
                        taxLine.TaxCodesInFormula.Add(codeInFormula);
                    }
                }

                switch (this.Formula.TaxableBasis)
                {
                case TaxableBasisIndia.MaxRetailPrice:
                    taxLine.IsIncludedInPrice = false;
                    break;

                case TaxableBasisIndia.ExclusiveLineAmount:
                    string[] tokens = this.Formula.ParseExpression();

                    // Iterate through the formula
                    if (tokens.Length > 1)
                    {
                        GetTaxCodeFormulaIndiaDataRequest dataRequest = new GetTaxCodeFormulaIndiaDataRequest(this.TaxGroup, tokens[1]);
                        FormulaIndia basisFormula = this.RequestContext.Execute <SingleEntityDataServiceResponse <FormulaIndia> >(dataRequest).Entity;

                        if (basisFormula != null && basisFormula.TaxableBasis == TaxableBasisIndia.MaxRetailPrice)
                        {
                            taxLine.IsIncludedInPrice = false;
                        }
                    }

                    break;

                default:
                    break;
                }

                taxLine.TaxBasis = this.TaxBasis;

                this.TaxableEntity.TaxLines.Add(taxLine);

                return(taxAmount);
            }