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

psp-8772 lease payment export corrections. #4170

Merged
merged 7 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -184,11 +184,11 @@ public IActionResult ExportLeasePayments(int fiscalYearStart)

DateTime startDate = fiscalYearStart.ToFiscalYearDate();
var allPayments = _leasePaymentService.GetAllByDateRange(startDate, startDate.AddYears(1).AddDays(-1)); // Add years will give you the equivalent month, except for 29th/ 28th of leap years which is not the case here.
var paymentItems = _mapper.Map<IEnumerable<LeasePaymentReportModel>>(allPayments);
var paymentItems = _mapper.Map<IEnumerable<LeasePaymentReportModel>>(allPayments.OrderBy(p => p?.LeasePeriod?.Lease?.RegionCode).ThenBy(p => p?.LeasePeriod?.Lease?.LFileNo).ThenByDescending(p => p.PaymentReceivedDate));

return acceptHeader.ToString() switch
{
ContentTypes.CONTENTTYPECSV => ReportHelper.GenerateCsv<LeasePaymentReportModel>(paymentItems.OrderBy(p => p.Region).ThenBy(p => p.LFileNumber).ThenByDescending(p => p.PaymentReceivedDate)),
ContentTypes.CONTENTTYPECSV => ReportHelper.GenerateCsv<LeasePaymentReportModel>(paymentItems),
_ => ReportHelper.GenerateExcel(paymentItems, $"LeaseLicense_Payments")
};
}
Expand Down
7 changes: 4 additions & 3 deletions source/backend/api/Models/Report/LeasePaymentReportMap.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using Mapster;
using Pims.Api.Services;
using Pims.Core.Helpers;
using Pims.Dal.Entities;
using Pims.Dal.Helpers.Extensions;
Expand Down Expand Up @@ -29,12 +30,12 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.PaymentDueString, src => src.LeasePeriod.PaymentDueDate)
.Map(dest => dest.ExpectedPayment, src => src.LeasePeriod.PaymentAmount)
.Map(dest => dest.PaymentTotal, src => src.PaymentAmountTotal)
.Map(dest => dest.PaymentStatus, src => src.LeasePaymentStatusTypeCodeNavigation != null ? src.LeasePaymentStatusTypeCodeNavigation.Description : string.Empty)
.Map(dest => dest.PaymentStatus, src => src.LeasePaymentStatusTypeCodeNavigation != null ? src.LeasePaymentStatusTypeCodeNavigation.Description : LeasePaymentService.GetPaymentStatus(src, src.LeasePeriod))
.Map(dest => dest.PaymentAmount, src => src.PaymentAmountPreTax)
.Map(dest => dest.PaymentGst, src => src.PaymentAmountGst)
.Map(dest => dest.PaymentReceivedDate, src => src.PaymentReceivedDate.ToString("MMMM dd, yyyy"))
.Map(dest => dest.LatestPaymentDate, src => src.LeasePeriod.PimsLeasePayments.OrderByDescending(lp => lp.PaymentReceivedDate).FirstOrDefault() != null ?
src.LeasePeriod.PimsLeasePayments.OrderByDescending(lp => lp.PaymentReceivedDate).FirstOrDefault().PaymentReceivedDate.ToString("MMMM dd, yyyy") : string.Empty);
.Map(dest => dest.LatestPaymentDate, src => src.LeasePeriod.Lease.PimsLeasePeriods.SelectMany(lp => lp.PimsLeasePayments).OrderByDescending(lp => lp.PaymentReceivedDate).FirstOrDefault() != null ?
src.LeasePeriod.Lease.PimsLeasePeriods.SelectMany(lp => lp.PimsLeasePayments).OrderByDescending(lp => lp.PaymentReceivedDate).FirstOrDefault().PaymentReceivedDate.ToString("MMMM dd, yyyy") : string.Empty);
}

