After processing the payment request for Advance payment setting the status to be done
This commit is contained in:
parent
643501ee9e
commit
f22f6c4ad9
@ -1487,7 +1487,7 @@ namespace Marco.Pms.Services.Service
|
||||
|
||||
var nextStatuses = await context.ExpensesStatusMapping
|
||||
.Include(esm => esm.NextStatus)
|
||||
.Where(esm => esm.StatusId == paymentRequest.ExpenseStatusId && esm.NextStatus != null)
|
||||
.Where(esm => esm.StatusId == paymentRequest.ExpenseStatusId && esm.NextStatus != null && !(esm.NextStatusId == Done && paymentRequest.IsAdvancePayment))
|
||||
.Select(esm => esm.NextStatus!)
|
||||
.ToListAsync();
|
||||
|
||||
@ -1920,6 +1920,8 @@ namespace Marco.Pms.Services.Service
|
||||
paymentRequest.ExpenseStatusId = statusTransition.NextStatusId;
|
||||
paymentRequest.ExpenseStatus = statusTransition.NextStatus;
|
||||
|
||||
var updatedAt = DateTime.UtcNow;
|
||||
|
||||
|
||||
// 7. Add Payment details if applicable
|
||||
if (model.StatusId == Processed)
|
||||
@ -1943,29 +1945,68 @@ namespace Marco.Pms.Services.Service
|
||||
paymentRequest.BaseAmount = model.BaseAmount;
|
||||
paymentRequest.TaxAmount = model.TaxAmount;
|
||||
|
||||
var lastTransaction = await _context.AdvancePaymentTransactions.OrderByDescending(apt => apt.CreatedAt).FirstOrDefaultAsync(apt => apt.TenantId == tenantId);
|
||||
double lastBalance = 0;
|
||||
if (lastTransaction != null)
|
||||
if (paymentRequest.IsAdvancePayment)
|
||||
{
|
||||
lastBalance = lastTransaction.CurrentBalance;
|
||||
}
|
||||
var lastTransactionTask = Task.Run(async () =>
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await context.AdvancePaymentTransactions
|
||||
.OrderByDescending(apt => apt.CreatedAt)
|
||||
.FirstOrDefaultAsync(apt => apt.TenantId == tenantId);
|
||||
});
|
||||
|
||||
_context.AdvancePaymentTransactions.Add(new AdvancePaymentTransaction
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
FinanceUIdPostfix = paymentRequest.UIDPostfix,
|
||||
FinanceUIdPrefix = paymentRequest.UIDPrefix,
|
||||
Title = paymentRequest.Title,
|
||||
ProjectId = paymentRequest.ProjectId,
|
||||
EmployeeId = paymentRequest.CreatedById,
|
||||
Amount = paymentRequest.Amount,
|
||||
CurrentBalance = lastBalance + paymentRequest.Amount,
|
||||
PaidAt = model.PaidAt!.Value,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
CreatedById = loggedInEmployee.Id,
|
||||
IsActive = true,
|
||||
TenantId = tenantId
|
||||
});
|
||||
var doneStatusTask = Task.Run(async () =>
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await context.ExpensesStatusMaster.FirstOrDefaultAsync(es => es.Id == Done && es.IsActive);
|
||||
});
|
||||
|
||||
await Task.WhenAll(lastTransactionTask, doneStatusTask);
|
||||
|
||||
var lastTransaction = lastTransactionTask.Result;
|
||||
var doneStatus = doneStatusTask.Result;
|
||||
|
||||
double lastBalance = 0;
|
||||
if (lastTransaction != null)
|
||||
{
|
||||
lastBalance = lastTransaction.CurrentBalance;
|
||||
}
|
||||
|
||||
_context.AdvancePaymentTransactions.Add(new AdvancePaymentTransaction
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
FinanceUIdPostfix = paymentRequest.UIDPostfix,
|
||||
FinanceUIdPrefix = paymentRequest.UIDPrefix,
|
||||
Title = paymentRequest.Title,
|
||||
ProjectId = paymentRequest.ProjectId,
|
||||
EmployeeId = paymentRequest.CreatedById,
|
||||
Amount = paymentRequest.Amount,
|
||||
CurrentBalance = lastBalance + paymentRequest.Amount,
|
||||
PaidAt = model.PaidAt!.Value,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
CreatedById = loggedInEmployee.Id,
|
||||
IsActive = true,
|
||||
TenantId = tenantId
|
||||
});
|
||||
|
||||
if (doneStatus != null)
|
||||
{
|
||||
paymentRequest.ExpenseStatusId = doneStatus.Id;
|
||||
paymentRequest.ExpenseStatus = doneStatus;
|
||||
|
||||
_context.StatusUpdateLogs.Add(new StatusUpdateLog
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
EntityId = paymentRequest.Id,
|
||||
StatusId = statusTransition.NextStatusId,
|
||||
NextStatusId = doneStatus.Id,
|
||||
UpdatedById = loggedInEmployee.Id,
|
||||
UpdatedAt = DateTime.UtcNow.AddMilliseconds(10),
|
||||
Comment = model.Comment,
|
||||
TenantId = tenantId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
@ -2008,7 +2049,7 @@ namespace Marco.Pms.Services.Service
|
||||
StatusId = statusTransition.StatusId,
|
||||
NextStatusId = statusTransition.NextStatusId,
|
||||
UpdatedById = loggedInEmployee.Id,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = updatedAt,
|
||||
Comment = model.Comment,
|
||||
TenantId = tenantId
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user