Exemplo n.º 1
0
        public void Provider_IS_VAT_Payer_Client_lives_IN_EU_Dont_pay_VAT_Different_countries_return_121()
        {
            IInvoiceCalculator calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomLT;
            var customer = UsersFixture.CustomerInEUSE;
            var order    = new Order(100);

            var mockIsInEuropeanUnion = Substitute.For <ICountryInfoProvider>();

            mockIsInEuropeanUnion.IsInEurope(provider.Country).Returns(true);
            mockIsInEuropeanUnion.IsInEurope(customer.Country).Returns(true);
            calculator.CountryProvider = mockIsInEuropeanUnion;

            var mockVatGetter = Substitute.For <IVatGetter>();

            mockVatGetter.GetVAT(provider.Country).Returns(21);
            mockVatGetter.GetVAT(customer.Country).Returns(25);
            calculator.VATGetter = mockVatGetter;


            var result = calculator.Calculate(customer, provider, order);

            Assert.Equal(121, result);
        }
Exemplo n.º 2
0
        public static InvoiceDTO ToInvoiceDTO(Trip trip, Company company)
        {
            var invoiceCalculator = new InvoiceCalculator(trip.PassengerCount, trip.DistanceInKM, trip.Departure, trip.Recurrence);

            return(new InvoiceDTO()
            {
                InvoiceNumber = trip.Id,
                CompanyName = company.Name,
                Departure = trip.Departure,
                RecurrenceTime = trip.Recurrence,
                BenefitReciever = trip.Recipient,
                Purpose = trip.Purpose,
                DistanceInKM = trip.DistanceInKM,
                LocationDeparture = trip.LocationDeparture,
                LocationDestination = trip.LocationDestination,
                Description = trip.Description,
                PassengerCount = trip.PassengerCount,
                KMAllowanceUnit = invoiceCalculator.CompensationPerKM,
                KMAllowanceTotal = invoiceCalculator.CalculateKMAllowance(),
                PartDayBenefit = invoiceCalculator.PartDayBenefit,
                FullDayBenefit = invoiceCalculator.FullDayBenefit,
                TotalFullDaysBenefit = invoiceCalculator.CalculateTotalFullDaysBenefit(),
                TotalDayBenefit = invoiceCalculator.CalculateTotalDayBenefit(),
                Total = invoiceCalculator.CalculateTotal(),
                Created = trip.Created
            });
        }
Exemplo n.º 3
0
        public void ItWillCalculateTaxFree()
        {
            var job = new Job
            {
                Name = "Job 3",
                RequiresExtraMargin = true,
                Items = new List <PrintItem>
                {
                    new PrintItem
                    {
                        Name     = "frisbees",
                        Cost     = 19385.38m,
                        Taxation = TaxationType.TaxFree
                    },
                    new PrintItem
                    {
                        Name     = "yo-yos",
                        Cost     = 1829m,
                        Taxation = TaxationType.TaxFree
                    },
                }
            };

            var invoice = new InvoiceCalculator().Calculate(job, "Customer");

            Assert.IsNotNull("invoice");
            Assert.AreEqual(19385.38m, invoice.Items.Single(x => x.Name == "frisbees").Amount);
            Assert.AreEqual(1829.00m, invoice.Items.Single(x => x.Name == "yo-yos").Amount);
            Assert.AreEqual(24608.68m, invoice.TotalAmount, "Total amount is incorrect");
        }
Exemplo n.º 4
0
        public void Provider_IS_VAT_Payer_Client_lives_outside_EU_return_1500()
        {
            IInvoiceCalculator calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomDE;
            var customer = UsersFixture.CustomerOutsideEUJAV;
            var order    = new Order(1500);


            var mockIsInEuropeanUnion = Substitute.For <ICountryInfoProvider>();

            mockIsInEuropeanUnion.IsInEurope(provider.Country).Returns(true);
            mockIsInEuropeanUnion.IsInEurope(customer.Country).Returns(false);
            calculator.CountryProvider = mockIsInEuropeanUnion;

            var mockVatGetter = Substitute.For <IVatGetter>();

            mockVatGetter.GetVAT(provider.Country).Returns(19);
            mockVatGetter.GetVAT(customer.Country).Returns(11);
            calculator.VATGetter = mockVatGetter;

            var result = calculator.Calculate(customer, provider, order);

            Assert.Equal(1500, result);
        }
