Returning the list recurring templates while creating payment request from recurring template
This commit is contained in:
parent
ac711c7254
commit
14be381f5f
@ -288,7 +288,10 @@ namespace Marco.Pms.Services.MappingProfiles
|
||||
dest => dest.NextStrikeDate,
|
||||
opt => opt.MapFrom(src => src.StrikeDate.Date));
|
||||
CreateMap<UpdateRecurringTemplateDto, RecurringPayment>();
|
||||
CreateMap<RecurringPayment, RecurringPaymentVM>();
|
||||
CreateMap<RecurringPayment, RecurringPaymentVM>()
|
||||
.ForMember(
|
||||
dest => dest.RecurringPaymentUId,
|
||||
opt => opt.MapFrom(src => $"{src.UIDPrefix}/{src.UIDPostfix:D5}"));
|
||||
CreateMap<RecurringPayment, RecurringPaymentDetailsVM>()
|
||||
.ForMember(
|
||||
dest => dest.RecurringPaymentUID,
|
||||
|
||||
@ -3030,7 +3030,7 @@ namespace Marco.Pms.Services.Service
|
||||
var paymentRequests = new List<PaymentRequest>();
|
||||
|
||||
// Generate UID prefix for payment requests for this period (month/year)
|
||||
string uIDPrefix = $"PR/{DateTime.Now:MM.yy}";
|
||||
string uIDPrefix = $"PR/{DateTime.Now:MMyy}";
|
||||
|
||||
// Get last generated payment request for UID postfixing (to maintain unique numbering)
|
||||
var lastPR = await _context.PaymentRequests
|
||||
@ -3044,13 +3044,18 @@ namespace Marco.Pms.Services.Service
|
||||
{
|
||||
if (recurringPayment.NextStrikeDate.HasValue)
|
||||
{
|
||||
var nextStrikeDate = GetNextStrikeDate(recurringPayment.Frequency, recurringPayment.NextStrikeDate.Value);
|
||||
// Update latest generated date to today (UTC)
|
||||
recurringPayment.LatestPRGeneratedAt = DateTime.UtcNow.Date;
|
||||
recurringPayment.NextStrikeDate = GetNextStrikeDate(recurringPayment.Frequency, recurringPayment.NextStrikeDate.Value, recurringPayment.EndDate);
|
||||
if (recurringPayment.EndDate.Date < DateTime.UtcNow.Date)
|
||||
if (nextStrikeDate.Date > recurringPayment.EndDate.Date)
|
||||
{
|
||||
recurringPayment.NextStrikeDate = null;
|
||||
recurringPayment.StatusId = CompletedTemplateStatus;
|
||||
}
|
||||
else
|
||||
{
|
||||
recurringPayment.NextStrikeDate = nextStrikeDate.Date;
|
||||
}
|
||||
updatedRecurringPayments.Add(recurringPayment);
|
||||
|
||||
// Create new payment request mapped from recurring payment data
|
||||
@ -3101,12 +3106,27 @@ namespace Marco.Pms.Services.Service
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var emails = updatedRecurringPayments.Select(rp => rp.NotifyTo.Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)).ToList();
|
||||
var newRecurringTemplateIds = updatedRecurringPayments.Select(rp => rp.Id).ToList();
|
||||
|
||||
var newRecurringPayments = await _context.RecurringPayments
|
||||
.Include(rp => rp.Currency)
|
||||
.Include(rp => rp.ExpenseCategory)
|
||||
.Include(rp => rp.Status)
|
||||
.Include(rp => rp.Project)
|
||||
.AsNoTracking()
|
||||
.Where(rp => newRecurringTemplateIds.Contains(rp.Id))
|
||||
.ToListAsync();
|
||||
|
||||
_logger.LogInfo("{Count} payment requests created successfully from recurring payments by EmployeeId: {EmployeeId} for TenantId: {TenantId}",
|
||||
paymentRequests.Count, loggedInEmployee.Id, tenantId);
|
||||
|
||||
return ApiResponse<object>.SuccessResponse(emails, $"{paymentRequests.Count} conversion(s) to payment request completed successfully.", 201);
|
||||
var response = newRecurringPayments.Select(rp => new
|
||||
{
|
||||
RecurringPayment = _mapper.Map<RecurringPaymentVM>(rp),
|
||||
Emails = rp.NotifyTo.Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
}).ToList();
|
||||
|
||||
return ApiResponse<object>.SuccessResponse(response, $"{paymentRequests.Count} conversion(s) to payment request completed successfully.", 201);
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
@ -3881,7 +3901,7 @@ namespace Marco.Pms.Services.Service
|
||||
return null; // Validation successful, no error
|
||||
}
|
||||
|
||||
private DateTime? GetNextStrikeDate(PLAN_FREQUENCY frequency, DateTime currentStrikeDate, DateTime endDate)
|
||||
private DateTime GetNextStrikeDate(PLAN_FREQUENCY frequency, DateTime currentStrikeDate)
|
||||
{
|
||||
var nextStrikeDate = currentStrikeDate.AddDays(1);
|
||||
switch (frequency)
|
||||
@ -3909,10 +3929,6 @@ namespace Marco.Pms.Services.Service
|
||||
nextStrikeDate = currentStrikeDate.AddDays(7);
|
||||
break;
|
||||
}
|
||||
if (endDate < nextStrikeDate)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return nextStrikeDate;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user