public ActionResult Create(StaffSocialInsuranceViewModel model)
        {
            bool   checkcode_medical = StaffSocialInsuranceRepository.GetAllStaffSocialInsurance().Any(n => !string.IsNullOrEmpty(n.MedicalCode) && n.MedicalCode.Equals(model.MedicalCode.Trim()));
            bool   checkcode_social  = StaffSocialInsuranceRepository.GetAllStaffSocialInsurance().Any(n => !string.IsNullOrEmpty(n.SocietyCode) && n.SocietyCode.Equals(model.SocietyCode.Trim()));
            string fail = "";

            if (checkcode_medical)
            {
                fail = "Mã bảo hiểm y tế đã được cấp";
            }

            if (checkcode_social)
            {
                if (!string.IsNullOrEmpty(fail))
                {
                    fail = fail + " và Mã bảo hiểm xã hội đã được cấp";
                }
                else
                {
                    fail = "Mã bảo hiểm xã hội đã được cấp";
                }
            }

            if (!string.IsNullOrEmpty(fail))
            {
                ViewBag.FailedMessage = fail;
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                var province             = locationRepository.GetProvinceList();
                var StaffSocialInsurance = new StaffSocialInsurance();

                StaffSocialInsurance.IsDeleted      = false;
                StaffSocialInsurance.CreatedUserId  = WebSecurity.CurrentUserId;
                StaffSocialInsurance.ModifiedUserId = WebSecurity.CurrentUserId;
                StaffSocialInsurance.AssignedUserId = WebSecurity.CurrentUserId;
                StaffSocialInsurance.CreatedDate    = DateTime.Now;
                StaffSocialInsurance.ModifiedDate   = DateTime.Now;


                if (!string.IsNullOrEmpty(model.MedicalCode))
                {
                    StaffSocialInsurance.MedicalCode         = model.MedicalCode.Trim();
                    StaffSocialInsurance.MedicalDefaultValue = Decimal.Parse(model.MedicalDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                    StaffSocialInsurance.MedicalStartDate    = model.MedicalStartDate;
                    StaffSocialInsurance.MedicalEndDate      = model.MedicalEndDate;
                    StaffSocialInsurance.MedicalIssue        = model.ProvinceMedical != null?province.SingleOrDefault(n => n.Id == model.ProvinceMedical.Value.ToString()).Name : "";
                }
                else
                {
                    StaffSocialInsurance.MedicalDefaultValue = 0;
                }


                if (!string.IsNullOrEmpty(model.SocietyCode))
                {
                    StaffSocialInsurance.SocietyCode         = model.SocietyCode.Trim();
                    StaffSocialInsurance.SocietyDefaultValue = Decimal.Parse(model.SocietyDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                    StaffSocialInsurance.SocietyIssue        = model.ProvinceSociety != null?province.SingleOrDefault(n => n.Id == model.ProvinceSociety.Value.ToString()).Name : "";

                    StaffSocialInsurance.SocietyStartDate = model.SocietyStartDate;
                    StaffSocialInsurance.SocietyEndDate   = model.SocietyEndDate;
                }
                else
                {
                    StaffSocialInsurance.MedicalDefaultValue = 0;
                }

                //Thông tin lương
                StaffSocialInsurance.TienLuong = string.IsNullOrEmpty(model.TienLuong) ? 0 : Decimal.Parse(model.TienLuong.Replace(",", "."), new CultureInfo("en-GB"));
                StaffSocialInsurance.PC_CV     = string.IsNullOrEmpty(model.PC_CV) ? 0 : Decimal.Parse(model.PC_CV.Replace(",", "."), new CultureInfo("en-GB"));
                StaffSocialInsurance.PC_TNN    = string.IsNullOrEmpty(model.PC_TNN) ? 0 : Decimal.Parse(model.PC_TNN.Replace(",", "."), new CultureInfo("en-GB"));
                StaffSocialInsurance.PC_TNVK   = string.IsNullOrEmpty(model.PC_TNVK) ? 0 : Decimal.Parse(model.PC_TNVK.Replace(",", "."), new CultureInfo("en-GB"));
                StaffSocialInsurance.PC_Khac   = string.IsNullOrEmpty(model.PC_Khac) ? 0 : Decimal.Parse(model.PC_Khac.Replace(",", "."), new CultureInfo("en-GB"));

                StaffSocialInsurance.StaffId = model.StaffId;
                StaffSocialInsurance.Note    = model.Note;
                StaffSocialInsurance.Status  = StatusSocialInsurance.DangHoatDong.GetName();

                StaffSocialInsuranceRepository.InsertStaffSocialInsurance(StaffSocialInsurance);

                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #2
0
        public ActionResult Edit(DotBCBHXHDetailViewModel model, bool IsPopup)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var province        = locationRepository.GetProvinceList();
                    var DotBCBHXHDetail = DotBCBHXHDetailRepository.GetDotBCBHXHDetailById(model.Id);

                    DotBCBHXHDetail.ModifiedUserId = WebSecurity.CurrentUserId;
                    DotBCBHXHDetail.ModifiedDate   = DateTime.Now;

                    DotBCBHXHDetail.MedicalIssue = model.ProvinceMedical != null?province.SingleOrDefault(n => n.Id == model.ProvinceMedical.Value.ToString()).Name : "";

                    DotBCBHXHDetail.SocietyIssue = model.ProvinceSociety != null?province.SingleOrDefault(n => n.Id == model.ProvinceSociety.Value.ToString()).Name : "";

                    DotBCBHXHDetail.MedicalCode         = model.MedicalCode;
                    DotBCBHXHDetail.MedicalStartDate    = model.MedicalStartDate;
                    DotBCBHXHDetail.MedicalEndDate      = model.MedicalEndDate;
                    DotBCBHXHDetail.MedicalDefaultValue = Decimal.Parse(model.MedicalDefaultValue == null ? "0" : model.MedicalDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                    DotBCBHXHDetail.SocietyCode         = model.SocietyCode;
                    DotBCBHXHDetail.SocietyStartDate    = model.SocietyStartDate;
                    DotBCBHXHDetail.SocietyEndDate      = model.SocietyEndDate;
                    DotBCBHXHDetail.SocietyDefaultValue = Decimal.Parse(model.SocietyDefaultValue == null ? "0" : model.SocietyDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                    DotBCBHXHDetail.PC_CV     = string.IsNullOrEmpty(model.PC_CV) ? 0 : Decimal.Parse(model.PC_CV.Replace(",", "."), new CultureInfo("en-GB"));
                    DotBCBHXHDetail.PC_TNN    = string.IsNullOrEmpty(model.PC_TNN) ? 0 : Decimal.Parse(model.PC_TNN.Replace(",", "."), new CultureInfo("en-GB"));
                    DotBCBHXHDetail.PC_TNVK   = string.IsNullOrEmpty(model.PC_TNVK) ? 0 : Decimal.Parse(model.PC_TNVK.Replace(",", "."), new CultureInfo("en-GB"));
                    DotBCBHXHDetail.PC_Khac   = string.IsNullOrEmpty(model.PC_Khac) ? 0 : Decimal.Parse(model.PC_Khac.Replace(",", "."), new CultureInfo("en-GB"));
                    DotBCBHXHDetail.TienLuong = model.TienLuong;
                    DotBCBHXHDetail.Note      = model.Note;
                    DotBCBHXHDetail.Status    = model.Status;
                    DotBCBHXHDetailRepository.UpdateDotBCBHXHDetail(DotBCBHXHDetail);

                    if (model.SocialInsuranceId != null) // nếu có hồ sơ BHXH thì cập nhật lại
                    {
                        var StaffSocialInsurance = StaffSocialInsuranceRepository.GetStaffSocialInsuranceByStaffId(DotBCBHXHDetail.StaffId.Value);

                        StaffSocialInsurance.MedicalCode      = model.MedicalCode;
                        StaffSocialInsurance.MedicalStartDate = model.MedicalStartDate;
                        StaffSocialInsurance.MedicalEndDate   = model.MedicalEndDate;
                        StaffSocialInsurance.MedicalIssue     = model.ProvinceMedical != null?province.SingleOrDefault(n => n.Id == model.ProvinceMedical.Value.ToString()).Name : "";

                        StaffSocialInsurance.MedicalDefaultValue = Decimal.Parse(model.MedicalDefaultValue == null ? "0" : model.MedicalDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.SocietyCode         = model.SocietyCode;
                        StaffSocialInsurance.SocietyStartDate    = model.SocietyStartDate;
                        StaffSocialInsurance.SocietyEndDate      = model.SocietyEndDate;
                        StaffSocialInsurance.SocietyIssue        = model.ProvinceSociety != null?province.SingleOrDefault(n => n.Id == model.ProvinceSociety.Value.ToString()).Name : "";

                        StaffSocialInsurance.SocietyDefaultValue = Decimal.Parse(model.SocietyDefaultValue == null ? "0" : model.SocietyDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.PC_CV     = string.IsNullOrEmpty(model.PC_CV) ? 0 : Decimal.Parse(model.PC_CV.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.PC_TNN    = string.IsNullOrEmpty(model.PC_TNN) ? 0 : Decimal.Parse(model.PC_TNN.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.PC_TNVK   = string.IsNullOrEmpty(model.PC_TNVK) ? 0 : Decimal.Parse(model.PC_TNVK.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.PC_Khac   = string.IsNullOrEmpty(model.PC_Khac) ? 0 : Decimal.Parse(model.PC_Khac.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.TienLuong = model.TienLuong;
                        StaffSocialInsurance.Note      = model.Note;
                        StaffSocialInsuranceRepository.UpdateStaffSocialInsurance(StaffSocialInsurance);

                        DotBCBHXHDetail.SocialInsuranceId = StaffSocialInsurance.Id;
                        DotBCBHXHDetailRepository.UpdateDotBCBHXHDetail(DotBCBHXHDetail);
                    }
                    else // ngược lại nếu không có thì thêm mới hồ sơ BHXH
                    {
                        var StaffSocialInsurance = new StaffSocialInsurance();

                        StaffSocialInsurance.IsDeleted      = false;
                        StaffSocialInsurance.CreatedUserId  = WebSecurity.CurrentUserId;
                        StaffSocialInsurance.ModifiedUserId = WebSecurity.CurrentUserId;
                        StaffSocialInsurance.AssignedUserId = WebSecurity.CurrentUserId;
                        StaffSocialInsurance.CreatedDate    = DateTime.Now;
                        StaffSocialInsurance.ModifiedDate   = DateTime.Now;


                        if (!string.IsNullOrEmpty(model.MedicalCode))
                        {
                            StaffSocialInsurance.MedicalCode         = model.MedicalCode.Trim();
                            StaffSocialInsurance.MedicalDefaultValue = Decimal.Parse(model.MedicalDefaultValue == null ? "0" : model.MedicalDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                            StaffSocialInsurance.MedicalStartDate    = model.MedicalStartDate;
                            StaffSocialInsurance.MedicalEndDate      = model.MedicalEndDate;
                            StaffSocialInsurance.MedicalIssue        = model.ProvinceMedical != null?province.SingleOrDefault(n => n.Id == model.ProvinceMedical.Value.ToString()).Name : "";
                        }
                        else
                        {
                            StaffSocialInsurance.MedicalDefaultValue = 0;
                        }


                        if (!string.IsNullOrEmpty(model.SocietyCode))
                        {
                            StaffSocialInsurance.SocietyCode         = model.SocietyCode.Trim();
                            StaffSocialInsurance.SocietyDefaultValue = Decimal.Parse(model.SocietyDefaultValue == null ? "0" : model.SocietyDefaultValue.Replace(",", "."), new CultureInfo("en-GB"));
                            StaffSocialInsurance.SocietyIssue        = model.ProvinceSociety != null?province.SingleOrDefault(n => n.Id == model.ProvinceSociety.Value.ToString()).Name : "";

                            StaffSocialInsurance.SocietyStartDate = model.SocietyStartDate;
                            StaffSocialInsurance.SocietyEndDate   = model.SocietyEndDate;
                        }
                        else
                        {
                            StaffSocialInsurance.MedicalDefaultValue = 0;
                        }

                        //Thông tin lương
                        StaffSocialInsurance.TienLuong = model.TienLuong;
                        StaffSocialInsurance.PC_CV     = string.IsNullOrEmpty(model.PC_CV) ? 0 : Decimal.Parse(model.PC_CV.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.PC_TNN    = string.IsNullOrEmpty(model.PC_TNN) ? 0 : Decimal.Parse(model.PC_TNN.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.PC_TNVK   = string.IsNullOrEmpty(model.PC_TNVK) ? 0 : Decimal.Parse(model.PC_TNVK.Replace(",", "."), new CultureInfo("en-GB"));
                        StaffSocialInsurance.PC_Khac   = string.IsNullOrEmpty(model.PC_Khac) ? 0 : Decimal.Parse(model.PC_Khac.Replace(",", "."), new CultureInfo("en-GB"));

                        StaffSocialInsurance.StaffId = model.StaffId;
                        StaffSocialInsurance.Note    = model.Note;
                        StaffSocialInsurance.Status  = Erp.BackOffice.Staff.Controllers.StaffSocialInsuranceController.StatusSocialInsurance.DangHoatDong.GetName();

                        StaffSocialInsuranceRepository.InsertStaffSocialInsurance(StaffSocialInsurance);

                        DotBCBHXHDetail.SocialInsuranceId = StaffSocialInsurance.Id;
                        DotBCBHXHDetailRepository.UpdateDotBCBHXHDetail(DotBCBHXHDetail);
                    }


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

                return(View(model));
            }

            return(View(model));

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