Exemplo n.º 5
0
 public InvoiceService(IInvoiceRepository invoiceRepository, ICurrencyRepository currencyRepository, IMapper mapper, InvoiceCalculator calculator)
 {
     this._invoiceRepository  = invoiceRepository;
     this._currencyRepository = currencyRepository;
     this._mapper             = mapper;
     this._calculator         = calculator;
 }
Exemplo n.º 6
0
        public void ItWillCalculateExtraMargin()
        {
            var job = new Job
            {
                Name = "Job 1",
                RequiresExtraMargin = true,
                Items = new List <PrintItem>
                {
                    new PrintItem
                    {
                        Name     = "envelopes",
                        Cost     = 520.00m,
                        Taxation = TaxationType.Standard
                    },
                    new PrintItem
                    {
                        Name     = "letterhead",
                        Cost     = 1983.37m,
                        Taxation = TaxationType.TaxFree
                    },
                }
            };

            var invoice = new InvoiceCalculator().Calculate(job, "Customer");

            Assert.IsNotNull("invoice");
            Assert.AreEqual(556.40m, invoice.Items.Single(x => x.Name == "envelopes").Amount);
            Assert.AreEqual(1983.37m, invoice.Items.Single(x => x.Name == "letterhead").Amount);
            Assert.AreEqual(2940.30m, invoice.TotalAmount, "Total amount is incorrect");
        }
Exemplo n.º 7
0
        public void ItWillCreateInvoice()
        {
            var job = new Job
            {
                Name = "Job 3",
                RequiresExtraMargin = true,
                Items = new List <PrintItem>
                {
                    new PrintItem
                    {
                        Name     = "frisbees",
                        Cost     = 19385.38m,
                        Taxation = TaxationType.TaxFree
                    },
                    new PrintItem
                    {
                        Name     = "yo-yos",
                        Cost     = 1829m,
                        Taxation = TaxationType.TaxFree
                    },
                }
            };

            var invoice = new InvoiceCalculator().Calculate(job, "Customer");

            new PdfInvoiceWriter().Write(invoice, "sample.invoice.pdf");
        }
        public static IInvoice GetInvoice3()
        {
            List <IItem> item3 = new List <IItem>();

            //· 1 imported bottle of perfume at 27.99
            item3.Add(
                new Models.Entities.Invoice.Item(
                    1,
                    new Description("imported bottle of perfume", string.Empty),
                    27.99F,
                    1,
                    Enum.ItemCategories.Others,
                    true
                    ));
            //· 1 bottle of perfume at 18.99
            item3.Add(
                new Models.Entities.Invoice.Item(
                    2,
                    new Description("bottle of perfume", string.Empty),
                    18.99f,
                    1,
                    Enum.ItemCategories.Others,
                    true
                    ));
            //· 1 packet of headache pills at 9.75
            item3.Add(
                new Models.Entities.Invoice.Item(
                    3,
                    new Description("packet of headache pills", string.Empty),
                    9.75F,
                    1,
                    Enum.ItemCategories.MedicalProduct,
                    false
                    ));
            //· 1 box of imported chocolates at 11.25
            item3.Add(
                new Models.Entities.Invoice.Item(
                    4,
                    new Description("imported box of chocolates", string.Empty),
                    11.25F,
                    1,
                    Enum.ItemCategories.Food,
                    true
                    ));
            #endregion


            List <IItem> items = new List <IItem>();

            items.AddRange(item3);



            IInvoice invoice = new Models.Entities.Invoice.Invoice(1, items);

            IInvoiceCalculator invoiceCalculator = new InvoiceCalculator();

            return(invoice);
        }
