Пример #1
0
        static void Main(string[] args)
        {
            ITaxable[] MyStuff = new ITaxable[3];

            MyStuff[0] = new House("Tel Aviv", "Arlozorov", 3400000, 150, 300);
            MyStuff[1] = new Bus(1211211, 130, 500000, 54);
            MyStuff[2] = new MyUnclesInheritance(10000000);

            // Calculate total value
            int MyTotalProperties = 0;

            for (int i = 0; i < MyStuff.Length; i++)
            {
                if (MyStuff[i] is House == true)
                {
                    MyTotalProperties += ((House)MyStuff[i]).Value;
                }
                else if (MyStuff[i] is Bus == true)
                {
                    MyTotalProperties += ((Bus)MyStuff[i]).Value;
                }
                else if (MyStuff[i] is MyUnclesInheritance == true)
                {
                    MyTotalProperties += ((MyUnclesInheritance)MyStuff[i]).HowMuch;
                }
            }

            MyTaxCalculator TCalc = new MyTaxCalculator();

            Console.WriteLine("My total taxes: " + TCalc.CalulateMyTaxes(MyStuff));
        }
Пример #2
0
        public decimal CalculateTax(ITaxable taxable, decimal preTaxAmount)
        {
            var allBasicTaxTypes = BasicTaxTypeRepository.GetAllBasicTaxTypes();

            return LevierFactory.CreateLevier(taxable, allBasicTaxTypes)
                .CalculateTax(preTaxAmount);
        }
Пример #3
0
 private static void DeductTax(Account[] accounts)
 {
     foreach (Account acc in accounts)
     {
         ITaxable t = acc as ITaxable;
         t?.Deduct();
     }
 }
Пример #4
0
 private static void DeductTax(Account[] group)
 {
     foreach (var acc in group)
     {
         ITaxable t = acc as ITaxable;
         t?.Deduct();             //if(t != null) t.Deduct()
     }
 }
Пример #5
0
 private static void DeductAnnualTax(Account[] accounts)
 {
     foreach (Account acc in accounts)
     {
         ITaxable t = acc as ITaxable;
         t?.Deduct();             //if(t != null) t.Deduct()
     }
 }
Пример #6
0
        private void ApplyTaxes(ITaxSchedule schedule, ITaxable item, IAddress address)
        {
            List <ITaxSchedule> schedules = new List <ITaxSchedule>();

            schedules.Add(schedule);
            List <ITaxable> items = new List <ITaxable>();

            items.Add(item);
            ApplyTaxes(schedules, items, address);
        }
        public double Calculate(ITaxable taxable)
        {
            double total = 0;

            foreach (var item in taxable.ItemsToBeTaxed())
            {
                total += item.Value > 1000 ? item.Value * 0.02 : item.Value * 0.01;
            }

            return(total);
        }
Пример #8
0
        public static Levier CreateLevier(ITaxable taxable, List<BasicTaxType> basicTaxTypes)
        {
            var levier = new Levier();

            if (taxable.IsImported)
                levier.AddTaxer(new TaxItem(Imported_TaxRate, RoundTax));

            var basicTaxType = basicTaxTypes.FindByCategory(taxable.Category);
            levier.AddTaxer(new TaxItem(basicTaxType.TaxRate, RoundTax));

            return levier;
        }
Пример #9
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));
         }
     }
 }
Пример #10
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));
         }
     }
 }
Пример #11
0
        static void Main(string[] args)
        {
            ITaxable[] tObjects =
                new ITaxable[] {
                new TaxableHouse("Lagos", true, 700, 500000M),
                new TaxableHouse("Adamawa", true, 1800, 300000M),
                new TaxableBus(50, 12345, 300000M),
                new TaxableBus(10, 345678, 25000M)
            };

            foreach (ITaxable it in tObjects)
            {
                Console.WriteLine("{0}", it.TaxValue());
            }
        }
        public double CalculteTax(ITaxable taxableItems)
        {
            double total = 0;

            foreach (Item item in taxableItems.ItemsToBeTaxable)
            {
                if (item.Value > 1000)
                {
                    total += item.Value * 0.02;
                }
                else
                {
                    total += item.Value * 0.01;
                }
            }

            return(total);
        }
Пример #13
0
        static void Main(string[] args)
        {
            ITaxable[] myAssets = new ITaxable[6];
            myAssets[0] = new Bus(25);
            myAssets[1] = new Bus(23);
            myAssets[2] = new Bus(27);
            myAssets[3] = new House(200, 90);
            myAssets[4] = new House(300, 100);
            myAssets[5] = new House(100, 0);
            double sum = 0;

            for (int i = 0; i < myAssets.Length; i++)
            {
                Console.WriteLine("The tax is worth: {0:c}", myAssets[i].CalculateTax());
                sum += myAssets[i].CalculateTax();
            }
            Console.WriteLine();
            Console.WriteLine("Total cost is: {0:c}", sum);
        }
Пример #14
0
        protected bool AppliesToItem(ITaxable item, IAddress address)
        {
            bool result = false;

            if (item.TaxScheduleId() == this.TaxScheduleId)
            {
                if (address.CountryData.Name.ToLowerInvariant() == this.CountryName.ToLowerInvariant())
                {
                    if (this.RegionAbbreviation == "" ||
                        address.RegionData.Abbreviation.ToLowerInvariant() == this.RegionAbbreviation.ToLowerInvariant())
                    {
                        if (this.PostalCode == "" ||
                            address.PostalCode.ToLowerInvariant() == this.PostalCode.ToLowerInvariant())
                        {
                            result = true;
                        }
                    }
                }
            }

            return result;
        }
