Merge branch 'Feature/Insurance/client-api' into Main

This commit is contained in:
2025-12-21 11:03:49 +03:30
2 changed files with 75 additions and 32 deletions

View File

@@ -102,7 +102,7 @@ public interface IInsuranceListApplication
public class InsuranceClientPrintViewModel public class InsuranceClientPrintViewModel
{ {
public string Monht { get; set; } public string Month { get; set; }
public string Year { get; set; } public string Year { get; set; }
public string WorkshopName { get; set; } public string WorkshopName { get; set; }
public string ListNo { get; set; } public string ListNo { get; set; }
@@ -202,4 +202,11 @@ public class InsuranceClientListViewModel
public int YearInt { get; set; } public int YearInt { get; set; }
public string MonthName { get; set; } public string MonthName { get; set; }
public int MonthInt { get; set; } public int MonthInt { get; set; }
public int PersonnelCount { get; set; }
public int LeftWorkCount { get; set; }
public string AllInsuredShare { get; set; }
public string InsuredShare { get; set; }
public string EmployerShare { get; set; }
public string UnEmploymentInsurance { get; set; }
} }

View File

@@ -1785,6 +1785,39 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
{ {
var workshopId = _authHelper.GetWorkshopId(); var workshopId = _authHelper.GetWorkshopId();
var query = _context.InsuranceListSet var query = _context.InsuranceListSet
.Where(x => x.WorkshopId == workshopId);
if (searchModel.Year > 0)
{
query = query.Where(x => x.Year == searchModel.Year.ToString("0000"));
}
if (searchModel.Month > 0)
{
query = query.Where(x => x.Month == searchModel.Month.ToString("00"));
}
var res = new PagedResult<InsuranceClientListViewModel>
{
TotalCount = query.Count()
};
var list = (await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync());
var insuranceListIds = list.Select(x => x.id).ToList();
var employeeData = await _context.EmployeeInsurancListDataSet
.Where(x => insuranceListIds.Contains(x.InsuranceListId))
.GroupBy(x => x.InsuranceListId)
.Select(g => new
{
g.Key,
Count = g.Count(x=>x.LeftWorkDate != null)
}).ToListAsync();
var resList = list
.Select(x => new InsuranceClientListViewModel .Select(x => new InsuranceClientListViewModel
{ {
Id = x.id, Id = x.id,
@@ -1794,34 +1827,29 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
Month = x.Month, Month = x.Month,
MonthName = x.Month.ToFarsiMonthByNumber(), MonthName = x.Month.ToFarsiMonthByNumber(),
MonthInt = Convert.ToInt32(x.Month), MonthInt = Convert.ToInt32(x.Month),
}).Where(x => x.WorkShopId == workshopId); EmployerShare = x.EmployerShare.ToMoney(),
InsuredShare = x.InsuredShare.ToMoney(),
UnEmploymentInsurance = x.UnEmploymentInsurance.ToMoney(),
if (searchModel.Year > 0) PersonnelCount = x.SumOfEmployees,
AllInsuredShare = (x.InsuredShare +
x.EmployerShare +
x.UnEmploymentInsurance).ToMoney(),
LeftWorkCount =employeeData.FirstOrDefault(e=>e.Key == x.id)?.Count ?? 0,
}).ToList();
resList = searchModel.Sorting switch
{ {
query = query.Where(x => x.YearInt == searchModel.Year); "CreationDate-Max" => resList.OrderByDescending(x => x.Id).ToList(),
} "CreationDate-Min" => resList.OrderBy(x => x.Id).ToList(),
"Month-Max" => resList.OrderByDescending(x => x.MonthInt).ToList(),
if (searchModel.Month > 0) "Month-Min" => resList.OrderBy(x => x.MonthInt).ToList(),
{ "Year-Max" => resList.OrderByDescending(x => x.YearInt).ToList(),
query = query.Where(x => x.MonthInt == searchModel.Month); "Year-Min" => resList.OrderBy(x => x.YearInt).ToList(),
} _ => resList.OrderByDescending(x => x.Id).ToList(),
var res = new PagedResult<InsuranceClientListViewModel>
{
TotalCount = query.Count()
}; };
query = searchModel.Sorting switch
{
"CreationDate-Max" => query.OrderByDescending(x => x.Id), res.List = resList;
"CreationDate-Min" => query.OrderBy(x => x.Id),
"Month-Max" => query.OrderByDescending(x => x.MonthInt),
"Month-Min" => query.OrderBy(x => x.MonthInt),
"Year-Max" => query.OrderByDescending(x => x.YearInt),
"Year-Min" => query.OrderBy(x => x.YearInt),
_ => query.OrderByDescending(x => x.Id),
};
res.List = await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync();
return res; return res;
} }
@@ -1968,19 +1996,27 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
public async Task<InsuranceClientPrintViewModel> ClientPrintOne(long id) public async Task<InsuranceClientPrintViewModel> ClientPrintOne(long id)
{ {
var insurance = await _context.InsuranceListSet.FirstOrDefaultAsync(x => x.id == id); var insurance = await _context.InsuranceListSet.FirstOrDefaultAsync(x => x.id == id);
if (insurance == null) if (insurance == null)
return null; return null;
var employeeInsurance = _context.EmployeeInsurancListDataSet.Where(x => x.InsuranceListId == insurance.id); var employeeInsurance = _context.EmployeeInsurancListDataSet
.Where(x => x.InsuranceListId == insurance.id);
var workshop = await _context.Workshops var workshop = await _context.Workshops
.Include(x => x.InsuranceWorkshopInfo) .Include(x => x.InsuranceWorkshopInfo)
.FirstOrDefaultAsync(x => x.id == insurance.WorkshopId); .FirstOrDefaultAsync(x => x.id == insurance.WorkshopId);
var employeeIds = await employeeInsurance.Select(x => x.EmployeeId).ToListAsync(); var employeeIds = await employeeInsurance
var employees = await _context.Employees.Where(x => employeeIds.Contains(x.id)).ToListAsync(); .Select(x => x.EmployeeId).ToListAsync();
var employees = await _context.Employees
.Where(x => employeeIds.Contains(x.id)).ToListAsync();
var jobIds = employeeInsurance.Select(x => x.JobId).ToList(); var jobIds = employeeInsurance.Select(x => x.JobId).ToList();
var jobs = await _context.Jobs.Where(x => jobIds.Contains(x.id)).ToDictionaryAsync(x => x.id, x => x.JobName);
var jobs = await _context.Jobs
.Where(x => jobIds.Contains(x.id)).ToDictionaryAsync(x => x.id, x => x.JobName);
var employeeData = employeeInsurance.ToList().Select(x => var employeeData = employeeInsurance.ToList().Select(x =>
{ {
@@ -2021,7 +2057,7 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
WorkshopInsuranceCode = workshop.InsuranceWorkshopInfo.InsuranceCode, WorkshopInsuranceCode = workshop.InsuranceWorkshopInfo.InsuranceCode,
AgreementNumber = workshop.InsuranceWorkshopInfo.AgreementNumber, AgreementNumber = workshop.InsuranceWorkshopInfo.AgreementNumber,
ListNo = "01", ListNo = "01",
Monht = insurance.Month, Month = insurance.Month,
Year = insurance.Year Year = insurance.Year
}; };