public CalculationType Build() { var result = new CalculationType { Name = _name, AccountTransactionType = _accountTransactionType, Amount = _amount, DecreaseAmount = _decreaseAmount }; return result; }
public void AddCalculation(CalculationType calculationType, decimal amount) { var calculation = Calculations.SingleOrDefault(x => x.CalculationTypeId == calculationType.Id) ?? Calculations.SingleOrDefault(x => x.AccountTransactionTypeId == calculationType.AccountTransactionType.Id); if (calculation == null) { calculation = new Calculation { Amount = amount, Name = calculationType.Name, CalculationType = calculationType.CalculationMethod, CalculationTypeId = calculationType.Id, IncludeTax = calculationType.IncludeTax, DecreaseAmount = calculationType.DecreaseAmount, UsePlainSum = calculationType.UsePlainSum, Order = calculationType.SortOrder, AccountTransactionTypeId = calculationType.AccountTransactionType.Id }; Calculations.Add(calculation); TransactionDocument.AddSingletonTransaction(calculation.AccountTransactionTypeId, calculationType.AccountTransactionType, GetTicketAccounts()); } else if (calculationType.ToggleCalculation && calculation.Amount == amount) { amount = 0; } else { calculation.Amount = amount; } calculation.Name = calculationType.Name; if (amount == 0 && calculation.CalculationType != 5) { Calculations.Remove(calculation); calculation.UpdateCalculationTransaction(TransactionDocument, 0, ExchangeRate); } }
public void AddCalculation(CalculationType template, decimal amount) { var t = Calculations.SingleOrDefault(x => x.CalculationTypeId == template.Id) ?? Calculations.SingleOrDefault(x => x.AccountTransactionTypeId == template.AccountTransactionType.Id); if (t == null) { t = new Calculation { Amount = amount, Name = template.Name, CalculationType = template.CalculationMethod, CalculationTypeId = template.Id, IncludeTax = template.IncludeTax, DecreaseAmount = template.DecreaseAmount, Order = template.Order, AccountTransactionTypeId = template.AccountTransactionType.Id }; Calculations.Add(t); TransactionDocument.AddSingletonTransaction(t.AccountTransactionTypeId, template.AccountTransactionType, AccountTypeId, AccountId); } else if (t.Amount == amount) { amount = 0; } else { t.Amount = amount; } t.Name = template.Name; if (amount == 0) { Calculations.Remove(t); UpdateCalculationTransaction(t, 0); } }
public void AddCalculation(CalculationType template, decimal amount) { var t = Calculations.SingleOrDefault(x => x.CalculationTypeId == template.Id) ?? Calculations.SingleOrDefault(x => x.AccountTransactionTypeId == template.AccountTransactionType.Id); if (t == null) { t = new Calculation { Amount = amount, Name = template.Name, CalculationType = template.CalculationMethod, CalculationTypeId = template.Id, IncludeTax = template.IncludeTax, DecreaseAmount = template.DecreaseAmount, Order = template.Order, AccountTransactionTypeId = template.AccountTransactionType.Id }; Calculations.Add(t); TransactionDocument.AddSingletonTransaction(t.AccountTransactionTypeId, template.AccountTransactionType, AccountTypeId, AccountId); } else if (t.Amount == amount) { amount = 0; } else t.Amount = amount; t.Name = template.Name; if (amount == 0) { Calculations.Remove(t); UpdateCalculationTransaction(t, 0); } }
public void AddCalculation(CalculationType calculationType, decimal amount) { var calculation = Calculations.SingleOrDefault(x => x.CalculationTypeId == calculationType.Id) ?? Calculations.SingleOrDefault(x => x.AccountTransactionTypeId == calculationType.AccountTransactionType.Id); if (calculation == null) { calculation = new Calculation { Amount = amount, Name = calculationType.Name, CalculationType = calculationType.CalculationMethod, CalculationTypeId = calculationType.Id, IncludeTax = calculationType.IncludeTax, DecreaseAmount = calculationType.DecreaseAmount, UsePlainSum = calculationType.UsePlainSum, Order = calculationType.SortOrder, AccountTransactionTypeId = calculationType.AccountTransactionType.Id }; Calculations.Add(calculation); TransactionDocument.AddSingletonTransaction(calculation.AccountTransactionTypeId, calculationType.AccountTransactionType, GetTicketAccounts()); } else if (calculationType.ToggleCalculation && calculation.Amount == amount) { amount = 0; } else calculation.Amount = amount; calculation.Name = calculationType.Name; if (amount == 0 && calculation.CalculationType != 5) { Calculations.Remove(calculation); calculation.UpdateCalculationTransaction(TransactionDocument, 0, ExchangeRate); } }
public void DoesTicketDiscountsWorks() { var ticket = SetupTicket(); var calculationType = new CalculationType { AccountTransactionType = AccountTransactionType.Default, DecreaseAmount = true }; ticket.AddCalculation(calculationType, 10); var orderSelector = new OrderSelector(); orderSelector.UpdateTicket(ticket); Assert.AreEqual(28 - 2.8, orderSelector.Selectors.Sum(x => x.TotalPrice)); }