Esempio n. 1
0
        public void CanCalculateSampleCase2()
        {
            var tax5 = TaxTemplateBuilder.Create("%5 Tax").WithRate(5)
                       .CreateAccountTransactionType().WithId(3).Do()
                       .WithRounding(0)
                       .Build();
            var ticket = TicketBuilder.Create(TicketType, Department.Default).TaxExcluded()
                         .AddOrderFor(Product).WithTaxTemplate(tax5).WithPrice(8.95m).WithQuantity(1).Do()
                         .Build();

            Assert.AreEqual(9.40m, ticket.GetSum());
        }
Esempio n. 2
0
        public void CanCalculateSampleCase1()
        {
            // http://forum2.sambapos.com/index.php/topic,1481.0.html

            var tax8 = TaxTemplateBuilder.Create("%8 Tax").WithRate(8)
                       .CreateAccountTransactionType().WithId(2).Do()
                       .WithRounding(0)
                       .Build();

            var tax18 = TaxTemplateBuilder.Create("%18 Tax").WithRate(18)
                        .CreateAccountTransactionType().WithId(3).Do()
                        .WithRounding(0)
                        .Build();

            var ticket = TicketBuilder.Create(TicketType, Department.Default).TaxIncluded()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(6).WithQuantity(16).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(10).WithQuantity(3).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(10).WithQuantity(3).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(3).WithQuantity(10).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax18).WithPrice(9).WithQuantity(1).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(7).WithQuantity(1).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(18).WithQuantity(3).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(5).WithQuantity(2).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(5).WithQuantity(2).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(28).WithQuantity(3).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(32).WithQuantity(3).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(10).WithQuantity(2).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax8).WithPrice(10).WithQuantity(2).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax18).WithPrice(9).WithQuantity(1).Do()
                         .AddOrderFor(Product).WithTaxTemplate(tax18).WithPrice(105).WithQuantity(2).Do()
                         .Build();

            Assert.AreEqual(715, ticket.GetSum());
            Assert.AreEqual(34.78 + 36.07, ticket.GetTaxTotal());
            Assert.AreEqual(36.07, ticket.TransactionDocument.AccountTransactions.Single(x => x.AccountTransactionTypeId == 2).Amount);
            Assert.AreEqual(34.78, ticket.TransactionDocument.AccountTransactions.Single(x => x.AccountTransactionTypeId == 3).Amount);
        }
Esempio n. 3
0
        public void Setup()
        {
            Pizza   = CreateMenuItem(1, "Pizza", 10);
            Cola    = CreateMenuItem(2, "Cola", 5);
            Beer    = CreateMenuItem(3, "Beer", 10);
            Product = CreateMenuItem(4, "Product", 1);

            var saleAccountType = new AccountType {
                Name = "Sales Accounts", Id = 1
            };
            var taxAccountType = new AccountType {
                Name = "Tax Accounts", Id = 2
            };
            var receivableAccountType = new AccountType {
                Name = "Receivable Accounts", Id = 3
            };
            var discountAccountType = new AccountType {
                Name = "Discount Accounts", Id = 4
            };
            var defaultSaleAccount = new Account {
                AccountTypeId = saleAccountType.Id, Name = "Sales", Id = 1
            };
            var receivableAccount = new Account {
                AccountTypeId = receivableAccountType.Id, Name = "Receivables", Id = 2
            };
            var stateTaxAccount = new Account {
                AccountTypeId = taxAccountType.Id, Name = "State Tax", Id = 3
            };
            var localTaxAccount = new Account {
                AccountTypeId = taxAccountType.Id, Name = "Local Tax", Id = 4
            };
            var defaultDiscountAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = "Discount", Id = 5
            };

            var saleTransactionType = new AccountTransactionType
            {
                Id   = 1,
                Name = "Sale Transaction",
                SourceAccountTypeId    = saleAccountType.Id,
                TargetAccountTypeId    = receivableAccountType.Id,
                DefaultSourceAccountId = defaultSaleAccount.Id,
                DefaultTargetAccountId = receivableAccount.Id
            };

            var localTaxTransactionType = new AccountTransactionType
            {
                Id   = 2,
                Name = "Local Tax Transaction",
                SourceAccountTypeId    = taxAccountType.Id,
                TargetAccountTypeId    = receivableAccountType.Id,
                DefaultSourceAccountId = localTaxAccount.Id,
                DefaultTargetAccountId = receivableAccount.Id
            };

            var stateTaxTransactionType = new AccountTransactionType
            {
                Id   = 3,
                Name = "State Tax Transaction",
                SourceAccountTypeId    = taxAccountType.Id,
                TargetAccountTypeId    = receivableAccountType.Id,
                DefaultSourceAccountId = stateTaxAccount.Id,
                DefaultTargetAccountId = receivableAccount.Id
            };

            DiscountTransactionType = new AccountTransactionType
            {
                Id   = 4,
                Name = "Discount Transaction",
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = receivableAccount.Id,
                DefaultTargetAccountId = defaultDiscountAccount.Id
            };

            var stateTax = TaxTemplateBuilder.Create("State Tax")
                           .WithRate(25)
                           .WithRounding(2)
                           .WithAccountTransactionType(stateTaxTransactionType)
                           .AddDefaultTaxTemplateMap()
                           .Build();

            var localTax = TaxTemplateBuilder.Create("Local Tax").WithRate(3)
                           .AddTaxTemplateMap(new TaxTemplateMap {
                MenuItemId = Cola.Id
            })
                           .AddTaxTemplateMap(new TaxTemplateMap {
                MenuItemId = Beer.Id
            })
                           .WithAccountTransactionType(localTaxTransactionType)
                           .WithRounding(2)
                           .Build();


            TaxTemplates = new List <TaxTemplate> {
                stateTax, localTax
            };

            TicketType = new TicketType {
                SaleTransactionType = saleTransactionType, TaxIncluded = true
            };
        }