Example #1
0
        public ActionResult MySettings(Taxpayer taxpayer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(taxpayer).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    //TODO: Improve message
                    ModelState.AddModelError(String.Empty, ex.Message);
                    ViewBag.DepartmentId   = new SelectList(db.Departments, "DepartmentId", "Name", taxpayer.DepartmentId);
                    ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", taxpayer.DocumentTypeId);
                    ViewBag.MunicipalityId = new SelectList(db.Municipalities
                                                            .Where(m => m.DepartmentId == db.Departments.FirstOrDefault().DepartmentId)
                                                            .OrderBy(m => m.Name), "MunicipalityId", "Name", taxpayer.MunicipalityId);
                    return(View(taxpayer));
                }
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.DepartmentId   = new SelectList(db.Departments, "DepartmentId", "Name", taxpayer.DepartmentId);
            ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", taxpayer.DocumentTypeId);
            ViewBag.MunicipalityId = new SelectList(db.Municipalities
                                                    .Where(m => m.DepartmentId == taxpayer.DepartmentId)
                                                    .OrderBy(m => m.Name), "MunicipalityId", "Name", taxpayer.MunicipalityId);

            return(View(taxpayer));
        }
Example #2
0
    public static Taxpayer Taxpayer_GetById(int id)
    {
        Taxpayer taxpayer = null;
        DataSet  ds       = db.ExecuteDataSet("spTaxpayerGetById", id);

        if (ds.Tables[0].Rows.Count > 0)
        {
            DataRow dr = ds.Tables[0].Rows[0];
            taxpayer               = new Taxpayer();
            taxpayer.Id            = Convert.ToInt32(dr["Id"]);
            taxpayer.CUIT          = dr["CUIT"].ToString();
            taxpayer.Name          = dr["Name"].ToString();
            taxpayer.PersonType    = new PersonType();
            taxpayer.PersonType.Id = Convert.ToInt32(dr["PersonTypeId"]);
            if ((dr["SocietyTypeId"] != DBNull.Value))
            {
                taxpayer.SocietyType    = new SocietyType();
                taxpayer.SocietyType.Id = Convert.ToInt32(dr["SocietyTypeId"]);
            }
            taxpayer.ClosingMonth = (int?)dr["ClosingMonth"];
            taxpayer.ClosingYear  = (int?)dr["ClosingYear"];

            taxpayer.Jurisdiction = dr["Jurisdiction"].ToString();
            if (dr["LegalAddressId"] != DBNull.Value)
            {
                taxpayer.LegalAddress = Address_GetById((int)dr["LegalAddressId"]);
            }
            if (dr["RealAddressId"] != DBNull.Value)
            {
                taxpayer.RealAddress = Address_GetById((int)dr["RealAddressId"]);
            }
        }
        return(taxpayer);
    }
