Merge branch 'Feature/institution-contract/refactor-list'
This commit is contained in:
@@ -24,9 +24,13 @@ public class CustomExceptionHandler : IExceptionHandler
|
||||
|
||||
public async ValueTask<bool> TryHandleAsync(HttpContext context, Exception exception, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogError(
|
||||
"Error Message: {exceptionMessage}, Time of occurrence {time}",
|
||||
exception.Message, DateTime.UtcNow);
|
||||
_logger.LogError(exception,
|
||||
"Error Message: {exceptionMessage}, Type: {exceptionType}, Time: {time}, Path: {path}, TraceId: {traceId}",
|
||||
exception.Message,
|
||||
exception.GetType().FullName,
|
||||
DateTime.UtcNow,
|
||||
context.Request.Path,
|
||||
context.TraceIdentifier);
|
||||
|
||||
(string Detail, string Title, int StatusCode, Dictionary<string, object>? Extra) details = exception switch
|
||||
{
|
||||
|
||||
@@ -91,6 +91,11 @@ public class GetInstitutionContractListItemsViewModel
|
||||
public bool IsInPersonContract { get; set; }
|
||||
|
||||
public bool IsOldContract { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// مبلغ قسط
|
||||
/// </summary>
|
||||
public double InstallmentAmount { get; set; }
|
||||
}
|
||||
|
||||
public class InstitutionContractListWorkshop
|
||||
|
||||
@@ -1098,26 +1098,41 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
public async Task<PagedResult<GetInstitutionContractListItemsViewModel>> GetList(
|
||||
InstitutionContractListSearchModel searchModel)
|
||||
{
|
||||
var query = _context.InstitutionContractSet
|
||||
.Include(x => x.WorkshopGroup)
|
||||
.ThenInclude(x => x.InitialWorkshops)
|
||||
.Include(x => x.WorkshopGroup)
|
||||
.ThenInclude(x => x.CurrentWorkshops)
|
||||
.Include(x => x.ContactInfoList).AsNoTracking();
|
||||
|
||||
var now = DateTime.Today;
|
||||
var nowFa = now.ToFarsi();
|
||||
var endFa = nowFa.FindeEndOfMonth();
|
||||
var endThisMontGr = endFa.ToGeorgianDateTime();
|
||||
|
||||
var joinedQuery = query.Join(_context.PersonalContractingParties
|
||||
var contractsWithExtension = await _context.InstitutionContractSet
|
||||
.Where(x => x.IsActiveString == "true")
|
||||
.Select(x => new { x.ContractingPartyId, x.ExtensionNo })
|
||||
.ToListAsync();
|
||||
|
||||
// var contractsWithExtensionLookup = contractsWithExtension
|
||||
// .GroupBy(x => x.ContractingPartyId)
|
||||
// .ToDictionary(
|
||||
// g => g.Key,
|
||||
// g => g.Max(x => x.ExtensionNo)
|
||||
// );
|
||||
|
||||
var rawQuery = _context.InstitutionContractSet
|
||||
.Include(x=>x.Installments)
|
||||
.AsNoTracking()
|
||||
.Join(_context.PersonalContractingParties
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Employers)
|
||||
.ThenInclude(x => x.WorkshopEmployers)
|
||||
.ThenInclude(x => x.Workshop),
|
||||
contract => contract.ContractingPartyId,
|
||||
contractingParty => contractingParty.id,
|
||||
(contract, contractingParty) => new { contract, contractingParty })
|
||||
.Select(x => new
|
||||
(contract, contractingParty) => new { contract, contractingParty });
|
||||
|
||||
// var pendingForRenewalContracts = _context.InstitutionContractSet.AsNoTracking()
|
||||
// .Where(c => c.IsActiveString == "true" &&
|
||||
// c.ContractEndGr >= now &&
|
||||
// c.ContractEndGr <= endThisMontGr);
|
||||
|
||||
var joinedQuery = rawQuery.Select(x => new
|
||||
{
|
||||
x.contract,
|
||||
x.contractingParty,
|
||||
@@ -1138,7 +1153,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
: x.contract.ContractAmount == 0
|
||||
? (int)InstitutionContractListStatus.Free
|
||||
: !x.contractingParty.Employers
|
||||
.SelectMany(e => e.WorkshopEmployers.Select(we => we.Workshop)).Any()
|
||||
.SelectMany(e => e.WorkshopEmployers
|
||||
.Select(we => we.Workshop)).Any()
|
||||
? (int)InstitutionContractListStatus.WithoutWorkshop
|
||||
: (int)InstitutionContractListStatus.Active
|
||||
});
|
||||
@@ -1301,6 +1317,15 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
var list = await orderedQuery.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync();
|
||||
var contractingPartyIds = list.Select(x => x.contractingParty.id).ToList();
|
||||
var contractIds = list.Select(x => x.contract.id).ToList();
|
||||
|
||||
// بارگذاری WorkshopGroups فقط برای قراردادهای صفحه فعلی
|
||||
var workshopGroups = await _context.InstitutionContractWorkshopGroups
|
||||
.AsNoTracking()
|
||||
.Include(x=>x.InitialWorkshops )
|
||||
.Include(x => x.CurrentWorkshops)
|
||||
.Where(x => contractIds.Contains(x.InstitutionContractId))
|
||||
.ToDictionaryAsync(x => x.InstitutionContractId, x => x);
|
||||
|
||||
var financialStatements = _context.FinancialStatments.Include(x => x.FinancialTransactionList)
|
||||
.Where(x => contractingPartyIds.Contains(x.ContractingPartyId)).ToList();
|
||||
@@ -1324,13 +1349,19 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
|
||||
var archiveCode = minArchiveCode == 10000000 ? 0 : minArchiveCode;
|
||||
var status = Enum.Parse<InstitutionContractListStatus>(x.StatusPriority.ToString());
|
||||
List<InstitutionContractWorkshopBase> currentStateWorkshops = x.contract.WorkshopGroup?.CurrentWorkshops
|
||||
|
||||
// دریافت WorkshopGroup از dictionary بارگذاری شده
|
||||
workshopGroups.TryGetValue(x.contract.id, out var workshopGroup);
|
||||
|
||||
List<InstitutionContractWorkshopBase> currentStateWorkshops = workshopGroup?.CurrentWorkshops
|
||||
.Cast<InstitutionContractWorkshopBase>().ToList();
|
||||
|
||||
var statement = financialStatements.FirstOrDefault(f => f.ContractingPartyId == x.contractingParty.id);
|
||||
|
||||
currentStateWorkshops?.AddRange(
|
||||
x.contract.WorkshopGroup?.InitialWorkshops.Where(w => !w.WorkshopCreated) ?? []);
|
||||
if (currentStateWorkshops != null && workshopGroup != null)
|
||||
{
|
||||
currentStateWorkshops.AddRange(workshopGroup.InitialWorkshops.Where(w => !w.WorkshopCreated));
|
||||
}
|
||||
|
||||
var workshopDetails = currentStateWorkshops?.Select(w =>
|
||||
{
|
||||
@@ -1360,9 +1391,28 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
var employeesCount = _context.LeftWorkList
|
||||
.Where(l => workshops.Select(w => w.id).Contains(l.WorkshopId))
|
||||
.Count(l => l.StartWorkDate <= DateTime.Now && l.LeftWorkDate >= DateTime.Now);
|
||||
|
||||
|
||||
var contractAmount = x.contract.SigningType is not InstitutionContractSigningType.Legacy
|
||||
&& !x.contract.IsInstallment?
|
||||
x.contract.TotalAmount:0;
|
||||
|
||||
var installmentAmount = 0d;
|
||||
try
|
||||
{
|
||||
installmentAmount =x.contract.SigningType == InstitutionContractSigningType.Legacy
|
||||
?x.contract.ContractAmount : x.contract.IsInstallment ? x.contract.Installments.First().Amount :0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
return new GetInstitutionContractListItemsViewModel()
|
||||
{
|
||||
ContractAmount = x.contract.ContractAmountWithTax,
|
||||
ContractAmount = contractAmount,
|
||||
InstallmentAmount = installmentAmount,
|
||||
Balance = statement?.FinancialTransactionList.Sum(ft => ft.Deptor - ft.Creditor) ?? 0,
|
||||
WorkshopsCount = workshops.Count(),
|
||||
ContractStartFa = x.contract.ContractStartGr.ToFarsi(),
|
||||
@@ -1380,7 +1430,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
IsExpired = x.contract.ContractEndGr <= endThisMontGr,
|
||||
ContractingPartyId = x.contractingParty.id,
|
||||
Workshops = workshopDetails,
|
||||
IsInPersonContract = x.contract.WorkshopGroup?.CurrentWorkshops
|
||||
IsInPersonContract = workshopGroup?.CurrentWorkshops
|
||||
.Any(y => y.Services.ContractInPerson) ?? true,
|
||||
IsOldContract = x.contract.SigningType == InstitutionContractSigningType.Legacy
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user