Ejemplo n.º 1
0
            /// <summary>
            /// Sets the line item tax rate.
            /// </summary>
            /// <param name="taxableItem">The taxable item.</param>
            /// <param name="lineTaxResult">The line tax result.</param>
            protected static void SetLineItemTaxRate(TaxableItem taxableItem, LineTaxResult lineTaxResult)
            {
                if (taxableItem == null)
                {
                    throw new ArgumentNullException("taxableItem");
                }

                if (lineTaxResult == null)
                {
                    throw new ArgumentNullException("lineTaxResult");
                }

                // Ignore any portion of the TaxAmount that is 'Exempt' when computing the rate.
                decimal amount = lineTaxResult.TaxAmount - lineTaxResult.ExemptAmount;

                SetLineItemTaxRate(taxableItem, amount);
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Calculate tax on the given line item.
            /// </summary>
            /// <param name="taxableItem">The taxable item.</param>
            /// <param name="context">The context.</param>
            /// <param name="transaction">Current transaction.</param>
            private void CalculateTax(TaxableItem taxableItem, RequestContext context, SalesTransaction transaction)
            {
                ReadOnlyCollection <TaxCode> codes = this.GetTaxCodes(taxableItem, context, transaction);

                LineTaxResult lineTaxResult = new LineTaxResult
                {
                    HasExempt      = false,
                    TaxRatePercent = decimal.Zero,
                    TaxAmount      = decimal.Zero,
                    ExemptAmount   = decimal.Zero
                };

                foreach (TaxCode code in codes)
                {
                    var taxCodeAmount = code.CalculateTaxAmount(codes, this.taxCodeAmountRounder);
                    lineTaxResult.TaxAmount += taxCodeAmount;

                    // sum up the amounts that are exempt
                    if (code.Exempt)
                    {
                        lineTaxResult.HasExempt     = true;
                        lineTaxResult.ExemptAmount += lineTaxResult.TaxAmount;
                    }
                }

                // Set the 'virtual tax rate', if extended price is ZERO, then just add the full amount
                decimal extendedPrice = taxableItem.Price * Math.Abs(taxableItem.Quantity);

                if (extendedPrice == decimal.Zero)
                {
                    extendedPrice = decimal.One;
                }

                lineTaxResult.TaxRatePercent = (lineTaxResult.TaxAmount * 100) / extendedPrice;
                SetLineItemTaxRate(taxableItem, lineTaxResult);
            }