Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS83 scaffold changes, also includes many renames from term to period. #4136

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IActionResult AddPayment(long leaseId, [FromBody] PaymentModel paymentMod
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(LeasePaymentController),
nameof(AddPayment),
User.GetUsername(),
DateTime.Now);
Expand All @@ -89,7 +89,7 @@ public IActionResult UpdatePayment(long leaseId, long paymentId, [FromBody] Paym
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(LeasePaymentController),
nameof(UpdatePayment),
User.GetUsername(),
DateTime.Now);
Expand All @@ -114,7 +114,7 @@ public IActionResult DeletePayment(long leaseId, PaymentModel paymentModel)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(LeasePaymentController),
nameof(DeletePayment),
User.GetUsername(),
DateTime.Now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@
namespace Pims.Api.Areas.Lease.Controllers
{
/// <summary>
/// LeaseTermController class, provides endpoints for interacting with lease property terms.
/// LeasePeriodController class, provides endpoints for interacting with lease property periods.
/// </summary>
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Area("leases")]
[Route("v{version:apiVersion}/[area]")]
[Route("[area]")]
public class LeaseTermController : ControllerBase
public class LeasePeriodController : ControllerBase
{
#region Variables
private readonly ILeaseTermService _leaseTermService;
private readonly ILeasePeriodService _LeasePeriodService;
private readonly IMapper _mapper;
private readonly ILogger _logger;
#endregion

#region Constructors

/// <summary>
/// Creates a new instance of a LeaseTermController class, initializes it with the specified arguments.
/// Creates a new instance of a LeasePeriodController class, initializes it with the specified arguments.
/// </summary>
/// <param name="leaseTermService"></param>
/// <param name="LeasePeriodService"></param>
/// <param name="mapper"></param>
/// <param name="logger"></param>
///
public LeaseTermController(ILeaseTermService leaseTermService, IMapper mapper, ILogger<PropertyImprovementController> logger)
public LeasePeriodController(ILeasePeriodService LeasePeriodService, IMapper mapper, ILogger<PropertyImprovementController> logger)
{
_leaseTermService = leaseTermService;
_LeasePeriodService = LeasePeriodService;
_mapper = mapper;
_logger = logger;
}
Expand All @@ -52,102 +52,102 @@ public LeaseTermController(ILeaseTermService leaseTermService, IMapper mapper, I
#region Endpoints

/// <summary>
/// Update the specified term on the passed lease.
/// Update the specified period on the passed lease.
/// </summary>
/// <returns></returns>
[HttpGet("{leaseId:long}/terms")]
[HttpGet("{leaseId:long}/periods")]
[HasPermission(Permissions.LeaseView)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<LeaseTermModel>), 200)]
[ProducesResponseType(typeof(IEnumerable<LeasePeriodModel>), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult GetTerms(long leaseId)
public IActionResult GetPeriods(long leaseId)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(GetTerms),
nameof(LeasePeriodController),
nameof(GetPeriods),
User.GetUsername(),
DateTime.Now);

var terms = _leaseTermService.GetTerms(leaseId);
var periods = _LeasePeriodService.GetPeriods(leaseId);

return new JsonResult(_mapper.Map<IEnumerable<LeaseTermModel>>(terms));
return new JsonResult(_mapper.Map<IEnumerable<LeasePeriodModel>>(periods));
}

