From b519ff70a1c53442d230a4c6249023bd27499c8f Mon Sep 17 00:00:00 2001 From: Smith Date: Wed, 8 Jan 2025 17:33:09 -0800 Subject: [PATCH 1/3] scaffold - note - comp reqs are broken until psp-9066 is implemented. --- .../api/Services/AcquisitionFileService.cs | 60 +++---- .../CompensationRequisitionMap.cs | 10 +- .../CompensationRequisitionRepository.cs | 9 +- source/backend/entities/PimsBaseContext.cs | 94 ++++++++++- .../entities/ef/PimsAcquisitionFile.cs | 42 ++--- .../entities/ef/PimsAcquisitionFileHist.cs | 24 +-- .../entities/ef/PimsAcquisitionFileTeam.cs | 2 +- .../entities/ef/PimsAcquisitionOwner.cs | 2 +- .../backend/entities/ef/PimsCompReqPayee.cs | 154 ++++++++++++++++++ .../entities/ef/PimsCompReqPayeeHist.cs | 88 ++++++++++ .../ef/PimsCompensationRequisition.cs | 36 +--- source/backend/entities/ef/PimsDocument.cs | 2 +- .../backend/entities/ef/PimsDocumentQueue.cs | 8 +- .../backend/entities/ef/PimsInterestHolder.cs | 2 +- 14 files changed, 408 insertions(+), 125 deletions(-) create mode 100644 source/backend/entities/ef/PimsCompReqPayee.cs create mode 100644 source/backend/entities/ef/PimsCompReqPayeeHist.cs diff --git a/source/backend/api/Services/AcquisitionFileService.cs b/source/backend/api/Services/AcquisitionFileService.cs index f0977fd07e..7058871f16 100644 --- a/source/backend/api/Services/AcquisitionFileService.cs +++ b/source/backend/api/Services/AcquisitionFileService.cs @@ -852,29 +852,29 @@ private void ValidatePayeeDependency(PimsAcquisitionFile acquisitionFile) foreach (var compReq in compensationRequisitions) { - // Check for Acquisition File Owner removed - if (compReq.AcquisitionOwnerId is not null - && !acquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(compReq.AcquisitionOwnerId)) - && currentAcquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(compReq.AcquisitionOwnerId))) - { - throw new ForeignKeyDependencyException("Acquisition File Owner can not be removed since it's assigned as a payee for a compensation requisition"); - } - - // Check for Acquisition InterestHolders - if (compReq.InterestHolderId is not null - && !acquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId)) - && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId))) - { - throw new ForeignKeyDependencyException("Acquisition File Interest Holders can not be removed since it's assigned as a payee for a compensation requisition"); - } - - // Check for File Person - if (compReq.AcquisitionFileTeamId is not null - && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(compReq.AcquisitionFileTeamId)) - && currentAcquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(compReq.AcquisitionFileTeamId))) - { - throw new ForeignKeyDependencyException("Acquisition File team member can not be removed since it's assigned as a payee for a compensation requisition"); - } + // Check for Acquisition File Owner removed TODO: update for multiple payees. + //if (compReq.AcquisitionOwnerId is not null + // && !acquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(compReq.AcquisitionOwnerId)) + // && currentAcquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(compReq.AcquisitionOwnerId))) + //{ + // throw new ForeignKeyDependencyException("Acquisition File Owner can not be removed since it's assigned as a payee for a compensation requisition"); + //} + + //// Check for Acquisition InterestHolders + //if (compReq.InterestHolderId is not null + // && !acquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId)) + // && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId))) + //{ + // throw new ForeignKeyDependencyException("Acquisition File Interest Holders can not be removed since it's assigned as a payee for a compensation requisition"); + //} + + //// Check for File Person + //if (compReq.AcquisitionFileTeamId is not null + // && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(compReq.AcquisitionFileTeamId)) + // && currentAcquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(compReq.AcquisitionFileTeamId))) + //{ + // throw new ForeignKeyDependencyException("Acquisition File team member can not be removed since it's assigned as a payee for a compensation requisition"); + //} } } @@ -890,13 +890,13 @@ private void ValidateInterestHoldersDependency(long acquisitionFileId, List x.InterestHolderId.Equals(compReq.InterestHolderId)) - && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId))) - { - throw new ForeignKeyDependencyException("Acquisition File Interest Holder can not be removed since it's assigned as a payee for a compensation requisition"); - } + // Check for Interest Holder: TODO: update for multiple payees. + //if (compReq.InterestHolderId is not null + // && !interestHolders.Any(x => x.InterestHolderId.Equals(compReq.InterestHolderId)) + // && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId))) + //{ + // throw new ForeignKeyDependencyException("Acquisition File Interest Holder can not be removed since it's assigned as a payee for a compensation requisition"); + //} } } diff --git a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs index d87ffd2158..5e48da269a 100644 --- a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs +++ b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs @@ -1,5 +1,6 @@ using Mapster; using Pims.Api.Models.Base; +using System.Linq; using Entity = Pims.Dal.Entities; namespace Pims.Api.Models.Concepts.CompensationRequisition @@ -27,12 +28,6 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.ExpropriationVestingDate, src => src.ExpropVestingDt) .Map(dest => dest.GenerationDate, src => src.GenerationDt) .Map(dest => dest.Financials, src => src.PimsCompReqFinancials) - .Map(dest => dest.AcquisitionOwnerId, src => src.AcquisitionOwnerId) - .Map(dest => dest.AcquisitionOwner, src => src.AcquisitionOwner) - .Map(dest => dest.InterestHolderId, src => src.InterestHolderId) - .Map(dest => dest.InterestHolder, src => src.InterestHolder) - .Map(dest => dest.AcquisitionFileTeamId, src => src.AcquisitionFileTeamId) - .Map(dest => dest.AcquisitionFileTeam, src => src.AcquisitionFileTeam) .Map(dest => dest.LegacyPayee, src => src.LegacyPayee) .Map(dest => dest.IsPaymentInTrust, src => src.IsPaymentInTrust) .Map(dest => dest.GstNumber, src => src.GstNumber) @@ -61,9 +56,6 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.ExpropVestingDt, src => src.ExpropriationVestingDate) .Map(dest => dest.GenerationDt, src => src.GenerationDate) .Map(dest => dest.PimsCompReqFinancials, src => src.Financials) - .Map(dest => dest.AcquisitionOwnerId, src => src.AcquisitionOwnerId) - .Map(dest => dest.InterestHolderId, src => src.InterestHolderId) - .Map(dest => dest.AcquisitionFileTeamId, src => src.AcquisitionFileTeamId) .Map(dest => dest.LegacyPayee, src => src.LegacyPayee) .Map(dest => dest.IsPaymentInTrust, src => src.IsPaymentInTrust) .Map(dest => dest.GstNumber, src => src.GstNumber) diff --git a/source/backend/dal/Repositories/CompensationRequisitionRepository.cs b/source/backend/dal/Repositories/CompensationRequisitionRepository.cs index 0ed6a06ffa..0220772c44 100644 --- a/source/backend/dal/Repositories/CompensationRequisitionRepository.cs +++ b/source/backend/dal/Repositories/CompensationRequisitionRepository.cs @@ -59,9 +59,12 @@ public PimsCompensationRequisition GetById(long compensationRequisitionId) .Include(x => x.Responsibility) .Include(c => c.PimsCompReqFinancials) .ThenInclude(y => y.FinancialActivityCode) - .Include(x => x.AcquisitionOwner) - .Include(x => x.AcquisitionFileTeam) - .Include(x => x.InterestHolder) + .Include(x => x.PimsCompReqPayees) + .ThenInclude(x => x.AcquisitionOwner) + .Include(x => x.PimsCompReqPayees) + .ThenInclude(x => x.AcquisitionFileTeam) + .Include(x => x.PimsCompReqPayees) + .ThenInclude(x => x.InterestHolder) .Include(x => x.AlternateProject) .Include(x => x.PimsLeaseStakeholderCompReqs) .ThenInclude(y => y.LeaseStakeholder) diff --git a/source/backend/entities/PimsBaseContext.cs b/source/backend/entities/PimsBaseContext.cs index 2d81d1215b..bdd862a4a3 100644 --- a/source/backend/entities/PimsBaseContext.cs +++ b/source/backend/entities/PimsBaseContext.cs @@ -116,6 +116,10 @@ public PimsBaseContext(DbContextOptions options) public virtual DbSet PimsCompReqFinancialHists { get; set; } + public virtual DbSet PimsCompReqPayees { get; set; } + + public virtual DbSet PimsCompReqPayeeHists { get; set; } + public virtual DbSet PimsCompensationRequisitions { get; set; } public virtual DbSet PimsCompensationRequisitionHists { get; set; } @@ -2005,6 +2009,78 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.EffectiveDateHist).HasDefaultValueSql("(getutcdate())"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.CompReqPayeeId).HasName("CMPRQP_PK"); + + entity.ToTable("PIMS_COMP_REQ_PAYEE", tb => + { + tb.HasComment("Table to support multiple payees on a compensation requisition."); + tb.HasTrigger("PIMS_CMPRQP_A_S_IUD_TR"); + tb.HasTrigger("PIMS_CMPRQP_I_S_I_TR"); + tb.HasTrigger("PIMS_CMPRQP_I_S_U_TR"); + }); + + entity.Property(e => e.CompReqPayeeId) + .HasDefaultValueSql("(NEXT VALUE FOR [PIMS_COMP_REQ_PAYEE_ID_SEQ])") + .HasComment("Generated surrogate primary key."); + entity.Property(e => e.AcquisitionFileTeamId).HasComment("Foreign key reference to the PIMS_ACQUISITION_FILE_TEAM table."); + entity.Property(e => e.AcquisitionOwnerId).HasComment("Foreign key reference to the PIMS_ACQUISITION_OWNER table."); + entity.Property(e => e.AppCreateTimestamp) + .HasDefaultValueSql("(getutcdate())") + .HasComment("The date and time the user created the record."); + entity.Property(e => e.AppCreateUserDirectory) + .HasDefaultValueSql("(user_name())") + .HasComment("The directory of the user account that created the record."); + entity.Property(e => e.AppCreateUserGuid).HasComment("The GUID of the user account that created the record."); + entity.Property(e => e.AppCreateUserid) + .HasDefaultValueSql("(user_name())") + .HasComment("The user account that created the record."); + entity.Property(e => e.AppLastUpdateTimestamp) + .HasDefaultValueSql("(getutcdate())") + .HasComment("The date and time the user updated the record."); + entity.Property(e => e.AppLastUpdateUserDirectory) + .HasDefaultValueSql("(user_name())") + .HasComment("The directory of the user account that updated the record."); + entity.Property(e => e.AppLastUpdateUserGuid).HasComment("The GUID of the user account that updated the record."); + entity.Property(e => e.AppLastUpdateUserid) + .HasDefaultValueSql("(user_name())") + .HasComment("The user account that updated the record."); + entity.Property(e => e.CompensationRequisitionId).HasComment("Foreign key reference to the PIMS_COMPENSATION_REQUISITION table."); + entity.Property(e => e.ConcurrencyControlNumber) + .HasDefaultValue(1L) + .HasComment("Application code is responsible for retrieving the row and then incrementing the value of the CONCURRENCY_CONTROL_NUMBER column by one prior to issuing an update. If this is done then the update will succeed, provided that the row was not updated by any o"); + entity.Property(e => e.DbCreateTimestamp) + .HasDefaultValueSql("(getutcdate())") + .HasComment("The date and time the record was created."); + entity.Property(e => e.DbCreateUserid) + .HasDefaultValueSql("(user_name())") + .HasComment("The user or proxy account that created the record."); + entity.Property(e => e.DbLastUpdateTimestamp) + .HasDefaultValueSql("(getutcdate())") + .HasComment("The date and time the record was created or last updated."); + entity.Property(e => e.DbLastUpdateUserid) + .HasDefaultValueSql("(user_name())") + .HasComment("The user or proxy account that created or last updated the record."); + entity.Property(e => e.InterestHolderId).HasComment("Foreign key reference to the PIMS_INTEREST_HOLDER table."); + + entity.HasOne(d => d.AcquisitionFileTeam).WithMany(p => p.PimsCompReqPayees).HasConstraintName("PIM_ACQNTM_PIM_CMPRQP_FK"); + + entity.HasOne(d => d.AcquisitionOwner).WithMany(p => p.PimsCompReqPayees).HasConstraintName("PIM_ACQOWN_PIM_CMPRQP_FK"); + + entity.HasOne(d => d.CompensationRequisition).WithMany(p => p.PimsCompReqPayees).HasConstraintName("PIM_CMPREQ_PIM_CMPRQP_FK"); + + entity.HasOne(d => d.InterestHolder).WithMany(p => p.PimsCompReqPayees).HasConstraintName("PIM_INTHLD_PIM_CMPRQP_FK"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.CompReqPayeeHistId).HasName("PIMS_CMPRQP_H_PK"); + + entity.Property(e => e.CompReqPayeeHistId).HasDefaultValueSql("(NEXT VALUE FOR [PIMS_COMP_REQ_PAYEE_H_ID_SEQ])"); + entity.Property(e => e.EffectiveDateHist).HasDefaultValueSql("(getutcdate())"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.CompensationRequisitionId).HasName("CMPREQ_PK"); @@ -2021,8 +2097,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasDefaultValueSql("(NEXT VALUE FOR [PIMS_COMPENSATION_REQUISITION_ID_SEQ])") .HasComment("Generated surrogate primary key."); entity.Property(e => e.AcquisitionFileId).HasComment("Foreign key to the PIMS_ACQUISITION_FILE table."); - entity.Property(e => e.AcquisitionFileTeamId).HasComment("Foreign key to the PIMS_ACQUISITION_FILE_TEAM table."); - entity.Property(e => e.AcquisitionOwnerId).HasComment("Foreign key to the PIMS_ACQUISITION_OWNER table."); entity.Property(e => e.AgreementDt).HasComment("Agreement date."); entity.Property(e => e.AlternateProjectId).HasComment("Link a file to an \"Alternate Project\", so the user can make alternate payments that may be due after the original file's project closes."); entity.Property(e => e.AppCreateTimestamp) @@ -2068,7 +2142,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.FiscalYear).HasComment("Fiscal year of the compensation requisition."); entity.Property(e => e.GenerationDt).HasComment("Document generation date."); entity.Property(e => e.GstNumber).HasComment("GST number of the organization receiving the payment."); - entity.Property(e => e.InterestHolderId).HasComment("Foreign key to the PIMS_INTEREST_HOLDER table."); entity.Property(e => e.IsDisabled) .HasDefaultValue(false) .HasComment("Indicates if the requisition is inactive."); @@ -2086,16 +2159,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasOne(d => d.AcquisitionFile).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_ACQNFL_PIM_CMPREQ_FK"); - entity.HasOne(d => d.AcquisitionFileTeam).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_ACQPER_PIM_CMPREQ_FK"); - - entity.HasOne(d => d.AcquisitionOwner).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_ACQOWN_PIM_CMPREQ_FK"); - entity.HasOne(d => d.AlternateProject).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_PROJCT_PIM_CMPREQ_FK"); entity.HasOne(d => d.ChartOfAccounts).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_CHRTAC_PIM_CMPREQ_FK"); - entity.HasOne(d => d.InterestHolder).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_INTHLD_PIM_CMPREQ_FK"); - entity.HasOne(d => d.Lease).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_LEASE_PIM_CMPREQ_FK"); entity.HasOne(d => d.Responsibility).WithMany(p => p.PimsCompensationRequisitions).HasConstraintName("PIM_RESPCD_PIM_CMPREQ_FK"); @@ -9332,6 +9399,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.HasSequence("PIMS_COMP_REQ_FINANCIAL_ID_SEQ") .HasMin(1L) .HasMax(2147483647L); + modelBuilder.HasSequence("PIMS_COMP_REQ_PAYEE_H_ID_SEQ") + .HasMin(1L) + .HasMax(2147483647L); + modelBuilder.HasSequence("PIMS_COMP_REQ_PAYEE_ID_SEQ") + .HasMin(1L) + .HasMax(2147483647L); modelBuilder.HasSequence("PIMS_COMPENSATION_REQUISITION_H_ID_SEQ") .HasMin(1L) .HasMax(2147483647L); @@ -9695,6 +9768,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.HasSequence("PIMS_PROJECT_PROPERTY_ID_SEQ") .HasMin(1L) .HasMax(2147483647L); + modelBuilder.HasSequence("PIMS_PROJECT_TEAM_ID_SEQ") + .HasMin(1L) + .HasMax(2147483647L); modelBuilder.HasSequence("PIMS_PROJECT_WORKFLOW_MODEL_ID_SEQ") .HasMin(1L) .HasMax(2147483647L); diff --git a/source/backend/entities/ef/PimsAcquisitionFile.cs b/source/backend/entities/ef/PimsAcquisitionFile.cs index 9b3e519112..8bd624619a 100644 --- a/source/backend/entities/ef/PimsAcquisitionFile.cs +++ b/source/backend/entities/ef/PimsAcquisitionFile.cs @@ -94,27 +94,6 @@ public partial class PimsAcquisitionFile [StringLength(20)] public string SubfileInterestTypeCode { get; set; } - /// - /// Foreign key to the PIMS_ACQ_FILE_APPRAISAL_TYPE table. - /// - [Column("ACQ_FILE_APPRAISAL_TYPE_CODE")] - [StringLength(20)] - public string AcqFileAppraisalTypeCode { get; set; } - - /// - /// Foreign key to the PIMS_ACQ_FILE_LGL_SRVY_TYPE table. - /// - [Column("ACQ_FILE_LGL_SRVY_TYPE_CODE")] - [StringLength(20)] - public string AcqFileLglSrvyTypeCode { get; set; } - - /// - /// Foreign key to the PIMS_ACQ_FILE_EXPROP_RISK_TYPE table. - /// - [Column("ACQ_FILE_EXPROP_RISK_TYPE_CODE")] - [StringLength(20)] - public string AcqFileExpropRiskTypeCode { get; set; } - /// /// Descriptive name given to the acquisition file. /// @@ -289,6 +268,27 @@ public partial class PimsAcquisitionFile [StringLength(30)] public string DbLastUpdateUserid { get; set; } + /// + /// Foreign key to the PIMS_ACQ_FILE_APPRAISAL_TYPE table. + /// + [Column("ACQ_FILE_APPRAISAL_TYPE_CODE")] + [StringLength(20)] + public string AcqFileAppraisalTypeCode { get; set; } + + /// + /// Foreign key to the PIMS_ACQ_FILE_LGL_SRVY_TYPE table. + /// + [Column("ACQ_FILE_LGL_SRVY_TYPE_CODE")] + [StringLength(20)] + public string AcqFileLglSrvyTypeCode { get; set; } + + /// + /// Foreign key to the PIMS_ACQ_FILE_EXPROP_RISK_TYPE table. + /// + [Column("ACQ_FILE_EXPROP_RISK_TYPE_CODE")] + [StringLength(20)] + public string AcqFileExpropRiskTypeCode { get; set; } + [ForeignKey("AcqFileAppraisalTypeCode")] [InverseProperty("PimsAcquisitionFiles")] public virtual PimsAcqFileAppraisalType AcqFileAppraisalTypeCodeNavigation { get; set; } diff --git a/source/backend/entities/ef/PimsAcquisitionFileHist.cs b/source/backend/entities/ef/PimsAcquisitionFileHist.cs index 2af1474c7d..830079be41 100644 --- a/source/backend/entities/ef/PimsAcquisitionFileHist.cs +++ b/source/backend/entities/ef/PimsAcquisitionFileHist.cs @@ -57,18 +57,6 @@ public partial class PimsAcquisitionFileHist [StringLength(20)] public string SubfileInterestTypeCode { get; set; } - [Column("ACQ_FILE_APPRAISAL_TYPE_CODE")] - [StringLength(20)] - public string AcqFileAppraisalTypeCode { get; set; } - - [Column("ACQ_FILE_LGL_SRVY_TYPE_CODE")] - [StringLength(20)] - public string AcqFileLglSrvyTypeCode { get; set; } - - [Column("ACQ_FILE_EXPROP_RISK_TYPE_CODE")] - [StringLength(20)] - public string AcqFileExpropRiskTypeCode { get; set; } - [Required] [Column("FILE_NAME")] [StringLength(500)] @@ -171,4 +159,16 @@ public partial class PimsAcquisitionFileHist [Column("FILE_NUMBER")] [StringLength(18)] public string FileNumber { get; set; } + + [Column("ACQ_FILE_APPRAISAL_TYPE_CODE")] + [StringLength(20)] + public string AcqFileAppraisalTypeCode { get; set; } + + [Column("ACQ_FILE_LGL_SRVY_TYPE_CODE")] + [StringLength(20)] + public string AcqFileLglSrvyTypeCode { get; set; } + + [Column("ACQ_FILE_EXPROP_RISK_TYPE_CODE")] + [StringLength(20)] + public string AcqFileExpropRiskTypeCode { get; set; } } diff --git a/source/backend/entities/ef/PimsAcquisitionFileTeam.cs b/source/backend/entities/ef/PimsAcquisitionFileTeam.cs index adff4ecab8..0cab12f8ef 100644 --- a/source/backend/entities/ef/PimsAcquisitionFileTeam.cs +++ b/source/backend/entities/ef/PimsAcquisitionFileTeam.cs @@ -115,7 +115,7 @@ public partial class PimsAcquisitionFileTeam public virtual PimsPerson Person { get; set; } [InverseProperty("AcquisitionFileTeam")] - public virtual ICollection PimsCompensationRequisitions { get; set; } = new List(); + public virtual ICollection PimsCompReqPayees { get; set; } = new List(); [ForeignKey("PrimaryContactId")] [InverseProperty("PimsAcquisitionFileTeamPrimaryContacts")] diff --git a/source/backend/entities/ef/PimsAcquisitionOwner.cs b/source/backend/entities/ef/PimsAcquisitionOwner.cs index 169415fc4d..180b8e40ad 100644 --- a/source/backend/entities/ef/PimsAcquisitionOwner.cs +++ b/source/backend/entities/ef/PimsAcquisitionOwner.cs @@ -158,7 +158,7 @@ public partial class PimsAcquisitionOwner public virtual PimsAddress Address { get; set; } [InverseProperty("AcquisitionOwner")] - public virtual ICollection PimsCompensationRequisitions { get; set; } = new List(); + public virtual ICollection PimsCompReqPayees { get; set; } = new List(); [InverseProperty("AcquisitionOwner")] public virtual ICollection PimsExpropriationPayments { get; set; } = new List(); diff --git a/source/backend/entities/ef/PimsCompReqPayee.cs b/source/backend/entities/ef/PimsCompReqPayee.cs new file mode 100644 index 0000000000..7052392013 --- /dev/null +++ b/source/backend/entities/ef/PimsCompReqPayee.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace Pims.Dal.Entities; + +/// +/// Table to support multiple payees on a compensation requisition. +/// +[Table("PIMS_COMP_REQ_PAYEE")] +[Index("AcquisitionFileTeamId", Name = "CMPRQP_ACQUISITION_FILE_TEAM_ID_IDX")] +[Index("CompensationRequisitionId", Name = "CMPRQP_COMPENSATION_REQUISITION_ID_IDX")] +[Index("InterestHolderId", Name = "CMPRQP_INTEREST_HOLDER_ID_IDX")] +public partial class PimsCompReqPayee +{ + /// + /// Generated surrogate primary key. + /// + [Key] + [Column("COMP_REQ_PAYEE_ID")] + public long CompReqPayeeId { get; set; } + + /// + /// Foreign key reference to the PIMS_COMPENSATION_REQUISITION table. + /// + [Column("COMPENSATION_REQUISITION_ID")] + public long? CompensationRequisitionId { get; set; } + + /// + /// Foreign key reference to the PIMS_ACQUISITION_OWNER table. + /// + [Column("ACQUISITION_OWNER_ID")] + public long? AcquisitionOwnerId { get; set; } + + /// + /// Foreign key reference to the PIMS_INTEREST_HOLDER table. + /// + [Column("INTEREST_HOLDER_ID")] + public long? InterestHolderId { get; set; } + + /// + /// Foreign key reference to the PIMS_ACQUISITION_FILE_TEAM table. + /// + [Column("ACQUISITION_FILE_TEAM_ID")] + public long? AcquisitionFileTeamId { get; set; } + + /// + /// Application code is responsible for retrieving the row and then incrementing the value of the CONCURRENCY_CONTROL_NUMBER column by one prior to issuing an update. If this is done then the update will succeed, provided that the row was not updated by any o + /// + [Column("CONCURRENCY_CONTROL_NUMBER")] + public long ConcurrencyControlNumber { get; set; } + + /// + /// The date and time the user created the record. + /// + [Column("APP_CREATE_TIMESTAMP", TypeName = "datetime")] + public DateTime AppCreateTimestamp { get; set; } + + /// + /// The user account that created the record. + /// + [Required] + [Column("APP_CREATE_USERID")] + [StringLength(30)] + public string AppCreateUserid { get; set; } + + /// + /// The GUID of the user account that created the record. + /// + [Column("APP_CREATE_USER_GUID")] + public Guid? AppCreateUserGuid { get; set; } + + /// + /// The directory of the user account that created the record. + /// + [Required] + [Column("APP_CREATE_USER_DIRECTORY")] + [StringLength(30)] + public string AppCreateUserDirectory { get; set; } + + /// + /// The date and time the user updated the record. + /// + [Column("APP_LAST_UPDATE_TIMESTAMP", TypeName = "datetime")] + public DateTime AppLastUpdateTimestamp { get; set; } + + /// + /// The user account that updated the record. + /// + [Required] + [Column("APP_LAST_UPDATE_USERID")] + [StringLength(30)] + public string AppLastUpdateUserid { get; set; } + + /// + /// The GUID of the user account that updated the record. + /// + [Column("APP_LAST_UPDATE_USER_GUID")] + public Guid? AppLastUpdateUserGuid { get; set; } + + /// + /// The directory of the user account that updated the record. + /// + [Required] + [Column("APP_LAST_UPDATE_USER_DIRECTORY")] + [StringLength(30)] + public string AppLastUpdateUserDirectory { get; set; } + + /// + /// The date and time the record was created. + /// + [Column("DB_CREATE_TIMESTAMP", TypeName = "datetime")] + public DateTime DbCreateTimestamp { get; set; } + + /// + /// The user or proxy account that created the record. + /// + [Required] + [Column("DB_CREATE_USERID")] + [StringLength(30)] + public string DbCreateUserid { get; set; } + + /// + /// The date and time the record was created or last updated. + /// + [Column("DB_LAST_UPDATE_TIMESTAMP", TypeName = "datetime")] + public DateTime DbLastUpdateTimestamp { get; set; } + + /// + /// The user or proxy account that created or last updated the record. + /// + [Required] + [Column("DB_LAST_UPDATE_USERID")] + [StringLength(30)] + public string DbLastUpdateUserid { get; set; } + + [ForeignKey("AcquisitionFileTeamId")] + [InverseProperty("PimsCompReqPayees")] + public virtual PimsAcquisitionFileTeam AcquisitionFileTeam { get; set; } + + [ForeignKey("AcquisitionOwnerId")] + [InverseProperty("PimsCompReqPayees")] + public virtual PimsAcquisitionOwner AcquisitionOwner { get; set; } + + [ForeignKey("CompensationRequisitionId")] + [InverseProperty("PimsCompReqPayees")] + public virtual PimsCompensationRequisition CompensationRequisition { get; set; } + + [ForeignKey("InterestHolderId")] + [InverseProperty("PimsCompReqPayees")] + public virtual PimsInterestHolder InterestHolder { get; set; } +} diff --git a/source/backend/entities/ef/PimsCompReqPayeeHist.cs b/source/backend/entities/ef/PimsCompReqPayeeHist.cs new file mode 100644 index 0000000000..e4fe656a7d --- /dev/null +++ b/source/backend/entities/ef/PimsCompReqPayeeHist.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace Pims.Dal.Entities; + +[Table("PIMS_COMP_REQ_PAYEE_HIST")] +[Index("CompReqPayeeHistId", "EndDateHist", Name = "PIMS_CMPRQP_H_UK", IsUnique = true)] +public partial class PimsCompReqPayeeHist +{ + [Key] + [Column("_COMP_REQ_PAYEE_HIST_ID")] + public long CompReqPayeeHistId { get; set; } + + [Column("EFFECTIVE_DATE_HIST", TypeName = "datetime")] + public DateTime EffectiveDateHist { get; set; } + + [Column("END_DATE_HIST", TypeName = "datetime")] + public DateTime? EndDateHist { get; set; } + + [Column("COMP_REQ_PAYEE_ID")] + public long CompReqPayeeId { get; set; } + + [Column("COMPENSATION_REQUISITION_ID")] + public long? CompensationRequisitionId { get; set; } + + [Column("ACQUISITION_OWNER_ID")] + public long? AcquisitionOwnerId { get; set; } + + [Column("INTEREST_HOLDER_ID")] + public long? InterestHolderId { get; set; } + + [Column("ACQUISITION_FILE_TEAM_ID")] + public long? AcquisitionFileTeamId { get; set; } + + [Column("CONCURRENCY_CONTROL_NUMBER")] + public long ConcurrencyControlNumber { get; set; } + + [Column("APP_CREATE_TIMESTAMP", TypeName = "datetime")] + public DateTime AppCreateTimestamp { get; set; } + + [Required] + [Column("APP_CREATE_USERID")] + [StringLength(30)] + public string AppCreateUserid { get; set; } + + [Column("APP_CREATE_USER_GUID")] + public Guid? AppCreateUserGuid { get; set; } + + [Required] + [Column("APP_CREATE_USER_DIRECTORY")] + [StringLength(30)] + public string AppCreateUserDirectory { get; set; } + + [Column("APP_LAST_UPDATE_TIMESTAMP", TypeName = "datetime")] + public DateTime AppLastUpdateTimestamp { get; set; } + + [Required] + [Column("APP_LAST_UPDATE_USERID")] + [StringLength(30)] + public string AppLastUpdateUserid { get; set; } + + [Column("APP_LAST_UPDATE_USER_GUID")] + public Guid? AppLastUpdateUserGuid { get; set; } + + [Required] + [Column("APP_LAST_UPDATE_USER_DIRECTORY")] + [StringLength(30)] + public string AppLastUpdateUserDirectory { get; set; } + + [Column("DB_CREATE_TIMESTAMP", TypeName = "datetime")] + public DateTime DbCreateTimestamp { get; set; } + + [Required] + [Column("DB_CREATE_USERID")] + [StringLength(30)] + public string DbCreateUserid { get; set; } + + [Column("DB_LAST_UPDATE_TIMESTAMP", TypeName = "datetime")] + public DateTime DbLastUpdateTimestamp { get; set; } + + [Required] + [Column("DB_LAST_UPDATE_USERID")] + [StringLength(30)] + public string DbLastUpdateUserid { get; set; } +} diff --git a/source/backend/entities/ef/PimsCompensationRequisition.cs b/source/backend/entities/ef/PimsCompensationRequisition.cs index 82b6d786c1..9464426b04 100644 --- a/source/backend/entities/ef/PimsCompensationRequisition.cs +++ b/source/backend/entities/ef/PimsCompensationRequisition.cs @@ -11,11 +11,8 @@ namespace Pims.Dal.Entities; /// [Table("PIMS_COMPENSATION_REQUISITION")] [Index("AcquisitionFileId", Name = "CMPREQ_ACQUISITION_FILE_ID_IDX")] -[Index("AcquisitionFileTeamId", Name = "CMPREQ_ACQUISITION_FILE_PERSON_ID_IDX")] -[Index("AcquisitionOwnerId", Name = "CMPREQ_ACQUISITION_OWNER_ID_IDX")] [Index("AlternateProjectId", Name = "CMPREQ_ALTERNATE_PROJECT_ID_IDX")] [Index("ChartOfAccountsId", Name = "CMPREQ_CHART_OF_ACCOUNTS_ID_IDX")] -[Index("InterestHolderId", Name = "CMPREQ_INTEREST_HOLDER_ID_IDX")] [Index("LeaseId", Name = "CMPREQ_LEASE_ID_IDX")] [Index("ResponsibilityId", Name = "CMPREQ_RESPONSIBILITY_ID_IDX")] [Index("YearlyFinancialId", Name = "CMPREQ_YEARLY_FINANCIAL_ID_IDX")] @@ -40,24 +37,6 @@ public partial class PimsCompensationRequisition [Column("LEASE_ID")] public long? LeaseId { get; set; } - /// - /// Foreign key to the PIMS_ACQUISITION_OWNER table. - /// - [Column("ACQUISITION_OWNER_ID")] - public long? AcquisitionOwnerId { get; set; } - - /// - /// Foreign key to the PIMS_INTEREST_HOLDER table. - /// - [Column("INTEREST_HOLDER_ID")] - public long? InterestHolderId { get; set; } - - /// - /// Foreign key to the PIMS_ACQUISITION_FILE_TEAM table. - /// - [Column("ACQUISITION_FILE_TEAM_ID")] - public long? AcquisitionFileTeamId { get; set; } - /// /// Foreign key to the PIMS_CHART_OF_ACCOUNTS table. /// @@ -259,14 +238,6 @@ public partial class PimsCompensationRequisition [InverseProperty("PimsCompensationRequisitions")] public virtual PimsAcquisitionFile AcquisitionFile { get; set; } - [ForeignKey("AcquisitionFileTeamId")] - [InverseProperty("PimsCompensationRequisitions")] - public virtual PimsAcquisitionFileTeam AcquisitionFileTeam { get; set; } - - [ForeignKey("AcquisitionOwnerId")] - [InverseProperty("PimsCompensationRequisitions")] - public virtual PimsAcquisitionOwner AcquisitionOwner { get; set; } - [ForeignKey("AlternateProjectId")] [InverseProperty("PimsCompensationRequisitions")] public virtual PimsProject AlternateProject { get; set; } @@ -275,10 +246,6 @@ public partial class PimsCompensationRequisition [InverseProperty("PimsCompensationRequisitions")] public virtual PimsChartOfAccountsCode ChartOfAccounts { get; set; } - [ForeignKey("InterestHolderId")] - [InverseProperty("PimsCompensationRequisitions")] - public virtual PimsInterestHolder InterestHolder { get; set; } - [ForeignKey("LeaseId")] [InverseProperty("PimsCompensationRequisitions")] public virtual PimsLease Lease { get; set; } @@ -286,6 +253,9 @@ public partial class PimsCompensationRequisition [InverseProperty("CompensationRequisition")] public virtual ICollection PimsCompReqFinancials { get; set; } = new List(); + [InverseProperty("CompensationRequisition")] + public virtual ICollection PimsCompReqPayees { get; set; } = new List(); + [InverseProperty("CompensationRequisition")] public virtual ICollection PimsLeaseStakeholderCompReqs { get; set; } = new List(); diff --git a/source/backend/entities/ef/PimsDocument.cs b/source/backend/entities/ef/PimsDocument.cs index 1ebb797281..bf16d7a285 100644 --- a/source/backend/entities/ef/PimsDocument.cs +++ b/source/backend/entities/ef/PimsDocument.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; diff --git a/source/backend/entities/ef/PimsDocumentQueue.cs b/source/backend/entities/ef/PimsDocumentQueue.cs index 8efe09b4a7..a4dc9c20a1 100644 --- a/source/backend/entities/ef/PimsDocumentQueue.cs +++ b/source/backend/entities/ef/PimsDocumentQueue.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -29,7 +29,7 @@ public partial class PimsDocumentQueue public long? DocumentId { get; set; } /// - /// Code value that represents the current status of the document as it is processed by PIMS/MAYAN. + /// Code value that represents the current status of the document as it is processed by PIMS/MAYAN /// [Required] [Column("DOCUMENT_QUEUE_STATUS_TYPE_CODE")] @@ -65,7 +65,7 @@ public partial class PimsDocumentQueue public DateTime? DocProcessStartDt { get; set; } /// - /// When the document?s processing finishes, this will be populated. + /// When the document?s processing finishes, this will be populated /// [Column("DOC_PROCESS_END_DT", TypeName = "datetime")] public DateTime? DocProcessEndDt { get; set; } @@ -90,7 +90,7 @@ public partial class PimsDocumentQueue public byte[] Document { get; set; } /// - /// Application code is responsible for retrieving the row and then incrementing the value of the CONCURRENCY_CONTROL_NUMBER column by one prior to issuing an update. If this is done then the update will succeed, provided that the row was not updated by any o. + /// Application code is responsible for retrieving the row and then incrementing the value of the CONCURRENCY_CONTROL_NUMBER column by one prior to issuing an update. If this is done then the update will succeed, provided that the row was not updated by any o /// [Column("CONCURRENCY_CONTROL_NUMBER")] public long ConcurrencyControlNumber { get; set; } diff --git a/source/backend/entities/ef/PimsInterestHolder.cs b/source/backend/entities/ef/PimsInterestHolder.cs index db9115d24a..1c20e3e5b2 100644 --- a/source/backend/entities/ef/PimsInterestHolder.cs +++ b/source/backend/entities/ef/PimsInterestHolder.cs @@ -122,7 +122,7 @@ public partial class PimsInterestHolder public virtual PimsPerson Person { get; set; } [InverseProperty("InterestHolder")] - public virtual ICollection PimsCompensationRequisitions { get; set; } = new List(); + public virtual ICollection PimsCompReqPayees { get; set; } = new List(); [InverseProperty("InterestHolder")] public virtual ICollection PimsExpropriationPayments { get; set; } = new List(); From 21ad9dc398fb53889a06c456ea9ee6e5bb97497b Mon Sep 17 00:00:00 2001 From: Smith Date: Thu, 9 Jan 2025 09:53:19 -0800 Subject: [PATCH 2/3] comment out tests related to scaffold. --- .../Services/AcquisitionFileServiceTest.cs | 386 +++++++++--------- 1 file changed, 193 insertions(+), 193 deletions(-) diff --git a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs index e2a6dcf329..ad702a05fb 100644 --- a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs +++ b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs @@ -1020,199 +1020,199 @@ public void Update_ProjectContractor_Removed() act.Should().Throw(); } - [Fact] - public void Update_FKException_Removed_AcqFileOwner() - { - // Arrange - var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - var acqFile = EntityHelper.CreateAcquisitionFile(); - acqFile.PimsAcquisitionOwners = new List() { - new PimsAcquisitionOwner() { - AcquisitionOwnerId = 100, - }, - }; - - var repository = this._helper.GetService>(); - repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - var compReqRepository = this._helper.GetService>(); - compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - .Returns(new List() { - new PimsCompensationRequisition() { - CompensationRequisitionId = 1, - AcquisitionFileId = acqFile.Internal_Id, - AcquisitionOwnerId = 100, - }, - }); - - var lookupRepository = this._helper.GetService>(); - lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - var userRepository = this._helper.GetService>(); - userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - var agreementRepository = this._helper.GetService>(); - agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - var solver = this._helper.GetService>(); - solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // Act - var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // Assert - act.Should().Throw(); - repository.Verify(x => x.Update(It.IsAny()), Times.Never); - } - - [Fact] - public void Update_FKException_Removed_OwnerSolicitor() - { - // Arrange - var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - var acqFile = EntityHelper.CreateAcquisitionFile(); - acqFile.PimsInterestHolders = new List() { - new PimsInterestHolder() { - InterestHolderTypeCode = "AOSLCTR", - InterestHolderId = 100, - }, - }; - - var repository = this._helper.GetService>(); - repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - var compReqRepository = this._helper.GetService>(); - compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - .Returns(new List() { - new PimsCompensationRequisition() { - CompensationRequisitionId = 1, - AcquisitionFileId = acqFile.Internal_Id, - InterestHolderId = 100, - }, - }); - - var lookupRepository = this._helper.GetService>(); - lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - var userRepository = this._helper.GetService>(); - userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - var agreementRepository = this._helper.GetService>(); - agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - var solver = this._helper.GetService>(); - solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // Act - var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // Assert - act.Should().Throw(); - repository.Verify(x => x.Update(It.IsAny()), Times.Never); - } - - [Fact] - public void Update_FKException_Removed_OwnerRepresentative() - { - // Arrange - var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - var acqFile = EntityHelper.CreateAcquisitionFile(); - acqFile.PimsInterestHolders = new List() { - new PimsInterestHolder() { - InterestHolderTypeCode = "AOREP", - InterestHolderId = 100, - }, - }; - - var repository = this._helper.GetService>(); - repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - var compReqRepository = this._helper.GetService>(); - compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - .Returns(new List() { - new PimsCompensationRequisition() { - CompensationRequisitionId = 1, - AcquisitionFileId = acqFile.Internal_Id, - InterestHolderId = 100, - }, - }); - - var lookupRepository = this._helper.GetService>(); - lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - var userRepository = this._helper.GetService>(); - userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - var agreementRepository = this._helper.GetService>(); - agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - var solver = this._helper.GetService>(); - solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // Act - var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // Assert - act.Should().Throw(); - repository.Verify(x => x.Update(It.IsAny()), Times.Never); - } - - [Fact] - public void Update_FKException_Removed_PersonOfInterest() - { - // Arrange - var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - var acqFile = EntityHelper.CreateAcquisitionFile(); - acqFile.PimsAcquisitionFileTeams = new List() { - new PimsAcquisitionFileTeam() { - AcquisitionFileTeamId = 100, - }, - }; - - var repository = this._helper.GetService>(); - repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - var compReqRepository = this._helper.GetService>(); - compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - .Returns(new List() { - new PimsCompensationRequisition() { - CompensationRequisitionId = 1, - AcquisitionFileId = acqFile.Internal_Id, - AcquisitionFileTeamId = 100, - }, - }); - - var lookupRepository = this._helper.GetService>(); - lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - var userRepository = this._helper.GetService>(); - userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - var agreementRepository = this._helper.GetService>(); - agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - var solver = this._helper.GetService>(); - solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // Act - var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // Assert - act.Should().Throw(); - repository.Verify(x => x.Update(It.IsAny()), Times.Never); - } + //[Fact] + //public void Update_FKException_Removed_AcqFileOwner() + //{ + // // Arrange + // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + // var acqFile = EntityHelper.CreateAcquisitionFile(); + // acqFile.PimsAcquisitionOwners = new List() { + // new PimsAcquisitionOwner() { + // AcquisitionOwnerId = 100, + // }, + // }; + + // var repository = this._helper.GetService>(); + // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + // var compReqRepository = this._helper.GetService>(); + // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + // .Returns(new List() { + // new PimsCompensationRequisition() { + // CompensationRequisitionId = 1, + // AcquisitionFileId = acqFile.Internal_Id, + // AcquisitionOwnerId = 100, + // }, + // }); + + // var lookupRepository = this._helper.GetService>(); + // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + // var userRepository = this._helper.GetService>(); + // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + // var agreementRepository = this._helper.GetService>(); + // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + // var solver = this._helper.GetService>(); + // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // // Act + // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // // Assert + // act.Should().Throw(); + // repository.Verify(x => x.Update(It.IsAny()), Times.Never); + //} + + //[Fact] + //public void Update_FKException_Removed_OwnerSolicitor() + //{ + // // Arrange + // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + // var acqFile = EntityHelper.CreateAcquisitionFile(); + // acqFile.PimsInterestHolders = new List() { + // new PimsInterestHolder() { + // InterestHolderTypeCode = "AOSLCTR", + // InterestHolderId = 100, + // }, + // }; + + // var repository = this._helper.GetService>(); + // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + // var compReqRepository = this._helper.GetService>(); + // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + // .Returns(new List() { + // new PimsCompensationRequisition() { + // CompensationRequisitionId = 1, + // AcquisitionFileId = acqFile.Internal_Id, + // InterestHolderId = 100, + // }, + // }); + + // var lookupRepository = this._helper.GetService>(); + // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + // var userRepository = this._helper.GetService>(); + // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + // var agreementRepository = this._helper.GetService>(); + // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + // var solver = this._helper.GetService>(); + // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // // Act + // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // // Assert + // act.Should().Throw(); + // repository.Verify(x => x.Update(It.IsAny()), Times.Never); + //} + + //[Fact] + //public void Update_FKException_Removed_OwnerRepresentative() + //{ + // // Arrange + // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + // var acqFile = EntityHelper.CreateAcquisitionFile(); + // acqFile.PimsInterestHolders = new List() { + // new PimsInterestHolder() { + // InterestHolderTypeCode = "AOREP", + // InterestHolderId = 100, + // }, + // }; + + // var repository = this._helper.GetService>(); + // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + // var compReqRepository = this._helper.GetService>(); + // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + // .Returns(new List() { + // new PimsCompensationRequisition() { + // CompensationRequisitionId = 1, + // AcquisitionFileId = acqFile.Internal_Id, + // InterestHolderId = 100, + // }, + // }); + + // var lookupRepository = this._helper.GetService>(); + // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + // var userRepository = this._helper.GetService>(); + // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + // var agreementRepository = this._helper.GetService>(); + // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + // var solver = this._helper.GetService>(); + // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // // Act + // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // // Assert + // act.Should().Throw(); + // repository.Verify(x => x.Update(It.IsAny()), Times.Never); + //} + + //[Fact] + //public void Update_FKException_Removed_PersonOfInterest() + //{ + // // Arrange + // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + // var acqFile = EntityHelper.CreateAcquisitionFile(); + // acqFile.PimsAcquisitionFileTeams = new List() { + // new PimsAcquisitionFileTeam() { + // AcquisitionFileTeamId = 100, + // }, + // }; + + // var repository = this._helper.GetService>(); + // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + // var compReqRepository = this._helper.GetService>(); + // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + // .Returns(new List() { + // new PimsCompensationRequisition() { + // CompensationRequisitionId = 1, + // AcquisitionFileId = acqFile.Internal_Id, + // AcquisitionFileTeamId = 100, + // }, + // }); + + // var lookupRepository = this._helper.GetService>(); + // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + // var userRepository = this._helper.GetService>(); + // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + // var agreementRepository = this._helper.GetService>(); + // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + // var solver = this._helper.GetService>(); + // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // // Act + // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // // Assert + // act.Should().Throw(); + // repository.Verify(x => x.Update(It.IsAny()), Times.Never); + //} [Fact] public void Update_NewTotalAllowableCompensation_Success() From 8eae71e480ebfc66937f9da61082eb1aaf0bcf7a Mon Sep 17 00:00:00 2001 From: Smith Date: Mon, 13 Jan 2025 12:14:25 -0800 Subject: [PATCH 3/3] scaffold WIP --- .../CompensationRequisitionController.cs | 21 + .../api/Services/AcquisitionFileService.cs | 58 +-- .../CompensationRequisitionService.cs | 14 +- .../ICompensationRequisitionService.cs | 4 +- .../CompReqPayeeMap.cs | 31 ++ .../CompReqPayeeModel.cs | 27 ++ .../CompensationRequisitionMap.cs | 4 +- .../CompensationRequisitionModel.cs | 17 +- .../CompensationRequisitionRepository.cs | 30 +- .../ICompensationRequisitionRepository.cs | 4 +- .../entities/Partials/PimsCompReqPayee.cs | 14 + .../Services/AcquisitionFileServiceTest.cs | 386 +++++++++--------- .../GenerateForm/hooks/useGenerateH120.ts | 8 +- .../acquisition/models/PayeeOptionModel.ts | 201 ++++----- ...CompensationRequisitionDetailContainer.tsx | 74 ++-- .../CompensationRequisitionDetailView.tsx | 186 +++++---- .../list/CompensationListContainer.test.tsx | 4 +- .../list/CompensationListContainer.tsx | 2 +- .../models/AcquisitionPayeeFormModel.ts | 35 +- .../CompensationRequisitionFormModel.ts | 41 +- ...eCompensationRequisitionContainer.test.tsx | 4 +- ...UpdateCompensationRequisitionContainer.tsx | 22 +- .../UpdateCompensationRequisitionForm.tsx | 18 +- .../useApiRequisitionCompensations.ts | 6 + .../useRequisitionCompensationRepository.ts | 16 + .../frontend/src/mocks/compensations.mock.ts | 6 +- .../generated/ApiGen_Concepts_CompReqPayee.ts | 22 + ...ApiGen_Concepts_CompensationRequisition.ts | 13 +- .../GenerateCompensationPayee.test.ts | 8 +- .../acquisition/GenerateCompensationPayee.ts | 4 +- 30 files changed, 697 insertions(+), 583 deletions(-) create mode 100644 source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeMap.cs create mode 100644 source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeModel.cs create mode 100644 source/backend/entities/Partials/PimsCompReqPayee.cs create mode 100644 source/frontend/src/models/api/generated/ApiGen_Concepts_CompReqPayee.ts diff --git a/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs b/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs index d1bcd51f94..51295c0066 100644 --- a/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs +++ b/source/backend/api/Areas/CompensationRequisition/Controllers/CompensationRequisitionController.cs @@ -225,5 +225,26 @@ public IActionResult GetCompensationRequisitionFinancials([FromRoute] long id) return new JsonResult(_mapper.Map>(compReqFinancials)); } + + [HttpGet("{id:long}/payees")] + [HasPermission(Permissions.CompensationRequisitionView)] + [Produces("application/json")] + [ProducesResponseType(typeof(List), 200)] + [SwaggerOperation(Tags = new[] { "compensation-requisition" })] + [TypeFilter(typeof(NullJsonResultFilter))] + public IActionResult GetCompensationRequisitionPayees([FromRoute] long id) + { + _logger.LogInformation( + "Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}", + nameof(CompensationRequisitionController), + nameof(GetCompensationRequisitionPayees), + User.GetUsername(), + DateTime.Now); + _logger.LogInformation("Dispatching to service: {Service}", _compensationRequisitionService.GetType()); + + var compReqFinancials = _compensationRequisitionService.GetCompensationRequisitionPayees(id); + + return new JsonResult(_mapper.Map>(compReqFinancials)); + } } } diff --git a/source/backend/api/Services/AcquisitionFileService.cs b/source/backend/api/Services/AcquisitionFileService.cs index 7058871f16..337c1230b5 100644 --- a/source/backend/api/Services/AcquisitionFileService.cs +++ b/source/backend/api/Services/AcquisitionFileService.cs @@ -844,37 +844,38 @@ private void ValidatePayeeDependency(PimsAcquisitionFile acquisitionFile) { var currentAcquisitionFile = _acqFileRepository.GetById(acquisitionFile.Internal_Id); var compensationRequisitions = _compensationRequisitionRepository.GetAllByAcquisitionFileId(acquisitionFile.Internal_Id); + var compReqPayees = compensationRequisitions.SelectMany(x => x.PimsCompReqPayees).ToList(); - if (compensationRequisitions.Count == 0) + if (compReqPayees.Count == 0) { return; } - foreach (var compReq in compensationRequisitions) + foreach (var payee in compReqPayees) { // Check for Acquisition File Owner removed TODO: update for multiple payees. - //if (compReq.AcquisitionOwnerId is not null - // && !acquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(compReq.AcquisitionOwnerId)) - // && currentAcquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(compReq.AcquisitionOwnerId))) - //{ - // throw new ForeignKeyDependencyException("Acquisition File Owner can not be removed since it's assigned as a payee for a compensation requisition"); - //} + if (payee.AcquisitionOwnerId is not null + && !acquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(payee.AcquisitionOwnerId)) + && currentAcquisitionFile.PimsAcquisitionOwners.Any(x => x.Internal_Id.Equals(payee.AcquisitionOwnerId))) + { + throw new ForeignKeyDependencyException("Acquisition File Owner can not be removed since it's assigned as a payee for a compensation requisition"); + } //// Check for Acquisition InterestHolders - //if (compReq.InterestHolderId is not null - // && !acquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId)) - // && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId))) - //{ - // throw new ForeignKeyDependencyException("Acquisition File Interest Holders can not be removed since it's assigned as a payee for a compensation requisition"); - //} + if (payee.InterestHolderId is not null + && !acquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(payee.InterestHolderId)) + && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(payee.InterestHolderId))) + { + throw new ForeignKeyDependencyException("Acquisition File Interest Holders can not be removed since it's assigned as a payee for a compensation requisition"); + } //// Check for File Person - //if (compReq.AcquisitionFileTeamId is not null - // && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(compReq.AcquisitionFileTeamId)) - // && currentAcquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(compReq.AcquisitionFileTeamId))) - //{ - // throw new ForeignKeyDependencyException("Acquisition File team member can not be removed since it's assigned as a payee for a compensation requisition"); - //} + if (payee.AcquisitionFileTeamId is not null + && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(payee.AcquisitionFileTeamId)) + && currentAcquisitionFile.PimsAcquisitionFileTeams.Any(x => x.Internal_Id.Equals(payee.AcquisitionFileTeamId))) + { + throw new ForeignKeyDependencyException("Acquisition File team member can not be removed since it's assigned as a payee for a compensation requisition"); + } } } @@ -882,21 +883,22 @@ private void ValidateInterestHoldersDependency(long acquisitionFileId, List x.PimsCompReqPayees).ToList(); - if (compensationRequisitions.Count == 0) + if (compReqPayees.Count == 0) { return; } - foreach (var compReq in compensationRequisitions) + foreach (var payee in compReqPayees) { // Check for Interest Holder: TODO: update for multiple payees. - //if (compReq.InterestHolderId is not null - // && !interestHolders.Any(x => x.InterestHolderId.Equals(compReq.InterestHolderId)) - // && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(compReq.InterestHolderId))) - //{ - // throw new ForeignKeyDependencyException("Acquisition File Interest Holder can not be removed since it's assigned as a payee for a compensation requisition"); - //} + if (payee.InterestHolderId is not null + && !interestHolders.Any(x => x.InterestHolderId.Equals(payee.InterestHolderId)) + && currentAcquisitionFile.PimsInterestHolders.Any(x => x.Internal_Id.Equals(payee.InterestHolderId))) + { + throw new ForeignKeyDependencyException("Acquisition File Interest Holder can not be removed since it's assigned as a payee for a compensation requisition"); + } } } diff --git a/source/backend/api/Services/CompensationRequisitionService.cs b/source/backend/api/Services/CompensationRequisitionService.cs index 74ae0bd5a2..f2c51ba758 100644 --- a/source/backend/api/Services/CompensationRequisitionService.cs +++ b/source/backend/api/Services/CompensationRequisitionService.cs @@ -150,12 +150,20 @@ public IEnumerable GetFileCompensationRequisitions( return compReqs; } - public IEnumerable GetCompensationRequisitionFinancials(long id) + public IEnumerable GetCompensationRequisitionFinancials(long compReqId) { - _logger.LogInformation("Getting compensations financials for id: {acquisitionFileId}", id); + _logger.LogInformation("Getting compensations financials for id: {compReqId}", compReqId); _user.ThrowIfNotAuthorized(Permissions.CompensationRequisitionView); - return _compensationRequisitionRepository.GetCompensationRequisitionFinancials(id); + return _compensationRequisitionRepository.GetCompensationRequisitionFinancials(compReqId); + } + + public IEnumerable GetCompensationRequisitionPayees(long compReqId) + { + _logger.LogInformation("Getting compensations payees for id: {compReqId}", compReqId); + _user.ThrowIfNotAuthorized(Permissions.CompensationRequisitionView); + + return _compensationRequisitionRepository.GetCompensationRequisitionPayees(compReqId); } private static string GetCompensationRequisitionStatusText(bool? isDraft) diff --git a/source/backend/api/Services/ICompensationRequisitionService.cs b/source/backend/api/Services/ICompensationRequisitionService.cs index 884cbae6f1..d99d24979d 100644 --- a/source/backend/api/Services/ICompensationRequisitionService.cs +++ b/source/backend/api/Services/ICompensationRequisitionService.cs @@ -20,6 +20,8 @@ public interface ICompensationRequisitionService PimsCompensationRequisition AddCompensationRequisition(FileTypes fileType, PimsCompensationRequisition compensationRequisition); - IEnumerable GetCompensationRequisitionFinancials(long id); + IEnumerable GetCompensationRequisitionFinancials(long compReqId); + + IEnumerable GetCompensationRequisitionPayees(long compReqId); } } diff --git a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeMap.cs b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeMap.cs new file mode 100644 index 0000000000..1fbb004ff7 --- /dev/null +++ b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeMap.cs @@ -0,0 +1,31 @@ +using Mapster; +using Pims.Api.Models.Base; +using Entity = Pims.Dal.Entities; + +namespace Pims.Api.Models.Concepts.CompensationRequisition +{ + public class CompReqPayeeMap : IRegister + { + public void Register(TypeAdapterConfig config) + { + config.NewConfig() + .Map(dest => dest.CompReqPayeeId, src => src.CompReqPayeeId) + .Map(dest => dest.CompensationRequisitionId, src => src.CompensationRequisitionId) + .Map(dest => dest.AcquisitionFileTeamId, src => src.AcquisitionFileTeamId) + .Map(dest => dest.AcquisitionFileTeam, src => src.AcquisitionFileTeam) + .Map(dest => dest.AcquisitionOwnerId, src => src.AcquisitionOwnerId) + .Map(dest => dest.AcquisitionOwner, src => src.AcquisitionOwner) + .Map(dest => dest.InterestHolderId, src => src.InterestHolderId) + .Map(dest => dest.InterestHolder, src => src.InterestHolder) + .Inherits(); + + config.NewConfig() + .Map(dest => dest.CompReqPayeeId, src => src.CompReqPayeeId) + .Map(dest => dest.CompensationRequisitionId, src => src.CompensationRequisitionId) + .Map(dest => dest.AcquisitionFileTeamId, src => src.AcquisitionFileTeamId) + .Map(dest => dest.AcquisitionOwnerId, src => src.AcquisitionOwnerId) + .Map(dest => dest.InterestHolderId, src => src.InterestHolderId) + .Inherits(); + } + } +} diff --git a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeModel.cs b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeModel.cs new file mode 100644 index 0000000000..09fbd89c1e --- /dev/null +++ b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompReqPayeeModel.cs @@ -0,0 +1,27 @@ +using Pims.Api.Models.Base; +using Pims.Api.Models.Concepts.AcquisitionFile; +using Pims.Api.Models.Concepts.InterestHolder; + +namespace Pims.Api.Models.Concepts.CompensationRequisition +{ + public class CompReqPayeeModel : BaseAuditModel + { + public long? CompReqPayeeId { get; set; } + + public long CompensationRequisitionId { get; set; } + + public CompensationRequisitionModel CompensationRequisition { get; set; } + + public long AcquisitionOwnerId { get; set; } + + public AcquisitionFileOwnerModel AcquisitionOwner { get; set; } + + public long InterestHolderId { get; set; } + + public InterestHolderModel InterestHolder { get; set; } + + public long AcquisitionFileTeamId { get; set; } + + public AcquisitionFileTeamModel AcquisitionFileTeam { get; set; } + } +} diff --git a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs index 5e48da269a..1a4e0f5390 100644 --- a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs +++ b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionMap.cs @@ -36,7 +36,7 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.DetailedRemarks, src => src.DetailedRemarks) .Map(dest => dest.AlternateProjectId, src => src.AlternateProjectId) .Map(dest => dest.AlternateProject, src => src.AlternateProject) - .Map(dest => dest.CompReqLeaseStakeholder, src => src.PimsLeaseStakeholderCompReqs) + .Map(dest => dest.CompReqLeaseStakeholders, src => src.PimsLeaseStakeholderCompReqs) .Map(dest => dest.CompReqAcquisitionProperties, src => src.PimsPropAcqFlCompReqs) .Map(dest => dest.CompReqLeaseProperties, src => src.PimsPropLeaseCompReqs) .Inherits(); @@ -64,7 +64,7 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.DetailedRemarks, src => src.DetailedRemarks) .Map(dest => dest.AlternateProjectId, src => src.AlternateProjectId) .Map(dest => dest.AlternateProject, src => src.AlternateProject) - .Map(dest => dest.PimsLeaseStakeholderCompReqs, src => src.CompReqLeaseStakeholder) + .Map(dest => dest.PimsLeaseStakeholderCompReqs, src => src.CompReqLeaseStakeholders) .Map(dest => dest.PimsPropAcqFlCompReqs, src => src.CompReqAcquisitionProperties) .Map(dest => dest.PimsPropLeaseCompReqs, src => src.CompReqLeaseProperties) .Inherits(); diff --git a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionModel.cs b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionModel.cs index 4a8f276ce7..2e8e449bce 100644 --- a/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionModel.cs +++ b/source/backend/apimodels/Models/Concepts/CompensationRequisition/CompensationRequisitionModel.cs @@ -3,7 +3,6 @@ using Pims.Api.Models.Base; using Pims.Api.Models.Concepts.AcquisitionFile; using Pims.Api.Models.Concepts.FinancialCode; -using Pims.Api.Models.Concepts.InterestHolder; using Pims.Api.Models.Concepts.Project; namespace Pims.Api.Models.Concepts.CompensationRequisition @@ -46,18 +45,6 @@ public class CompensationRequisitionModel : BaseAuditModel public List Financials { get; set; } - public long? AcquisitionOwnerId { get; set; } - - public AcquisitionFileOwnerModel AcquisitionOwner { get; set; } - - public long? InterestHolderId { get; set; } - - public InterestHolderModel InterestHolder { get; set; } - - public long? AcquisitionFileTeamId { get; set; } - - public AcquisitionFileTeamModel AcquisitionFileTeam { get; set; } - public string LegacyPayee { get; set; } public bool? IsPaymentInTrust { get; set; } @@ -72,7 +59,9 @@ public class CompensationRequisitionModel : BaseAuditModel public ProjectModel AlternateProject { get; set; } - public IEnumerable CompReqLeaseStakeholder { get; set; } + public IEnumerable CompReqPayees { get; set; } + + public IEnumerable CompReqLeaseStakeholders { get; set; } public IEnumerable CompReqAcquisitionProperties { get; set; } diff --git a/source/backend/dal/Repositories/CompensationRequisitionRepository.cs b/source/backend/dal/Repositories/CompensationRequisitionRepository.cs index 0220772c44..1fe26dd159 100644 --- a/source/backend/dal/Repositories/CompensationRequisitionRepository.cs +++ b/source/backend/dal/Repositories/CompensationRequisitionRepository.cs @@ -58,13 +58,6 @@ public PimsCompensationRequisition GetById(long compensationRequisitionId) .Include(x => x.ChartOfAccounts) .Include(x => x.Responsibility) .Include(c => c.PimsCompReqFinancials) - .ThenInclude(y => y.FinancialActivityCode) - .Include(x => x.PimsCompReqPayees) - .ThenInclude(x => x.AcquisitionOwner) - .Include(x => x.PimsCompReqPayees) - .ThenInclude(x => x.AcquisitionFileTeam) - .Include(x => x.PimsCompReqPayees) - .ThenInclude(x => x.InterestHolder) .Include(x => x.AlternateProject) .Include(x => x.PimsLeaseStakeholderCompReqs) .ThenInclude(y => y.LeaseStakeholder) @@ -187,12 +180,31 @@ public List GetLeaseCompReqPropertiesById(long compensationRe .ToList(); } - public IEnumerable GetCompensationRequisitionFinancials(long id) + public IEnumerable GetCompensationRequisitionFinancials(long compReqId) { return Context.PimsCompReqFinancials .AsNoTracking() .Include(y => y.FinancialActivityCode) - .Where(x => x.CompensationRequisitionId == id) + .Where(x => x.CompensationRequisitionId == compReqId) + .ToList(); + } + + public IEnumerable GetCompensationRequisitionPayees(long compReqId) + { + return Context.PimsCompReqPayees + .AsNoTracking() + .Include(x => x.AcquisitionOwner) + .Include(x => x.AcquisitionFileTeam) + .ThenInclude(y => y.Person) + .Include(x => x.AcquisitionFileTeam) + .ThenInclude(y => y.Organization) + .Include(x => x.InterestHolder) + .ThenInclude(y => y.InterestHolderTypeCodeNavigation) + .Include(x => x.InterestHolder) + .ThenInclude(y => y.Person) + .Include(x => x.InterestHolder) + .ThenInclude(y => y.Organization) + .Where(x => x.CompensationRequisitionId == compReqId) .ToList(); } } diff --git a/source/backend/dal/Repositories/Interfaces/ICompensationRequisitionRepository.cs b/source/backend/dal/Repositories/Interfaces/ICompensationRequisitionRepository.cs index a8f559b9f9..0228966c6f 100644 --- a/source/backend/dal/Repositories/Interfaces/ICompensationRequisitionRepository.cs +++ b/source/backend/dal/Repositories/Interfaces/ICompensationRequisitionRepository.cs @@ -21,6 +21,8 @@ public interface ICompensationRequisitionRepository : IRepository GetLeaseCompReqPropertiesById(long compensationRequisitionId); - IEnumerable GetCompensationRequisitionFinancials(long id); + IEnumerable GetCompensationRequisitionFinancials(long compReqId); + + IEnumerable GetCompensationRequisitionPayees(long compReqId); } } diff --git a/source/backend/entities/Partials/PimsCompReqPayee.cs b/source/backend/entities/Partials/PimsCompReqPayee.cs new file mode 100644 index 0000000000..13500ef14c --- /dev/null +++ b/source/backend/entities/Partials/PimsCompReqPayee.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Pims.Dal.Entities +{ + + /// + /// PimsCompReqPayee class, provides an entity for the datamodel to manage the relationship between Compensation Requisitions and the payee. + /// + public partial class PimsCompReqPayee : StandardIdentityBaseAppEntity, IBaseAppEntity + { + [NotMapped] + public override long Internal_Id { get => CompReqPayeeId; set => CompReqPayeeId = value; } + } +} diff --git a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs index ad702a05fb..e2a6dcf329 100644 --- a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs +++ b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs @@ -1020,199 +1020,199 @@ public void Update_ProjectContractor_Removed() act.Should().Throw(); } - //[Fact] - //public void Update_FKException_Removed_AcqFileOwner() - //{ - // // Arrange - // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - // var acqFile = EntityHelper.CreateAcquisitionFile(); - // acqFile.PimsAcquisitionOwners = new List() { - // new PimsAcquisitionOwner() { - // AcquisitionOwnerId = 100, - // }, - // }; - - // var repository = this._helper.GetService>(); - // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - // var compReqRepository = this._helper.GetService>(); - // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - // .Returns(new List() { - // new PimsCompensationRequisition() { - // CompensationRequisitionId = 1, - // AcquisitionFileId = acqFile.Internal_Id, - // AcquisitionOwnerId = 100, - // }, - // }); - - // var lookupRepository = this._helper.GetService>(); - // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - // var userRepository = this._helper.GetService>(); - // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - // var agreementRepository = this._helper.GetService>(); - // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - // var solver = this._helper.GetService>(); - // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // // Act - // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // // Assert - // act.Should().Throw(); - // repository.Verify(x => x.Update(It.IsAny()), Times.Never); - //} - - //[Fact] - //public void Update_FKException_Removed_OwnerSolicitor() - //{ - // // Arrange - // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - // var acqFile = EntityHelper.CreateAcquisitionFile(); - // acqFile.PimsInterestHolders = new List() { - // new PimsInterestHolder() { - // InterestHolderTypeCode = "AOSLCTR", - // InterestHolderId = 100, - // }, - // }; - - // var repository = this._helper.GetService>(); - // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - // var compReqRepository = this._helper.GetService>(); - // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - // .Returns(new List() { - // new PimsCompensationRequisition() { - // CompensationRequisitionId = 1, - // AcquisitionFileId = acqFile.Internal_Id, - // InterestHolderId = 100, - // }, - // }); - - // var lookupRepository = this._helper.GetService>(); - // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - // var userRepository = this._helper.GetService>(); - // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - // var agreementRepository = this._helper.GetService>(); - // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - // var solver = this._helper.GetService>(); - // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // // Act - // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // // Assert - // act.Should().Throw(); - // repository.Verify(x => x.Update(It.IsAny()), Times.Never); - //} - - //[Fact] - //public void Update_FKException_Removed_OwnerRepresentative() - //{ - // // Arrange - // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - // var acqFile = EntityHelper.CreateAcquisitionFile(); - // acqFile.PimsInterestHolders = new List() { - // new PimsInterestHolder() { - // InterestHolderTypeCode = "AOREP", - // InterestHolderId = 100, - // }, - // }; - - // var repository = this._helper.GetService>(); - // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - // var compReqRepository = this._helper.GetService>(); - // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - // .Returns(new List() { - // new PimsCompensationRequisition() { - // CompensationRequisitionId = 1, - // AcquisitionFileId = acqFile.Internal_Id, - // InterestHolderId = 100, - // }, - // }); - - // var lookupRepository = this._helper.GetService>(); - // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - // var userRepository = this._helper.GetService>(); - // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - // var agreementRepository = this._helper.GetService>(); - // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - // var solver = this._helper.GetService>(); - // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // // Act - // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // // Assert - // act.Should().Throw(); - // repository.Verify(x => x.Update(It.IsAny()), Times.Never); - //} - - //[Fact] - //public void Update_FKException_Removed_PersonOfInterest() - //{ - // // Arrange - // var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); - - // var acqFile = EntityHelper.CreateAcquisitionFile(); - // acqFile.PimsAcquisitionFileTeams = new List() { - // new PimsAcquisitionFileTeam() { - // AcquisitionFileTeamId = 100, - // }, - // }; - - // var repository = this._helper.GetService>(); - // repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); - // repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); - // repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); - - // var compReqRepository = this._helper.GetService>(); - // compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) - // .Returns(new List() { - // new PimsCompensationRequisition() { - // CompensationRequisitionId = 1, - // AcquisitionFileId = acqFile.Internal_Id, - // AcquisitionFileTeamId = 100, - // }, - // }); - - // var lookupRepository = this._helper.GetService>(); - // lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); - // var userRepository = this._helper.GetService>(); - // userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); - - // var agreementRepository = this._helper.GetService>(); - // agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); - - // var solver = this._helper.GetService>(); - // solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); - - // // Act - // var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); - // Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); - - // // Assert - // act.Should().Throw(); - // repository.Verify(x => x.Update(It.IsAny()), Times.Never); - //} + [Fact] + public void Update_FKException_Removed_AcqFileOwner() + { + // Arrange + var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + var acqFile = EntityHelper.CreateAcquisitionFile(); + acqFile.PimsAcquisitionOwners = new List() { + new PimsAcquisitionOwner() { + AcquisitionOwnerId = 100, + }, + }; + + var repository = this._helper.GetService>(); + repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + var compReqRepository = this._helper.GetService>(); + compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + .Returns(new List() { + new PimsCompensationRequisition() { + CompensationRequisitionId = 1, + AcquisitionFileId = acqFile.Internal_Id, + AcquisitionOwnerId = 100, + }, + }); + + var lookupRepository = this._helper.GetService>(); + lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + var userRepository = this._helper.GetService>(); + userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + var agreementRepository = this._helper.GetService>(); + agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + var solver = this._helper.GetService>(); + solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // Act + var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // Assert + act.Should().Throw(); + repository.Verify(x => x.Update(It.IsAny()), Times.Never); + } + + [Fact] + public void Update_FKException_Removed_OwnerSolicitor() + { + // Arrange + var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + var acqFile = EntityHelper.CreateAcquisitionFile(); + acqFile.PimsInterestHolders = new List() { + new PimsInterestHolder() { + InterestHolderTypeCode = "AOSLCTR", + InterestHolderId = 100, + }, + }; + + var repository = this._helper.GetService>(); + repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + var compReqRepository = this._helper.GetService>(); + compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + .Returns(new List() { + new PimsCompensationRequisition() { + CompensationRequisitionId = 1, + AcquisitionFileId = acqFile.Internal_Id, + InterestHolderId = 100, + }, + }); + + var lookupRepository = this._helper.GetService>(); + lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + var userRepository = this._helper.GetService>(); + userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + var agreementRepository = this._helper.GetService>(); + agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + var solver = this._helper.GetService>(); + solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // Act + var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // Assert + act.Should().Throw(); + repository.Verify(x => x.Update(It.IsAny()), Times.Never); + } + + [Fact] + public void Update_FKException_Removed_OwnerRepresentative() + { + // Arrange + var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + var acqFile = EntityHelper.CreateAcquisitionFile(); + acqFile.PimsInterestHolders = new List() { + new PimsInterestHolder() { + InterestHolderTypeCode = "AOREP", + InterestHolderId = 100, + }, + }; + + var repository = this._helper.GetService>(); + repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + var compReqRepository = this._helper.GetService>(); + compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + .Returns(new List() { + new PimsCompensationRequisition() { + CompensationRequisitionId = 1, + AcquisitionFileId = acqFile.Internal_Id, + InterestHolderId = 100, + }, + }); + + var lookupRepository = this._helper.GetService>(); + lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + var userRepository = this._helper.GetService>(); + userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + var agreementRepository = this._helper.GetService>(); + agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + var solver = this._helper.GetService>(); + solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // Act + var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // Assert + act.Should().Throw(); + repository.Verify(x => x.Update(It.IsAny()), Times.Never); + } + + [Fact] + public void Update_FKException_Removed_PersonOfInterest() + { + // Arrange + var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); + + var acqFile = EntityHelper.CreateAcquisitionFile(); + acqFile.PimsAcquisitionFileTeams = new List() { + new PimsAcquisitionFileTeam() { + AcquisitionFileTeamId = 100, + }, + }; + + var repository = this._helper.GetService>(); + repository.Setup(x => x.GetRowVersion(It.IsAny())).Returns(1); + repository.Setup(x => x.Update(It.IsAny())).Returns(acqFile); + repository.Setup(x => x.GetById(It.IsAny())).Returns(acqFile); + + var compReqRepository = this._helper.GetService>(); + compReqRepository.Setup(x => x.GetAllByAcquisitionFileId(It.IsAny())) + .Returns(new List() { + new PimsCompensationRequisition() { + CompensationRequisitionId = 1, + AcquisitionFileId = acqFile.Internal_Id, + AcquisitionFileTeamId = 100, + }, + }); + + var lookupRepository = this._helper.GetService>(); + lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + var userRepository = this._helper.GetService>(); + userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser("Test")); + + var agreementRepository = this._helper.GetService>(); + agreementRepository.Setup(x => x.GetAgreementsByAcquisitionFile(It.IsAny())).Returns(new List()); + + var solver = this._helper.GetService>(); + solver.Setup(x => x.CanEditDetails(It.IsAny())).Returns(true); + + // Act + var updatedAcqFile = EntityHelper.CreateAcquisitionFile(); + Action act = () => service.Update(updatedAcqFile, new List() { UserOverrideCode.UpdateRegion }); + + // Assert + act.Should().Throw(); + repository.Verify(x => x.Update(It.IsAny()), Times.Never); + } [Fact] public void Update_NewTotalAllowableCompensation_Success() diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH120.ts b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH120.ts index 4d907f4a67..5d9f04bac2 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH120.ts +++ b/source/frontend/src/features/mapSideBar/acquisition/common/GenerateForm/hooks/useGenerateH120.ts @@ -145,14 +145,14 @@ export const useGenerateH120 = () => { file.fileProperties = fileProperties; - if (compensation.compReqLeaseStakeholder?.length > 0) { - const leaseStakeHolder = compensation.compReqLeaseStakeholder[0].leaseStakeholder; + if (compensation.compReqLeaseStakeholders?.length > 0) { + const leaseStakeHolder = compensation.compReqLeaseStakeholders[0].leaseStakeholder; if (leaseStakeHolder.lessorType.id === ApiGen_CodeTypes_LessorTypes.PER) { const { data } = await getPersonConcept(leaseStakeHolder.personId); - compensation.compReqLeaseStakeholder[0].leaseStakeholder.person = data; + compensation.compReqLeaseStakeholders[0].leaseStakeholder.person = data; } else if (leaseStakeHolder.lessorType.id === ApiGen_CodeTypes_LessorTypes.ORG) { const { data } = await getOrganizationConcept(leaseStakeHolder.organizationId); - compensation.compReqLeaseStakeholder[0].leaseStakeholder.organization = data; + compensation.compReqLeaseStakeholders[0].leaseStakeholder.organization = data; } } diff --git a/source/frontend/src/features/mapSideBar/acquisition/models/PayeeOptionModel.ts b/source/frontend/src/features/mapSideBar/acquisition/models/PayeeOptionModel.ts index c68cd4436c..7850c00ce1 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/models/PayeeOptionModel.ts +++ b/source/frontend/src/features/mapSideBar/acquisition/models/PayeeOptionModel.ts @@ -1,19 +1,18 @@ import { InterestHolderType } from '@/constants/interestHolderTypes'; -import { ApiGen_CodeTypes_LeaseStakeholderTypes } from '@/models/api/generated/ApiGen_CodeTypes_LeaseStakeholderTypes'; -import { ApiGen_CodeTypes_LessorTypes } from '@/models/api/generated/ApiGen_CodeTypes_LessorTypes'; import { ApiGen_Concepts_AcquisitionFileOwner } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFileOwner'; import { ApiGen_Concepts_AcquisitionFileTeam } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFileTeam'; import { ApiGen_Concepts_CompensationRequisition } from '@/models/api/generated/ApiGen_Concepts_CompensationRequisition'; -import { ApiGen_Concepts_CompReqLeaseStakeholder } from '@/models/api/generated/ApiGen_Concepts_CompReqLeaseStakeholder'; +import { ApiGen_Concepts_CompReqPayee } from '@/models/api/generated/ApiGen_Concepts_CompReqPayee'; import { ApiGen_Concepts_InterestHolder } from '@/models/api/generated/ApiGen_Concepts_InterestHolder'; import { ApiGen_Concepts_LeaseStakeholder } from '@/models/api/generated/ApiGen_Concepts_LeaseStakeholder'; import { getEmptyBaseAudit } from '@/models/defaultInitializers'; -import { exists, isNullOrWhitespace } from '@/utils'; +import { exists } from '@/utils'; import { formatApiPersonNames } from '@/utils/personUtils'; import { PayeeType } from './PayeeTypeModel'; export class PayeeOption { + public readonly payee_api_id: number | null; public readonly api_id: number; public readonly text: string; public readonly fullText: string; @@ -21,20 +20,21 @@ export class PayeeOption { public readonly payeeType: PayeeType; private constructor( + payee_api_id: number | null, api_id: number, name: string, key: string, value: string, payeeType: PayeeType, ) { + this.payee_api_id = payee_api_id; this.api_id = api_id; this.fullText = `${name} (${key})`; this.text = `${PayeeOption.truncateName(name)} (${key})`; this.value = value; this.payeeType = payeeType; } - - public static fromApi(apiModel: ApiGen_Concepts_CompensationRequisition): string { + public static getKeyFromPayee(apiModel: ApiGen_Concepts_CompReqPayee): string { if (apiModel.acquisitionOwnerId) { return PayeeOption.generateKey(apiModel.acquisitionOwnerId, PayeeType.Owner); } @@ -57,100 +57,65 @@ export class PayeeOption { } } - if (apiModel.compReqLeaseStakeholder?.length > 0) { - return PayeeOption.generateKey( - apiModel.compReqLeaseStakeholder[0].leaseStakeholderId, - PayeeType.LeaseStakeholder, - ); - } + return ''; + } - if (apiModel.legacyPayee) { - return PayeeOption.generateKey(apiModel.id, PayeeType.LegacyPayee); - } + public static getKeyFromLeaseStakeholder(apiModel: ApiGen_Concepts_LeaseStakeholder): string { + return PayeeOption.generateKey(apiModel.leaseStakeholderId, PayeeType.LeaseStakeholder); + } - return ''; + public static getKeyFromLegacyPayee(compReqId: number): string { + return PayeeOption.generateKey(compReqId, PayeeType.LegacyPayee); + } + + public static fromApi(compReqPayee: ApiGen_Concepts_CompReqPayee): PayeeOption { + if (compReqPayee.acquisitionOwnerId) { + return PayeeOption.createOwner( + compReqPayee.acquisitionOwner, + compReqPayee.compensationRequisitionId, + ); + } else if (compReqPayee.acquisitionFileTeamId) { + return PayeeOption.createTeamMember( + compReqPayee.acquisitionFileTeam, + compReqPayee.compensationRequisitionId, + ); + } else if (compReqPayee.interestHolderId) { + return PayeeOption.createInterestHolder( + compReqPayee.interestHolder, + compReqPayee.compensationRequisitionId, + ); + } } - public static toApi( - compensationRequisitionId: number, - payeeKey: string, - options: PayeeOption[], - ): ApiGen_Concepts_CompensationRequisition { - const compensationModel: ApiGen_Concepts_CompensationRequisition = { - acquisitionFileId: null, - leaseId: null, - isPaymentInTrust: null, - gstNumber: null, + public toApi(): ApiGen_Concepts_CompReqPayee { + const compReqPayeeModel: ApiGen_Concepts_CompReqPayee = { + compensationRequisitionId: null, + compensationRequisition: null, acquisitionOwnerId: null, - alternateProject: null, - alternateProjectId: null, - interestHolderId: null, - acquisitionFileTeam: null, acquisitionOwner: null, + interestHolderId: null, interestHolder: null, acquisitionFileTeamId: null, - id: null, - acquisitionFile: null, - isDraft: null, - fiscalYear: null, - yearlyFinancialId: null, - yearlyFinancial: null, - chartOfAccountsId: null, - chartOfAccounts: null, - responsibilityId: null, - responsibility: null, - agreementDate: null, - expropriationNoticeServedDate: null, - expropriationVestingDate: null, - generationDate: null, - financials: [], - compReqLeaseStakeholder: [], - compReqAcquisitionProperties: [], - compReqLeaseProperties: [], - legacyPayee: null, - finalizedDate: null, - specialInstruction: null, - detailedRemarks: null, + acquisitionFileTeam: null, + compReqPayeeId: null, ...getEmptyBaseAudit(), }; - if (isNullOrWhitespace(payeeKey)) { - return compensationModel; - } - - const payeeOption = options?.find(x => x.value === payeeKey) ?? null; - - if (payeeOption === null) { - return compensationModel; - } - - switch (payeeOption.payeeType) { + switch (this.payeeType) { case PayeeType.AcquisitionTeam: - compensationModel.acquisitionFileTeamId = payeeOption.api_id; + compReqPayeeModel.acquisitionFileTeamId = this.api_id; break; case PayeeType.OwnerRepresentative: case PayeeType.OwnerSolicitor: case PayeeType.InterestHolder: - compensationModel.interestHolderId = payeeOption.api_id; + compReqPayeeModel.interestHolderId = this.api_id; break; case PayeeType.Owner: - compensationModel.acquisitionOwnerId = payeeOption.api_id; - break; - case PayeeType.LeaseStakeholder: - { - const leaseStakeHolderPayee: ApiGen_Concepts_CompReqLeaseStakeholder = { - compReqLeaseStakeholderId: null, - compensationRequisitionId: compensationRequisitionId, - leaseStakeholderId: payeeOption.api_id, - leaseStakeholder: null, - } as ApiGen_Concepts_CompReqLeaseStakeholder; - - compensationModel.compReqLeaseStakeholder = [leaseStakeHolderPayee]; - } + compReqPayeeModel.acquisitionOwnerId = this.api_id; break; } - return compensationModel; + return compReqPayeeModel; } private static truncateName(name: string): string { @@ -161,12 +126,16 @@ export class PayeeOption { } } - public static createOwner(model: ApiGen_Concepts_AcquisitionFileOwner): PayeeOption { + public static createOwner( + model: ApiGen_Concepts_AcquisitionFileOwner, + compReqPayeeId: number | null, + ): PayeeOption { const name = model.isOrganization ? `${model.lastNameAndCorpName}, Inc. No. ${model.incorporationNumber} (OR Reg. No. ${model.registrationNumber})` : [model.givenName, model.lastNameAndCorpName, model.otherName].filter(x => !!x).join(' '); return new PayeeOption( + compReqPayeeId, model.id || 0, name, 'Owner', @@ -175,7 +144,10 @@ export class PayeeOption { ); } - public static createOwnerSolicitor(model: ApiGen_Concepts_InterestHolder): PayeeOption { + public static createOwnerSolicitor( + model: ApiGen_Concepts_InterestHolder, + compReqPayeeId: number | null, + ): PayeeOption { let name = ''; if (model.person) { name = formatApiPersonNames(model.person); @@ -183,6 +155,7 @@ export class PayeeOption { name = model.organization?.name || ''; } return new PayeeOption( + compReqPayeeId, model.interestHolderId || 0, name, `Owner's Solicitor`, @@ -191,9 +164,13 @@ export class PayeeOption { ); } - public static createOwnerRepresentative(model: ApiGen_Concepts_InterestHolder): PayeeOption { + public static createOwnerRepresentative( + model: ApiGen_Concepts_InterestHolder, + compReqPayeeId: number | null, + ): PayeeOption { const name = formatApiPersonNames(model.person); return new PayeeOption( + compReqPayeeId, model.interestHolderId || 0, name, `Owner's Representative`, @@ -202,7 +179,10 @@ export class PayeeOption { ); } - public static createTeamMember(model: ApiGen_Concepts_AcquisitionFileTeam): PayeeOption { + public static createTeamMember( + model: ApiGen_Concepts_AcquisitionFileTeam, + compReqPayeeId: number | null, + ): PayeeOption { let name = ''; if (model.person) { name = formatApiPersonNames(model.person); @@ -210,6 +190,7 @@ export class PayeeOption { name = model.organization?.name || ''; } return new PayeeOption( + compReqPayeeId, model.id || 0, name, model.teamProfileType?.description ?? '', @@ -218,11 +199,14 @@ export class PayeeOption { ); } - public static createInterestHolder(model: ApiGen_Concepts_InterestHolder): PayeeOption { + public static createInterestHolder( + model: ApiGen_Concepts_InterestHolder, + compReqPayeeId: number | null, + ): PayeeOption { if (model.interestHolderType?.id === InterestHolderType.OWNER_SOLICITOR) { - return this.createOwnerSolicitor(model); + return this.createOwnerSolicitor(model, compReqPayeeId); } else if (model.interestHolderType?.id === InterestHolderType.OWNER_REPRESENTATIVE) { - return this.createOwnerRepresentative(model); + return this.createOwnerRepresentative(model, compReqPayeeId); } let name = ''; @@ -242,6 +226,7 @@ export class PayeeOption { : 'ERROR: Missing interest holder'; return new PayeeOption( + null, model.interestHolderId || 0, name, `${typeDescription}`, @@ -250,46 +235,12 @@ export class PayeeOption { ); } - public static createLeaseStakeholder(model: ApiGen_Concepts_LeaseStakeholder): PayeeOption { - let payeeName: string; - let payeeDescription: string; - - switch (model.lessorType.id) { - case ApiGen_CodeTypes_LessorTypes.ORG: - payeeName = `${model?.organization?.name ?? ''}, Inc. No. ${ - model?.organization?.incorporationNumber ?? '' - }`; - break; - case ApiGen_CodeTypes_LessorTypes.PER: - payeeName = formatApiPersonNames(model.person); - break; - default: - payeeName = ApiGen_CodeTypes_LessorTypes.UNK; - } - - switch (model.stakeholderTypeCode.id) { - case ApiGen_CodeTypes_LeaseStakeholderTypes.OWNER: - payeeDescription = 'Owner'; - break; - case ApiGen_CodeTypes_LeaseStakeholderTypes.OWNREP: - payeeDescription = `Owner's Representative`; - break; - default: - payeeDescription = model.stakeholderTypeCode.description; - break; - } - - return new PayeeOption( - model.leaseStakeholderId || 0, - payeeName, - payeeDescription, - PayeeOption.generateKey(model.leaseStakeholderId, PayeeType.LeaseStakeholder), - PayeeType.LeaseStakeholder, - ); - } - - public static createLegacyPayee(model: ApiGen_Concepts_CompensationRequisition): PayeeOption { + public static createLegacyPayee( + model: ApiGen_Concepts_CompensationRequisition, + compReqPayeeId: number | null, + ): PayeeOption { return new PayeeOption( + compReqPayeeId, model.id || 0, model.legacyPayee || '', 'Legacy free-text value', diff --git a/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailContainer.tsx b/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailContainer.tsx index 3f7d0a3b31..ef90924031 100644 --- a/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailContainer.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailContainer.tsx @@ -13,8 +13,7 @@ import { ApiGen_Concepts_AcquisitionFile } from '@/models/api/generated/ApiGen_C import { ApiGen_Concepts_CompensationRequisition } from '@/models/api/generated/ApiGen_Concepts_CompensationRequisition'; import { ApiGen_Concepts_FileProperty } from '@/models/api/generated/ApiGen_Concepts_FileProperty'; import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease'; -import { ApiGen_Concepts_Organization } from '@/models/api/generated/ApiGen_Concepts_Organization'; -import { ApiGen_Concepts_Person } from '@/models/api/generated/ApiGen_Concepts_Person'; +import { ApiGen_Concepts_LeaseStakeholder } from '@/models/api/generated/ApiGen_Concepts_LeaseStakeholder'; import { exists, isValidId } from '@/utils'; import { CompensationRequisitionDetailViewProps } from './CompensationRequisitionDetailView'; @@ -33,8 +32,9 @@ export const CompensationRequisitionDetailContainer: React.FunctionComponent< React.PropsWithChildren > = ({ compensation, setEditMode, View, clientConstant, fileType, file, loading }) => { const onGenerate = useGenerateH120(); - const [payeePerson, setPayeePerson] = useState(); - const [payeeOrganization, setPayeeOrganization] = useState(); + const [compensationLeaseStakeHolders, setCompensationLeaseStakeHolders] = useState< + ApiGen_Concepts_LeaseStakeholder[] | null + >(); const [compensationRequisitionProperties, setCompensationRequisitionProperties] = useState< ApiGen_Concepts_FileProperty[] @@ -45,6 +45,11 @@ export const CompensationRequisitionDetailContainer: React.FunctionComponent< execute: getCompensationProperties, loading: loadingCompReqProperties, }, + getCompensationRequisitionPayees: { + execute: getCompensationPayees, + loading: loadingCompReqPayees, + response: compReqPayees, + }, } = useCompensationRequisitionRepository(); const { @@ -58,42 +63,24 @@ export const CompensationRequisitionDetailContainer: React.FunctionComponent< const fetchCompensationPayee = useCallback(async () => { if (isValidId(compensation.id)) { try { - if (exists(compensation.acquisitionFileTeam)) { - if (isValidId(compensation.acquisitionFileTeam.personId)) { - const person = await getPerson(compensation.acquisitionFileTeam.personId); - setPayeePerson(person); - } - if (isValidId(compensation.acquisitionFileTeam.organizationId)) { - const organization = await getOrganization( - compensation.acquisitionFileTeam.organizationId, - ); - setPayeeOrganization(organization); - } - } else if (compensation.interestHolder) { - if (isValidId(compensation.interestHolder.personId)) { - const person = await getPerson(compensation.interestHolder.personId); - setPayeePerson(person); - } - if (isValidId(compensation.interestHolder.organizationId)) { - const organization = await getOrganization(compensation.interestHolder.organizationId); - setPayeeOrganization(organization); - } - } else if (compensation.compReqLeaseStakeholder?.length > 0) { - const stakeHolder = compensation.compReqLeaseStakeholder[0].leaseStakeholder; + if ( + (!exists(compReqPayees) || compReqPayees.length === 0) && + compensation.compReqLeaseStakeholders?.length > 0 + ) { + const stakeHolder = compensation.compReqLeaseStakeholders[0].leaseStakeholder; if (stakeHolder.lessorType.id === ApiGen_CodeTypes_LessorTypes.ORG) { const org = await getOrganization(stakeHolder.organizationId); - setPayeeOrganization(org); + setCompensationLeaseStakeHolders([{ ...stakeHolder, organization: org }]); } else if (stakeHolder.lessorType.id === ApiGen_CodeTypes_LessorTypes.PER) { const person = await getPerson(stakeHolder.personId); - setPayeePerson(person); + setCompensationLeaseStakeHolders([{ ...stakeHolder, person: person }]); } } } catch (e) { if (axios.isAxiosError(e)) { const axiosError = e as AxiosError; if (axiosError.response?.status === 404) { - setPayeePerson(null); - setPayeeOrganization(null); + setCompensationLeaseStakeHolders([]); } else { toast.error(axiosError.response?.data.error); } @@ -101,10 +88,9 @@ export const CompensationRequisitionDetailContainer: React.FunctionComponent< } } }, [ - compensation.acquisitionFileTeam, - compensation.compReqLeaseStakeholder, + compReqPayees, + compensation.compReqLeaseStakeholders, compensation.id, - compensation.interestHolder, getOrganization, getPerson, ]); @@ -116,6 +102,12 @@ export const CompensationRequisitionDetailContainer: React.FunctionComponent< } }, [compensation.id, fileType, getCompensationProperties]); + const fetchCompensationPayees = useCallback(async () => { + if (isValidId(compensation.id)) { + await getCompensationPayees(compensation.id); + } + }, [compensation.id, getCompensationPayees]); + useEffect(() => { fetchCompensationPayee(); }, [fetchCompensationPayee]); @@ -124,18 +116,28 @@ export const CompensationRequisitionDetailContainer: React.FunctionComponent< fetchCompensationProperties(); }, [fetchCompensationProperties]); + useEffect(() => { + fetchCompensationPayees(); + }, [fetchCompensationPayees]); + return compensation ? ( ) : null; }; diff --git a/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.tsx b/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.tsx index 7f502a7c14..3136ebcd61 100644 --- a/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useMemo } from 'react'; import { Col, Row } from 'react-bootstrap'; import { FaExternalLinkAlt, FaFileContract } from 'react-icons/fa'; import { Link } from 'react-router-dom'; @@ -18,11 +18,11 @@ import useKeycloakWrapper from '@/hooks/useKeycloakWrapper'; import { ApiGen_CodeTypes_FileTypes } from '@/models/api/generated/ApiGen_CodeTypes_FileTypes'; import { ApiGen_Concepts_AcquisitionFile } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFile'; import { ApiGen_Concepts_CompensationRequisition } from '@/models/api/generated/ApiGen_Concepts_CompensationRequisition'; +import { ApiGen_Concepts_CompReqPayee } from '@/models/api/generated/ApiGen_Concepts_CompReqPayee'; import { ApiGen_Concepts_FileProperty } from '@/models/api/generated/ApiGen_Concepts_FileProperty'; import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease'; -import { ApiGen_Concepts_Organization } from '@/models/api/generated/ApiGen_Concepts_Organization'; -import { ApiGen_Concepts_Person } from '@/models/api/generated/ApiGen_Concepts_Person'; -import { exists, formatMoney, getFilePropertyName, prettyFormatDate } from '@/utils'; +import { ApiGen_Concepts_LeaseStakeholder } from '@/models/api/generated/ApiGen_Concepts_LeaseStakeholder'; +import { exists, formatMoney, getFilePropertyName, isValidId, prettyFormatDate } from '@/utils'; import { formatApiPersonNames } from '@/utils/personUtils'; import { cannotEditMessage } from '../../acquisition/common/constants'; @@ -35,8 +35,8 @@ export interface CompensationRequisitionDetailViewProps { file: ApiGen_Concepts_AcquisitionFile | ApiGen_Concepts_Lease; compensation: ApiGen_Concepts_CompensationRequisition; compensationProperties: ApiGen_Concepts_FileProperty[]; - compensationContactPerson: ApiGen_Concepts_Person | undefined; - compensationContactOrganization: ApiGen_Concepts_Organization | undefined; + compensationPayees: ApiGen_Concepts_CompReqPayee[]; + compensationLeaseStakeHolders: ApiGen_Concepts_LeaseStakeholder[]; clientConstant: string; loading: boolean; setEditMode: (editMode: boolean) => void; @@ -47,8 +47,8 @@ export interface CompensationRequisitionDetailViewProps { } export interface PayeeViewDetails { + compReqPayeeId: number; displayName: string; - isGstApplicable: boolean; isPaymentInTrust: boolean; contactEnabled: boolean; contactString: string | null; @@ -61,80 +61,106 @@ export const CompensationRequisitionDetailView: React.FunctionComponent< file, compensation, compensationProperties, - compensationContactPerson, - compensationContactOrganization, + compensationPayees, + compensationLeaseStakeHolders, clientConstant, loading, setEditMode, onGenerate, }) => { const { hasClaim, hasRole } = useKeycloakWrapper(); - const [payeeDetails, setPayeeDetails] = useState(null); const alternateProjectName = exists(compensation?.alternateProject) ? compensation?.alternateProject?.code + ' - ' + compensation?.alternateProject?.description : ''; - useEffect(() => { + const payeeDetails = useMemo(() => [], []); + + const results = + compensation.financials?.filter(el => { + return el.isGstRequired === true; + }) || []; + + const isGstApplicable = results.length > 0; + + useMemo(() => { if (!compensation) { - setPayeeDetails(null); return; } - const payeeDetail: PayeeViewDetails = { - contactEnabled: false, - isPaymentInTrust: compensation?.isPaymentInTrust || false, - isGstApplicable: false, - contactString: null, - displayName: '', - }; - - if (compensation.acquisitionOwner) { - const ownerDetail = DetailAcquisitionFileOwner.fromApi(compensation.acquisitionOwner); - payeeDetail.displayName = ownerDetail.ownerName ?? ''; - } else if (compensation.interestHolderId) { - if (compensationContactPerson) { - payeeDetail.displayName = formatApiPersonNames(compensationContactPerson); - payeeDetail.contactString = 'P' + compensationContactPerson?.id; - payeeDetail.contactEnabled = true; - } else if (compensationContactOrganization) { - payeeDetail.displayName = compensationContactOrganization?.name ?? ''; - payeeDetail.contactString = 'O' + compensationContactOrganization.id; - payeeDetail.contactEnabled = true; - } - } else if (compensation.acquisitionFileTeamId) { - if (compensationContactPerson) { - payeeDetail.displayName = formatApiPersonNames(compensationContactPerson); - payeeDetail.contactString = 'P' + compensationContactPerson?.id; - payeeDetail.contactEnabled = true; - } else if (compensationContactOrganization) { - payeeDetail.displayName = compensationContactOrganization?.name ?? ''; - payeeDetail.contactString = 'O' + compensationContactOrganization.id; - payeeDetail.contactEnabled = true; - } - } else if (compensation.compReqLeaseStakeholder?.length > 0) { - if (compensationContactPerson) { - payeeDetail.displayName = formatApiPersonNames(compensationContactPerson); - payeeDetail.contactString = 'P' + compensationContactPerson?.id; + if (compensationPayees?.length > 0) { + compensationPayees.forEach((currentPayee: ApiGen_Concepts_CompReqPayee) => { + const currentPayeeDetail: PayeeViewDetails = { + compReqPayeeId: currentPayee.compReqPayeeId, + contactEnabled: false, + isPaymentInTrust: compensation?.isPaymentInTrust || false, + contactString: null, + displayName: '', + }; + + if (currentPayee.acquisitionOwner) { + const ownerDetail = DetailAcquisitionFileOwner.fromApi(currentPayee.acquisitionOwner); + currentPayeeDetail.displayName = ownerDetail.ownerName ?? ''; + } else if (isValidId(currentPayee.interestHolderId)) { + if (exists(currentPayee?.interestHolder?.personId)) { + currentPayeeDetail.displayName = formatApiPersonNames( + currentPayee.interestHolder.person, + ); + currentPayeeDetail.contactString = 'P' + currentPayee.interestHolder.person.id; + currentPayeeDetail.contactEnabled = true; + } else if (currentPayee?.interestHolder?.organizationId) { + currentPayeeDetail.displayName = currentPayee.interestHolder.organization.name ?? ''; + currentPayeeDetail.contactString = 'O' + currentPayee.interestHolder.organization.id; + currentPayeeDetail.contactEnabled = true; + } + } else if (isValidId(currentPayee?.acquisitionFileTeamId)) { + if (currentPayee?.acquisitionFileTeam?.personId) { + currentPayeeDetail.displayName = formatApiPersonNames( + currentPayee.acquisitionFileTeam.person, + ); + currentPayeeDetail.contactString = 'P' + currentPayee.acquisitionFileTeam.person?.id; + currentPayeeDetail.contactEnabled = true; + } else if (currentPayee?.acquisitionFileTeam?.organizationId) { + currentPayeeDetail.displayName = + currentPayee.acquisitionFileTeam.organization?.name ?? ''; + currentPayeeDetail.contactString = + 'O' + currentPayee.acquisitionFileTeam.organization?.id; + currentPayeeDetail.contactEnabled = true; + } + } + + payeeDetails.push(currentPayeeDetail); + }); + } else if (compensationLeaseStakeHolders?.length > 0) { + const stakeHolder = compensationLeaseStakeHolders[0]; + const payeeDetail: PayeeViewDetails = { + compReqPayeeId: stakeHolder.leaseStakeholderId, + contactEnabled: false, + isPaymentInTrust: compensation?.isPaymentInTrust || false, + contactString: null, + displayName: '', + }; + + if (exists(stakeHolder?.personId)) { + payeeDetail.displayName = formatApiPersonNames(stakeHolder?.person); + payeeDetail.contactString = 'P' + stakeHolder.person?.id; payeeDetail.contactEnabled = true; - } else if (compensationContactOrganization) { - payeeDetail.displayName = compensationContactOrganization?.name ?? ''; - payeeDetail.contactString = 'O' + compensationContactOrganization.id; + } else if (exists(stakeHolder?.organizationId)) { + payeeDetail.displayName = stakeHolder.organization?.name ?? ''; + payeeDetail.contactString = 'O' + stakeHolder.organization?.id; payeeDetail.contactEnabled = true; } } else if (compensation.legacyPayee) { + const payeeDetail: PayeeViewDetails = { + compReqPayeeId: 0, + contactEnabled: false, + isPaymentInTrust: compensation?.isPaymentInTrust || false, + contactString: null, + displayName: '', + }; payeeDetail.displayName = `${compensation.legacyPayee}`; } - - const results = - compensation.financials?.filter(el => { - return el.isGstRequired === true; - }) || []; - - payeeDetail.isGstApplicable = results.length > 0; - - setPayeeDetails(payeeDetail); - }, [compensation, compensationContactOrganization, compensationContactPerson]); + }, [compensation, compensationLeaseStakeHolders, compensationPayees, payeeDetails]); const compPretaxAmount = compensation?.financials ?.map(f => f.pretaxAmount ?? 0) @@ -358,30 +384,30 @@ export const CompensationRequisitionDetailView: React.FunctionComponent<
- - - {payeeDetails?.contactEnabled && payeeDetails?.contactString && ( - - {payeeDetails.displayName} - - - )} - - {!payeeDetails?.contactEnabled && } - {payeeDetails?.isPaymentInTrust && } - + + {payeeDetails.map(payeeDetail => ( + + {payeeDetail?.contactEnabled && payeeDetail?.contactString && ( + + {payeeDetail.displayName} + + + )} + + {!payeeDetail?.contactEnabled && } + {payeeDetail?.isPaymentInTrust && } + + ))} {formatMoney(compPretaxAmount ?? 0)} - - {payeeDetails?.isGstApplicable ? 'Yes' : 'No'} - - {payeeDetails?.isGstApplicable && ( + {isGstApplicable ? 'Yes' : 'No'} + {isGstApplicable && ( <> {formatMoney(compTaxAmount ?? 0)} {compensation.gstNumber} diff --git a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx index c453fa8ab7..f86f7915df 100644 --- a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.test.tsx @@ -274,7 +274,7 @@ describe('compensation list view container', () => { }, ], compReqLeaseProperties: null, - compReqLeaseStakeholder: null, + compReqLeaseStakeholders: null, } as ApiGen_Concepts_CompensationRequisition; expect(mockPostApi.execute).toHaveBeenCalledWith( @@ -343,7 +343,7 @@ describe('compensation list view container', () => { }, ], compReqAcquisitionProperties: null, - compReqLeaseStakeholder: null, + compReqLeaseStakeholders: null, } as ApiGen_Concepts_CompensationRequisition; expect(mockPostApi.execute).toHaveBeenCalledWith( diff --git a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx index bfd7538eea..e105eb88b4 100644 --- a/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/list/CompensationListContainer.tsx @@ -199,7 +199,7 @@ export const CompensationListContainer: React.FC(formPayee => + formPayee.toApi(), + ); return { - ...modelWithPayeeInformation, id: this.id, acquisitionFileId: this.acquisitionFileId, leaseId: this.leaseId, @@ -88,6 +96,10 @@ export class CompensationRequisitionFormModel { : null, specialInstruction: stringToNull(this.specialInstruction), detailedRemarks: stringToNull(this.detailedRemarks), + legacyPayee: this.legacyPayee, + isPaymentInTrust: this.isPaymentInTrust, + gstNumber: this.gstNumber, + financials: this.financials .filter(x => !x.isEmpty()) .map(x => x.toApi()), @@ -113,7 +125,12 @@ export class CompensationRequisitionFormModel { } as ApiGen_Concepts_CompReqLeaseProperty; }) : null, + compReqPayees: compReqPayees ?? [], + compReqLeaseStakeholders: this.leaseStakeholders ?? [], rowVersion: this.rowVersion ?? null, + acquisitionFile: null, + alternateProject: null, + ...getEmptyBaseAudit(), }; } @@ -180,10 +197,12 @@ export class CompensationRequisitionFormModel { apiModel?.financials?.map(f => f.totalAmount ?? 0).reduce((prev, next) => prev + next, 0) ?? 0; - compensation.payee = CompensationPayeeFormModel.fromApi(apiModel); - compensation.payee.pretaxAmount = payeePretaxAmount; - compensation.payee.taxAmount = payeeTaxAmount; - compensation.payee.totalAmount = payeeTotalAmount; + compensation.payees = + apiModel?.compReqPayees?.map(compReqPayee => PayeeOption.fromApi(compReqPayee)) ?? []; + compensation.pretaxAmount = payeePretaxAmount; + compensation.taxAmount = payeeTaxAmount; + compensation.totalAmount = payeeTotalAmount; + compensation.isPaymentInTrust = apiModel.isPaymentInTrust; if (apiModel.acquisitionFileId != null) { compensation.selectedProperties = apiModel.compReqAcquisitionProperties.map( diff --git a/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.test.tsx b/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.test.tsx index 37184e76cb..cb0c2afe06 100644 --- a/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.test.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.test.tsx @@ -318,9 +318,9 @@ describe('UpdateCompensationRequisition Container component', () => { ApiGen_CodeTypes_FileTypes.Lease, { ...concept, - compReqLeaseStakeholder: [ + compReqLeaseStakeholders: [ { - compReqLeaseStakeholderId: null, + compReqLeaseStakeholdersId: null, compensationRequisitionId: 1, leaseStakeholder: null, leaseStakeholderId: 2, diff --git a/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.tsx b/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.tsx index 0a1cd118ae..9002f2321c 100644 --- a/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionContainer.tsx @@ -80,7 +80,7 @@ const UpdateCompensationRequisitionContainer: React.FC< } = useLeaseStakeholderRepository(); const updateCompensation = async (compensation: CompensationRequisitionFormModel) => { - const compensationApiModel = compensation.toApi(payeeOptions); + const compensationApiModel = compensation.toApi(); const result = await updateCompensationRequisition(fileType, compensationApiModel); if (result !== undefined) { @@ -99,24 +99,18 @@ const UpdateCompensationRequisitionContainer: React.FC< await Promise.all([acquisitionOwnersCall, interestHoldersCall]).then( ([acquisitionOwners, interestHolders]) => { - const matchedInterestHolder = - interestHolders?.find( - ih => ih.interestHolderId === compensation.interestHolderId, - ) ?? null; - compensation.interestHolder = matchedInterestHolder; - const options = payeeOptions ?? []; if (acquisitionOwners !== undefined) { const ownersOptions: PayeeOption[] = acquisitionOwners.map(x => - PayeeOption.createOwner(x), + PayeeOption.createOwner(x, null), ); options.push(...ownersOptions); } if (interestHolders !== undefined) { const interestHolderOptions: PayeeOption[] = interestHolders.map(x => - PayeeOption.createInterestHolder(x), + PayeeOption.createInterestHolder(x, null), ); options.push(...interestHolderOptions); } @@ -127,11 +121,11 @@ const UpdateCompensationRequisitionContainer: React.FC< (x): x is ApiGen_Concepts_AcquisitionFileTeam => exists(x) && x.teamProfileTypeCode === 'MOTILAWYER', ) - .map(x => PayeeOption.createTeamMember(x)) || []; + .map(x => PayeeOption.createTeamMember(x, null)) || []; options.push(...teamMemberOptions); if (compensation.legacyPayee) { - options.push(PayeeOption.createLegacyPayee(compensation)); + options.push(PayeeOption.createLegacyPayee(compensation, null)); } setPayeeOptions(options); @@ -142,8 +136,10 @@ const UpdateCompensationRequisitionContainer: React.FC< case ApiGen_CodeTypes_FileTypes.Lease: { const leaseStakeHolders = await getLeaseStakeholders(file.id); - const stakeHoldersOptions = leaseStakeHolders.map(x => - PayeeOption.createLeaseStakeholder(x), + const stakeHoldersOptions = leaseStakeHolders.map( + x => null, + //PayeeOption.createLeaseStakeholder(x, null), + //TODO ); setPayeeOptions(stakeHoldersOptions); diff --git a/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionForm.tsx b/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionForm.tsx index afe34557ac..32e00ff05a 100644 --- a/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionForm.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/update/UpdateCompensationRequisitionForm.tsx @@ -9,6 +9,7 @@ import { FastCurrencyInput, FastDatePicker, Input, + Multiselect, ProjectSelector, Select, SelectOption, @@ -280,15 +281,16 @@ const UpdateCompensationRequisitionForm: React.FC -