Exemplo n.º 9
0
        public IInvoice CompileInvoice(IInvoice invoice)
        {
            InvoiceCalculator invoiceCalculator = new InvoiceCalculator();

            invoiceCalculator.CreateTaxes(invoice);
            invoiceCalculator.ApplyTaxes(invoice);
            return(invoice);
        }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            //  CreateHostBuilder(args).Build().Run();
            //var  invoice = new IInvoiceCalculator();
            Customer           customer        = new Customer(new Country("JAV"), new Company("Kompanija", true));
            Provider           provider        = new Provider(new Country("LT"), new Company("ProviderCompany", true));
            Order              order           = new Order(15);
            IInvoiceCalculator invoiceCalulate = new InvoiceCalculator();

            invoiceCalulate.CountryProvider = new CountryInfoProvider();
            invoiceCalulate.VATGetter       = new VATGetter();
            invoiceCalulate.Calculate(customer, provider, order);
        }
Exemplo n.º 11
0
        public static IInvoice GetInvoice1()
        {
            #region Input1
            //Input 1:

            List <IItem> item1 = new List <IItem>();
            //· 1 book at 12.49
            item1.Add(
                new Models.Entities.Invoice.Item(
                    1,
                    new Description("Book", string.Empty),
                    12.49F,
                    1,
                    Enum.ItemCategories.Books,
                    false
                    ));
            //· 1 music CD at 14.99
            item1.Add(
                new Models.Entities.Invoice.Item(
                    2,
                    new Description("music CD", string.Empty),
                    14.99f,
                    1,
                    Enum.ItemCategories.Others,
                    false
                    ));
            //· 1 chocolate bar at 0.8
            item1.Add(
                new Models.Entities.Invoice.Item(
                    2,
                    new Description("chocolate bar", string.Empty),
                    0.8f,
                    1,
                    Enum.ItemCategories.Food,
                    false
                    ));
            #endregion

            List <IItem> items = new List <IItem>();

            items.AddRange(item1);

            IInvoice invoice = new Models.Entities.Invoice.Invoice(1, items);

            IInvoiceCalculator invoiceCalculator = new InvoiceCalculator();

            return(invoice);
        }
Exemplo n.º 12
0
        public void Provider_IS_VAT_Payer_Client_lives_outside_EU_return_50()
        {
            var calculator = new InvoiceCalculator();

            var                  provider        = UsersFixture.ProviderIsVATPayerFomLT;
            var                  customer        = UsersFixture.CustomerOutsideEUZE;
            var                  order           = new Order(50);
            IVatGetter           vat             = new VATGetter();
            ICountryInfoProvider countryprovider = new CountryInfoProvider();

            calculator.CountryProvider = countryprovider;
            calculator.VATGetter       = vat;

            var result = calculator.Calculate(customer, provider, order);

            Assert.Equal(50, result);
        }
Exemplo n.º 13
0
        public void Provider_IS_VAT_Payer_Client_lives_IN_EU_pay_VAT_Same_countries_return_1210()
        {
            IInvoiceCalculator calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomLT;
            var customer = UsersFixture.CustomerInEULTPayVAT;
            var order    = new Order(1000);

            IVatGetter           vat             = new VATGetter();
            ICountryInfoProvider countryprovider = new CountryInfoProvider();

            calculator.CountryProvider = countryprovider;
            calculator.VATGetter       = vat;

            var result = calculator.Calculate(customer, provider, order);

            Assert.Equal(1210, result);
        }
Exemplo n.º 14
0
        public void Provider_IS_VAT_Payer_JAV_Client_lives_outside_EUClient_Not_VAT_payer()
        {
            IInvoiceCalculator calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomJAV;
            var customer = UsersFixture.CustomerInEUSE;
            var order    = new Order(1000);

            IVatGetter           vat             = new VATGetter();
            ICountryInfoProvider countryprovider = new CountryInfoProvider();

            calculator.CountryProvider = countryprovider;
            calculator.VATGetter       = vat;

            var result = calculator.Calculate(customer, provider, order);

            Assert.Equal(1110, result);
        }