/// <summary>
/// Update the specified term on the passed lease.
/// Update the specified period on the passed lease.
/// </summary>
/// <returns></returns>
[HttpPost("{leaseId:long}/terms")]
[HttpPost("{leaseId:long}/periods")]
[HasPermission(Permissions.LeaseAdd)]
[Produces("application/json")]
[ProducesResponseType(typeof(LeaseTermModel), 200)]
[ProducesResponseType(typeof(LeasePeriodModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult AddTerm(long leaseId, [FromBody] LeaseTermModel termModel)
public IActionResult AddPeriod(long leaseId, [FromBody] LeasePeriodModel periodModel)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(AddTerm),
nameof(LeasePeriodController),
nameof(AddPeriod),
User.GetUsername(),
DateTime.Now);

var termEntity = _mapper.Map<PimsLeaseTerm>(termModel);
var updatedLease = _leaseTermService.AddTerm(leaseId, termEntity);
var periodEntity = _mapper.Map<PimsLeasePeriod>(periodModel);
var updatedLease = _LeasePeriodService.AddPeriod(leaseId, periodEntity);

return new JsonResult(_mapper.Map<LeaseTermModel>(updatedLease));
return new JsonResult(_mapper.Map<LeasePeriodModel>(updatedLease));
}

/// <summary>
/// Update the specified term on the passed lease.
/// Update the specified period on the passed lease.
/// </summary>
/// <returns></returns>
[HttpPut("{leaseId:long}/terms/{termId:long}")]
[HttpPut("{leaseId:long}/periods/{periodId:long}")]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(LeaseTermModel), 200)]
[ProducesResponseType(typeof(LeasePeriodModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdateTerm(long leaseId, long termId, [FromBody] LeaseTermModel termModel)
public IActionResult UpdatePeriod(long leaseId, long periodId, [FromBody] LeasePeriodModel periodModel)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(UpdateTerm),
nameof(LeasePeriodController),
nameof(UpdatePeriod),
User.GetUsername(),
DateTime.Now);

var termEntity = _mapper.Map<PimsLeaseTerm>(termModel);
var updatedLease = _leaseTermService.UpdateTerm(leaseId, termId, termEntity);
var periodEntity = _mapper.Map<PimsLeasePeriod>(periodModel);
var updatedLease = _LeasePeriodService.UpdatePeriod(leaseId, periodId, periodEntity);

return new JsonResult(_mapper.Map<LeaseTermModel>(updatedLease));
return new JsonResult(_mapper.Map<LeasePeriodModel>(updatedLease));
}

/// <summary>
/// Delete the specified term on the passed lease.
/// Delete the specified period on the passed lease.
/// </summary>
/// <returns></returns>
[HttpDelete("{leaseId:long}/terms")]
[HttpDelete("{leaseId:long}/periods")]
[HasPermission(Permissions.LeaseEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(LeaseTermModel), 200)]
[ProducesResponseType(typeof(LeasePeriodModel), 200)]
[SwaggerOperation(Tags = new[] { "lease" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult DeleteTerm(long leaseId, LeaseTermModel termModel)
public IActionResult DeletePeriod(long leaseId, LeasePeriodModel periodModel)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(LeaseTermController),
nameof(DeleteTerm),
nameof(LeasePeriodController),
nameof(DeletePeriod),
User.GetUsername(),
DateTime.Now);

var termEntity = _mapper.Map<PimsLeaseTerm>(termModel);
var updatedLease = _leaseTermService.DeleteTerm(leaseId, termEntity);
var periodEntity = _mapper.Map<PimsLeasePeriod>(periodModel);
var updatedLease = _LeasePeriodService.DeletePeriod(leaseId, periodEntity);

return new JsonResult(_mapper.Map<LeaseTermModel>(updatedLease));
return new JsonResult(_mapper.Map<LeasePeriodModel>(updatedLease));
}
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,17 @@ public IActionResult ExportLeasePayments(int fiscalYearStart)
#endregion

/// <summary>
/// Create duplicate lease rows for every unique property lease, tenant, and term.
/// Create duplicate lease rows for every unique property lease, tenant, and period.
/// </summary>
/// <param name="filter"></param>
/// <param name="all"></param>
/// <returns></returns>
public IEnumerable<LeaseModel> GetCrossJoinLeases(Lease.Models.Search.LeaseFilterModel filter, bool all = false)
{
var page = _leaseService.GetPage((LeaseFilter)filter, all);
var allLeases = page.Items.SelectMany(l => l.PimsLeaseTerms.DefaultIfEmpty(), (lease, term) => (lease, term))
.SelectMany(lt => lt.lease.PimsPropertyLeases.DefaultIfEmpty(), (leaseTerm, property) => (leaseTerm.term, leaseTerm.lease, property))
.SelectMany(ltp => ltp.lease.PimsLeaseTenants.DefaultIfEmpty(), (leaseTermProperty, tenant) => (leaseTermProperty.term, leaseTermProperty.lease, leaseTermProperty.property, tenant));
var allLeases = page.Items.SelectMany(l => l.PimsLeasePeriods.DefaultIfEmpty(), (lease, period) => (lease, period))
.SelectMany(lt => lt.lease.PimsPropertyLeases.DefaultIfEmpty(), (leasePeriod, property) => (leasePeriod.period, leasePeriod.lease, property))
.SelectMany(ltp => ltp.lease.PimsLeaseTenants.DefaultIfEmpty(), (leasePeriodProperty, tenant) => (leasePeriodProperty.period, leasePeriodProperty.lease, leasePeriodProperty.property, tenant));
var flatLeases = _mapper.Map<IEnumerable<LeaseModel>>(allLeases);
return flatLeases;
}
Expand Down
18 changes: 9 additions & 9 deletions source/backend/api/Areas/Reports/Mapping/Lease/LeaseMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ public class LeaseMap : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<(Entity.PimsLeaseTerm term, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseTenant tenant), Model.LeaseModel>()
config.NewConfig<(Entity.PimsLeasePeriod period, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseTenant tenant), Model.LeaseModel>()
.AfterMapping((src, dest) =>
{
MapLease(src, dest);
});
}

private static void MapLease((Entity.PimsLeaseTerm term, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseTenant tenant) src, Model.LeaseModel dest)
private static void MapLease((Entity.PimsLeasePeriod period, Entity.PimsLease lease, Entity.PimsPropertyLease property, Entity.PimsLeaseTenant tenant) src, Model.LeaseModel dest)
{
dest.LFileNo = src.lease.LFileNo;
dest.MotiRegion = src.lease.RegionCodeNavigation?.RegionName;
dest.StartDate = src.lease.OrigStartDate.FilterSqlMinDate().ToNullableDateOnly();
dest.EndDate = src.lease.OrigExpiryDate?.FilterSqlMinDate().ToNullableDateOnly();
dest.CurrentTermStartDate = src.lease.GetCurrentTermStartDate()?.FilterSqlMinDate().ToNullableDateOnly();
dest.CurrentTermEndDate = src.lease.GetCurrentTermEndDate()?.FilterSqlMinDate().ToNullableDateOnly();
dest.CurrentPeriodStartDate = src.lease.GetCurrentPeriodStartDate()?.FilterSqlMinDate().ToNullableDateOnly();
dest.CurrentTermEndDate = src.lease.GetCurrentPeriodEndDate()?.FilterSqlMinDate().ToNullableDateOnly();
dest.ProgramName = src.lease.LeaseProgramTypeCodeNavigation?.GetTypeDescriptionOther(src.lease.OtherLeaseProgramType);
dest.PurposeType = src.lease.LeasePurposeTypeCodeNavigation?.GetTypeDescriptionOther(src.lease.OtherLeasePurposeType);
dest.StatusType = src.lease.LeaseStatusTypeCodeNavigation?.Description;
Expand All @@ -37,11 +37,11 @@ private static void MapLease((Entity.PimsLeaseTerm term, Entity.PimsLease lease,
dest.InspectionDate = src.lease.InspectionDate?.FilterSqlMinDate();
dest.LeaseNotes = src.lease.LeaseNotes;
dest.IsExpired = (src.lease.GetExpiryDate() < DateTime.Now).BoolToYesNo();
dest.LeaseAmount = src.term?.PaymentAmount;
dest.TermStartDate = src.term?.TermStartDate.FilterSqlMinDate().ToNullableDateOnly();
dest.TermExpiryDate = src.term?.TermExpiryDate?.FilterSqlMinDate().ToNullableDateOnly();
dest.TermRenewalDate = src.term?.TermRenewalDate?.FilterSqlMinDate().ToNullableDateOnly();
dest.LeasePaymentFrequencyType = src.term?.LeasePmtFreqTypeCodeNavigation?.Description;
dest.LeaseAmount = src.period?.PaymentAmount;
dest.PeriodStartDate = src.period?.PeriodStartDate.FilterSqlMinDate().ToNullableDateOnly();
dest.PeriodExpiryDate = src.period?.PeriodExpiryDate?.FilterSqlMinDate().ToNullableDateOnly();
dest.PeriodRenewalDate = src.period?.PeriodRenewalDate?.FilterSqlMinDate().ToNullableDateOnly();
dest.LeasePaymentFrequencyType = src.period?.LeasePmtFreqTypeCodeNavigation?.Description;
dest.CivicAddress = src.property?.Property?.Address?.FormatAddress(true);
dest.Pid = src.property?.Property?.Pid;
dest.Pin = src.property?.Property?.Pin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public AggregatedLeaseModel(IEnumerable<PimsLease> leases, int fiscalYear, strin

DateTime fiscalYearStartDate = fiscalYear.ToFiscalYearDate();
DateTime fiscalYearEndDate = fiscalYearStartDate.AddYears(1);
var terms = leases.SelectMany(l => l.PimsLeaseTerms).Where(t => t.TermStartDate <= fiscalYearEndDate
&& (t.TermExpiryDate >= fiscalYearStartDate || t.TermExpiryDate == null));
var payments = terms.SelectMany(t => t.PimsLeasePayments).Where(p => p.PaymentReceivedDate <= fiscalYearEndDate && (p.PaymentReceivedDate >= fiscalYearStartDate));
var periods = leases.SelectMany(l => l.PimsLeasePeriods).Where(t => t.PeriodStartDate <= fiscalYearEndDate
&& (t.PeriodExpiryDate >= fiscalYearStartDate || t.PeriodExpiryDate == null));
var payments = periods.SelectMany(t => t.PimsLeasePayments).Where(p => p.PaymentReceivedDate <= fiscalYearEndDate && (p.PaymentReceivedDate >= fiscalYearStartDate));

this.Region = region;
this.Program = program;
AgreementCount = leases.Count(l => l.PimsLeaseTerms.Any(t => t.TermStartDate <= fiscalYearEndDate && (t.TermExpiryDate >= fiscalYearStartDate || t.TermExpiryDate == null)));
AgreementCount = leases.Count(l => l.PimsLeasePeriods.Any(t => t.PeriodStartDate <= fiscalYearEndDate && (t.PeriodExpiryDate >= fiscalYearStartDate || t.PeriodExpiryDate == null)));
ActualTotal = payments.Aggregate((decimal)0, (sum, payment) => sum + payment.PaymentAmountPreTax);
ExpectedTotal = terms.Aggregate((decimal)0, (sum, term) => sum + term.PaymentAmount ?? 0);
ExpectedTotal = periods.Aggregate((decimal)0, (sum, period) => sum + period.PaymentAmount ?? 0);
ActualsByMonth = new decimal[12];
foreach (var (value, index) in ActualsByMonth.Select((value, index) => (value, index)))
{
Expand Down
8 changes: 4 additions & 4 deletions source/backend/api/Areas/Reports/Models/Lease/LeaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LeaseModel

[DisplayName("Current Term Start Date")]
[CsvHelper.Configuration.Attributes.Name("Current Term Start Date")]
public DateOnly? CurrentTermStartDate { get; set; }
public DateOnly? CurrentPeriodStartDate { get; set; }

[DisplayName("Current Term End Date")]
[CsvHelper.Configuration.Attributes.Name("Current Term End Date")]
Expand Down Expand Up @@ -79,15 +79,15 @@ public class LeaseModel

[DisplayName("Term Start Date")]
[CsvHelper.Configuration.Attributes.Name("Term Start Date")]
public DateOnly? TermStartDate { get; set; }
public DateOnly? PeriodStartDate { get; set; }

[DisplayName("Term Renewal Date")]
[CsvHelper.Configuration.Attributes.Name("Term Renewal Date")]
public DateOnly? TermRenewalDate { get; set; }
public DateOnly? PeriodRenewalDate { get; set; }

[DisplayName("Term Expiry Date")]
[CsvHelper.Configuration.Attributes.Name("Term Expiry Date")]
public DateOnly? TermExpiryDate { get; set; }
public DateOnly? PeriodExpiryDate { get; set; }

[DisplayName("Lease Payment Frequency")]
[CsvHelper.Configuration.Attributes.Name("Lease Payment Frequency")]
Expand Down
4 changes: 2 additions & 2 deletions source/backend/api/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public IActionResult GetAll()
var leasePurposeTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeasePurposeTypes());
var leaseResponsibilityTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeaseResponsibilityTypes());
var leaseStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeaseStatusTypes());
var leaseTermStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeaseTermStatusTypes());
var leasePeriodStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeasePeriodStatusTypes());
var leaseTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllLeaseTypes());
var organizationTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllOrganizationTypes());
var propertyImprovementTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllPropertyImprovementTypes());
Expand Down Expand Up @@ -167,7 +167,7 @@ public IActionResult GetAll()
codes.AddRange(leasePurposeTypes);
codes.AddRange(leaseResponsibilityTypes);
codes.AddRange(leaseStatusTypes);
codes.AddRange(leaseTermStatusTypes);
codes.AddRange(leasePeriodStatusTypes);
codes.AddRange(leaseTypes);
codes.AddRange(organizationTypes);
codes.AddRange(propertyImprovementTypes);
Expand Down
Loading
Loading