Skip to content

Commit 535feec

Browse files
authored
Merge pull request #1548 from bcgov/dev
Dev
2 parents f832e37 + 7cac551 commit 535feec

47 files changed

Lines changed: 4875 additions & 384 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

applications/Unity.GrantManager/modules/Unity.Flex/src/Unity.Flex.Application.Contracts/Scoresheets/QuestionDto.cs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,74 @@ public class QuestionDto : ExtensibleEntityDto<Guid>
2222

2323
public string? GetMin()
2424
{
25-
return JsonSerializer.Deserialize<NumericDefinition>(Definition ?? "{}")?.Min.ToString();
25+
try
26+
{
27+
var def = JsonSerializer.Deserialize<NumericDefinition>(Definition ?? "{}");
28+
if (def?.Min == null)
29+
return null;
30+
// Only allow Int64 values
31+
if (long.TryParse(def.Min.ToString(), out var minValue))
32+
return minValue.ToString();
33+
return null;
34+
}
35+
catch
36+
{
37+
return null;
38+
}
2639
}
2740

2841
public string? GetMax()
2942
{
30-
return JsonSerializer.Deserialize<NumericDefinition>(Definition ?? "{}")?.Max.ToString();
43+
try
44+
{
45+
var def = JsonSerializer.Deserialize<NumericDefinition>(Definition ?? "{}");
46+
if (def?.Max == null)
47+
return null;
48+
// Only allow Int64 values
49+
if (long.TryParse(def.Max.ToString(), out var maxValue))
50+
return maxValue.ToString();
51+
return null;
52+
}
53+
catch
54+
{
55+
return null;
56+
}
3157
}
3258

3359
public string? GetMinLength()
3460
{
35-
return JsonSerializer.Deserialize<TextDefinition>(Definition ?? "{}")?.MinLength.ToString();
61+
try
62+
{
63+
var def = JsonSerializer.Deserialize<TextDefinition>(Definition ?? "{}");
64+
if (def?.MinLength == null)
65+
return null;
66+
// Only allow Int64 values
67+
if (long.TryParse(def.MinLength.ToString(), out var minLength))
68+
return minLength.ToString();
69+
return null;
70+
}
71+
catch
72+
{
73+
return null;
74+
}
3675
}
3776

3877
public string? GetMaxLength()
3978
{
40-
return JsonSerializer.Deserialize<TextDefinition>(Definition ?? "{}")?.MaxLength.ToString();
79+
try
80+
{
81+
var def = JsonSerializer.Deserialize<TextDefinition>(Definition ?? "{}");
82+
if (def?.MaxLength == null)
83+
return null;
84+
// Only allow Int64 values
85+
if (long.TryParse(def.MaxLength.ToString(), out var maxLength))
86+
return maxLength.ToString();
87+
return null;
88+
}
89+
catch
90+
{
91+
return null;
92+
}
4193
}
4294

4395
public string? GetYesValue()

applications/Unity.GrantManager/modules/Unity.Payments/src/Unity.Payments.Application.Contracts/Enums/PaymentRequestStatus.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ public enum PaymentRequestStatus
99
L1Pending = 1,
1010
L1Declined = 2,
1111
L2Pending = 3,
12-
L2Declined = 4,
13-
L3Pending = 5,
12+
L2Declined = 4,
13+
L3Pending = 5,
1414
L3Declined = 6,
1515
Submitted = 7,
1616
Validated = 8,
1717
NotValidated = 9,
1818
Paid = 10,
19-
Failed = 11,
19+
Failed = 11,
20+
FSB = 12, // Financial Services Branch - Prevent CAS Payment
2021
}
2122
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using Volo.Abp.Application.Dtos;
3+
4+
namespace Unity.Payments.PaymentRequests
5+
{
6+
[Serializable]
7+
public class AccountCodingDto : AuditedEntityDto<Guid>
8+
{
9+
public string MinistryClient { get; private set; }
10+
public string Responsibility { get; private set; }
11+
public string ServiceLine { get; private set; }
12+
public string Stob { get; private set; }
13+
public string ProjectNumber { get; private set; }
14+
public AccountCodingDto()
15+
{
16+
MinistryClient = string.Empty;
17+
Responsibility = string.Empty;
18+
ServiceLine = string.Empty;
19+
Stob = string.Empty;
20+
ProjectNumber = string.Empty;
21+
}
22+
}
23+
}