Exemplo n.º 15
0
        public void ICalculator_InTerface_Provider_Not_EU_Exception()
        {
            IInvoiceCalculator calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomJAV;
            var customer = UsersFixture.CustomerInEUITPayVAT;
            var order    = new Order(6000);

            var mockIsInEuropeanUnion = Substitute.For <ICountryInfoProvider>();

            mockIsInEuropeanUnion.IsInEurope(provider.Country).Returns(false);
            mockIsInEuropeanUnion.IsInEurope(customer.Country).Returns(true);
            calculator.CountryProvider = mockIsInEuropeanUnion;

            var message = "Not Specified VATGetter";

            var exception = Assert.Throws <BussinessException>(() => calculator.Calculate(customer, provider, order));

            Assert.Equal(message, exception.Message);
        }
Exemplo n.º 16
0
        public void ICalculator_InTerface_Customer_VAT_NOT_fount()
        {
            IInvoiceCalculator calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomJAV;
            var customer = UsersFixture.CustomerNotInList;
            var order    = new Order(6000);

            ICountryInfoProvider mockIsInEuropeanUnion = new CountryInfoProvider();

            calculator.CountryProvider = mockIsInEuropeanUnion;

            IVatGetter mockVatGetter = new VATGetter();

            calculator.VATGetter = mockVatGetter;

            var message = "VAT were not found, edit your Country VAT list";

            var exception = Assert.Throws <BussinessException>(() => calculator.Calculate(customer, provider, order));

            Assert.Equal(message, exception.Message);
        }
        private void InitializeSut()
        {
            var mockRepository = new Mock <ICurrencyRepository>();
            var resultList     = new List <Currency>
            {
                new Currency {
                    Code = "USD", Name = "Euro", ExchangeRate = 1, ExchangeRateDate = new DateTime(2019, 4, 9, 12, 45, 0)
                },
                new Currency {
                    Code = "EUR", Name = "British Pound", ExchangeRate = 0.886552m, ExchangeRateDate = new DateTime(2019, 4, 9, 12, 45, 0)
                },
                new Currency {
                    Code = "CHF", Name = "Swiss Franc", ExchangeRate = 0.998312m, ExchangeRateDate = new DateTime(2019, 4, 9, 12, 45, 0)
                },
                new Currency {
                    Code = "RUB", Name = "Russian Ruble", ExchangeRate = 64.767361m, ExchangeRateDate = new DateTime(2019, 4, 9, 13, 40, 0)
                }
            };

            mockRepository.Setup(repo => repo.GetAllAsync()).ReturnsAsync(resultList);
            _sut = new InvoiceCalculator(mockRepository.Object);
        }
Exemplo n.º 18
0
        public void ItWillCalculateStandardJob()
        {
            var job = new Job
            {
                Name = "Job 2",
                RequiresExtraMargin = false,
                Items = new List <PrintItem>
                {
                    new PrintItem
                    {
                        Name     = "t-shirts",
                        Cost     = 294.04m,
                        Taxation = TaxationType.Standard
                    }
                }
            };

            var invoice = new InvoiceCalculator().Calculate(job, "Customer");

            Assert.IsNotNull("invoice");
            Assert.AreEqual(314.62m, invoice.Items.Single(x => x.Name == "t-shirts").Amount);
            Assert.AreEqual(346.96m, invoice.TotalAmount, "Total amount is incorrect");
        }
Exemplo n.º 19
0
        public static IInvoice GetInvoice2()
        {
            List <IItem> item2 = new List <IItem>();

            //· 1 imported box of chocolates at 10.00
            item2.Add(
                new Models.Entities.Invoice.Item(
                    1,
                    new Description("imported box of chocolates", string.Empty),
                    10.00F,
                    1,
                    Enum.ItemCategories.Food,
                    true
                    ));

            //- 1 imported bottle of perfume at 47.50

            item2.Add(
                new Models.Entities.Invoice.Item(
                    1,
                    new Description("imported bottle of perfume", string.Empty),
                    10.00F,
                    1,
                    Enum.ItemCategories.Others,
                    true
                    ));

            List <IItem> items = new List <IItem>();

            items.AddRange(item2);

            IInvoice invoice = new Models.Entities.Invoice.Invoice(1, items);

            IInvoiceCalculator invoiceCalculator = new InvoiceCalculator();

            return(invoice);
        }
