public ActionResult Create(ThuNhapChiuThueViewModel model)
        {
            if (ModelState.IsValid)
            {
                var ThuNhapChiuThue = new ThuNhapChiuThue();
                AutoMapper.Mapper.Map(model, ThuNhapChiuThue);
                ThuNhapChiuThue.IsDeleted      = false;
                ThuNhapChiuThue.CreatedUserId  = WebSecurity.CurrentUserId;
                ThuNhapChiuThue.ModifiedUserId = WebSecurity.CurrentUserId;
                ThuNhapChiuThue.AssignedUserId = WebSecurity.CurrentUserId;
                ThuNhapChiuThue.CreatedDate    = DateTime.Now;
                ThuNhapChiuThue.ModifiedDate   = DateTime.Now;
                ThuNhapChiuThueRepository.InsertThuNhapChiuThue(ThuNhapChiuThue);

                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                return(RedirectToAction("_ClosePopup", "Home", new { area = "", FunctionCallback = "ClosePopupAndReloadPage" }));
            }
            return(View(model));
        }
Example #2
0
        public ActionResult Synch(int?Id)
        {
            var model = TaxRepository.GetTaxById(Id.Value);

            try
            {
                if (model != null)
                {
                    //Xóa 2 bảng
                    thuNhapChiuThueRepository.DeleteThuNhapChiuThueByTaxId(model.Id);
                    giamTruThueTNCNRepository.DeleteGiamTruThueTNCNByTaxId(model.Id);

                    //Hiện tại lấy hết nhân viên theo mã thuế
                    var staff_in_tax = taxIncomePersonDetailRepository.GetAllTaxIncomePersonDetail().Where(n => n.TaxIncomePersonId == model.TaxIncomePersonId).ToList();

                    //Lấy dữ liệu từ bảng lương
                    var salaryReport = salaryTableDetailReportRepository.GetSalaryTableDetailReportBySalaryTableId(model.SalaryTableId.Value).ToList();

                    //Lấy dữ liệu giảm trừ từ người thân
                    var staff_family = staffFamilyRepository.GetAllStaffFamily().Where(n => n.IsDependencies == true).ToList();

                    //Cate Thu nhập chịu thếu và Giảm trừ
                    var cate = categoryRepository.GetCategoryByCode("TaxCode").ToList();

                    for (int a = 0; a < staff_in_tax.Count(); a++)
                    {
                        var tnct = cate.Where(n => n.Description == "TNCT").ToList();
                        for (int i = 0; i < tnct.Count; i++)
                        {
                            var             value           = salaryReport.SingleOrDefault(n => n.StaffId == staff_in_tax[a].StaffId && n.ColumName.Equals(tnct[i].Value));
                            ThuNhapChiuThue thunhapchiuthue = new ThuNhapChiuThue();
                            thunhapchiuthue.IsDeleted      = false;
                            thunhapchiuthue.CreatedUserId  = WebSecurity.CurrentUserId;
                            thunhapchiuthue.ModifiedUserId = WebSecurity.CurrentUserId;
                            thunhapchiuthue.AssignedUserId = WebSecurity.CurrentUserId;
                            thunhapchiuthue.CreatedDate    = DateTime.Now;
                            thunhapchiuthue.ModifiedDate   = DateTime.Now;

                            //Name
                            thunhapchiuthue.TaxId   = model.Id;
                            thunhapchiuthue.StaffId = staff_in_tax[a].StaffId;
                            thunhapchiuthue.TaxIncomePersonDetailId = staff_in_tax[a].Id;
                            thunhapchiuthue.Name  = tnct[i].Name;
                            thunhapchiuthue.Value = value == null ? 0 : decimal.Parse(value.Value);
                            thuNhapChiuThueRepository.InsertThuNhapChiuThue(thunhapchiuthue);
                        }

                        //Thêm thu nhập giảm thuế
                        var gt = cate.Where(n => n.Description == "GT").ToList();
                        for (int i = 0; i < gt.Count; i++)
                        {
                            var             value   = salaryReport.SingleOrDefault(n => n.StaffId == staff_in_tax[a].StaffId && n.ColumName.Equals(gt[i].Value));
                            GiamTruThueTNCN giamtru = new GiamTruThueTNCN();
                            giamtru.IsDeleted      = false;
                            giamtru.CreatedUserId  = WebSecurity.CurrentUserId;
                            giamtru.ModifiedUserId = WebSecurity.CurrentUserId;
                            giamtru.AssignedUserId = WebSecurity.CurrentUserId;
                            giamtru.CreatedDate    = DateTime.Now;
                            giamtru.ModifiedDate   = DateTime.Now;

                            //Name
                            giamtru.TaxId   = model.Id;
                            giamtru.StaffId = staff_in_tax[a].StaffId;
                            giamtru.TaxIncomePersonDetailId = staff_in_tax[a].Id;
                            giamtru.Name  = gt[i].Name;
                            giamtru.Value = value == null ? 0 : decimal.Parse(value.Value);
                            giamTruThueTNCNRepository.InsertGiamTruThueTNCN(giamtru);
                        }

                        //Thêm giảm trừ từ gia đình có thành viên phụ thuộc
                        var gd = staff_family.Where(n => n.StaffId == staff_in_tax[a].StaffId).ToList();
                        for (int i = 0; i < gd.Count; i++)
                        {
                            GiamTruThueTNCN giamtru = new GiamTruThueTNCN();
                            giamtru.IsDeleted      = false;
                            giamtru.CreatedUserId  = WebSecurity.CurrentUserId;
                            giamtru.ModifiedUserId = WebSecurity.CurrentUserId;
                            giamtru.AssignedUserId = WebSecurity.CurrentUserId;
                            giamtru.CreatedDate    = DateTime.Now;
                            giamtru.ModifiedDate   = DateTime.Now;

                            //Name
                            giamtru.TaxId   = model.Id;
                            giamtru.StaffId = staff_in_tax[a].StaffId;
                            giamtru.TaxIncomePersonDetailId = staff_in_tax[a].Id;
                            giamtru.Name  = string.Format("Người phụ thuộc [{0}]", gd[i].Name);
                            giamtru.Value = 3600000;
                            giamTruThueTNCNRepository.InsertGiamTruThueTNCN(giamtru);
                        }
                    }
                    //Thêm thu nhập chịu thuế

                    TempData[Globals.SuccessMessageKey] = "Cập nhật thành công.";
                    return(RedirectToAction("Detail", "Tax", new { area = "Staff", Id = model.Id }));
                }
            }
            catch (Exception ex)
            {
                TempData[Globals.SuccessMessageKey] = "Cập nhật thất bại: " + ex.Message;
                return(RedirectToAction("Detail", "Tax", new { area = "Staff", Id = model.Id }));
            }

            return(View());
            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }
