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));
        }
Beispiel #2
0
        public ActionResult Create(TaxViewModel model)
        {
            if (ModelState.IsValid)
            {
                var Tax = new Tax();
                AutoMapper.Mapper.Map(model, Tax);
                Tax.IsDeleted      = false;
                Tax.CreatedUserId  = WebSecurity.CurrentUserId;
                Tax.ModifiedUserId = WebSecurity.CurrentUserId;
                Tax.AssignedUserId = WebSecurity.CurrentUserId;
                Tax.CreatedDate    = DateTime.Now;
                Tax.ModifiedDate   = DateTime.Now;
                Tax.Status         = App_GlobalResources.Wording.Processing;

                TaxRepository.InsertTax(Tax);

                //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();
                //Cate Thu nhập chịu thếu và Giảm trừ
                var cate = categoryRepository.GetCategoryByCode("TaxCode").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();

                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));
        }