Exemplo n.º 20
0
        public InvoiceControllerFixture()
        {
            var x = Directory.GetCurrentDirectory();
            var y = Environment.CurrentDirectory;
            var z = Assembly.GetExecutingAssembly();

            _config = new ConfigurationBuilder()
                      .SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile("appsettings.json")
                      .Build();

            var mongoSettings = _config.GetSection("MongoSettings").Get <MongoSettings>();
            var options       = Options.Create <MongoSettings>(mongoSettings);

            _context            = new MongoDbContext(options);
            _invoiceRepository  = new MongoInvoiceRepository(_context);
            _currencyRepository = new MongoCurrencyRepository(_context);
            var mapperConfig = new MapperConfiguration(cfg => cfg.AddProfile(new AddInvoiceMapping()));

            _mapper             = new Mapper(mapperConfig);
            _invoiceCalculator  = new InvoiceCalculator(_currencyRepository);
            _invoiceService     = new InvoiceService(_invoiceRepository, _currencyRepository, _mapper, _invoiceCalculator);
            _invoicesController = new InvoicesController(_invoiceService);
        }
Exemplo n.º 21
0
        public void Provider_IS_VAT_Payer_Client_lives_IN_EU_pay_VAT_Same_countries_return_6000()
        {
            IInvoiceCalculator calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomIT;
            var customer = UsersFixture.CustomerInEUITPayVAT;
            var order    = new Order(6000);

            var mockIsInEuropeanUnion = Substitute.For <ICountryInfoProvider>();

            mockIsInEuropeanUnion.IsInEurope(provider.Country).Returns(true);
            mockIsInEuropeanUnion.IsInEurope(customer.Country).Returns(true);
            calculator.CountryProvider = mockIsInEuropeanUnion;

            var mockVatGetter = Substitute.For <IVatGetter>();

            mockVatGetter.GetVAT(provider.Country).Returns(22);
            mockVatGetter.GetVAT(customer.Country).Returns(22);
            calculator.VATGetter = mockVatGetter;

            var result = calculator.Calculate(customer, provider, order);

            Assert.NotEqual(6000, result, 0);
        }
Exemplo n.º 22
0
        public void Provider_NOY_VAT_Payer_150()
        {
            var calculator = new InvoiceCalculator();

            var provider = UsersFixture.ProviderIsVATPayerFomLTNOTVATPayer;
            var customer = UsersFixture.CustomerOutsideEUZE;
            var order    = new Order(150);

            var mockIsInEuropeanUnion = Substitute.For <ICountryInfoProvider>();

            mockIsInEuropeanUnion.IsInEurope(provider.Country).Returns(false);
            mockIsInEuropeanUnion.IsInEurope(customer.Country).Returns(true);
            calculator.CountryProvider = mockIsInEuropeanUnion;

            var mockVatGetter = Substitute.For <IVatGetter>();

            mockVatGetter.GetVAT(provider.Country).Returns(21);
            mockVatGetter.GetVAT(customer.Country).Returns(25);
            calculator.VATGetter = mockVatGetter;

            var result = calculator.Calculate(customer, provider, order);

            Assert.Equal(150, result);
        }
