-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApplication.cs
More file actions
271 lines (214 loc) · 9.33 KB
/
Application.cs
File metadata and controls
271 lines (214 loc) · 9.33 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
using System;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Unity.GrantManager.Assessments;
using Unity.GrantManager.GrantApplications;
using Unity.GrantManager.Identity;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace Unity.GrantManager.Applications;
// NOTE: See https://learn.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#required-navigation-properties
public class Application : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
public Guid ApplicationFormId { get; set; }
public virtual ApplicationForm ApplicationForm
{
set => _applicationForm = value;
get => _applicationForm
?? throw new InvalidOperationException("Uninitialized property: " + nameof(Applicant));
}
private ApplicationForm? _applicationForm;
public Guid ApplicantId { get; set; }
public virtual Applicant Applicant
{
set => _applicant = value;
get => _applicant
?? throw new InvalidOperationException("Uninitialized property: " + nameof(Applicant));
}
private Applicant? _applicant;
public virtual ApplicantAgent? ApplicantAgent { get; set; }
public Guid ApplicationStatusId { get; set; }
public virtual ApplicationStatus ApplicationStatus
{
set => _applicationStatus = value;
get => _applicationStatus
?? throw new InvalidOperationException("Uninitialized property: " + nameof(ApplicationStatus));
}
private ApplicationStatus? _applicationStatus;
public virtual Collection<Assessment>? Assessments { get; set; }
public virtual Collection<ApplicationTags>? ApplicationTags { get; set; }
public virtual Collection<ApplicationAssignment>? ApplicationAssignments { get; set; }
public string ProjectName { get; set; } = string.Empty;
public string ReferenceNo { get; set; } = string.Empty;
public decimal RequestedAmount { get; set; }
public decimal TotalProjectBudget { get; set; }
public string? EconomicRegion { get; set; } = null;
public string? City { get; set; } = null;
public DateTime? ProposalDate { get; set; }
public DateTime SubmissionDate { get; set; }
public DateTime? AssessmentStartDate { get; set; }
public DateTime? FinalDecisionDate { get; set; }
public DateTime? DueDate { get; set; }
public DateTime? NotificationDate { get; set; }
[Column(TypeName = "jsonb")]
public string? Payload { get; set; }
public string? ProjectSummary { get; set; }
public int? TotalScore { get; set; } = null;
public decimal RecommendedAmount { get; set; } = 0;
public decimal ApprovedAmount { get; set; } = 0;
public string? LikelihoodOfFunding { get; set; }
public string? DueDiligenceStatus { get; set; }
public string? SubStatus { get; set; }
public string? DeclineRational { get; set; }
public string? Notes { get; set; }
public string? AssessmentResultStatus { get; set; }
public DateTime? AssessmentResultDate { get; set; }
public DateTime? ProjectStartDate { get; set; }
public DateTime? ProjectEndDate { get; set; }
public double? PercentageTotalProjectBudget { get; set; }
public decimal? ProjectFundingTotal { get; set; }
public string? Community { get; set; }
public int? CommunityPopulation { get; set; }
public string? Acquisition { get; set; }
public string? Forestry { get; set; }
public string? ForestryFocus { get; set; }
// This is the Project Level Electoral District, not the Applicant's Electoral District.
public string? ElectoralDistrict { get; set; }
public string? Place { get; set; }
public string? RegionalDistrict { get; set; }
public Guid? TenantId { get; set; }
public Guid? OwnerId { get; set; }
// Navigation Property - Application Status
public virtual Person? Owner { get; set; }
public string? SigningAuthorityFullName { get; set; }
public string? SigningAuthorityTitle { get; set; }
public string? SigningAuthorityEmail { get; set; }
public string? SigningAuthorityBusinessPhone { get; set; }
public string? SigningAuthorityCellPhone { get; set; }
public string? ContractNumber { get; set; }
public DateTime? ContractExecutionDate { get; set; }
public string? RiskRanking { get; set; }
public virtual Collection<ApplicantAddress>? ApplicantAddresses { get; set; }
public bool IsInFinalDecisionState()
{
return GrantApplicationStateGroups.FinalDecisionStates.Contains(ApplicationStatus.StatusCode);
}
public void UpdateAlwaysChangeableFields(string? notes, string? subStatus, string? likelihoodOfFunding, decimal? totalProjectBudget, DateTime? notificationDate, string? riskRanking)
{
Notes = notes;
SubStatus = subStatus;
LikelihoodOfFunding = likelihoodOfFunding;
TotalProjectBudget = totalProjectBudget ?? 0;
NotificationDate = notificationDate;
RiskRanking = riskRanking;
// Recalculate percentage when TotalProjectBudget changes
UpdatePercentageTotalProjectBudget();
}
public void UpdateApprovalFieldsRequiringPostEditPermission(decimal? approvedAmount)
{
ApprovedAmount = approvedAmount ?? 0;
}
public void UpdateAssessmentResultFieldsRequiringPostEditPermission(decimal? requestedAmount, int? totalScore)
{
RequestedAmount = requestedAmount ?? 0;
TotalScore = totalScore ?? 0;
// Recalculate percentage when RequestedAmount changes
UpdatePercentageTotalProjectBudget();
}
public void UpdateAssessmentResultStatus(string? assessmentResultStatus)
{
if (assessmentResultStatus != AssessmentResultStatus)
{
AssessmentResultDate = DateTime.UtcNow;
}
AssessmentResultStatus = assessmentResultStatus;
}
public void UpdateFieldsOnlyForPreFinalDecision(string? dueDiligenceStatus, decimal? recommendedAmount, string? declineRational)
{
DueDiligenceStatus = dueDiligenceStatus;
RecommendedAmount = recommendedAmount ?? 0;
DeclineRational = declineRational;
}
/// <summary>
/// Validates and sets the DueDate property.
/// </summary>
/// <param name="dueDate"></param>
/// <exception cref="BusinessException"></exception>
public void ValidateAndSetDueDate(DateTime? dueDate)
{
if ((DueDate != dueDate) && dueDate != null && dueDate.Value < DateTime.Now.AddDays(-1))
{
throw new BusinessException("Due Date cannot be a past date.");
}
else
{
DueDate = dueDate;
}
}
/// <summary>
/// Validates and sets the FinalDecisionDate property.
/// </summary>
/// <param name="finalDecisionDate"></param>
/// <exception cref="BusinessException"></exception>
public void ValidateAndSetFinalDecisionDate(DateTime? finalDecisionDate)
{
if ((FinalDecisionDate != finalDecisionDate) && finalDecisionDate != null && finalDecisionDate.Value > DateTime.Now)
{
throw new BusinessException("Decision Date cannot not be a future date.");
}
else
{
FinalDecisionDate = finalDecisionDate;
}
}
/// <summary>
/// Validates and sets the ApprovedAmount property.
/// </summary>
/// <param name="approvedAmount"></param>
/// <exception cref="BusinessException"></exception>
public void ValidateAndSetApprovedAmount(decimal approvedAmount)
{
if ((ApprovedAmount != approvedAmount) && approvedAmount <= 0m)
{
throw new BusinessException("Approved amount cannot be 0.");
}
else
{
ApprovedAmount = approvedAmount;
}
}
/// <summary>
/// Validates the recommended amount for direct approval.
/// </summary>
/// <param name="recommendedAmount"></param>
/// <param name="isDirectApproval"></param>
/// <exception cref="BusinessException"></exception>
public void ValidateDirectApprovalRecommendedAmount(decimal recommendedAmount, bool? isDirectApproval)
{
if (isDirectApproval != true && (RecommendedAmount != recommendedAmount) && recommendedAmount <= 0m)
{
throw new BusinessException("Recommended amount cannot be 0.");
}
}
/// <summary>
/// Calculates and updates the PercentageTotalProjectBudget property based on
/// RequestedAmount and TotalProjectBudget values.
/// This method should be called whenever either of those properties change.
/// </summary>
public void UpdatePercentageTotalProjectBudget()
{
PercentageTotalProjectBudget
= (this.TotalProjectBudget == 0)
? 0 : decimal.Multiply(decimal.Divide(this.RequestedAmount, this.TotalProjectBudget), 100).To<double>();
}
/// <summary>
/// Sets the Electoral District for the application.
/// </summary>
/// <param name="electoralDistrict"></param>
public void SetElectoralDistrict(string electoralDistrict)
{
ElectoralDistrict = electoralDistrict;
}
}