-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPaymentsApprovalModel.cs
More file actions
78 lines (65 loc) · 3.08 KB
/
PaymentsApprovalModel.cs
File metadata and controls
78 lines (65 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Unity.Payments.Enums;
using Unity.Payments.Localization;
using Volo.Abp.Users;
namespace Unity.Payments.Web.Pages.PaymentApprovals
{
public class PaymentsApprovalModel : IValidatableObject
{
[Required]
public Guid Id { get; set; }
[DisplayName("ApplicationPaymentStatusRequest:Id")]
[Required]
public string ReferenceNumber { get; set; } = string.Empty;
[DisplayName("ApplicationPaymentStatusRequest:Amount")]
[Required]
public decimal Amount { get; set; }
[DisplayName("ApplicationPaymentStatusRequest:Description")]
public string? Description { get; set; }
[Required(ErrorMessage = "This field is required.")]
[DisplayName("ApplicationPaymentStatusRequest:InvoiceNumber")]
public string InvoiceNumber { get; set; } = string.Empty;
public Guid CorrelationId { get; set; }
[Required(ErrorMessage = "This field is required.")]
[DisplayName("ApplicationPaymentStatusRequest:SiteNumber")]
public string? ApplicantName { get; set; }
public PaymentRequestStatus Status { get; set; }
public bool isPermitted { get; set; }
public bool IsL3ApprovalRequired { get; set; }
public PaymentRequestStatus ToStatus { get; set; }
public string StatusText { get; set; } = string.Empty;
public string ToStatusText { get; set; } = string.Empty;
public Guid? PreviousL1Approver { get; set; }
public bool HasUserPaymentThreshold { get; set; }
public bool IsApproval { get; set; }
public bool IsValid { get; set; } = false;
public Guid CurrentUser { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var currentUser = validationContext.GetRequiredService<ICurrentUser>();
var localizer = validationContext.GetRequiredService<IStringLocalizer<PaymentsResource>>();
// Rule AB#26693: Reject Payment Request update batch if violates L1 and L2 separation of duties
if (IsApproval
&& Status == PaymentRequestStatus.L2Pending
&& PreviousL1Approver == currentUser.Id)
{
yield return new ValidationResult(
errorMessage: localizer["ApplicationPaymentRequest:Validations:L2ApproverRestriction"],
memberNames: [nameof(PreviousL1Approver)]
);
} else if (IsApproval
&& Status == PaymentRequestStatus.L2Pending && !HasUserPaymentThreshold)
{
yield return new ValidationResult(
errorMessage: "Your User has not been configured with an Approved Payment Threshold. Please contact your system administrator.",
memberNames: [nameof(PreviousL1Approver)]
);
}
}
}
}