Example #3
0
        public ActionResult Create([Bind(Include = "TaxpayerId,FirstName,LastName,UserName,Phone,DepartmentId,MunicipalityId,Address,DocumentTypeId,Document")] Taxpayer taxpayer)
        {
            if (ModelState.IsValid)
            {
                db.Taxpayers.Add(taxpayer);
                try
                {
                    db.SaveChanges();
                    Utilities.CreateUserASP(taxpayer.UserName, "taxpayer");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(String.Empty, ex.Message);
                    ViewBag.DepartmentId   = new SelectList(db.Departments, "DepartmentId", "Name", taxpayer.DepartmentId);
                    ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", taxpayer.DocumentTypeId);
                    ViewBag.MunicipalityId = new SelectList(db.Municipalities
                                                            .Where(m => m.DepartmentId == db.Departments.FirstOrDefault().DepartmentId)
                                                            .OrderBy(m => m.Name), "MunicipalityId", "Name", taxpayer.MunicipalityId);
                    return(View(taxpayer));
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId   = new SelectList(db.Departments, "DepartmentId", "Name", taxpayer.DepartmentId);
            ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", taxpayer.DocumentTypeId);
            ViewBag.MunicipalityId = new SelectList(db.Municipalities
                                                    .Where(m => m.DepartmentId == db.Departments.FirstOrDefault().DepartmentId)
                                                    .OrderBy(m => m.Name), "MunicipalityId", "Name", taxpayer.MunicipalityId);
            return(View(taxpayer));
        }
Example #4
0
        public void InsertIPTU(Taxpayer taxpayer, IPTU iptu)
        {
            var taxpayer1 = _col.Find(c => c.Id == taxpayer.Id).FirstOrDefault();

            if (taxpayer1 == null)
            {
                taxpayer1 = new Taxpayer {
                    Id       = taxpayer.Id,
                    Document = taxpayer.Document,
                    Email    = taxpayer.Email,
                    Name     = taxpayer.Name,
                    GetIPTUs = new List <IPTU> {
                        iptu
                    }
                };
                _col.InsertOne(taxpayer);
            }
            else
            {
                var cartItemFromDb = taxpayer1.GetIPTUs.FirstOrDefault(ci => ci.Reference == iptu.Reference && ci.Validity == iptu.Validity);
                if (cartItemFromDb == null)
                {
                    taxpayer1.GetIPTUs.Add(iptu);
                }

                var update = Builders <Taxpayer> .Update
                             .Set(c => c.GetIPTUs, taxpayer1.GetIPTUs);

                _col.UpdateOne(c => c.Id == taxpayer.Id, update);
            }
        }
Example #5
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            //submit

            try
            {
                String  name;
                decimal salary;
                int     exemptionCount;
                bool    isMarried;
                decimal investment;

                Taxpayer newTaxpayer;

                name           = nameTextBox.Text;
                salary         = decimal.Parse(salaryTextBox.Text);
                exemptionCount = (int)numericUpDown1.Value;
                isMarried      = checkBox1.Checked;
                investment     = decimal.Parse(investmentTextBox.Text);

                newTaxpayer = new Taxpayer(name, salary, investment, isMarried, exemptionCount);

                Taxpayers.Add(newTaxpayer);
                taxpayerBindingSource.Add(newTaxpayer);
                fileSaved = true;

                ClearForm();
                groupBox1.Visible = false;
            }
            catch
            {
                MessageBox.Show("Please enter Data");
            }
        }
        public async Task <TaxpayerResponse> CreateAsync(Taxpayer taxpayer)
        {
            var existingTaxpayerByCPF = await _taxpayerRepository.GetByCPFAsync(taxpayer.CPF);

            if (existingTaxpayerByCPF != null)
            {
                return(TaxpayerResponse.CreateFail("Já existe um usuário na base com o CPF especificado."));
            }

            try
            {
                await _taxpayerRepository.AddAsync(taxpayer);

                await _unitOfWork.CompleteAsync();

                var basicWage = await _basicWageService.GetBasicWageDataAsync();

                PopulateTaxData(taxpayer, basicWage);

                return(TaxpayerResponse.CreateSuccess(taxpayer));
            }
            catch (Exception ex)
            {
                return(TaxpayerResponse.CreateFail(ex.Message));
            }
        }
        public async Task <TaxpayerResponse> UpdateAsync(int id, Taxpayer taxpayer)
        {
            try
            {
                var existingTaxpayer = await _taxpayerRepository.GetByIdAsync(id);

                if (existingTaxpayer == null)
                {
                    return(TaxpayerResponse.CreateFail("Contribuinte não encontrado na base de dados para atualização."));
                }

                existingTaxpayer.Name = taxpayer.Name;
                existingTaxpayer.CPF  = taxpayer.CPF;
                existingTaxpayer.MonthlyGrossIncome = taxpayer.MonthlyGrossIncome;
                existingTaxpayer.NumberOfDependents = taxpayer.NumberOfDependents;

                _taxpayerRepository.Update(existingTaxpayer);
                await _unitOfWork.CompleteAsync();

                var basicWage = await _basicWageService.GetBasicWageDataAsync();

                PopulateTaxData(existingTaxpayer, basicWage);

                return(TaxpayerResponse.CreateSuccess(existingTaxpayer));
            }
            catch (Exception ex)
            {
                return(TaxpayerResponse.CreateFail(ex.Message));
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            List <Taxpayer> list = new List <Taxpayer>();

            double _minumimWage;

            while (true)
            {
                Taxpayer taxpayer = new Taxpayer();

                Console.Write("Digite o CPF: ");
                taxpayer.CPF = Console.ReadLine();
                if (taxpayer.CPF.Equals("0"))
                {
                    Console.Clear();
                    if (list.Count > 0)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

                Console.Write("Digite o nome completo: ");
                taxpayer.Name = Console.ReadLine();

                Console.Write("Número de dependentes: ");
                taxpayer.NumberOfDependents = WriteOnlyNumbersMaxValueInteger();

                Console.Write("Renda bruta mensal: R$ ");
                taxpayer.GrossIncome = WriteOnlyCoin();

                Console.Clear();

                list.Add(taxpayer);
            }

            Console.Write("Valor salário mínimo: R$ ");
            _minumimWage = WriteOnlyCoin();

            Console.Clear();

            CalculateIncomeTax incomeTax = new CalculateIncomeTax(_minumimWage);

            foreach (Taxpayer taxpayer in list)
            {
                taxpayer.AmountToPay = incomeTax.AmountToPay(taxpayer.GrossIncome, taxpayer.NumberOfDependents);
            }

            foreach (Taxpayer taxpayer in list.OrderBy(x => x.AmountToPay).ThenBy(y => y.Name))
            {
                Console.WriteLine(taxpayer.ToString());
            }

            Console.ReadKey();
        }
Example #9
0
 public T103()
 {
     Device         = new Device();
     Taxpayer       = new Taxpayer();
     TaxpayerBranch = new TaxpayerBranch();
     TaxTypes       = new List <TaxType>();
 }
Example #10
0
        public ActionResult DeleteConfirmed(int id)
        {
            Taxpayer taxpayer = db.Taxpayers.Find(id);

            db.Taxpayers.Remove(taxpayer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #11
0
    public static int?Taxpayer_Insert(Taxpayer taxpayer)
    {
        int?legalAddressId = taxpayer.LegalAddress.Set();
        int?realAddressId  = taxpayer.RealAddress.Set();

        return(Convert.ToInt32(db.ExecuteScalar("spTaxpayerInsert", taxpayer.CUIT,
                                                taxpayer.Name, taxpayer.PersonType.Id, taxpayer.SocietyType.Id, taxpayer.ClosingMonth, taxpayer.ClosingYear,
                                                legalAddressId, realAddressId, taxpayer.Jurisdiction, HttpContext.Current.Session["UserId"])));
    }
        public void Should_Return_Zero_As_Discount_For_Null_Taxpayer_Or_Basic_Wage()
        {
            Taxpayer  taxpayer  = null;
            BasicWage basicWage = null;

            var discount = _incomeTaxCalulcatorService.CalculateIncomeTaxRateDiscountFor(taxpayer, basicWage);

            Assert.AreEqual(0, discount);
        }
        public decimal CalculateDiscountFor(Taxpayer taxpayer, BasicWage basicWage)
        {
            // Primeiro calcula o desconto de 5% em cima do salário mínimo
            var basicWageDiscountPercentage = (basicWage.Value * 5) / 100;

            // Então retorna o valor do desconto vezes a quantidade de dependentes
            // de um contribuinte.
            return(taxpayer.NumberOfDependents * basicWageDiscountPercentage);
        }
        public void Should_Return_No_Discount_Strategy_When_Taxpayer_Does_Not_Have_Dependents()
        {
            var taxpayer = new Taxpayer {
                NumberOfDependents = 0
            };
            var strategy = TaxpayerDiscountStrategyFactory.GetDiscountStrategyFor(taxpayer);

            Assert.IsInstanceOfType(strategy, typeof(NoTaxpayerDiscountStrategy));
        }
        private void PopulateTaxData(Taxpayer taxpayer, BasicWage basicWage)
        {
            var discountValue = _incomeTaxCalculatorService.CalculateIncomeTaxRateDiscountFor(taxpayer, basicWage);

            taxpayer.IncomeTaxRatePercentage = _incomeTaxCalculatorService.CalculateIncomeTaxRatePercentageFor(taxpayer, basicWage, discountValue);

            taxpayer.TotalIncomeTax = _incomeTaxCalculatorService.CalculateTotalIncomeTax(monthlyGrowthRate: taxpayer.MonthlyGrossIncome,
                                                                                          taxRatePercentage: taxpayer.IncomeTaxRatePercentage,
                                                                                          discount: discountValue);
        }
        public static ITaxpayerDiscountStrategy GetDiscountStrategyFor(Taxpayer taxpayer)
        {
            // Caso o contribuinte tenha dependentes, tem direito a um desconto de 5% do valor do salário mínimo para cada dependente.
            if (taxpayer.NumberOfDependents > 0)
            {
                return(new DependentsTaxpayerDiscountStrategy());
            }

            // Caso o contribuinte não tenha dependentes, não tem direito a desconto.
            return(new NoTaxpayerDiscountStrategy());
        }
        public async Task Should_Not_Create_Taxpayer_When_CPF_Is_Already_In_Use()
        {
            var taxpayer = new Taxpayer {
                Id = 1, NumberOfDependents = 0, MonthlyGrossIncome = 2000, CPF = 11111111111
            };

            var result = await _taxpayerService.CreateAsync(taxpayer);

            Assert.IsFalse(result.Success);
            Assert.AreEqual("Já existe um usuário na base com o CPF especificado.", result.Message);
        }
        public async Task Should_Update_Taxpayer_When_They_Are_In_The_Database_And_Valid_Data_Is_Provided()
        {
            var taxpayer = new Taxpayer {
                Name = "Updated", NumberOfDependents = 0, MonthlyGrossIncome = 2000, CPF = 22222222222
            };

            var result = await _taxpayerService.UpdateAsync(1, taxpayer);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(taxpayer.Name, result.Taxpayer.Name);
        }
        public async Task Should_Create_Taxpayer_When_CPF_Is_Not_In_Use_And_Data_Is_Valid()
        {
            var taxpayer = new Taxpayer {
                NumberOfDependents = 0, MonthlyGrossIncome = 2000, CPF = 22222222222
            };

            var result = await _taxpayerService.CreateAsync(taxpayer);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(taxpayer.CPF, result.Taxpayer.CPF);
        }
        public async Task Should_Not_Update_Taxpayer_When_They_Are_Not_In_The_Database()
        {
            var taxpayer = new Taxpayer {
                Name = "Updated", NumberOfDependents = 0, MonthlyGrossIncome = 2000, CPF = 22222222222
            };

            var result = await _taxpayerService.UpdateAsync(2, taxpayer);

            Assert.IsFalse(result.Success);
            Assert.AreEqual("Contribuinte não encontrado na base de dados para atualização.", result.Message);
        }
Example #21
0
        /// Calcula o valor de desconto no imposto para um contribuinte do importo de renda, levando em conta o salário mínimo atual.
        /// </summary>
        /// <param name="taxpayer">Contribuinte.</param>
        /// <param name="basicWage">Salário mínimo atual.</param>
        /// <returns>Valor de desconto.</returns>
        public decimal CalculateIncomeTaxRateDiscountFor(Taxpayer taxpayer, BasicWage basicWage)
        {
            if (taxpayer == null || basicWage == null)
            {
                return(0);
            }

            ITaxpayerDiscountStrategy discountStrategy = TaxpayerDiscountStrategyFactory.GetDiscountStrategyFor(taxpayer);
            decimal totalDiscount = discountStrategy.CalculateDiscountFor(taxpayer, basicWage);

            return(totalDiscount);
        }
Example #22
0
        private void resetButton_Click(object sender, EventArgs e)
        {
            //reset

            SavingBeforeExit();

            Taxpayer.ResetData();
            Taxpayers.Clear();
            displayTextBox.Clear();
            taxpayerBindingSource.Clear();
            ClearForm();
            groupBox1.Visible = false;
        }
Example #23
0
        /// <summary>
        /// Calcula a porcentagem da alíquota do imposto de renda para um contribuinte, levando em conta o salário mínimo atual e eventual
        /// desconto nas taxas do imposto.
        /// </summary>
        /// <param name="taxpayer">Contribuinte.</param>
        /// <param name="basicWage">Dados do salário mínimo.</param>
        /// <param name="discount">Desconto para o contribuinte.</param>
        /// <returns>Porcentagem.</returns>

        public decimal CalculateIncomeTaxRatePercentageFor(Taxpayer taxpayer, BasicWage basicWage, decimal discount)
        {
            // Primeiro calcula a renda líquida para saber a alíquota do imposto.
            // Renda líquida = salário bruto mensal - desconto
            decimal netIncome = taxpayer.MonthlyGrossIncome - discount;

            // Agora calcula a quantidade de salários mínimos que o contribuinte recebe, da seguinte forma:
            // Qtd. Salários = renda líqudia / valor do salário mínimo.
            var basicWageQuantity = netIncome / basicWage.Value;

            // Dependento da quantidade de salários, retorna a porcentagem da alíquota:
            return(CalculateIncomeTaxRatePercentageFor(basicWageQuantity));
        }
        public void Should_Return_15_As_Percentage_For_Taxpayer_That_Receives_Up_To_5_Basic_Wages()
        {
            var taxpayer = new Taxpayer {
                MonthlyGrossIncome = 5000
            };
            var basicWage = new BasicWage {
                Value = 1000
            };

            var percentage = _incomeTaxCalulcatorService.CalculateIncomeTaxRatePercentageFor(taxpayer, basicWage, discount: 0);

            Assert.AreEqual(15M, percentage);
        }
        public void Should_Calculate_Income_Tax_Rate_Discount_For_Taxpayer_With_Dependents()
        {
            var taxpayer = new Taxpayer {
                NumberOfDependents = 1
            };
            var basicWage = new BasicWage {
                Value = 1000
            };

            var discount = _incomeTaxCalulcatorService.CalculateIncomeTaxRateDiscountFor(taxpayer, basicWage);

            Assert.AreEqual(50, discount);
        }
        public void Should_Return_0_As_Percentage_For_Taxpayer_That_Receives_Up_To_4_Basic_Wages_But_Has_Enough_Discount()
        {
            var taxpayer = new Taxpayer {
                MonthlyGrossIncome = 2050
            };
            var basicWage = new BasicWage {
                Value = 1000
            };

            var percentage = _incomeTaxCalulcatorService.CalculateIncomeTaxRatePercentageFor(taxpayer, basicWage, discount: 50);

            Assert.AreEqual(0, percentage);
        }
Example #27
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Taxpayer taxpayer = db.Taxpayers.Find(id);

            if (taxpayer == null)
            {
                return(HttpNotFound());
            }
            return(View(taxpayer));
        }
Example #28
0
    private void LoadTaxpayer()
    {
        if ((!String.IsNullOrEmpty(Request.QueryString["id"]) && Convert.ToInt32(Request.QueryString["id"]) > 0) ||
            (Session["ContribId"] != null && Convert.ToInt32(Session["ContribId"]) > 0))
        {
            int id = 0;
            if (!String.IsNullOrEmpty(Request.QueryString["id"]) && Convert.ToInt32(Request.QueryString["id"]) > 0)
            {
                id = Convert.ToInt32(Request.QueryString["id"]);
            }
            else if (Session["ContribId"] != null && Convert.ToInt32(Session["ContribId"]) > 0)
            {
                id = Convert.ToInt32(Session["ContribId"]);
            }
            Taxpayer taxpayer = DataAccess.Taxpayer_GetById(id);
            hdnIdContrib.Value              = taxpayer.Id.ToString();
            Session["ContribId"]            = hdnIdContrib.Value;
            Session["ContribPersonaFisica"] = ((int)Application["PersonaFisicaId"] == taxpayer.PersonType.Id);
            txtCUIT.Text   = taxpayer.CUIT;
            txtNombre.Text = taxpayer.Name;
            cboTipoPersona.SelectedIndex = cboTipoPersona.Items.IndexOf(cboTipoPersona.Items.FindByValue(taxpayer.PersonType.Id.ToString()));
            if (taxpayer.SocietyType != null)
            {
                cboTipoSociedad.SelectedIndex = cboTipoSociedad.Items.IndexOf(cboTipoSociedad.Items.FindByValue(taxpayer.SocietyType.Id.ToString()));
            }
            txtMesCierre.Text    = taxpayer.ClosingMonth.ToString();
            txtAnioCierre.Text   = taxpayer.ClosingYear.ToString();
            txtJurisdiccion.Text = taxpayer.Jurisdiction;

            if (taxpayer.RealAddress != null && taxpayer.RealAddress.Id > 0)
            {
                hdnIdDirReal.Value = taxpayer.RealAddress.Id.ToString();
                txtDireccionR.Text = taxpayer.RealAddress.StreetAddress;
                txtCiudadR.Text    = taxpayer.RealAddress.City;
                txtProvinciaR.Text = taxpayer.RealAddress.State;
                txtCPR.Text        = taxpayer.RealAddress.PostCode;
                txtPaisR.Text      = taxpayer.RealAddress.Country;
            }

            if (taxpayer.LegalAddress != null && taxpayer.LegalAddress.Id > 0)
            {
                hdnIdDirLegal.Value = taxpayer.LegalAddress.Id.ToString();
                txtDireccionL.Text  = taxpayer.LegalAddress.StreetAddress;
                txtCiudadL.Text     = taxpayer.LegalAddress.City;
                txtProvinciaL.Text  = taxpayer.LegalAddress.State;
                txtCPL.Text         = taxpayer.LegalAddress.PostCode;
                txtPaisL.Text       = taxpayer.LegalAddress.Country;
            }
        }
    }
Example #29
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Taxpayer taxpayer = db.Taxpayers.Find(id);

            taxpayer.Properties.OrderBy(p => p.Department.Name).ThenBy(p => p.Municipality.Name).ThenBy(p => p.PropertyType.Description).ThenBy(p => p.Address);
            if (taxpayer == null)
            {
                return(HttpNotFound());
            }
            return(View(taxpayer));
        }
Example #30
0
 public ActionResult Edit([Bind(Include = "TaxpayerId,FirstName,LastName,UserName,Phone,DepartmentId,MunicipalityId,Address,DocumentTypeId,Document")] Taxpayer taxpayer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(taxpayer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId   = new SelectList(db.Departments, "DepartmentId", "Name", taxpayer.DepartmentId);
     ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", taxpayer.DocumentTypeId);
     ViewBag.MunicipalityId = new SelectList(db.Municipalities
                                             .Where(m => m.DepartmentId == taxpayer.DepartmentId)
                                             .OrderBy(m => m.Name), "MunicipalityId", "Name", taxpayer.MunicipalityId);
     return(View(taxpayer));
 }