Esempio n. 1
0
        public IActionResult Index(TaxViewModel taxViewModel)
        {
            if (ModelState.IsValid)
            {
                var taxCalculatedResponse = _taxCalculation.CalculationIncomeTax(taxViewModel);

                if (taxCalculatedResponse != null)
                {
                    var taxCalculationModel = new Models.DbModel.TaxCalculation
                    {
                        AnnualIncome    = (decimal)taxViewModel.AnnualIncome,
                        Name            = taxViewModel.Name.ToLower(),
                        TaxCalculated   = (decimal)taxCalculatedResponse.CalculatedTax,
                        CalculationType = taxCalculatedResponse.CalculationType.ToLower(),
                        DateCreated     = DateTime.Now
                    };

                    var hasSaved = _sqlRepository.Save(taxCalculationModel);

                    //this is just to send a message to rabbitMQ
                    //disable this if you do not have a local instance of rabbit installed :)
                    if (doRabbitPublish)
                    {
                        _publisher.PublishMessage(taxCalculationModel);
                    }
                }
            }

            return(RedirectToAction("Index", "Data"));
        }
Esempio n. 2
0
        public ActionResult Edit(int id)
        {
            Tax          tax   = new Tax();
            TaxViewModel model = new TaxViewModel();

            tax = taxDal.ReadTaxById(id);

            model.TaxId   = tax.TaxId;
            model.TaxName = tax.TaxName;
            model.Value   = tax.Value;

            var lst = taxDal.ReadAllTax();

            model.lst = new List <TaxViewModel>();
            model.lst = lst.ConvertAll(x => new TaxViewModel
            {
                TaxId   = x.TaxId,
                TaxName = x.TaxName,
                Value   = x.Value
            });
            model.IsEdit = true;


            return(View("Index", model));
        }
Esempio n. 3
0
        public JsonResult GetTaxes(TaxViewModel tViewModel)
        {
            PaginationInfo pager = new PaginationInfo();

            pager = tViewModel.Pager;

            PaginationViewModel pViewModel = new PaginationViewModel();

            try
            {
                pViewModel.dt = _tRepo.GetTaxes(tViewModel.Filter.TaxName, tViewModel.Filter.IsActive, ref pager);

                pViewModel.Pager = pager;

                Logger.Debug("Tax Controller GetTaxes");
            }

            catch (Exception ex)
            {
                tViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01"));

                Logger.Error("Tax Controller - GetTaxes" + ex.ToString());
            }

            return(Json(JsonConvert.SerializeObject(pViewModel), JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> AddTax(TaxViewModel input)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
                }

                await _userTaxRepository.AddUserTax(new UserTax
                {
                    UserId            = user.Id,
                    CharityPaidAmount = input.CharityPaidAmount.Value,
                    TotalIncome       = input.TotalIncome.Value,
                    NumberOfChildren  = input.NumberOfChildren.Value,
                    Year         = input.Year.Value,
                    TaxDueAmount = _taxService.CalculateTax(input.Year.Value, input.NumberOfChildren.Value, input.CharityPaidAmount.Value, input.TotalIncome.Value)
                });

                _logger.LogInformation("New Tax Created");

                return(LocalRedirect($"/Tax/getTax?year={input.Year}"));
            }

            return(View(input));
        }
Esempio n. 5
0
        public async Task AddTax_SubmitInvalidYear_ThrowValidation()
        {
            // Arrange
            var taxViewModel = new TaxViewModel
            {
                CharityPaidAmount = 10,
                NumberOfChildren  = 1,
                TotalIncome       = 10000,
                Year = 0
            };
            var taxViewModelData = taxViewModel.ToDictionary();

            // Act
            await UserManager.CreateAsync(new ApplicationUser
            {
                Email    = Email,
                UserName = Email
            }, Password);

            var response = await PostAsync(AddTaxUrl, taxViewModelData, Email, Password);

            var responseContent = await response.Content.ReadAsStringAsync();

            var taxResult = await UserTaxRepository.GetUserTax(User.Id, taxViewModel.Year.Value);

            //Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            // checking no data is inserted
            Assert.Null(taxResult);
            Assert.Contains("The field Tax Year must be between 2000 and 2020.", responseContent);
        }
