Skip to content

Commit 4e157af

Browse files
author
CIS Guru
committed
fix: auto-expire lease updates property status, clears renewal, filters dashboard widget
1 parent ac5ae19 commit 4e157af

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

2-Nine.Application/Services/LeaseService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ public async Task<Lease> UpdateLeaseStatusAsync(Guid leaseId, string newStatus)
502502
if (!hasOtherActiveLeases)
503503
{
504504
property.IsActive = true;
505+
property.Status = ApplicationConstants.PropertyStatuses.Available;
505506
}
506507
}
507508

2-Nine.Application/Services/Workflows/LeaseWorkflowService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,29 @@ public async Task<WorkflowResult<int>> ExpireOverdueLeaseAsync(Guid organization
607607
{
608608
var oldStatus = lease.Status;
609609
lease.Status = ApplicationConstants.LeaseStatuses.Expired;
610+
lease.RenewalStatus = "Expired";
610611
lease.LastModifiedBy = userId;
611612
lease.LastModifiedOn = DateTime.UtcNow;
612613

614+
// Update property status if no other active leases exist for it
615+
if (lease.Property != null)
616+
{
617+
var hasOtherActiveLeases = await _context.Leases
618+
.AnyAsync(l => l.PropertyId == lease.PropertyId
619+
&& l.Id != lease.Id
620+
&& !l.IsDeleted
621+
&& (l.Status == ApplicationConstants.LeaseStatuses.Active
622+
|| l.Status == ApplicationConstants.LeaseStatuses.Pending));
623+
624+
if (!hasOtherActiveLeases)
625+
{
626+
lease.Property.Status = ApplicationConstants.PropertyStatuses.Available;
627+
lease.Property.IsActive = true;
628+
lease.Property.LastModifiedBy = userId;
629+
lease.Property.LastModifiedOn = DateTime.UtcNow;
630+
}
631+
}
632+
613633
await LogTransitionAsync(
614634
"Lease",
615635
lease.Id,

3-Nine.Shared.UI/Components/Entities/Leases/LeaseRenewalList.razor

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,24 @@
135135
var today = DateTime.Today;
136136

137137
leases30Days = Leases
138-
.Where(l => l.EndDate <= today.AddDays(30))
138+
.Where(l => l.Status != "Expired"
139+
&& l.Status != "Terminated"
140+
&& l.EndDate >= today
141+
&& l.EndDate <= today.AddDays(30))
139142
.ToList();
140143

141144
leases60Days = Leases
142-
.Where(l => l.EndDate <= today.AddDays(60))
145+
.Where(l => l.Status != "Expired"
146+
&& l.Status != "Terminated"
147+
&& l.EndDate >= today
148+
&& l.EndDate <= today.AddDays(60))
143149
.ToList();
144150

145151
leases90Days = Leases
146-
.Where(l => l.EndDate <= today.AddDays(90))
152+
.Where(l => l.Status != "Expired"
153+
&& l.Status != "Terminated"
154+
&& l.EndDate >= today
155+
&& l.EndDate <= today.AddDays(90))
147156
.ToList();
148157
}
149158
catch (Exception ex)

0 commit comments

Comments
 (0)