private static string GetFallbackPropertyIdentifier(PimsPropertyLease propertyLease)
Expand Down
5 changes: 2 additions & 3 deletions source/backend/api/Services/LeasePaymentService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using Pims.Api.Models.CodeTypes;
using Pims.Dal.Entities;
Expand All @@ -22,7 +21,7 @@ public LeasePaymentService(ILeasePeriodRepository leasePeriodRepository, ILeaseP

public IEnumerable<PimsLeasePayment> GetAllByDateRange(DateTime startDate, DateTime endDate)
{
return _leasePaymentRepository.GetAll(startDate, endDate);
return _leasePaymentRepository.GetAllTracking(startDate, endDate);
}

public bool DeletePayment(long leaseId, PimsLeasePayment payment)
Expand Down Expand Up @@ -58,7 +57,7 @@ public static string GetPaymentStatus(PimsLeasePayment payment, PimsLeasePeriod
{
if (!Enum.TryParse(payment.LeasePaymentCategoryTypeCode, out LeasePaymentCategoryTypes leasePaymentCategoryType))
{
throw new InvalidOperationException();
payment.LeasePaymentCategoryTypeCode = LeasePaymentCategoryTypes.BASE.ToString();
}
decimal? expectedTotal;
switch (leasePaymentCategoryType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface ILeasePaymentRepository : IRepository

PimsLeasePayment Add(PimsLeasePayment pimsLeasePayment);

IEnumerable<PimsLeasePayment> GetAll(DateTime startDate, DateTime endDate);
IEnumerable<PimsLeasePayment> GetAllTracking(DateTime startDate, DateTime endDate);
}
}
9 changes: 7 additions & 2 deletions source/backend/dal/Repositories/LeasePaymentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PimsLeasePayment Add(PimsLeasePayment pimsLeasePayment)
return updatedEntity.Entity;
}

public IEnumerable<PimsLeasePayment> GetAll(DateTime startDate, DateTime endDate)
public IEnumerable<PimsLeasePayment> GetAllTracking(DateTime startDate, DateTime endDate)
{
return this.Context.PimsLeasePayments
.Include(p => p.LeasePaymentCategoryTypeCodeNavigation)
Expand Down Expand Up @@ -72,7 +72,12 @@ public IEnumerable<PimsLeasePayment> GetAll(DateTime startDate, DateTime endDate
.Include(p => p.LeasePeriod)
.ThenInclude(t => t.LeasePeriodStatusTypeCodeNavigation)
.Include(p => p.LeasePeriod)
.ThenInclude(t => t.LeasePmtFreqTypeCodeNavigation).Where(p => p.PaymentReceivedDate <= endDate && p.PaymentReceivedDate >= startDate).AsNoTracking();
.ThenInclude(t => t.LeasePmtFreqTypeCodeNavigation)
.Include(p => p.LeasePeriod)
.ThenInclude(t => t.Lease)
.ThenInclude(t => t.PimsLeasePeriods)
.ThenInclude(t => t.PimsLeasePayments)
.Where(p => p.PaymentReceivedDate <= endDate && p.PaymentReceivedDate >= startDate);
}
}
}
37 changes: 37 additions & 0 deletions source/backend/tests/unit/api/Mapping/LeasePaymentReportMapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,49 @@ public void MapLeasePaymentReport_LastPaymentDate()
var leasePaymentOlder = new PimsLeasePayment() { PaymentReceivedDate = DateTime.Now.AddDays(-2) };

leasePayment.LeasePeriod = new PimsLeasePeriod() { Lease = lease, PimsLeasePayments = new List<PimsLeasePayment>() { leasePaymentOld, leasePayment, leasePaymentOlder } };
lease.PimsLeasePeriods.Add(leasePayment.LeasePeriod);

// Arrange
var mapped = this._mapper.Map<LeasePaymentReportModel>(leasePayment);

mapped.LatestPaymentDate.Should().Be(DateTime.Now.ToString("MMMM dd, yyyy"));
}

[Fact]
public void MapLeasePaymentReport_LastPaymentDate_MultiplePeriods()
{
var lease = EntityHelper.CreateLease(1, addProperty: false);

var leasePayment = new PimsLeasePayment() { PaymentReceivedDate = DateTime.Now };
var leasePaymentOld = new PimsLeasePayment() { PaymentReceivedDate = DateTime.Now.AddDays(-1) };
var leasePaymentOlder = new PimsLeasePayment() { PaymentReceivedDate = DateTime.Now.AddDays(-2) };

leasePaymentOlder.LeasePeriod = new PimsLeasePeriod() { Lease = lease, PimsLeasePayments = new List<PimsLeasePayment>() { leasePaymentOld, leasePaymentOlder } };
leasePayment.LeasePeriod = new PimsLeasePeriod() { Lease = lease, PimsLeasePayments = new List<PimsLeasePayment>() { leasePayment } };
lease.PimsLeasePeriods.Add(leasePaymentOlder.LeasePeriod);
lease.PimsLeasePeriods.Add(leasePayment.LeasePeriod);

// Arrange
var mapped = this._mapper.Map<LeasePaymentReportModel>(leasePaymentOlder);

mapped.LatestPaymentDate.Should().Be(DateTime.Now.ToString("MMMM dd, yyyy"));
}

[Fact]
public void MapLeasePaymentReport_MissingPaymentStatus()
{
var lease = EntityHelper.CreateLease(1, addProperty: false);

var leasePayment = new PimsLeasePayment() { PaymentAmountTotal = 100 };

leasePayment.LeasePeriod = new PimsLeasePeriod() { Lease = lease, PimsLeasePayments = new List<PimsLeasePayment>() { leasePayment }, PaymentAmount = 100 };
lease.PimsLeasePeriods.Add(leasePayment.LeasePeriod);

// Arrange
var mapped = this._mapper.Map<LeasePaymentReportModel>(leasePayment);

mapped.PaymentStatus.Should().Be("PAID");
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export const PeriodPaymentsContainer: React.FunctionComponent<
values = {
...values,
isGstEligible: isReceivableLease ? true : false,
isAdditionalRentGstEligible: isReceivableLease ? true : false,
isVariableRentGstEligible: isReceivableLease ? true : false,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export const PeriodForm: React.FunctionComponent<React.PropsWithChildren<IPeriod
Add Base Rent
<TooltipIcon
toolTipId="base-rent-tooltip"
toolTip="Fixed Amount of Rent per Payment Payment Period, excluding Operating Expenses."
toolTip="Fixed Amount of Rent per Payment Period, excluding Operating Expenses."
/>
</>
}
Expand Down Expand Up @@ -247,7 +247,7 @@ export const PeriodForm: React.FunctionComponent<React.PropsWithChildren<IPeriod
Add Variable Rent
<TooltipIcon
toolTipId="variable-rent-tooltip"
toolTip="Percentage Rent payable by Tenant."
toolTip="Percentage Rent or Other Amount payable by Tenant."
/>
</>
}
Expand Down
Loading