Compare commits

...

3 Commits

5 changed files with 315 additions and 98 deletions

View File

@@ -78,6 +78,7 @@ public interface IInsuranceListRepository:IRepository<long, InsuranceList>
#endregion #endregion
Task<List<InsuranceListViewModel>> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); Task<List<InsuranceListViewModel>> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel);
Task<InsuranceClientPrintViewModel> ClientPrintOne(long id);
} }

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using _0_Framework.Application; using _0_Framework.Application;
using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.InsuranceList;
using CompanyManagment.App.Contracts.Workshop;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -96,6 +97,94 @@ public interface IInsuranceListApplication
#endregion #endregion
Task<List<InsuranceListViewModel>> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); Task<List<InsuranceListViewModel>> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel);
Task<InsuranceClientPrintViewModel> ClientPrintOne(long id);
}
public class InsuranceClientPrintViewModel
{
public string Month { get; set; }
public string Year { get; set; }
public string WorkshopName { get; set; }
public string ListNo { get; set; }
public string AgreementNumber { get; set; }
public string WorkshopInsuranceCode { get; set; }
public string WorkshopEmployerName { get; set; }
public string WorkshopAddress { get; set; }
public List<InsuranceClientPrintItemsViewModel> Items { get; set; }
public string EmployerShare { get; set; }
public string InsuredShare { get; set; }
public string UnEmploymentInsurance { get; set; }
public string AllInsuredShare { get; set; }
}
public class InsuranceClientPrintItemsViewModel
{
/// <summary>
/// شماره بیمه
/// </summary>
public string InsuranceCode { get; set; }
/// <summary>
/// نام و نام خانوادگی
/// </summary>
public string FullName { get; set; }
/// <summary>
/// شغل
/// </summary>
public string JobName { get; set; }
/// <summary>
/// کد ملی
/// </summary>
public string NationalCode { get; set; }
/// <summary>
/// شروع به کار
/// </summary>
public string StartWork { get; set; }
/// <summary>
/// ترک کار
/// </summary>
public string LeftWork { get; set; }
/// <summary>
/// روزهای کارکرد
/// </summary>
public string WorkingDays { get; set; }
/// <summary>
/// دستمزد روزانه
/// </summary>
public string DailyWage { get; set; }
/// <summary>
/// پایه سنوات روزانه
/// </summary>
public string BaseYears { get; set; }
/// <summary>
/// دستمزد ماهانه
/// </summary>
public string MonthlySalary { get; set; }
/// <summary>
/// مزایای ماهیانه مشمول
/// </summary>
public string MonthlyBenefits { get; set; }
/// <summary>
/// حق تاهل
/// </summary>
public string MarriedAllowance { get; set; }
/// <summary>
/// حقوق و مزایای ماهیانه مشمول
/// </summary>
public string BenefitsIncludedContinuous { get; set; }
/// <summary>
/// حقوق و مزایای ماهیانه غیر مشمول
/// </summary>
public string BenefitsIncludedNonContinuous { get; set; }
/// <summary>
/// مجموع مزایای ماهیانه مشمول و غیر مشمول
/// </summary>
public string IncludedAndNotIncluded { get; set; }
/// <summary>
/// حق بیمه سهم بیمه شده
/// </summary>
public string InsuranceShare { get; set; }
} }
public class InsuranceClientSearchModel:PaginationRequest public class InsuranceClientSearchModel:PaginationRequest
@@ -113,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

@@ -2381,5 +2381,10 @@ public class InsuranceListApplication : IInsuranceListApplication
return await _insuranceListRepositpry.GetNotCreatedWorkshop(searchModel); return await _insuranceListRepositpry.GetNotCreatedWorkshop(searchModel);
} }
public async Task<InsuranceClientPrintViewModel> ClientPrintOne(long id)
{
return await _insuranceListRepositpry.ClientPrintOne(id);
}
#endregion #endregion
} }

View File