Esempio n. 6
0
        public ActionResult Index(TaxViewModel model)
        {
            Tax tax = new Tax();

            if (ModelState.IsValid)
            {
                tax.TaxName   = model.TaxName;
                tax.Value     = Convert.ToDecimal(model.Value);
                tax.CreatedBy = "Admin";
                tax.CreatedOn = DateTime.Now;

                taxDal.Create(tax);
                TempData["SuccessMsg"] = "Tax Created Successfully";
                return(RedirectToAction("Index"));
            }

            var lst = taxDal.ReadAllTax();

            model.lst = new List <TaxViewModel>();
            model.lst = lst.ConvertAll(x => new TaxViewModel
            {
                TaxId   = x.TaxId,
                TaxName = x.TaxName,
                Value   = x.Value
            });
            model.IsEdit = false;
            return(View(model));
        }
        public async Task <IActionResult> GetTax(int?year)
        {
            if (!year.HasValue)
            {
                _logger.LogError("no year is provided");
                throw new ApplicationException("Year must be provided");
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var userTax = await _userTaxRepository.GetUserTax(user.Id, year.Value);

            var result = new TaxViewModel
            {
                CharityPaidAmount = userTax.CharityPaidAmount,
                NumberOfChildren  = userTax.NumberOfChildren,
                TotalIncome       = userTax.TotalIncome,
                Year         = userTax.Year,
                TaxDueAmount = userTax.TaxDueAmount
            };

            return(View(result));
        }
Esempio n. 8
0
        public AddTax()
        {
            TaxViewModel ViewModel;

            InitializeComponent();
            ViewModel        = new TaxViewModel();
            this.DataContext = ViewModel;
        }
        public IHttpActionResult Get()
        {
            var vm = new TaxViewModel();

            vm.HandleRequest();
            vm.IsValid = true;
            return(Ok(vm));
        }
Esempio n. 10
0
        // GET: DonorTax/Home
        public ActionResult Index()
        {
            var vm = new TaxViewModel();

            vm.HandleRequest();
            vm.IsValid = true;
            return(View(vm));
        }
Esempio n. 11
0
        public IActionResult Index(TaxViewModel model)
        {
            var command = new CalculateTaxCommand();

            model.Tax = command.CalculateTax(model.TaxCode, model.Income);

            return(View(model));
        }
Esempio n. 12
0
        public ActionResult Index(TaxViewModel tViewModel)
        {
            if (TempData["tViewModel"] != null)
            {
                tViewModel = (TaxViewModel)TempData["tViewModel"];
            }

            return(View("Index", tViewModel));
        }
Esempio n. 13
0
        void TaxViewController_Loaded(object sender, RoutedEventArgs e)
        {
            taxViewModel = new TaxViewModel();
            taxViewModel.LoadTCodeEntitys();
            taxViewModel.LoadTaxClass();

            taxViewModel.ViewSource.Source = taxViewModel.GoodsTaxRates;
            this.DataContext = taxViewModel;
        }
Esempio n. 14
0
        public TaxViewModel DisplayTaxes()
        {
            TaxViewModel taxViewModel = new TaxViewModel();
            Tax          taxList      = db.Taxes.Single();

            taxViewModel.CGST       = (float)taxList.CGST;
            taxViewModel.SGST       = (float)taxList.SGST;
            taxViewModel.ServiceTax = (float)taxList.ServiceTax;
            return(taxViewModel);
        }
Esempio n. 15
0
 public ActionResult Edit(TaxViewModel tax)
 {
     if (ModelState.IsValid)
     {
         var entity = Mapper.Map <Tax>(tax);
         taxService.Update(entity);
         return(RedirectToAction("Index"));
     }
     return(View(tax));
 }
Esempio n. 16
0
        /// <summary>
        /// Add Tax Method updates tax table with new values
        /// </summary>
        /// <param name="tax"></param>
        /// <returns></returns>
        public bool AddTax(TaxViewModel tax)
        {
            Tax taxConfig = db.Taxes.FirstOrDefault();

            taxConfig.CGST            = tax.CGST;
            taxConfig.SGST            = tax.SGST;
            taxConfig.ServiceTax      = tax.ServiceTax;
            db.Entry(taxConfig).State = EntityState.Modified;
            db.SaveChanges();
            return(true);
        }
Esempio n. 17
0
        public override List <TaxViewModel> ParseFile(string fileName, System.IO.Stream inputStream)
        {
            StreamReader csvreader = new StreamReader(inputStream);

            List <TaxViewModel> modelList = new List <TaxViewModel>();

            for (int i = 0; i < 5; i++)
            {
                csvreader.ReadLine();
            }
            try {
                while (!csvreader.EndOfStream)
                {
                    var line = csvreader.ReadLine();
                    if (String.IsNullOrEmpty(line))
                    {
                        break;
                    }
                    var values   = line.Split(';');
                    var taxModel = new TaxViewModel();
                    taxModel.DocumentName = fileName;
                    if (!string.IsNullOrEmpty(values[0]))
                    {
                        taxModel.Account = values[0];
                    }
                    if (!string.IsNullOrEmpty(values[1]))
                    {
                        taxModel.Description = values[1];
                    }
                    if (!string.IsNullOrEmpty(values[2]))
                    {
                        taxModel.CurrencyCode = values[2];
                    }

                    if (!string.IsNullOrEmpty(values[3]))
                    // if (decimal.TryParse(values[3], out amount))
                    {
                        taxModel.Amount = values[3];
                    }

                    modelList.Add(taxModel);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            finally
            {
                csvreader.Close();
            }
            return(modelList);
        }
Esempio n. 18
0
 private static void SetPostalCode(TaxViewModel viewModel, List <PostalCode> postalCodes)
 {
     foreach (var tax in viewModel.Taxes)
     {
         var postalCode = postalCodes.FirstOrDefault(p => p.Id == int.Parse(tax.PostalCode));
         if (postalCode != null)
         {
             tax.PostalCode = postalCode.Code;
         }
     }
 }
Esempio n. 19
0
        private async Task <string> SetCalculationType(string result, TaxViewModel viewModel)
        {
            foreach (var tax in viewModel.Taxes)
            {
                result = await HttpClientGet($"calctype/gettypebypostalcode?Id={tax.PostalCode}");

                var calculationType = JsonConvert.DeserializeObject <CalculationType>(result);
                tax.CalculationType = calculationType.Description;
            }

            return(result);
        }
        public TaxViewModel GetTaxInfo()
        {
            Tax t = _context.Tax.First();
            // det går också att använda ett anonymt objekt
            TaxViewModel tax = new TaxViewModel()
            {
                ActualTax  = t.ActualTax,
                TotalPayed = t.TotalPayed
            };

            return(tax);
        }
Esempio n. 21
0
        public ActionResult GetTax(int?id)
        {
            //var tax = ComputePaye((double)id);
            var tax = _payeRepo.ComputePaye((double)id);
            var d   = new TaxViewModel
            {
                Tax = _payeRepo.Dictionary
            };

            ViewBag.TotalTax     = _payeRepo.TotalTax;
            ViewBag.FinalBalance = _payeRepo.FinalBalance;
            return(View(d));
        }
Esempio n. 22
0
        public TaxList()
        {
            InitializeComponent();
            ViewModel        = new TaxViewModel();
            this.DataContext = ViewModel;
            //dataGrid.ItemsSource = ListGrid1;
            //CatGridRef = dataGrid;

            dataGrid.ItemsSource = ListGrid;
            ListGridRef          = dataGrid;

            dataGrid1.ItemsSource = ListGridBuss;
            ListGrdMainRef        = dataGrid1;
        }
Esempio n. 23
0
        // GET: Taxes/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TaxViewModel tax = Mapper.Map <TaxViewModel>(taxService.Get(id.Value));

            if (tax == null)
            {
                return(HttpNotFound());
            }
            return(View(tax));
        }
Esempio n. 24
0
        public ActionResult Continue(TaxViewModel model)
        {
            var tax = db.Taxes.Where(m => m.Name.Equals(model.Name)).FirstOrDefault();

            if (tax != null)
            {
                model.Iban = tax.TaxIban;
                return(View("TaxConfirmation", model));
            }
            else
            {
                return(RedirectToAction("Home", "Home"));
            }
        }
Esempio n. 25
0
        public CalculationResponse CalculationIncomeTax(TaxViewModel taxViewModel)
        {
            var annualIncome = taxViewModel.AnnualIncome;

            var postalCode = _sqlRepository.GetPostalCode(taxViewModel.PostalCode);

            var taxType = _sqlRepository
                          .GetCalculationType(postalCode.TaxTypeId)
                          .TaxTypeName;

            taxType = taxType.Replace(" ", "").ToLower();

            switch (taxType)
            {
            case _flatValue:
            {
                _taxCalculator = new FlatValueTaxCalculator();
                var tax = _taxCalculator.CalcualtionTax(annualIncome);
                return(new CalculationResponse {
                        CalculatedTax = tax, CalculationType = taxType
                    });
            }

            case _flatRate:
            {
                _taxCalculator = new FlatRateTaxCalculator();
                var tax = _taxCalculator.CalcualtionTax(annualIncome);
                return(new CalculationResponse {
                        CalculatedTax = tax, CalculationType = taxType
                    });
            }

            case _progressive:
            {
                var rates = _sqlRepository.GetRates().ToList();
                _taxCalculator = new ProgressiveTaxCalculator(rates);
                var tax = _taxCalculator.CalcualtionTax(annualIncome);
                return(new CalculationResponse {
                        CalculatedTax = tax, CalculationType = taxType
                    });
            }

            default:
                return(null);
            }
        }
        public ActionResult TaxConfig(TaxViewModel taxView)
        {
            if (taxView == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            bool flag = manage.AddTax(taxView);

            if (flag == true)
            {
                return(RedirectToAction("Dashboard"));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Esempio n. 27
0
        public ActionResult Index()
        {
            var lst = taxDal.ReadAllTax();

            TaxViewModel taxViewModel = new TaxViewModel();

            taxViewModel.lst = new List <TaxViewModel>();
            taxViewModel.lst = lst.ConvertAll(x => new TaxViewModel
            {
                TaxId   = x.TaxId,
                TaxName = x.TaxName,
                Value   = x.Value
            });
            taxViewModel.IsEdit = false;

            return(View(taxViewModel));
        }
        public void AddTax_InvalidInput_ThrowValidation()
        {
            // Arrange
            var model   = new TaxViewModel();
            var context = new ValidationContext(model, null, null);
            var result  = new List <ValidationResult>();

            // Act
            var valid = Validator.TryValidateObject(model, context, result, true);

            // Assert
            Assert.False(valid);
            Assert.Equal(4, result.Count);
            Assert.Contains(result, i => i.ErrorMessage == "The Tax Year field is required.");
            Assert.Contains(result, i => i.ErrorMessage == "The Total Income field is required.");
            Assert.Contains(result, i => i.ErrorMessage == "The Charity Paid Amount field is required.");
            Assert.Contains(result, i => i.ErrorMessage == "The Number Of Children field is required.");
        }
        protected override ValidationResult IsValid(object value,
                                                    ValidationContext validationContext)
        {
            TaxViewModel tmodel      = ((TaxViewModel)validationContext.ObjectInstance);
            var          currentcode = tmodel.CurrencyCode;

            if ((from culture in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.InstalledWin32Cultures)
                 where culture.Name.Length > 0 && !culture.IsNeutralCulture
                 let region = new System.Globalization.RegionInfo(culture.LCID)
                              where String.Equals(region.ISOCurrencySymbol, currentcode, StringComparison.InvariantCultureIgnoreCase)
                              select region).FirstOrDefault() == null)
            {
                string[] memberNames = new string[] { validationContext.MemberName };
                return(new ValidationResult("Currency code is not valid", memberNames));
            }

            return(ValidationResult.Success);
        }
Esempio n. 30
0
        public ActionResult Create(TaxViewModel model)
        {
            if (ModelState.IsValid)
            {
                var tax        = db.Taxes.Where(m => m.Name.Equals(model.Name)).FirstOrDefault();
                var accountSrc = db.Accounts.Where(m => m.Iban.Equals(model.SenderIban)).FirstOrDefault();
                if (tax != null && accountSrc != null)
                {
                    if (accountSrc.Balance > (double)model.Amount)
                    {
                        if (accountSrc.CardLimit < (double)(accountSrc.Balance - (double)model.Amount))
                        {
                            var transaction = new Transaction((double)model.Amount, "out", accountSrc.AccountId, 0, model.SaveToMyServices, model.Details, model.TransactionName);
                            accountSrc.Transactions.Add(transaction);
                            accountSrc.Balance -= (double)model.Amount;
                            if (!string.IsNullOrEmpty(model.TransactionName))
                            {
                                model.SaveToMyServices        = true;
                                transaction.SaveToMyTransfers = true;
                            }
                            transaction.Created = DateTime.Now;
                            db.Transactions.Add(transaction);
                            db.SaveChanges();
                            return(RedirectToAction("Home", "Home"));
                        }
                        else
                        {
                            return(View("ErrorInsufficientFunds"));
                        }
                    }
                    else
                    {
                        return(View("ErrorInsufficientFunds"));
                    }
                }
                else
                {
                    return(View("ErrorDestOrSourceAccountNotFound"));
                }
            }

            return(View("Error"));
        }