diff --git a/0_Framework/InfraStructure/RepositoryBase.cs b/0_Framework/InfraStructure/RepositoryBase.cs index 7079af53..931739f2 100644 --- a/0_Framework/InfraStructure/RepositoryBase.cs +++ b/0_Framework/InfraStructure/RepositoryBase.cs @@ -18,6 +18,10 @@ namespace _0_Framework.InfraStructure _context = context; } + public void AddRange(IEnumerable entities) + { + _context.AddRange(entities); + } public void Create(T entity) { _context.Add(entity); diff --git a/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs b/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs index 8059dd11..b5fa80a1 100644 --- a/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs +++ b/Company.Domain/EmployeeBankInformationAgg/IEmployeeBankInformationRepository.cs @@ -7,14 +7,17 @@ namespace Company.Domain.EmployeeBankInformationAgg { public interface IEmployeeBankInformationRepository : IRepository { - List Search(long workshopId, EmployeeBankInformationSearchModel searchParams); - + void AddRange(IEnumerable entities); void Remove(EmployeeBankInformation bankInformation); + void RemoveRange(List entities); + + List Search(long workshopId, EmployeeBankInformationSearchModel searchParams); GroupedEmployeeBankInformationViewModel GetByEmployeeId(long workshopId, long employeeId); List GetRangeByEmployeeId(long workshopId, long employeeId); - void RemoveRange(List entities); EmployeeBankInformationViewModel GetDetails(long id); List GetAllByWorkshopId(long workshopId); + + } } diff --git a/CompanyManagment.App.Contracts/EmployeeBankInformation/CreateEmployeeInformation.cs b/CompanyManagment.App.Contracts/EmployeeBankInformation/CreateEmployeeInformation.cs index 8c4e3fd5..1f8508e2 100644 --- a/CompanyManagment.App.Contracts/EmployeeBankInformation/CreateEmployeeInformation.cs +++ b/CompanyManagment.App.Contracts/EmployeeBankInformation/CreateEmployeeInformation.cs @@ -10,7 +10,7 @@ namespace CompanyManagment.App.Contracts.EmployeeBankInformation { public long EmployeeId { get; set; } public string EmployeeName { get; set; } - public long WorkshopId { get; set; } + public long WorkshopId { get; set; } public long BankId { get; set; } //شماره حساب diff --git a/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModel.cs b/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModel.cs index 60217e49..7ce67bb1 100644 --- a/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModel.cs +++ b/CompanyManagment.App.Contracts/EmployeeBankInformation/EmployeeBankInformationViewModel.cs @@ -14,4 +14,5 @@ public class EmployeeBankInformationViewModel public string BankAccountNumber { get; set; } public bool IsDefault { get; set; } public long BankId { get; set; } + public long BankLogoMediaId { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/EmployeeBankInformation/GroupedEmployeeBankInformationViewModel.cs b/CompanyManagment.App.Contracts/EmployeeBankInformation/GroupedEmployeeBankInformationViewModel.cs index 16562a85..49de7c4f 100644 --- a/CompanyManagment.App.Contracts/EmployeeBankInformation/GroupedEmployeeBankInformationViewModel.cs +++ b/CompanyManagment.App.Contracts/EmployeeBankInformation/GroupedEmployeeBankInformationViewModel.cs @@ -11,4 +11,5 @@ public class GroupedEmployeeBankInformationViewModel public int TotalBankAccountsCount { get; set; } public List BankInformation { get; set; } public List BankPicturesList { get; set; } + public List BankNamesList { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs b/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs index 12a4853b..6b2b791a 100644 --- a/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs +++ b/CompanyManagment.App.Contracts/EmployeeBankInformation/IEmployeeBankInformationApplication.cs @@ -6,7 +6,8 @@ namespace CompanyManagment.App.Contracts.EmployeeBankInformation public interface IEmployeeBankInformationApplication { OperationResult Create(CreateEmployeeInformation command); - OperationResult Edit(EditEmployeeInformation command); + OperationResult GroupCreate(long workshopId, List command); + OperationResult Edit(EditEmployeeInformation command); List Search(long workshopId, EmployeeBankInformationSearchModel searchParams); GroupedEmployeeBankInformationViewModel GetByEmployeeId(long workshopId, long employeeId); EmployeeBankInformationViewModel GetDetails(long id); diff --git a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs index 799d7eb3..c6a712c6 100644 --- a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs +++ b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs @@ -1305,17 +1305,6 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo double salary = command.Salary.MoneyToDouble(); - var employeesShifts = - command.ShiftViewModel.Select(x => - { - if (!TimeOnly.TryParseExact(x.StartTime, "HH:mm", out TimeOnly start)) - throw new InvalidDataException(); - if (!TimeOnly.TryParseExact(x.EndTime, "HH:mm", out TimeOnly end)) - throw new InvalidDataException(); - - return new CustomizeWorkshopEmployeeSettingsShift(start, end, x.Placement); - - }).ToList(); bool isChanged; if (fridayPay == entity.FridayPay && overTimePay == entity.OverTimePay && baseYearsPay == entity.BaseYearsPay && bonusesPay == entity.BonusesPay diff --git a/CompanyManagment.Application/EmployeeBankInformationApplication.cs b/CompanyManagment.Application/EmployeeBankInformationApplication.cs index 8c54daaa..842dec47 100644 --- a/CompanyManagment.Application/EmployeeBankInformationApplication.cs +++ b/CompanyManagment.Application/EmployeeBankInformationApplication.cs @@ -17,51 +17,63 @@ namespace CompanyManagment.Application } - //todo: add CardNumber, BankAccountNumber, etc validations public OperationResult Create(CreateEmployeeInformation command) - { - OperationResult op = new(); + { + var workshopEmployeeBankInfoList = + _employeeBankInformationRepository.GetAllByWorkshopId(command.WorkshopId); - if (HasAtLeastOneFormFilled(command) == false) - return op.Failed("لطفا حداقل یکی از مشخصات بانکی را کامل کنید"); + OperationResult op = ValidateCreateOperation(workshopEmployeeBankInfoList,command); - //if (_employeeBankInformationRepository.Exists(x => - // x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && - // x.BankId == command.BankId)) - // return op.Failed("این کاربر در بانک انتخاب شده حساب دارد"); + if (op.IsSuccedded == false) + return op; - - - - if (!string.IsNullOrWhiteSpace(command.BankAccountNumber) && _employeeBankInformationRepository.Exists(x => - x.WorkshopId == command.WorkshopId && - x.BankAccountNumber == command.BankAccountNumber)) - return op.Failed("این شماره حساب قبلا ثبت شده است"); - - if (!string.IsNullOrWhiteSpace(command.CardNumber) && _employeeBankInformationRepository.Exists(x => - x.WorkshopId == command.WorkshopId && - x.CardNumber == command.CardNumber)) - return op.Failed("این شماره کارت قبلا ثبت شده است"); - - if (!string.IsNullOrWhiteSpace(command.ShebaNumber) && _employeeBankInformationRepository.Exists(x => - x.WorkshopId == command.WorkshopId && - x.ShebaNumber == command.ShebaNumber)) - return op.Failed("این شماره شبا قبلا ثبت شده است"); - - - var entity = new EmployeeBankInformation(command.EmployeeId, command.WorkshopId, command.BankId, + var entity = new EmployeeBankInformation(command.EmployeeId, command.WorkshopId, command.BankId, command.BankAccountNumber, command.CardNumber, command.ShebaNumber); - if(HasNoRecordInWorkshop(command.WorkshopId,command.EmployeeId)) + if (HasNoRecordInWorkshop(command.WorkshopId, command.EmployeeId, workshopEmployeeBankInfoList)) entity.SetDefault(); _employeeBankInformationRepository.Create(entity); _employeeBankInformationRepository.SaveChanges(); + return op.Succcedded(entity.id); } - public OperationResult SetDefault(long workshopId, long bankInfoId) + + public OperationResult GroupCreate(long workshopId,List command) + { + var workshopEmployeeBankInfoList = + _employeeBankInformationRepository.GetAllByWorkshopId(workshopId); + + + OperationResult op = new(); + //Validations + foreach (var newEBI in command) + { + op = ValidateCreateOperation(workshopEmployeeBankInfoList, newEBI); + if (op.IsSuccedded == false) + return op; + } + + //ShapeShifting + var entities = command.Select(x=> new EmployeeBankInformation(x.EmployeeId, workshopId, x.BankId, + x.BankAccountNumber, x.CardNumber, x.ShebaNumber)).ToList(); + + + entities.ForEach(newEBI => + { + if (HasNoRecordInWorkshop(workshopId, newEBI.EmployeeId, workshopEmployeeBankInfoList)) + newEBI.SetDefault(); + }); + + _employeeBankInformationRepository.AddRange(entities); + _employeeBankInformationRepository.SaveChanges(); + + return op.Succcedded(); + } + + public OperationResult SetDefault(long workshopId, long bankInfoId) { OperationResult op = new(); @@ -100,6 +112,7 @@ namespace CompanyManagment.Application if (HasAtLeastOneFormFilled(command) == false) return op.Failed("لطفا حداقل یکی از مشخصات بانکی را کامل کنید"); + //if (_employeeBankInformationRepository.Exists(x => // x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && // x.BankId == command.BankId && x.id!= command.Id)) @@ -116,6 +129,11 @@ namespace CompanyManagment.Application x.CardNumber == command.CardNumber && x.id != command.Id)) return op.Failed("این شماره کارت قبلا ثبت شده است"); + if (!string.IsNullOrWhiteSpace(command.ShebaNumber) && _employeeBankInformationRepository.Exists(x => + x.WorkshopId == command.WorkshopId && + x.ShebaNumber == command.ShebaNumber && x.id != command.Id)) + return op.Failed("این شماره شبا قبلا ثبت شده است"); + if (!string.IsNullOrWhiteSpace(command.ShebaNumber) && _employeeBankInformationRepository.Exists(x => x.WorkshopId == command.WorkshopId && x.ShebaNumber == command.ShebaNumber && x.id != command.Id)) @@ -189,6 +207,34 @@ namespace CompanyManagment.Application #region Private Methods + private OperationResult ValidateCreateOperation(List workshopEmployeeBankInfoList, CreateEmployeeInformation command) + { + OperationResult op = new(); + + + //if (workshopEmployeeBankInfoList.Exists(x => + // x.EmployeeId == command.EmployeeId && x.WorkshopId == workshopId && + // x.BankId == command.BankId)) + // return op.Failed("این کاربر در بانک انتخاب شده حساب دارد"); + + if (HasAtLeastOneFormFilled(command) == false) + return op.Failed("لطفا حداقل یکی از مشخصات بانکی را کامل کنید"); + + //Conditions below and multiple accesses to DB can be optimized if needed + if (!string.IsNullOrWhiteSpace(command.BankAccountNumber) && workshopEmployeeBankInfoList.Exists(x => + x.BankInformation.Exists(y => y.BankAccountNumber == command.BankAccountNumber))) + return op.Failed("این شماره حساب قبلا ثبت شده است"); + + if (!string.IsNullOrWhiteSpace(command.CardNumber) && workshopEmployeeBankInfoList.Exists(x => + x.BankInformation.Exists(y => y.CardNumber == command.CardNumber))) + return op.Failed("این شماره کارت قبلا ثبت شده است"); + + if (!string.IsNullOrWhiteSpace(command.ShebaNumber) && workshopEmployeeBankInfoList.Exists(x => + x.BankInformation.Exists(y => y.ShebaNumber == command.ShebaNumber))) + return op.Failed("این شماره شبا قبلا ثبت شده است"); + + return op.Succcedded(); + } private bool HasAtLeastOneFormFilled(CreateEmployeeInformation inputs) { return !string.IsNullOrWhiteSpace(inputs.BankAccountNumber) || @@ -196,12 +242,13 @@ namespace CompanyManagment.Application !string.IsNullOrWhiteSpace(inputs.ShebaNumber); } - private bool HasNoRecordInWorkshop(long workshopId, long employeeId) + private bool HasNoRecordInWorkshop(long workshopId, long employeeId,List workshopRecords) { - return !_employeeBankInformationRepository.Exists(x => + return !workshopRecords.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId); } + #endregion } } diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 500dd894..007bb879 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -388,8 +388,8 @@ public class InsuranceListApplication: IInsuranceListApplication x.Year == searchModel.Year && x.Month == searchModel.Month && searchModel.WorkshopIds.Contains(x.WorkshopId))) { - var startMonthFa = $"{searchModel.Year}/{searchModel.Month}/01"; - DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); + var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; + DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); DateTime endDateGr = startMonthFa.FindeEndOfMonth() .ToGeorgianDateTime(); int endOfMonth = Convert.ToInt32((startMonthFa.FindeEndOfMonth()).Substring(8, 2)); @@ -423,7 +423,9 @@ public class InsuranceListApplication: IInsuranceListApplication //بدست آوردن پایه سنوات var baseYears = _insuranceListRepositpry.GetEmployeeInsuranceBaseYear(employee.EmployeeId, workshopId, workingDays.countWorkingDays, startDateGr, endDateGr,workingDays.startWork, workingDays.endWork, workingDays.hasLeftWorkInMonth); - baseYears.baseYear = employee.JobId is 10 or 16 or 17 or 18 ? 0 : baseYears.baseYear; + //آیا کارفرما یا مدیر عامل است؟ + bool isManager = employee.JobId is 10 or 16 or 17 or 18 ; + baseYears.baseYear = isManager ? 0 : baseYears.baseYear; Console.WriteLine(employee.JobId + " - "+ baseYears.baseYear); //جمع مزد روزانه و پایه سنوات var dailyWagePlusBaseYears = dailyWage + baseYears.baseYear; @@ -433,7 +435,7 @@ public class InsuranceListApplication: IInsuranceListApplication var monthlySalary = GetRoundValue(dailyWagePlusBaseYears * workingDays.countWorkingDays); //حق تاهل - var marriedAllowance = employee.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0; + var marriedAllowance = employee.MaritalStatus == "متاهل" && !isManager ? yearlysaleries.MarriedAllowance : 0; //محاسبه مزایای ماهانه var monthlyBenefits = GetMonthlyBenefits(endOfMonth, yearlysaleries.ConsumableItems, yearlysaleries.HousingAllowance, marriedAllowance, workingDays.countWorkingDays, searchModel.TypeOfInsuranceSendWorkshop, employee.JobId, employee.EmployeeId,employee.IncludeStatus); @@ -514,7 +516,7 @@ public class InsuranceListApplication: IInsuranceListApplication DailyWagePlusBaseYears = dailyWagePlusBaseYears, //حق تاهل - MarriedAllowance = employee.MaritalStatus == "متاهل" ? yearlysaleries.MarriedAllowance : 0, + MarriedAllowance = marriedAllowance, //دستمزد ماهانه MonthlySalary = monthlySalary, @@ -1370,7 +1372,7 @@ public class InsuranceListApplication: IInsuranceListApplication { var result = new MainEmployeeDetailsViewModel(); var workshopId = searchModel.WorkshopIds.FirstOrDefault(); - var startMonthFa = $"{searchModel.Year}/{searchModel.Month}/01"; + var startMonthFa = $"{searchModel.Year}/{searchModel.Month.PadLeft(2, '0')}/01"; DateTime startDateGr = startMonthFa.ToGeorgianDateTime(); DateTime endDateGr = startMonthFa.FindeEndOfMonth() .ToGeorgianDateTime(); @@ -1396,6 +1398,9 @@ public class InsuranceListApplication: IInsuranceListApplication var leftWorkFa = workingDays.hasLeftWorkInMonth ? employeeData.LeftWorkDateGr.ToFarsi() : ""; var startWorkFa = employeeData.StartWorkDateGr.ToFarsi(); + //آیا کارفرما است + bool isManager = employeeData.JobId is 10 or 16 or 17 or 18; + //محاسبه حق بیمه سهم کارفرما var employerShare = (employeeData.BenefitsIncludedContinuous * 20) / 100; @@ -1456,7 +1461,7 @@ public class InsuranceListApplication: IInsuranceListApplication DailyWagePlusBaseYears = employeeData.DailyWagePlusBaseYears, //حق تاهل - MarriedAllowance = employeeData.MarriedAllowance, + MarriedAllowance = isManager ? 0 : employeeData.MarriedAllowance, //دستمزد ماهانه MonthlySalary = employeeData.MonthlySalary, diff --git a/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs b/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs index fe6d0130..41dc0e2b 100644 --- a/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs +++ b/CompanyManagment.EFCore/Repository/EmployeeBankInformationRepository.cs @@ -48,22 +48,31 @@ namespace CompanyManagment.EFCore.Repository var bankInfoList = bankInfoQuery.ToList(); - var groupedBanks = bankInfoList.GroupBy(x => x.Bank).Select(x => x.Key).ToList(); + var groupedBanks = bankInfoList.GroupBy(x => x.EmployeeId) + .Select(x => new { EmployeeId=x.Key,Banks= x.Select(y=>y.Bank).ToList() }).ToList(); //Get bank logos from account context - var mediaIds = groupedBanks.Select(x => x.BankLogoMediaId).ToList(); + var mediaIds = groupedBanks.SelectMany(x => x.Banks.Select(y=>y.BankLogoMediaId)).ToList(); + var banksLogos = _accountContext.Medias.Where(y => mediaIds.Contains(y.id)) .Select(media => new { media.Path, MediaId = media.id }).ToList(); - return bankInfoList.GroupBy(x => x.EmployeeId).Select(x => new GroupedEmployeeBankInformationViewModel() + return bankInfoList.GroupBy(x => x.EmployeeId).Select(x => { - BankPicturesList = banksLogos.Select(y => y.Path).ToList(), - EmployeeId = x.Key, - WorkshopId = workshopId, - EmployeeName = x.FirstOrDefault()?.FullName ?? "", - TotalBankAccountsCount = x.Count(), - PersonnelCode = personnelCodes.FirstOrDefault(y => y.EmployeeId == x.Key)?.PersonnelCode.ToString() ?? "", + var banks = groupedBanks.First(y => y.EmployeeId == x.Key).Banks; + return new GroupedEmployeeBankInformationViewModel() + { + BankPicturesList = banksLogos.Where(y => banks.Any(z => y.MediaId == z.BankLogoMediaId)) + .Select(y => y.Path).ToList(), + EmployeeId = x.Key, + WorkshopId = workshopId, + EmployeeName = x.FirstOrDefault()?.FullName ?? "", + TotalBankAccountsCount = x.Count(), + PersonnelCode = + personnelCodes.FirstOrDefault(y => y.EmployeeId == x.Key)?.PersonnelCode.ToString() ?? "", + BankNamesList = banks.Select(y => y.BankName).ToList() + }; }).ToList(); } @@ -86,12 +95,15 @@ namespace CompanyManagment.EFCore.Repository var groupedBanks = bankInfoList.GroupBy(x => x.Bank).Select(x => x.Key).ToList(); var mediaIds = groupedBanks.Select(x => x.BankLogoMediaId).ToList(); - var banksLogos = _accountContext.Medias.Where(y => mediaIds.Contains(y.id)) - .Select(media => new { media.Path, MediaId = media.id }).ToList(); - return new GroupedEmployeeBankInformationViewModel() + var banksLogos = _accountContext.Medias.Where(y => mediaIds.Contains(y.id)) + .Select(media => new { media.Path, MediaId = media.id }); + + var banksLogosList = banksLogos.ToList(); + + var result = new GroupedEmployeeBankInformationViewModel() { - BankPicturesList = banksLogos.Select(y => y.Path).ToList(), + BankPicturesList = banksLogosList.Select(y => y.Path).ToList(), EmployeeId = employeeId, WorkshopId = workshopId, EmployeeName = entities.FirstOrDefault()?.Employee.FullName ?? "", @@ -101,6 +113,7 @@ namespace CompanyManagment.EFCore.Repository { Id = y.id, BankId = y.BankId, + BankLogoMediaId=y.Bank.BankLogoMediaId, BankAccountNumber = y.BankAccountNumber, BankName = y.Bank.BankName, CardNumber = y.CardNumber, @@ -108,7 +121,12 @@ namespace CompanyManagment.EFCore.Repository IsDefault = y.IsDefault }).OrderByDescending(y=>y.IsDefault).ToList() }; + result.BankInformation.ForEach(x => + { + x.BankLogoPath = banksLogos.FirstOrDefault(z => z.MediaId == x.BankLogoMediaId)?.Path ?? ""; + }); + return result; } public List GetRangeByEmployeeId(long workshopId, long employeeId) @@ -117,6 +135,8 @@ namespace CompanyManagment.EFCore.Repository x.WorkshopId == workshopId && x.EmployeeId == employeeId).ToList(); } + + public void RemoveRange(List entities) { _companyContext.EmployeeBankInformationSet.RemoveRange(entities); @@ -160,30 +180,38 @@ namespace CompanyManagment.EFCore.Repository var bankInfoList = bankInfoQuery.ToList(); + var groupedBanks = bankInfoList.GroupBy(x => x.EmployeeId).Select(x =>new{EmployeeId=x.Key,Banks=x.Select(y=>y.Bank).ToList()}).ToList(); //Get bank logos from account context - var groupedBanks = bankInfoList.GroupBy(x => x.Bank).Select(x => x.Key).ToList(); - var mediaIds = groupedBanks.Select(x => x.BankLogoMediaId).ToList(); + var mediaIds = groupedBanks.SelectMany(x => x.Banks.Select(y=>y.BankLogoMediaId)).ToList(); var banksLogos = _accountContext.Medias.Where(y => mediaIds.Contains(y.id)) .Select(media => new { media.Path, MediaId = media.id }).ToList(); - return bankInfoQuery.GroupBy(x => x.Employee).Select(x => new GroupedEmployeeBankInformationViewModel() + return bankInfoList.GroupBy(x => x.Employee).Select(x => { - BankPicturesList = banksLogos.Select(y => y.Path).ToList(), - EmployeeId = x.Key.id, - WorkshopId = workshopId, - EmployeeName = x.Key.FullName, - TotalBankAccountsCount = x.Count(), - PersonnelCode = personnelCodes.FirstOrDefault(y => y.EmployeeId == x.Key.id).PersonnelCode.ToString(), - BankInformation = x.OrderByDescending(y=>y.IsDefault).Select(y => new EmployeeBankInformationViewModel() - { - Id = y.id, - BankAccountNumber = y.BankAccountNumber, - BankName = y.Bank.BankName, - CardNumber = y.CardNumber, - ShebaNumber = y.ShebaNumber, - IsDefault = y.IsDefault, - }).ToList() + var banks = groupedBanks.First(y => y.EmployeeId == x.Key.id).Banks; + return new GroupedEmployeeBankInformationViewModel() + { + BankPicturesList = banksLogos.Where(y => banks.Any(z => y.MediaId == z.BankLogoMediaId)) + .Select(y => y.Path).ToList(), + BankNamesList = banks.Select(y => y.BankName).ToList(), + EmployeeId = x.Key.id, + WorkshopId = workshopId, + EmployeeName = x.Key.FullName, + TotalBankAccountsCount = x.Count(), + PersonnelCode = personnelCodes.FirstOrDefault(y => y.EmployeeId == x.Key.id).PersonnelCode + .ToString(), + BankInformation = x.OrderByDescending(y => y.IsDefault).Select(y => + new EmployeeBankInformationViewModel() + { + Id = y.id, + BankAccountNumber = y.BankAccountNumber, + BankName = y.Bank.BankName, + CardNumber = y.CardNumber, + ShebaNumber = y.ShebaNumber, + IsDefault = y.IsDefault, + }).ToList() + }; }).ToList(); diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml index 102437d9..1502062c 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Create.cshtml @@ -364,7 +364,7 @@
- +
@@ -731,7 +731,7 @@ $(this).find('td:eq(2)').text($('#StartWorkDate').val()); $(this).find('td:eq(3)').text(jobName); $(this).find('td:eq(4)').text($('#InsuranceShare').val()); - var monthlySalary = getNumberValue($('#MonthlySalary').val()); + var monthlySalaryPlusBaseyear = getNumberValue($('#hiddenMonthlySalaryPlusBaseYear').val()); var benefitsIncludedContinuous = getNumberValue($('#BenefitsIncludedContinuous').val()); var benefitsIncluded = Number(monthlySalaryPlusBaseyear) + Number(benefitsIncludedContinuous); @@ -755,8 +755,8 @@ $(this).find('td:eq(7)').text($('#BenefitsIncludedContinuous').val()); $(this).find('td:eq(7)').attr('data-monthlybenefits', benefitsIncludedContinuous); - $(this).find('td:eq(8)').text($('#MonthlySalary').val()); - $(this).find('td:eq(8)').attr("data-monthlysalary", monthlySalary); + $(this).find('td:eq(8)').text($('#hiddenMonthlySalaryPlusBaseYear').val()); + $(this).find('td:eq(8)').attr("data-monthlysalary", monthlySalaryPlusBaseyear); $(this).find('td:eq(11)').text($('#DailyWage').val()); $(this).find('td:eq(11)').attr("data-dailywage", getNumberValue($('#DailyWage').val())); @@ -968,7 +968,7 @@ // console.log(response); $("#WorkingDays").val(response.workingDay); $("#DailyWage").val(response.dailyWag); - $("#MonthlySalary").val(response.monthlySalary); + $("#MonthlySalary").val(response.monthlySalaryPlusBaseYear); $("#InsuranceShare").val(response.insuranceShare); $("#BenefitsIncludedContinuous").val(response.benefitsIncludedContinuous); $("#hiddenMonthlySalaryPlusBaseYear").val(response.monthlySalaryPlusBaseYear); diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Edit.cshtml b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Edit.cshtml index ad08034a..fb2b36c9 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Edit.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Edit.cshtml @@ -308,7 +308,7 @@
- +
@@ -673,7 +673,7 @@ $(this).find('td:eq(2)').text($('#StartWorkDate').val()); $(this).find('td:eq(3)').text(jobName); $(this).find('td:eq(4)').text($('#InsuranceShare').val()); - var monthlySalary = getNumberValue($('#MonthlySalary').val()); + var monthlySalaryPlusBaseyear = getNumberValue($('#hiddenMonthlySalaryPlusBaseYear').val()); var benefitsIncludedContinuous = getNumberValue($('#BenefitsIncludedContinuous').val()); var benefitsIncluded = Number(monthlySalaryPlusBaseyear) + Number(benefitsIncludedContinuous); @@ -697,8 +697,8 @@ $(this).find('td:eq(7)').text($('#BenefitsIncludedContinuous').val()); $(this).find('td:eq(7)').attr('data-monthlybenefits', benefitsIncludedContinuous); - $(this).find('td:eq(8)').text($('#MonthlySalary').val()); - $(this).find('td:eq(8)').attr("data-monthlysalary", monthlySalary); + $(this).find('td:eq(8)').text($('#hiddenMonthlySalaryPlusBaseYear').val()); + $(this).find('td:eq(8)').attr("data-monthlysalary", monthlySalaryPlusBaseyear); $(this).find('td:eq(11)').text($('#DailyWage').val()); $(this).find('td:eq(11)').attr("data-dailywage", getNumberValue($('#DailyWage').val())); @@ -977,7 +977,7 @@ success: function(response) { // console.log(response); $("#WorkingDays").val(response.workingDay); $("#DailyWage").val(response.dailyWag); - $("#MonthlySalary").val(response.monthlySalary); + $("#MonthlySalary").val(response.monthlySalaryPlusBaseYear); $("#InsuranceShare").val(response.insuranceShare); $("#BenefitsIncludedContinuous").val(response.benefitsIncludedContinuous); $("#hiddenMonthlySalaryPlusBaseYear").val(response.monthlySalaryPlusBaseYear); diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs index 1f832949..ad29eed6 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs @@ -1,5 +1,6 @@ using System.Text; using _0_Framework.Application; +using Company.Domain.EmployeeAgg; using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.Employer; using CompanyManagment.App.Contracts.InsuranceList; @@ -923,8 +924,11 @@ public class IndexModel : PageModel { var benefitsIncludedContinuousL = benefitsIncludedContinuous.MoneyToDouble(); + bool isManager = jobId is "10" or "16" or "17" or "18"; + if (isManager) + maritalStatus = 0; - double sum = 0; + double sum = 0; var employeeMaritalStatus = _employeeApplication.GetDetails(employeeId); if (employeeMaritalStatus.MaritalStatus == "متاهل") sum = consumableItems.MoneyToDouble() + housingAllowance.MoneyToDouble() + maritalStatus; @@ -986,7 +990,7 @@ public class IndexModel : PageModel { - monthlySalaryPlusBaseYear = monthlySalaryL, + monthlySalaryPlusBaseYear = monthlySalaryL.ToMoney(), monthlySalary = monthlySalaryWithOutBaseYear.ToMoney(), benefitsIncludedContinuous = benefitsIncludedContinuousL.ToMoney(), insuranceShare = insuranceShareL.ToMoney(), diff --git a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml index 2cd64f11..5163bcf5 100644 --- a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/CreateBankInfoModal.cshtml @@ -23,7 +23,7 @@
اسامی پرسنل
-
@@ -51,6 +51,18 @@
+ +
+ + + +
+ +
@@ -62,7 +74,7 @@
نام پرسنل
تعداد افزودن
بانک
-
عملیات
+
عملیات
@@ -73,7 +85,7 @@
-
هیچ اطلاعات بانکی وارد نشده است!
+
هیچ اطلاعات بانکی را وارد نشده است!
@@ -90,8 +102,8 @@
-
- -
- -
- - + - + + \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml index c1a539bf..1ddc2b72 100644 --- a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml @@ -60,7 +60,7 @@
-
+
@@ -167,7 +167,7 @@
نام پرسنل
شماره پرسنلی
-
تعداد کارت ثبت شده
+
تعداد کارت ثبت شده
بانک
عملیات
diff --git a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs index 90c5b602..75905ca1 100644 --- a/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/EmployeesBankInfo/Index.cshtml.cs @@ -24,8 +24,10 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo private readonly long _workshopId; public string WorkshopFullName; public int PageIndex = 0; + private readonly IWebHostEnvironment _hostEnvironment; - public IndexModel(IPasswordHasher passwordHasher, IWorkshopApplication workshopApplication, IHttpContextAccessor contextAccessor, IAuthHelper authHelper, IEmployeeBankInformationApplication employeeBankInformationApplication, IEmployeeApplication employeeApplication, IBankApplication bankApplication) + + public IndexModel(IPasswordHasher passwordHasher, IWorkshopApplication workshopApplication, IHttpContextAccessor contextAccessor, IAuthHelper authHelper, IEmployeeBankInformationApplication employeeBankInformationApplication, IEmployeeApplication employeeApplication, IBankApplication bankApplication, IWebHostEnvironment hostEnvironment) { _passwordHasher = passwordHasher; _workshopApplication = workshopApplication; @@ -34,6 +36,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo _employeeBankInformationApplication = employeeBankInformationApplication; _employeeApplication = employeeApplication; _bankApplication = bankApplication; + _hostEnvironment = hostEnvironment; var workshopHash = _contextAccessor.HttpContext?.User.FindFirstValue("WorkshopSlug"); _workshopId = _passwordHasher.SlugDecrypt(workshopHash); @@ -42,12 +45,13 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo throw new InvalidDataException("اختلال در کارگاه"); } - public void OnGet() - { - WorkshopFullName = _workshopApplication.GetWorkshopFullname(_workshopId); - } + public void OnGet() + { + var workshop = _workshopApplication.GetWorkshopInfo(_workshopId); + WorkshopFullName = workshop.WorkshopFullName; + } - public IActionResult OnGetEmployeeListAjax() + public IActionResult OnGetEmployeeListAjax() { var resultData = _employeeApplication.GetWorkingEmployeesByWorkshopId(_workshopId); return new JsonResult(new @@ -132,6 +136,17 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo }); } + public IActionResult OnPostGroupCreate(List command) + { + var result = _employeeBankInformationApplication.GroupCreate(_workshopId, command); + return new JsonResult(new + { + success = result.IsSuccedded, + message = result.Message, + id = result.SendId + }); + } + //public IActionResult OnGetEdit(long id) //{ // var dataBankInfo = _employeeBankInformationApplication.GetDetails(id); @@ -151,13 +166,8 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo public IActionResult OnPostEdit(EditEmployeeInformation command) { command.WorkshopId = _workshopId; - - if (!string.IsNullOrWhiteSpace(command.CardNumber)) - command.CardNumber = command.CardNumber.Replace("-", ""); - - if (!string.IsNullOrWhiteSpace(command.ShebaNumber)) - command.ShebaNumber = command.ShebaNumber.Replace("-", ""); - + command.CardNumber = command.CardNumber.Replace("-", ""); + command.ShebaNumber = command.ShebaNumber.Replace("-", ""); var result = _employeeBankInformationApplication.Edit(command); return new JsonResult(new { @@ -185,5 +195,20 @@ namespace ServiceHost.Areas.Client.Pages.Company.EmployeesBankInfo message = result.Message, }); } - } + + public IActionResult OnGetShowPicture(string filePath) + { + if (string.IsNullOrEmpty(filePath)) + return NotFound(); + + var path = Path.Combine(_hostEnvironment.ContentRootPath, filePath); + + if (!System.IO.File.Exists(path)) + return NotFound(); + + + var contentType = Tools.GetContentTypeImage(Path.GetExtension(path)); + return PhysicalFile(path, contentType); + } + } } diff --git a/ServiceHost/InsuranceList/11/1403_09/DSKKAR00.dbf b/ServiceHost/InsuranceList/11/1403_09/DSKKAR00.dbf index c886aaac..53ee3e4c 100644 Binary files a/ServiceHost/InsuranceList/11/1403_09/DSKKAR00.dbf and b/ServiceHost/InsuranceList/11/1403_09/DSKKAR00.dbf differ diff --git a/ServiceHost/InsuranceList/11/1403_09/DSKWOR00.dbf b/ServiceHost/InsuranceList/11/1403_09/DSKWOR00.dbf index 5bc69752..70915c1e 100644 Binary files a/ServiceHost/InsuranceList/11/1403_09/DSKWOR00.dbf and b/ServiceHost/InsuranceList/11/1403_09/DSKWOR00.dbf differ diff --git a/ServiceHost/InsuranceList/11/1403_10/DSKKAR00.dbf b/ServiceHost/InsuranceList/11/1403_10/DSKKAR00.dbf new file mode 100644 index 00000000..e213a800 Binary files /dev/null and b/ServiceHost/InsuranceList/11/1403_10/DSKKAR00.dbf differ diff --git a/ServiceHost/InsuranceList/11/1403_10/DSKWOR00.dbf b/ServiceHost/InsuranceList/11/1403_10/DSKWOR00.dbf new file mode 100644 index 00000000..e223664b Binary files /dev/null and b/ServiceHost/InsuranceList/11/1403_10/DSKWOR00.dbf differ diff --git a/ServiceHost/Medias/BankLogos/بانک ملت-638742955549086698.png b/ServiceHost/Medias/BankLogos/بانک ملت-638742955549086698.png new file mode 100644 index 00000000..4855d4a8 Binary files /dev/null and b/ServiceHost/Medias/BankLogos/بانک ملت-638742955549086698.png differ diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/CreateBankInfoModal.css b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/CreateBankInfoModal.css index f6e06d58..4119c295 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/CreateBankInfoModal.css +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/CreateBankInfoModal.css @@ -20,6 +20,10 @@ font-weight: 500; } +.form-control::placeholder { + color: #94a3b8; +} + .textLFontColor span { font-size: 16px; font-weight: 600; @@ -38,6 +42,21 @@ background-color: #5f9213; } +.btnEditNew { + font-size: 14px; + font-weight: 500; + background-color: #0ea5e9; + color: #FFFFFF; + border-radius: 8px; + padding: 10px 70px; + width: 100%; +} + +.btnEditNew:hover { + background-color: #0284c7; +} + + .btnCreateNew, .btn-cancel2 { width: 100% !important; diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css index dccbdbd3..a8d8dc1d 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/css/Index.css @@ -10,6 +10,14 @@ border-radius: 7px; } +.bankIcon { + height: 30px; + /*width: 35px;*/ + object-fit: cover; + object-position: center; + border-radius: 5px; +} + .goToTop { position: fixed; bottom: -10px; @@ -35,7 +43,7 @@ } .width2 { - width: 18% !important; + width: 10% !important; } .width3 { @@ -47,7 +55,7 @@ } .width5 { - width: 10% !important; + width: 18% !important; } .width6 { diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js index 59209326..ec410d8a 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/CreateBankInfoModal.js @@ -1,6 +1,8 @@ var urlPathname = location.pathname; var filledBankCount = 0; -hasModalCreate = true; +var newItemIndex = 1; +var command = []; + $(document).ready(function () { $('.loading').hide(); @@ -17,7 +19,7 @@ $(document).ready(function () { return data.text; } }); - + $("#CardNumber").each(function () { $("#CardNumber").mask("0000-0000-0000-0000"); $("#CardNumber").attr("placeholder", "XXXX-XXXX-XXXX-XXXX"); @@ -99,45 +101,147 @@ function ajaxCreateBanks() { }); } -$(document).on('click', 'button[data-edit-id]', function () { - // Get the data attributes from the clicked button - var editId = $(this).data('edit-id'); - var employeeId = $(this).data('edit-employeeid'); - var employeeName = $(this).data('edit-employeename'); - var bankId = $(this).data('edit-bankid'); - var cardNumber = $(this).data('edit-cardnumber'); - var shebaNumber = $(this).data('edit-sheba-number'); - var bankAccountNumber = $(this).data('edit-bankaccountnumber'); +$(document).on('change', '#employeeSelectCreate', function () { + var selectedValueId = $(this).val(); - $('#modalCustom').find('#editId').val(editId); - $('#modalCustom').find('#bankSelectEdit').val(bankId); - $('#modalCustom').find('#employeeId').val(employeeId); + $.ajax({ + url: getDetailsAjaxUrl, + type: 'GET', + data: { + employeeId: selectedValueId + }, + success: function (response) { + if (response.success) { + if (response.data.bankInformation.length > 0) { - $('#CardNumberEdit').mask("0000-0000-0000-0000", { - placeholder: "XXXX-XXXX-XXXX-XXXX" + var n = 1; + var html = `
`; + + response.data.bankInformation.forEach(function (item) { + + let resultBankCount = 0; + + if (item.bankAccountNumber !== null) resultBankCount++; + if (item.cardNumber !== null) resultBankCount++; + if (item.shebaNumber !== null) resultBankCount++; + + html += ` +
+
+ +
+
+
${response.data.employeeName}
+
+
+
${resultBankCount}
+
+
+
${item.bankName}
+
+ +
+
+ + +
+
+
`; + + n++; + }); + + $('#emptyData').addClass("d-none"); + filledBankCount = 0; + $('.data-load .wrapper').show(); + $('#dataLoad').html(html); + } else { + $('#emptyData').removeClass("d-none"); + $('.data-load .wrapper').hide(); + $('#dataLoad').html(""); + } + } + }, + error: function (xhr, status, error) { + console.error('AJAX error:', error); + } }); - $('#CardNumberEdit').val(cardNumber).keyup(); - - - $('#ShebaNumberEdit').mask("IR-00-0000-0000-0000-0000-0000-00", { - placeholder: "IR-XX-XXXX-XXXX-XXXX-XXXX-XXXX-XX" - }); - $('#ShebaNumberEdit').val(shebaNumber).keyup(); - - - //$('#modalCustom').find('#CardNumberEdit').val(cardNumber); - //$('#modalCustom').find('#ShebaNumberEdit').val(shebaNumber); - $('#modalCustom').find('#BankAccountNumberEdit').val(bankAccountNumber); - - $('#EmployeeNameShow').text(employeeName); - - ajaxBanksListEdit(bankId); }); $('#createData').on('click', SaveDataAjax); + function SaveDataAjax() { var loading = $('#createData .spinner-loading'); + $('#createData').addClass('disable'); + + //var data = $('#create-form').serialize(); + + $.ajax({ + async: false, + dataType: 'json', + type: 'POST', + url: saveGroupNewEmployeeBankAjax, + headers: { "RequestVerificationToken": antiForgeryToken }, + data: { command }, + success: function (response) { + if (response.success) { + loading.show(); + $('.alert-success-msg').show(); + $('.alert-success-msg p').text(response.message); + setTimeout(function () { + $('.alert-success-msg').hide(); + $('.alert-success-msg p').text(''); + }, 2000); + + //$('#emptyData').addClass("d-none"); + //loadDataCreate(response.id, employeeSelectName, bankSelectName, filledBankCount); + loading.hide(); + $('#createData').removeClass('disable'); + + $('#EmployeeBankListAjax').html(''); + loadEmployeeBankList(); + $('#MainModal').modal('hide'); + + } else { + $('.alert-msg').show(); + $('.alert-msg p').text(response.message); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + }, 3500); + + loading.hide(); + $('#createData').removeClass('disable'); + } + }, + error: function (err) { + loading.hide(); + $('#createData').removeClass('disable'); + console.log(err); + } + }); +} + +function addDataToTable() { var employeeSelectName = $('#select2-employeeSelectCreate-container').text(); var employeeSelect = $('#employeeSelectCreate').val(); var bankSelectName = $('#select2-bankSelectCreate-container').text(); @@ -146,6 +250,7 @@ function SaveDataAjax() { var shebaNumber = $('#ShebaNumber'); var bankAccountNumber = $('#BankAccountNumber'); + filledBankCount = 0; if (cardNumber.val() !== '') { filledBankCount++; } @@ -187,7 +292,7 @@ function SaveDataAjax() { $('.alert-msg').show(); $('.alert-msg p').text('لطفا حداقل یکی از فیلدها را وارد نمائید'); - + setTimeout(function () { $('.alert-msg').hide(); $('.alert-msg p').text(''); @@ -227,60 +332,56 @@ function SaveDataAjax() { }, 3500); return; } - - $('#createData').addClass('disable'); - var data = $('#create-form').serialize(); - $.ajax({ - async: false, - dataType: 'json', - type: 'POST', - url: saveNewEmployeeBankAjax, - headers: { "RequestVerificationToken": antiForgeryToken }, - data: data, - success: function (response) { - if (response.success) { - loading.show(); - $('.alert-success-msg').show(); - $('.alert-success-msg p').text(response.message); - setTimeout(function () { - $('.alert-success-msg').hide(); - $('.alert-success-msg p').text(''); - }, 2000); + var newId = newItemIndex++; + //const createEmployeeInformation = {}; + //createEmployeeInformation.EmployeeId = employeeSelect; + //createEmployeeInformation.BankId = bankSelect; + //createEmployeeInformation.BankAccountNumber = bankAccountNumber.val(); + //createEmployeeInformation.CardNumber = cardNumber.val(); + //createEmployeeInformation.ShebaNumber = shebaNumber.val(); + //createEmployeeInformation.newItemId = newId; - $('#emptyData').addClass("d-none"); + let employeeData = { + EmployeeId: employeeSelect, + BankId: bankSelect, + BankAccountNumber: bankAccountNumber.val(), + CardNumber: cardNumber.val().replace(/-/g, ""), + ShebaNumber: shebaNumber.val().replace(/-/g, ""), + newItemId: newId + }; - loadDataCreate(response.id, employeeSelectName, bankSelectName, filledBankCount, employeeSelect, bankSelect, cardNumber.val(), shebaNumber.val(), bankAccountNumber.val()); + let isDuplicate = command.some(existingItem => + existingItem.EmployeeId === employeeData.EmployeeId && + existingItem.BankId === employeeData.BankId && + existingItem.BankAccountNumber === employeeData.BankAccountNumber && + existingItem.CardNumber === employeeData.CardNumber && + existingItem.ShebaNumber === employeeData.ShebaNumber + ); - $('#EmployeeBankListAjax').html(''); - loadEmployeeBankList(); + if (!isDuplicate) { + command.push(employeeData); + } else { + $('.alert-msg').show(); + $('.alert-msg p').text('این داده قبلاً وارد شده است'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + shebaNumber.removeClass('errored'); + }, 3500); + return; + } - loading.hide(); - $('#createData').removeClass('disable'); - } else { - $('.alert-msg').show(); - $('.alert-msg p').text(response.message); - setTimeout(function () { - $('.alert-msg').hide(); - $('.alert-msg p').text(''); - }, 3500); - - loading.hide(); - $('#createData').removeClass('disable'); - } - }, - error: function (err) { - loading.hide(); - $('#createData').removeClass('disable'); - console.log(err); - } - }); + loadDataCreate(newId, employeeSelectName, bankSelectName, filledBankCount); } -function loadDataCreate(id, employeeName, bankName, bankCount, employeeId, bankId, cardNumber, shebaNumber, bankAccountNumber) { +function loadDataCreate(newId, employeeName, bankName, bankCount) { + $('.select-alert-employee .select2.select2-container.select2-container--default').addClass("disable"); + $('#createData').removeClass("disable"); + var n = $('#dataLoad .Rtable-row').length + 1; var html = `
-
+
-
${bankCount}
+
${bankCount}
-
${bankName}
+
${bankName}
-
-
- +
`; - // + $('#bankSelectCreate').val("0").trigger('change'); + $('#CardNumber').val(""); + $('#ShebaNumber').val(""); + $('#BankAccountNumber').val(""); - filledBankCount = 0; $('.data-load .wrapper').show(); $('#dataLoad').append(html); } @@ -368,7 +464,7 @@ function removeBank(id) { $('.alert-success-msg').hide(); $('.alert-success-msg p').text(''); }, 2000); - + $(`[data-employee-id="${id}"]`).remove(); updateRows(); $('#EmployeeBankListAjax').html(''); @@ -388,13 +484,198 @@ function removeBank(id) { }); } +function alertRemoveRecordAfterAddNewItem(id) { + swal({ + title: "آیا از حذف این حساب اطمینان دارید؟", + text: "", + type: "warning", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: "بله", + cancelButtonText: "خیر", + closeOnConfirm: true, + closeOnCancel: true + }, function (isConfirm) { + if (isConfirm) { + removeRecordAfterAddNewItem(id); + } + }); +} + +function removeRecordAfterAddNewItem(id) { + $(`[data-item-new-id="${id}"]`).remove(); + updateRows(); + + $('.alert-success-msg').show(); + $('.alert-success-msg p').text("عملیات با موفقیت انجام شد"); + setTimeout(function () { + $('.alert-success-msg').hide(); + $('.alert-success-msg p').text(''); + }, 2000); + + command = command.filter(employee => employee.newItemId !== id); + //let indexToDelete = command.findIndex(employee => employee.newItemId === id); + //if (indexToDelete !== -1) { + // command.splice(indexToDelete, 1); + //} + + if (command.length === 0) { + $('.select-alert-employee .select2.select2-container.select2-container--default').removeClass("disable"); + $('#createData').addClass("disable"); + } +} + +function editNewItem(newId) { + $('#addNewItemBtn').hide(); + $('#editNewItemBtn').show(); + + $('#createData').addClass("disable"); + + let employeeBankInfo = command.find(employee => employee.newItemId === newId); + + $('#editNewItemBtn').attr('onclick', 'saveEditNewItem(' + newId + ')'); + + $('#bankSelectCreate').val(employeeBankInfo.BankId).trigger('change'); + $('#CardNumber').val(employeeBankInfo.CardNumber); + $('#ShebaNumber').val(employeeBankInfo.ShebaNumber); + $('#BankAccountNumber').val(employeeBankInfo.BankAccountNumber); + + $('#CardNumber').mask("0000-0000-0000-0000", { + placeholder: "XXXX-XXXX-XXXX-XXXX" + }); + $('#CardNumber').val(cardNumber).keyup(); + + + $('#ShebaNumber').mask("IR-00-0000-0000-0000-0000-0000-00", { + placeholder: "IR-XX-XXXX-XXXX-XXXX-XXXX-XXXX-XX" + }); + $('#ShebaNumber').val(shebaNumber).keyup(); +} + +function saveEditNewItem(newId) { + var employeeSelect = $('#employeeSelectCreate').val(); + var bankSelectName = $('#select2-bankSelectCreate-container').text(); + var bankSelect = $('#bankSelectCreate').val(); + var cardNumber = $('#CardNumber'); + var shebaNumber = $('#ShebaNumber'); + var bankAccountNumber = $('#BankAccountNumber'); + + filledBankCount = 0; + if (cardNumber.val() !== '') { + filledBankCount++; + } + if (shebaNumber.val() !== '') { + filledBankCount++; + } + if (bankAccountNumber.val() !== '') { + filledBankCount++; + } + + if (employeeSelect === "0") { + $('.alert-msg').show(); + $('.alert-msg p').text('لطفا اسامی پرسنل را کلیک و مشخص نمائید'); + $('.select-alert-employee').addClass('errored'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + $('.select-alert-employee').removeClass('errored'); + }, 3500); + return; + } + + if (bankSelect === "0") { + $('.alert-msg').show(); + $('.alert-msg p').text('لطفا نام بانک را کلیک و مشخص نمائید'); + $('.select-alert-bank').addClass('errored'); + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + $('.select-alert-bank').removeClass('errored'); + }, 3500); + return; + } + + if (!cardNumber.val() && !shebaNumber.val() && !bankAccountNumber.val()) { + cardNumber.addClass('errored'); + shebaNumber.addClass('errored'); + bankAccountNumber.addClass('errored'); + + $('.alert-msg').show(); + $('.alert-msg p').text('لطفا حداقل یکی از فیلدها را وارد نمائید'); + + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + cardNumber.removeClass('errored'); + shebaNumber.removeClass('errored'); + bankAccountNumber.removeClass('errored'); + }, 3500); + return; + } + + var cardNumberLength = cardNumber.val().length; + if (cardNumberLength > 0 && cardNumberLength !== 19) { + cardNumber.addClass('errored'); + + $('.alert-msg').show(); + $('.alert-msg p').text('شماره کارت باید 16 رقم باشد'); + + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + cardNumber.removeClass('errored'); + }, 3500); + return; + } + + var shebaNumberLength = shebaNumber.val().length; + if (shebaNumber.val() && shebaNumberLength !== 33) { + shebaNumber.addClass('errored'); + + $('.alert-msg').show(); + $('.alert-msg p').text('شماره کارت باید 24 رقم باشد'); + + setTimeout(function () { + $('.alert-msg').hide(); + $('.alert-msg p').text(''); + shebaNumber.removeClass('errored'); + }, 3500); + return; + } + + let updatedData = { + EmployeeId: employeeSelect, + BankId: bankSelect, + BankAccountNumber: bankAccountNumber.val(), + CardNumber: cardNumber.val().replace(/-/g, ""), + ShebaNumber: shebaNumber.val().replace(/-/g, ""), + newItemId: newId + }; + + let indexToEdit = command.findIndex(employee => employee.newItemId === newId); + + if (indexToEdit !== -1) { + command[indexToEdit] = { ...command[indexToEdit], ...updatedData }; + } + + $('#bankSelectCreate').val("0").trigger('change'); + $('#CardNumber').val(""); + $('#ShebaNumber').val(""); + $('#BankAccountNumber').val(""); + + $('#editNewItemBtn').attr('onclick', 'saveEditNewItem()'); + + $(`[data-item-new-id="${newId}"] #bankCount`).text(filledBankCount); + $(`[data-item-new-id="${newId}"] #bankName`).text(bankSelectName); + + $('#addNewItemBtn').show(); + $('#editNewItemBtn').hide(); + + $('#createData').removeClass("disable"); +} + function updateRows() { $('.load-create-row.width1').each(function (index) { $(this).find('span.row-number').text(index + 1); }); -} - -function openModalEdit() { - var modalCustom = document.getElementById("modalCustom"); - modalCustom.style.display = "block"; } \ No newline at end of file diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/DetailsBankInfoModal.js b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/DetailsBankInfoModal.js index 9ad6b5e5..d9477bf7 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/DetailsBankInfoModal.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/DetailsBankInfoModal.js @@ -89,14 +89,17 @@ function loadDetailsAjax() { headers: { "RequestVerificationToken": antiForgeryToken }, success: function (response) { var responseData = response.data; - + console.log(responseData); if (response.success) { if (responseData.bankInformation.length > 0) { responseData.bankInformation.forEach(function (item) { index++; html += `
-
${item.bankName}
+
+ + ${item.bankName} +
شماره کارت:
diff --git a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js index 9a40b0e0..a1d19844 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/EmployeesBankInfo/js/Index.js @@ -138,11 +138,13 @@ function loadEmployeeBankList() { responseData.forEach(function (item) { index++; html += `
-
+
@@ -153,11 +155,15 @@ function loadEmployeeBankList() {
${item.personnelCode}
-
-
${item.totalBankAccountsCount}
+
+
${item.totalBankAccountsCount}
-
بانک ها
+
`; + item.bankPicturesList.forEach(function (itemBank, index) { + html += ``; + }); + html += `
@@ -199,9 +205,13 @@ function loadEmployeeBankList() { تعداد کارت ثبت شده: ${item.totalBankAccountsCount}
-
+
بانک: - بانک + `; + item.bankPicturesList.forEach(function (itemBank, index) { + html += `${index !== item.bankPicturesList.length - 1 ? '، ' : ''}`; + }); + html += `