Example #3
0
        public ActionResult Edit(TaxViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var Tax = TaxRepository.GetTaxById(model.Id);
                    AutoMapper.Mapper.Map(model, Tax);
                    Tax.ModifiedUserId = WebSecurity.CurrentUserId;
                    Tax.ModifiedDate   = DateTime.Now;
                    TaxRepository.UpdateTax(Tax);

                    //Xóa 2 bảng
                    thuNhapChiuThueRepository.DeleteThuNhapChiuThueByTaxId(model.Id);
                    giamTruThueTNCNRepository.DeleteGiamTruThueTNCNByTaxId(model.Id);

                    //Hiện tại lấy hết nhân viên theo mã thuế
                    var staff_in_tax = taxIncomePersonDetailRepository.GetAllTaxIncomePersonDetail().Where(n => n.TaxIncomePersonId == model.TaxIncomePersonId).ToList();

                    //Lấy dữ liệu từ bảng lương
                    var salaryReport = salaryTableDetailReportRepository.GetSalaryTableDetailReportBySalaryTableId(model.SalaryTableId.Value).ToList();

                    //Lấy dữ liệu giảm trừ từ người thân
                    var staff_family = staffFamilyRepository.GetAllStaffFamily().Where(n => n.IsDependencies == true).ToList();

                    //Cate Thu nhập chịu thếu và Giảm trừ
                    var cate = categoryRepository.GetCategoryByCode("TaxCode").ToList();

                    for (int a = 0; a < staff_in_tax.Count(); a++)
                    {
                        var tnct = cate.Where(n => n.Description == "TNCT").ToList();
                        for (int i = 0; i < tnct.Count; i++)
                        {
                            var             value           = salaryReport.SingleOrDefault(n => n.StaffId == staff_in_tax[a].StaffId && n.ColumName.Equals(tnct[i].Value));
                            ThuNhapChiuThue thunhapchiuthue = new ThuNhapChiuThue();
                            thunhapchiuthue.IsDeleted      = false;
                            thunhapchiuthue.CreatedUserId  = WebSecurity.CurrentUserId;
                            thunhapchiuthue.ModifiedUserId = WebSecurity.CurrentUserId;
                            thunhapchiuthue.AssignedUserId = WebSecurity.CurrentUserId;
                            thunhapchiuthue.CreatedDate    = DateTime.Now;
                            thunhapchiuthue.ModifiedDate   = DateTime.Now;

                            //Name
                            thunhapchiuthue.TaxId   = Tax.Id;
                            thunhapchiuthue.StaffId = staff_in_tax[a].StaffId;
                            thunhapchiuthue.TaxIncomePersonDetailId = staff_in_tax[a].Id;
                            thunhapchiuthue.Name  = tnct[i].Name;
                            thunhapchiuthue.Value = value == null ? 0 : decimal.Parse(value.Value);
                            thuNhapChiuThueRepository.InsertThuNhapChiuThue(thunhapchiuthue);
                        }

                        //Thêm thu nhập giảm thuế
                        var gt = cate.Where(n => n.Description == "GT").ToList();
                        for (int i = 0; i < gt.Count; i++)
                        {
                            var             value   = salaryReport.SingleOrDefault(n => n.StaffId == staff_in_tax[a].StaffId && n.ColumName.Equals(gt[i].Value));
                            GiamTruThueTNCN giamtru = new GiamTruThueTNCN();
                            giamtru.IsDeleted      = false;
                            giamtru.CreatedUserId  = WebSecurity.CurrentUserId;
                            giamtru.ModifiedUserId = WebSecurity.CurrentUserId;
                            giamtru.AssignedUserId = WebSecurity.CurrentUserId;
                            giamtru.CreatedDate    = DateTime.Now;
                            giamtru.ModifiedDate   = DateTime.Now;

                            //Name
                            giamtru.TaxId   = Tax.Id;
                            giamtru.StaffId = staff_in_tax[a].StaffId;
                            giamtru.TaxIncomePersonDetailId = staff_in_tax[a].Id;
                            giamtru.Name  = gt[i].Name;
                            giamtru.Value = value == null ? 0 : decimal.Parse(value.Value);
                            giamTruThueTNCNRepository.InsertGiamTruThueTNCN(giamtru);
                        }

                        //Thêm giảm trừ từ gia đình có thành viên phụ thuộc
                        var gd = staff_family.Where(n => n.StaffId == staff_in_tax[a].StaffId).ToList();
                        for (int i = 0; i < gd.Count; i++)
                        {
                            GiamTruThueTNCN giamtru = new GiamTruThueTNCN();
                            giamtru.IsDeleted      = false;
                            giamtru.CreatedUserId  = WebSecurity.CurrentUserId;
                            giamtru.ModifiedUserId = WebSecurity.CurrentUserId;
                            giamtru.AssignedUserId = WebSecurity.CurrentUserId;
                            giamtru.CreatedDate    = DateTime.Now;
                            giamtru.ModifiedDate   = DateTime.Now;

                            //Name
                            giamtru.TaxId   = Tax.Id;
                            giamtru.StaffId = staff_in_tax[a].StaffId;
                            giamtru.TaxIncomePersonDetailId = staff_in_tax[a].Id;
                            giamtru.Name  = string.Format("Người phụ thuộc [{0}]", gd[i].Name);
                            giamtru.Value = 3600000;
                            giamTruThueTNCNRepository.InsertGiamTruThueTNCN(giamtru);
                        }
                    }
                    //Thêm thu nhập chịu thuế

                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                    return(RedirectToAction("_ClosePopup", "Home", new { area = "", FunctionCallback = "ClosePopupAndReloadPage" }));
                }

                return(View(model));
            }

            return(View(model));

            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }