Beispiel #1
0
 void ITaxRate.TaxItem(ITaxable item, IAddress address)
 {
     if (AppliesToItem(item, address))
     {
         if (this.ApplyToShipping)
         {
             item.IncrementTaxValue((item.TaxableValue() + item.TaxableShippingValue()) * (this.Rate / 100M));
         }
         else
         {
             item.IncrementTaxValue(item.TaxableValue() * (this.Rate / 100M));
         }
     }
 }
Beispiel #2
0
 void ITaxRate.TaxItem(ITaxable item, IAddress address)
 {
     if (AppliesToItem(item, address))
     {
         if (this.ApplyToShipping)
         {
             item.IncrementTaxValue((item.TaxableValue() + item.TaxableShippingValue()) * (this.Rate / 100M));
         }
         else
         {
             item.IncrementTaxValue(item.TaxableValue() * (this.Rate / 100M));
         }
     }
 }
Beispiel #3
0
        private void TaxItems(ITaxSchedule schedule, List <ITaxable> items, IAddress address)
        {
            if (schedule == null)
            {
                return;
            }
            if (items == null)
            {
                return;
            }
            if (address == null)
            {
                return;
            }

            // Holds all taxes for the schedule summarized
            TaxableItem summaryForSchedule = new TaxableItem();

            summaryForSchedule.ScheduleId = schedule.TaxScheduleId();

            // Find all items that match the schedule
            List <ITaxable> itemsMatchingSchedule = new List <ITaxable>();

            foreach (ITaxable item in items)
            {
                if (item.TaxScheduleId() == schedule.TaxScheduleId())
                {
                    summaryForSchedule.Value         += item.TaxableValue();
                    summaryForSchedule.ShippingValue += item.TaxableShippingValue();
                    itemsMatchingSchedule.Add(item);
                }
            }

            // Now Apply all taxes in schedule to total price of all items
            foreach (ITaxRate rate in _app.OrderServices.Taxes.GetRates(_app.CurrentStore.Id, schedule.TaxScheduleId()))
            {
                rate.TaxItem(summaryForSchedule, address);
            }

            // Total Tax for all items on this schedule is calculated
            // Now, we assign the tax parts to each line item based on their
            // linetotal value. The last item should get the remainder of the tax
            decimal RoundedTotal = Math.Round(summaryForSchedule.TaxedValue, 2);

            decimal TotalApplied = 0M;

            for (int i = 0; i < itemsMatchingSchedule.Count(); i++)
            {
                ITaxable item = itemsMatchingSchedule[i];

                item.ClearTaxValue();
                if (i == itemsMatchingSchedule.Count() - 1)
                {
                    // last item
                    item.IncrementTaxValue(RoundedTotal - TotalApplied);
                }
                else
                {
                    decimal percentOfTotal = 0;
                    if (summaryForSchedule.TaxableValue() != 0)
                    {
                        percentOfTotal = item.TaxableValue() / summaryForSchedule.TaxableValue();
                    }
                    decimal part = Math.Round(percentOfTotal * summaryForSchedule.TaxedValue, 2);
                    item.IncrementTaxValue(part);
                    TotalApplied += part;
                }
            }
        }