public void CalculateTax(ITaxableItem taxableItem, IRetailTransaction retailTransaction) { var codes = GetTaxCodes(taxableItem); LineTaxResult lineTaxResult = new LineTaxResult { HasExempt = false, TaxRatePercent = decimal.Zero, TaxAmount = decimal.Zero, ExemptAmount = decimal.Zero }; foreach (TaxCode code in codes) { lineTaxResult.TaxAmount += code.CalculateTaxAmount(codes); // 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); }
protected static void SetLineItemTaxRate(ITaxableItem taxableItem, LineTaxResult lineTaxResult) { // Ignore any portion of the TaxAmount that is 'Exempt' when computing the rate. decimal amount = lineTaxResult.TaxAmount - lineTaxResult.ExemptAmount; SetLineItemTaxRate(taxableItem, amount); }