Exemplo n.º 23
0
        public IActionResult Invoice()
        {
            List <MeterInfo> meterList = new List <MeterInfo>();

            meterList.Add(new MeterInfo()
            {
                EnxpId               = 1,
                EtsoCode             = "40Z0001",
                PmumId               = 1,
                MeterName            = "Meter_1",
                MeterGroup           = "AG",
                DistrictName         = "Bedas",
                CityName             = "İstanbul",
                TariffType           = Tariff.Ticarethane,
                AGOG                 = AGOG.AG,
                MunicipalityTaxRatio = false,
                IsInPortfolio        = true,
            });

            meterList.Add(new MeterInfo()
            {
                EnxpId               = 2,
                EtsoCode             = "40Z0002",
                PmumId               = 2,
                MeterName            = "Meter_2",
                MeterGroup           = "OG",
                DistrictName         = "Ayedas",
                CityName             = "İstanbul",
                TariffType           = Tariff.Ticarethane,
                AGOG                 = AGOG.OG,
                MunicipalityTaxRatio = true,
                IsInPortfolio        = true,
            });

            List <ConsumeProfile> periodConsumeList = new List <ConsumeProfile>();

            periodConsumeList.Add(new ConsumeProfile()
            {
                AGOG = (int)AGOG.AG,
                CalculateMunicipalityTax = false,
                Consume  = 1000M,
                EtsoCode = "40Z0001",
                Period   = new DateTime(2016, 8, 1)
            });

            periodConsumeList.Add(new ConsumeProfile()
            {
                AGOG = (int)AGOG.OG,
                CalculateMunicipalityTax = false,
                Consume  = 2000M,
                EtsoCode = "40Z0002",
                Period   = new DateTime(2016, 8, 1)
            });


            List <ConsumeProfile> clearingConsumeList = new List <ConsumeProfile>();

            clearingConsumeList.Add(new ConsumeProfile()
            {
                AGOG = (int)AGOG.AG,
                CalculateMunicipalityTax = false,
                Consume  = -500M,
                EtsoCode = "40Z0001",
                Period   = new DateTime(2016, 7, 1)
            });

            clearingConsumeList.Add(new ConsumeProfile()
            {
                AGOG = (int)AGOG.OG,
                CalculateMunicipalityTax = false,
                Consume  = 400M,
                EtsoCode = "40Z0002",
                Period   = new DateTime(2016, 7, 1)
            });


            List <ConsumeProfile> correctionConsumeList = new List <ConsumeProfile>();

            correctionConsumeList.Add(new ConsumeProfile()
            {
                AGOG = (int)AGOG.AG,
                CalculateMunicipalityTax = false,
                Consume  = -100M,
                EtsoCode = "40Z0001",
                Period   = new DateTime(2016, 5, 1)
            });

            correctionConsumeList.Add(new ConsumeProfile()
            {
                AGOG = (int)AGOG.OG,
                CalculateMunicipalityTax = false,
                Consume  = 100M,
                EtsoCode = "40Z0002",
                Period   = new DateTime(2016, 5, 1)
            });

            List <TariffPrice> tariffPriceList = new List <TariffPrice>();


            tariffPriceList.Add(new TariffPrice()
            {
                StartPeriod             = new DateTime(2016, 7, 1),
                EndPeriod               = new DateTime(2016, 9, 1),
                AGDistributionUnitPrice = 0.08M,
                OGDistributionUnitPrice = 0.07M
            });

            tariffPriceList.Add(new TariffPrice()
            {
                StartPeriod             = new DateTime(2016, 7, 1),
                EndPeriod               = new DateTime(2016, 9, 1),
                AGDistributionUnitPrice = 0.09M,
                OGDistributionUnitPrice = 0.08M
            });

            tariffPriceList.Add(new TariffPrice()
            {
                StartPeriod             = new DateTime(2016, 10, 1),
                EndPeriod               = new DateTime(2016, 12, 1),
                AGDistributionUnitPrice = 0.10M,
                OGDistributionUnitPrice = 0.09M
            });

            InvoiceCalculator calculator = new InvoiceCalculator(new DateTime(2016, 8, 1), tariffPriceList);

            var result = calculator.CalculateOverallInvoice(meterList, periodConsumeList, clearingConsumeList, correctionConsumeList);


            return(View(result));
        }
 public InvoiceCalculatorTests()
 {
     _invoiceCalculator = new InvoiceCalculator();
 }