refactor: enhance error logging and add installment amount to institution contract view model
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
|
||||
|
||||
@@ -1108,14 +1108,15 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
.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 contractsWithExtensionLookup = contractsWithExtension
|
||||
// .GroupBy(x => x.ContractingPartyId)
|
||||
// .ToDictionary(
|
||||
// g => g.Key,
|
||||
// g => g.Max(x => x.ExtensionNo)
|
||||
// );
|
||||
|
||||
var joinedQuery = _context.InstitutionContractSet
|
||||
var rawQuery = _context.InstitutionContractSet
|
||||
.Include(x=>x.Installments)
|
||||
.AsNoTracking()
|
||||
.Join(_context.PersonalContractingParties
|
||||
.AsNoTracking()
|
||||
@@ -1124,8 +1125,14 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
.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,
|
||||
@@ -1384,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(),
|
||||
|
||||
Reference in New Issue
Block a user