@@ -176,18 +176,20 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
if (item.InsuranceShare.ToMoney() != checkout.InsuranceDeduction.ToMoney()) if (item.InsuranceShare.ToMoney() != checkout.InsuranceDeduction.ToMoney())
{ {
checkout.SetUpdateNeeded(); checkout.SetUpdateNeeded();
if (!_context.CheckoutWarningMessages.Any(x => x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning != TypeOfCheckoutWarning.InsuranceEmployeeShare)) if (!_context.CheckoutWarningMessages.Any(x =>
x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning !=
TypeOfCheckoutWarning.InsuranceEmployeeShare))
{ {
var createWarrning = var createWarrning =
new CheckoutWarningMessage( new CheckoutWarningMessage(
"مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد",
checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare);
_context.CheckoutWarningMessages.Add(createWarrning); _context.CheckoutWarningMessages.Add(createWarrning);
} }
_context.SaveChanges(); _context.SaveChanges();
} }
} }
} }
} }
@@ -729,7 +731,7 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
var id = insuranceListObj.id; var id = insuranceListObj.id;
if (command.EmployeeInsurancListDataList != null && command.EmployeeInsurancListDataList.Count > 0) if (command.EmployeeInsurancListDataList != null && command.EmployeeInsurancListDataList.Count > 0)
{ {
var farisMonthName = Tools.ToFarsiMonthByNumber(command.Month); var farisMonthName = Tools.ToFarsiMonthByNumber(command.Month);
var checkouts = _context.CheckoutSet.Where(x => var checkouts = _context.CheckoutSet.Where(x =>
x.WorkshopId == command.WorkshopId && x.Year == command.Year && x.Month == farisMonthName && x.WorkshopId == command.WorkshopId && x.Year == command.Year && x.Month == farisMonthName &&
@@ -755,20 +757,21 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
if (item.InsuranceShare.ToMoney() != checkout.InsuranceDeduction.ToMoney()) if (item.InsuranceShare.ToMoney() != checkout.InsuranceDeduction.ToMoney())
{ {
checkout.SetUpdateNeeded(); checkout.SetUpdateNeeded();
if (!_context.CheckoutWarningMessages.Any(x => x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning != TypeOfCheckoutWarning.InsuranceEmployeeShare)) if (!_context.CheckoutWarningMessages.Any(x =>
x.CheckoutId == checkout.id && x.TypeOfCheckoutWarning !=
TypeOfCheckoutWarning.InsuranceEmployeeShare))
{ {
var createWarrning = var createWarrning =
new CheckoutWarningMessage( new CheckoutWarningMessage(
"مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد", checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare); "مبلغ بیمه سهم کارگر با مبلغ محاسبه شده در لیست بیمه مغایرت دارد",
checkout.id, TypeOfCheckoutWarning.InsuranceEmployeeShare);
_context.CheckoutWarningMessages.Add(createWarrning); _context.CheckoutWarningMessages.Add(createWarrning);
} }
_context.SaveChanges(); _context.SaveChanges();
} }
} }
} }
} }
_employeeInsurancListDataRepository.SaveChanges(); _employeeInsurancListDataRepository.SaveChanges();
@@ -1777,46 +1780,76 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
return res; return res;
} }
public async Task<PagedResult<InsuranceClientListViewModel>> GetInsuranceClientList(InsuranceClientSearchModel searchModel) public async Task<PagedResult<InsuranceClientListViewModel>> GetInsuranceClientList(
InsuranceClientSearchModel searchModel)
{ {
var workshopId = _authHelper.GetWorkshopId(); var workshopId = _authHelper.GetWorkshopId();
var query = _context.InsuranceListSet var query = _context.InsuranceListSet
.Select(x => new InsuranceClientListViewModel .Where(x => x.WorkshopId == workshopId);
{
Id = x.id,
WorkShopId = x.WorkshopId,
Year = x.Year,
YearInt = Convert.ToInt32(x.Year),
Month = x.Month,
MonthName = x.Month.ToFarsiMonthByNumber(),
MonthInt = Convert.ToInt32(x.Month),
}).Where(x => x.WorkShopId == workshopId);
if (searchModel.Year>0) if (searchModel.Year > 0)
{ {
query = query.Where(x => x.YearInt == searchModel.Year); query = query.Where(x => x.Year == searchModel.Year.ToString("0000"));
} }
if (searchModel.Month > 0) if (searchModel.Month > 0)
{ {
query = query.Where(x => x.MonthInt == searchModel.Month); query = query.Where(x => x.Month == searchModel.Month.ToString("00"));
} }
var res = new PagedResult<InsuranceClientListViewModel> var res = new PagedResult<InsuranceClientListViewModel>
{ {
TotalCount = query.Count() TotalCount = query.Count()
}; };
query = searchModel.Sorting switch
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
{
Id = x.id,
WorkShopId = x.WorkshopId,
Year = x.Year,
YearInt = Convert.ToInt32(x.Year),
Month = x.Month,
MonthName = x.Month.ToFarsiMonthByNumber(),
MonthInt = Convert.ToInt32(x.Month),
EmployerShare = x.EmployerShare.ToMoney(),
InsuredShare = x.InsuredShare.ToMoney(),
UnEmploymentInsurance = x.UnEmploymentInsurance.ToMoney(),
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
{ {
"CreationDate-Max" => query.OrderByDescending(x => x.Id), "CreationDate-Max" => resList.OrderByDescending(x => x.Id).ToList(),
"CreationDate-Min" => query.OrderBy(x => x.Id), "CreationDate-Min" => resList.OrderBy(x => x.Id).ToList(),
"Month-Max" => query.OrderByDescending(x => x.MonthInt), "Month-Max" => resList.OrderByDescending(x => x.MonthInt).ToList(),
"Month-Min" => query.OrderBy(x => x.MonthInt), "Month-Min" => resList.OrderBy(x => x.MonthInt).ToList(),
"Year-Max" => query.OrderByDescending(x => x.YearInt), "Year-Max" => resList.OrderByDescending(x => x.YearInt).ToList(),
"Year-Min" => query.OrderBy(x => x.YearInt), "Year-Min" => resList.OrderBy(x => x.YearInt).ToList(),
_ => query.OrderByDescending(x => x.Id), _ => resList.OrderByDescending(x => x.Id).ToList(),
}; };
res.List =await query.ApplyPagination(searchModel.PageIndex,searchModel.PageSize).ToListAsync();
res.List = resList;
return res; return res;
} }
@@ -1848,38 +1881,38 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
(l.LeftWorkDate == null || l.LeftWorkDate >= firstDayOfMonth))); (l.LeftWorkDate == null || l.LeftWorkDate >= firstDayOfMonth)));
var query = notCreatedWorkshop.Select(result=>new InsuranceListViewModel var query = notCreatedWorkshop.Select(result => new InsuranceListViewModel
{ {
Year = searchModel.Year, Year = searchModel.Year,
Month = searchModel.Month, Month = searchModel.Month,
WorkShopId = result.id, WorkShopId = result.id,
WorkShopCode = result.InsuranceWorkshopInfo != null WorkShopCode = result.InsuranceWorkshopInfo != null
? result.InsuranceWorkshopInfo.InsuranceCode ? result.InsuranceWorkshopInfo.InsuranceCode
: result.InsuranceCode, : result.InsuranceCode,
WorkShopName = result.InsuranceWorkshopInfo != null WorkShopName = result.InsuranceWorkshopInfo != null
? result.InsuranceWorkshopInfo.WorkshopName ? result.InsuranceWorkshopInfo.WorkshopName
: result.WorkshopFullName, : result.WorkshopFullName,
TypeOfInsuranceSend = result.TypeOfInsuranceSend == "NormalList" ? "عادی" : TypeOfInsuranceSend = result.TypeOfInsuranceSend == "NormalList" ? "عادی" :
result.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : result.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" :
result.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", result.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "",
FixedSalary = result.FixedSalary, FixedSalary = result.FixedSalary,
StrFixedSalary = result.FixedSalary ? "دارد" : "ندارد", StrFixedSalary = result.FixedSalary ? "دارد" : "ندارد",
EmployerName = result.InsuranceWorkshopInfo != null EmployerName = result.InsuranceWorkshopInfo != null
? result.InsuranceWorkshopInfo.EmployerName ? result.InsuranceWorkshopInfo.EmployerName
: result.WorkshopFullName, : result.WorkshopFullName,
Branch = "", Branch = "",
City = "", City = "",
ArchiveCode = result.ArchiveCode, ArchiveCode = result.ArchiveCode,
}); });
if (!string.IsNullOrEmpty(searchModel.Month) && searchModel.Month != "0") if (!string.IsNullOrEmpty(searchModel.Month) && searchModel.Month != "0")
query = query.Where(x => x.Month == searchModel.Month).OrderByDescending(x => x.WorkShopName) query = query.Where(x => x.Month == searchModel.Month).OrderByDescending(x => x.WorkShopName)
.ThenByDescending(x => x.EmployerName).ThenByDescending(x => x.Year); .ThenByDescending(x => x.EmployerName).ThenByDescending(x => x.Year);
if (!string.IsNullOrEmpty(searchModel.Year) && searchModel.Year != "0") if (!string.IsNullOrEmpty(searchModel.Year) && searchModel.Year != "0")
query = query.Where(x => x.Year == searchModel.Year).OrderByDescending(x => x.EmployerName) query = query.Where(x => x.Year == searchModel.Year).OrderByDescending(x => x.EmployerName)
.ThenByDescending(x => x.WorkShopName).ThenByDescending(x => x.Month); .ThenByDescending(x => x.WorkShopName).ThenByDescending(x => x.Month);
if (!string.IsNullOrEmpty(searchModel.WorkShopCode)) if (!string.IsNullOrEmpty(searchModel.WorkShopCode))
@@ -1925,41 +1958,112 @@ public class InsuranceListRepository : RepositoryBase<long, InsuranceList>, IIns
var workshopList = await query.Skip(searchModel.PageIndex).Take(30).ToListAsync(); var workshopList = await query.Skip(searchModel.PageIndex).Take(30).ToListAsync();
var workshopIds = workshopList.Select(x=>x.WorkShopId); var workshopIds = workshopList.Select(x => x.WorkShopId);
var employers =await _context.WorkshopEmployers var employers = await _context.WorkshopEmployers
.Where(x=>workshopIds.Contains(x.WorkshopId)) .Where(x => workshopIds.Contains(x.WorkshopId))
.GroupBy(x=>x.WorkshopId) .GroupBy(x => x.WorkshopId)
.Select(x=>x.First()).ToListAsync(); .Select(x => x.First()).ToListAsync();
var res = workshopList.Select(x => var res = workshopList.Select(x =>
{ {
var employer = employers.FirstOrDefault(e => e.WorkshopId ==x.WorkShopId)?.Employer; var employer = employers.FirstOrDefault(e => e.WorkshopId == x.WorkShopId)?.Employer;
return new InsuranceListViewModel return new InsuranceListViewModel
{ {
WorkShopId = x.WorkShopId, WorkShopId = x.WorkShopId,
WorkShopCode = x.WorkShopCode, WorkShopCode = x.WorkShopCode,
WorkShopName = x.WorkShopName, WorkShopName = x.WorkShopName,
EmployerName = employer != null EmployerName = employer != null
? employer.FullName ? employer.FullName
: (x.EmployerName), : (x.EmployerName),
Year = searchModel.Year, Year = searchModel.Year,
Month = searchModel.Month, Month = searchModel.Month,
TypeOfInsuranceSend = x.TypeOfInsuranceSend == "NormalList" ? "عادی" : TypeOfInsuranceSend = x.TypeOfInsuranceSend == "NormalList" ? "عادی" :
x.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : x.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" :
x.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", x.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "",
FixedSalary = (bool)x.FixedSalary, FixedSalary = (bool)x.FixedSalary,
StrFixedSalary = (bool)x.FixedSalary ? "دارد" : "ندارد", StrFixedSalary = (bool)x.FixedSalary ? "دارد" : "ندارد",
EmployerId = employer?.id ?? 0, EmployerId = employer?.id ?? 0,
ArchiveCode = x.ArchiveCode, ArchiveCode = x.ArchiveCode,
City = x.City, City = x.City,
}; };
}).ToList(); }).ToList();
return res; return res;
} }
public async Task<InsuranceClientPrintViewModel> ClientPrintOne(long id)
{
var insurance = await _context.InsuranceListSet.FirstOrDefaultAsync(x => x.id == id);
if (insurance == null)
return null;
var employeeInsurance = _context.EmployeeInsurancListDataSet
.Where(x => x.InsuranceListId == insurance.id);
var workshop = await _context.Workshops
.Include(x => x.InsuranceWorkshopInfo)
.FirstOrDefaultAsync(x => x.id == insurance.WorkshopId);
var employeeIds = await employeeInsurance
.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 jobs = await _context.Jobs
.Where(x => jobIds.Contains(x.id)).ToDictionaryAsync(x => x.id, x => x.JobName);
var employeeData = employeeInsurance.ToList().Select(x =>
{
var employee = employees.FirstOrDefault(e => e.id == x.EmployeeId);
return new InsuranceClientPrintItemsViewModel()
{
BaseYears = x.BaseYears.ToMoney(),
BenefitsIncludedContinuous = x.BenefitsIncludedContinuous.ToMoney(),
BenefitsIncludedNonContinuous = x.BenefitsIncludedNonContinuous.ToMoney(),
DailyWage = x.DailyWage.ToMoney(),
IncludedAndNotIncluded = (x.BenefitsIncludedNonContinuous + x.BenefitsIncludedContinuous).ToMoney(),
WorkingDays = x.WorkingDays.ToString(),
MarriedAllowance = x.MarriedAllowance.ToMoney(),
StartWork = x.StartWorkDate.ToFarsi(),
LeftWork = x.LeftWorkDate.ToFarsi(),
MonthlyBenefits = x.MonthlyBenefits.ToMoney(),
MonthlySalary = x.MonthlySalary.ToMoney(),
NationalCode = employee.NationalCode,
InsuranceCode = employee.InsuranceCode,
JobName = jobs.GetValueOrDefault(x.JobId, ""),
FullName = employee.FullName,
InsuranceShare = x.InsuranceShare.ToMoney(),
};
}).ToList();
var result = new InsuranceClientPrintViewModel()
{
Items = employeeData.ToList(),
AllInsuredShare = (insurance.InsuredShare +
insurance.EmployerShare +
insurance.UnEmploymentInsurance).ToMoney(),
EmployerShare = insurance.EmployerShare.ToMoney(),
InsuredShare = insurance.InsuredShare.ToMoney(),
UnEmploymentInsurance = insurance.UnEmploymentInsurance.ToMoney(),
WorkshopName = workshop.InsuranceWorkshopInfo.WorkshopName,
WorkshopAddress = workshop.InsuranceWorkshopInfo.Address,
WorkshopEmployerName = workshop.InsuranceWorkshopInfo.EmployerName,
WorkshopInsuranceCode = workshop.InsuranceWorkshopInfo.InsuranceCode,
AgreementNumber = workshop.InsuranceWorkshopInfo.AgreementNumber,
ListNo = "01",
Month = insurance.Month,
Year = insurance.Year
};
return result;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@@ -19,4 +19,15 @@ public class InsuranceController:ClientBaseController
var insurances =await _insuranceListApplication.GetInsuranceClientList(searchModel); var insurances =await _insuranceListApplication.GetInsuranceClientList(searchModel);
return Ok(insurances); return Ok(insurances);
} }
[HttpGet("print-one")]
public async Task<ActionResult<InsuranceClientPrintViewModel>> ClientPrintList(long id)
{
InsuranceClientPrintViewModel res = await _insuranceListApplication.ClientPrintOne(id);
return res;
}
}
public class InsuranceClientViewModel
{
} }