applications/Unity.GrantManager/modules/Unity.Payments/src/Unity.Payments.Application.Contracts/PaymentRequests/PaymentRequestDto.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class PaymentRequestDto : AuditedEntityDto<Guid>
3535
public string? Note { get; set; }
3636
public string? ErrorSummary { get; set; }
3737
public Guid? AccountCodingId { get; set; }
38+
public AccountCodingDto? AccountCoding { get; set; }
39+
public string AccountCodingDisplay { get; set; } = string.Empty;
3840
public PaymentUserDto? CreatorUser { get; set; }
3941
public Collection<PaymentTagDto> PaymentTags { get; set; }
4042
public Collection<ExpenseApprovalDto> ExpenseApprovals { get; set; }

applications/Unity.GrantManager/modules/Unity.Payments/src/Unity.Payments.Application/Domain/PaymentRequests/PaymentRequest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Unity.Payments.Domain.Exceptions;
1111
using Unity.Payments.PaymentRequests;
1212
using Unity.Payments.Domain.PaymentTags;
13+
using Unity.Payments.Domain.AccountCodings;
1314

1415
namespace Unity.Payments.Domain.PaymentRequests
1516
{
@@ -60,7 +61,7 @@ public virtual Site Site
6061
public virtual int? CasHttpStatusCode { get; private set; } = null;
6162
public virtual string? CasResponse { get; private set; } = string.Empty;
6263
public virtual Guid? AccountCodingId { get; private set; }
63-
64+
public virtual AccountCoding? AccountCoding { get; set; } = null;
6465
public virtual string? Note { get; private set; } = null;
6566
protected PaymentRequest()
6667
{

applications/Unity.GrantManager/modules/Unity.Payments/src/Unity.Payments.Application/Domain/Services/IPaymentsManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ namespace Unity.Payments.Domain.Services
77
public interface IPaymentsManager
88
{
99
Task UpdatePaymentStatusAsync(Guid paymentRequestId, PaymentApprovalAction triggerAction);
10+
Task<bool> GetFormPreventPaymentStatusByPaymentRequestId(Guid paymentRequestId);
11+
Task<bool> GetFormPreventPaymentStatusByApplicationId(Guid applicationId);
1012
}
1113
}

applications/Unity.GrantManager/modules/Unity.Payments/src/Unity.Payments.Application/Domain/Services/PaymentsManager.cs

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using Stateless;
1+
using Microsoft.EntityFrameworkCore;
2+
using Stateless;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
56
using System.Threading.Tasks;
7+
using Unity.GrantManager.Applications;
68
using Unity.Payments.Domain.PaymentRequests;
79
using Unity.Payments.Domain.Shared;
810
using Unity.Payments.Domain.Workflow;
@@ -16,28 +18,15 @@
1618

1719
namespace Unity.Payments.Domain.Services
1820
{
19-
public class PaymentsManager : DomainService, IPaymentsManager
20-
{
21-
/* To be implemented */
22-
private readonly IPaymentRequestRepository _paymentRequestRepository;
23-
private readonly IUnitOfWorkManager _unitOfWorkManager;
24-
private readonly IPermissionChecker _permissionChecker;
25-
private readonly CasPaymentRequestCoordinator _casPaymentRequestCoordinator;
26-
private readonly ICurrentUser _currentUser;
27-
28-
public PaymentsManager(
21+
public class PaymentsManager(
22+
IApplicationRepository applicationRepository,
23+
IApplicationFormRepository applicationFormRepository,
2924
CasPaymentRequestCoordinator casPaymentRequestCoordinator,
3025
IPaymentRequestRepository paymentRequestRepository,
3126
IUnitOfWorkManager unitOfWorkManager,
3227
IPermissionChecker permissionChecker,
33-
ICurrentUser currentUser)
34-
{
35-
_casPaymentRequestCoordinator = casPaymentRequestCoordinator;
36-
_paymentRequestRepository = paymentRequestRepository;
37-
_unitOfWorkManager = unitOfWorkManager;
38-
_permissionChecker = permissionChecker;
39-
_currentUser = currentUser;
40-
}
28+
ICurrentUser currentUser) : DomainService, IPaymentsManager
29+
{
4130

4231
private void ConfigureWorkflow(StateMachine<PaymentRequestStatus, PaymentApprovalAction> paymentStateMachine)
4332
{
@@ -67,13 +56,12 @@ private void ConfigureWorkflow(StateMachine<PaymentRequestStatus, PaymentApprova
6756

6857
private bool HasPermission(string permission)
6958
{
70-
return _permissionChecker.IsGrantedAsync(permission).Result;
59+
return permissionChecker.IsGrantedAsync(permission).Result;
7160
}
7261

73-
7462
public async Task<List<PaymentActionResultItem>> GetActions(Guid paymentRequestsId)
7563
{
76-
var paymentRequest = await _paymentRequestRepository.GetAsync(paymentRequestsId, true);
64+
var paymentRequest = await paymentRequestRepository.GetAsync(paymentRequestsId, true);
7765

7866
var Workflow = new PaymentsWorkflow<PaymentRequestStatus, PaymentApprovalAction>(
7967
() => paymentRequest.Status,
@@ -98,8 +86,8 @@ public async Task<List<PaymentActionResultItem>> GetActions(Guid paymentRequests
9886

9987
public async Task<PaymentRequest> TriggerAction(Guid paymentRequestsId, PaymentApprovalAction triggerAction)
10088
{
101-
var paymentRequest = await _paymentRequestRepository.GetAsync(paymentRequestsId, true);
102-
var currentUserId = _currentUser.GetId();
89+
var paymentRequest = await paymentRequestRepository.GetAsync(paymentRequestsId, true);
90+
var currentUserId = currentUser.GetId();
10391

10492
var statusChange = paymentRequest.Status;
10593

@@ -114,33 +102,33 @@ public async Task<PaymentRequest> TriggerAction(Guid paymentRequestsId, PaymentA
114102

115103
if (triggerAction == PaymentApprovalAction.L1Approve)
116104
{
117-
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == Enums.ExpenseApprovalType.Level1);
105+
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level1);
118106
paymentRequest.ExpenseApprovals[index].Approve(currentUserId);
119107
statusChangedTo = PaymentRequestStatus.L2Pending;
120108
}
121109
else if (triggerAction == PaymentApprovalAction.L1Decline)
122110
{
123-
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == Enums.ExpenseApprovalType.Level1);
111+
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level1);
124112
paymentRequest.ExpenseApprovals[index].Decline(currentUserId);
125113
statusChangedTo = PaymentRequestStatus.L1Declined;
126114
}
127115
else if (triggerAction == PaymentApprovalAction.L2Approve)
128116
{
129-
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == Enums.ExpenseApprovalType.Level2);
117+
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level2);
130118
paymentRequest.ExpenseApprovals[index].Approve(currentUserId);
131119
statusChangedTo = PaymentRequestStatus.L3Pending;
132120

133121
}
134122
else if (triggerAction == PaymentApprovalAction.L2Decline)
135123
{
136-
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == Enums.ExpenseApprovalType.Level2);
124+
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level2);
137125
paymentRequest.ExpenseApprovals[index].Decline(currentUserId);
138126
statusChangedTo = PaymentRequestStatus.L2Declined;
139127
}
140128

141129
else if (triggerAction == PaymentApprovalAction.L3Decline)
142130
{
143-
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == Enums.ExpenseApprovalType.Level3);
131+
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level3);
144132
paymentRequest.ExpenseApprovals[index].Decline(currentUserId);
145133
statusChangedTo = PaymentRequestStatus.L3Declined;
146134
}
@@ -149,26 +137,56 @@ public async Task<PaymentRequest> TriggerAction(Guid paymentRequestsId, PaymentA
149137
{
150138
if (HasPermission(PaymentsPermissions.Payments.L2ApproveOrDecline))
151139
{
152-
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == Enums.ExpenseApprovalType.Level2);
140+
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level2);
153141
paymentRequest.ExpenseApprovals[index].Approve(currentUserId);
154142
}
155143
else if (HasPermission(PaymentsPermissions.Payments.L3ApproveOrDecline))
156144
{
157-
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == Enums.ExpenseApprovalType.Level3);
145+
var index = paymentRequest.ExpenseApprovals.FindIndex(i => i.Type == ExpenseApprovalType.Level3);
158146
paymentRequest.ExpenseApprovals[index].Approve(currentUserId);
159147
}
148+
bool preventPayment = await GetFormPreventPaymentStatusByApplicationId(paymentRequest.CorrelationId);
160149