Пример #15
0
        protected bool AppliesToItem(ITaxable item, IAddress address)
        {
            bool result = false;

            if (item.TaxScheduleId() == this.TaxScheduleId)
            {
                if (address.CountryData.Name.ToLowerInvariant() == this.CountryName.ToLowerInvariant())
                {
                    if (this.RegionAbbreviation == "" ||
                        address.RegionData.Abbreviation.ToLowerInvariant() == this.RegionAbbreviation.ToLowerInvariant())
                    {
                        if (this.PostalCode == "" ||
                            address.PostalCode.ToLowerInvariant() == this.PostalCode.ToLowerInvariant())
                        {
                            result = true;
                        }
                    }
                }
            }

            return(result);
        }
Пример #16
0
 private void ApplyTaxes(ITaxSchedule schedule, ITaxable item, IAddress address)
 {
     List<ITaxSchedule> schedules = new List<ITaxSchedule>();
     schedules.Add(schedule);
     List<ITaxable> items = new List<ITaxable>();
     items.Add(item);
     ApplyTaxes(schedules, items, address);
 }
Пример #17
0
        static void Main(string[] args)
        {
            ITaxable [] taxable = { };
            string      option  = "";
            int         i       = 0;

            double  area;
            string  location;
            bool    inCity = true;
            decimal valueHouse;

            int     numberOfSeats;
            int     regNumber;
            double  maxVelocity;
            decimal valueBus;

            string addOp = "";

            Console.WriteLine("Do you want to taxes for a house or bus?");
addHouseOrBus:
            Console.WriteLine("**Please write 'house' or 'bus'?");
            option = Console.ReadLine();
            if (option.ToLower() == "house")
            {
areaVal:
                Console.WriteLine("Area Value :");

                try
                {
                    area = double.Parse(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Area value is not a valid number.");
                    goto areaVal;
                }
locationVal:
                Console.WriteLine("Location Value :");
                location = Console.ReadLine();
                if (location == "")
                {
                    Console.WriteLine("You forgot to Write a Location value");
                    goto locationVal;
                }
yesNO:
                Console.WriteLine("In city 'yes' or 'no' :");
                try
                {
                    string incityVal = Console.ReadLine();
                    if (incityVal.Trim().ToLower() == "yes")
                    {
                        inCity = true;
                    }
                    else
                    if (incityVal.Trim().ToLower() == "no")
                    {
                        inCity = false;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Write 'yes' or 'no'!");
                    goto yesNO;
                }
houseVal:
                Console.WriteLine("House value :");
                try
                {
                    valueHouse = decimal.Parse(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("House value is not a valid number.");
                    goto houseVal;
                }

                taxable = new ITaxable[] { new TaxableHouse(area, location, inCity, valueHouse) };

                Console.WriteLine("Do you want to make another operation? 'yes/no'");
                addOp = Console.ReadLine();
                if (addOp == "yes")
                {
                    goto addHouseOrBus;
                }
                else if (addOp == "no")
                {
                    Console.WriteLine("Loading your data...");
                    goto showData;
                }
            }
            else if (option.ToLower() == "bus")
            {
                //nothing
                //int numberOfSeats;
                //int regNumber;
                //double maxVelocity;
                //decimal valueBus;

numberOfSeatsVal:
                Console.WriteLine("Number of seats :");

                try
                {
                    numberOfSeats = int.Parse(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Number of seats value is not valid.");
                    goto numberOfSeatsVal;
                }
regNumberVal:
                Console.WriteLine("Registration Number :");
                try
                {
                    regNumber = int.Parse(Console.ReadLine());
                }catch (Exception ex)
                {
                    Console.WriteLine("Registration Number is not valid.");
                    goto regNumberVal;
                }
maxVelocityVal:
                Console.WriteLine("Velocity :");
                try
                {
                    maxVelocity = double.Parse(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Velocity value is not valid");
                    goto maxVelocityVal;
                }
BusVal:
                Console.WriteLine("Bus value :");
                try
                {
                    valueBus = decimal.Parse(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Bus value is not a valid number.");
                    goto BusVal;
                }

                taxable = new ITaxable[] { new TaxableBus(numberOfSeats, regNumber, maxVelocity, valueBus) };

                Console.WriteLine("Do you want to make another operation? 'yes/no'");
                addOp = Console.ReadLine();
                if (addOp == "yes")
                {
                    goto addHouseOrBus;
                }
                else if (addOp == "no")
                {
                    Console.WriteLine("Loading your data...");
                    goto showData;
                }
            }
            else
            {
                Console.WriteLine("Please check if wrot 'house' or 'bus'?");
                goto showData;
            }

showData:
            foreach (ITaxable iTaxable in taxable)
            {
                Console.WriteLine("Line " + (i + 1) + " : " + iTaxable.TaxValue());
                i++;
            }
            Console.ReadLine();
        }
Пример #18
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;
                }
            }
        }
 public double CalculteTax(ITaxable taxableItems)
 {
     throw new NotImplementedException();
 }
Пример #20
0
 public void Accumulates(ITaxable t)
 {
     this.Total += t.CalculateTribute();
 }