161-
statusChangedTo = PaymentRequestStatus.Submitted;
162-
await _casPaymentRequestCoordinator.AddPaymentRequestsToInvoiceQueue(paymentRequest);
150+
if (preventPayment)
151+
{
152+
statusChangedTo = PaymentRequestStatus.FSB;
153+
}
154+
else
155+
{
156+
statusChangedTo = PaymentRequestStatus.Submitted;
157+
await casPaymentRequestCoordinator.AddPaymentRequestsToInvoiceQueue(paymentRequest);
158+
}
159+
160+
163161
}
164162
paymentRequest.SetPaymentRequestStatus(statusChangedTo);
165163

166-
return await _paymentRequestRepository.UpdateAsync(paymentRequest);
164+
return await paymentRequestRepository.UpdateAsync(paymentRequest);
165+
}
166+
167+
public async Task<bool> GetFormPreventPaymentStatusByPaymentRequestId(Guid paymentRequestId)
168+
{
169+
PaymentRequest paymentRequest = await paymentRequestRepository.GetAsync(paymentRequestId);
170+
Guid applicationId = paymentRequest.CorrelationId;
171+
var applicationQueryable = await applicationRepository.GetQueryableAsync();
172+
var applicationWithIncludes = await applicationQueryable.Where(a => a.Id == applicationId)
173+
.Include(a => a.ApplicationForm).ToListAsync();
174+
175+
var appForm = applicationWithIncludes.FirstOrDefault()?.ApplicationForm;
176+
return appForm != null && appForm.PreventPayment;
167177
}
178+
179+
public async Task<bool> GetFormPreventPaymentStatusByApplicationId(Guid applicationId)
180+
{
181+
Application application = await applicationRepository.GetAsync(applicationId);
182+
Guid formId = application.ApplicationForm.Id;
183+
ApplicationForm appForm = await applicationFormRepository.GetAsync(formId);
184+
return appForm.PreventPayment;
185+
}
168186

169187
public async Task UpdatePaymentStatusAsync(Guid paymentRequestId, PaymentApprovalAction triggerAction)
170188
{
171-
using var uow = _unitOfWorkManager.Begin();
189+
using var uow = unitOfWorkManager.Begin();
172190

173191
await TriggerAction(paymentRequestId, triggerAction);
174192

applications/Unity.GrantManager/modules/Unity.Payments/src/Unity.Payments.Application/EntityFrameworkCore/PaymentsDbContextModelCreatingExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public static void ConfigurePayments(
3434
.WithMany()
3535
.HasForeignKey(x => x.SiteId)
3636
.OnDelete(DeleteBehavior.NoAction);
37+
38+
b.HasOne(e => e.AccountCoding)
39+
.WithMany()
40+
.HasForeignKey(x => x.AccountCodingId)
41+
.OnDelete(DeleteBehavior.NoAction);
3742

3843
b.HasIndex(e => e.ReferenceNumber).IsUnique();
3944
});

0 commit comments

Comments
 (0)