-
Notifications
You must be signed in to change notification settings - Fork 2
/
lpa_progress_tracker.go
197 lines (167 loc) · 5.54 KB
/
lpa_progress_tracker.go
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
package page
import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
)
type ProgressTracker struct {
Localizer Localizer
}
type ProgressTask struct {
State actor.TaskState
Label string
}
type Progress struct {
isOrganisation bool
Paid ProgressTask
ConfirmedID ProgressTask
DonorSigned ProgressTask
CertificateProviderSigned ProgressTask
AttorneysSigned ProgressTask
LpaSubmitted ProgressTask
NoticesOfIntentSent ProgressTask
StatutoryWaitingPeriod ProgressTask
LpaRegistered ProgressTask
}
func (p Progress) ToSlice() []ProgressTask {
var list []ProgressTask
if p.isOrganisation {
list = append(list, p.Paid, p.ConfirmedID)
}
list = append(list, p.DonorSigned, p.CertificateProviderSigned, p.AttorneysSigned, p.LpaSubmitted)
if p.NoticesOfIntentSent.State.Completed() {
list = append(list, p.NoticesOfIntentSent)
}
list = append(list, p.StatutoryWaitingPeriod, p.LpaRegistered)
return list
}
func (pt ProgressTracker) Progress(lpa *lpastore.Lpa) Progress {
var labels map[string]string
if lpa.IsOrganisationDonor {
labels = map[string]string{
"paid": pt.Localizer.Format(
"donorFullNameHasPaid",
map[string]interface{}{"DonorFullName": lpa.Donor.FullName()},
),
"confirmedID": pt.Localizer.Format(
"donorFullNameHasConfirmedTheirIdentity",
map[string]interface{}{"DonorFullName": lpa.Donor.FullName()},
),
"donorSigned": pt.Localizer.Format(
"donorFullNameHasSignedTheLPA",
map[string]interface{}{"DonorFullName": lpa.Donor.FullName()},
),
"certificateProviderSigned": pt.Localizer.T("theCertificateProviderHasDeclared"),
"attorneysSigned": pt.Localizer.T("allAttorneysHaveSignedTheLpa"),
"lpaSubmitted": pt.Localizer.T("opgHasReceivedTheLPA"),
"noticesOfIntentSent": "weSentAnEmailTheLpaIsReadyToRegister",
"statutoryWaitingPeriod": pt.Localizer.T("theWaitingPeriodHasStarted"),
"lpaRegistered": pt.Localizer.T("theLpaHasBeenRegistered"),
}
} else {
labels = map[string]string{
"donorSigned": pt.Localizer.T("youveSignedYourLpa"),
"attorneysSigned": pt.Localizer.Count("attorneysHaveDeclared", len(lpa.Attorneys.Attorneys)),
"lpaSubmitted": pt.Localizer.T("weHaveReceivedYourLpa"),
"noticesOfIntentSent": "weSentAnEmailYourLpaIsReadyToRegister",
"statutoryWaitingPeriod": pt.Localizer.T("yourWaitingPeriodHasStarted"),
"lpaRegistered": pt.Localizer.T("yourLpaHasBeenRegistered"),
}
if lpa.CertificateProvider.FirstNames != "" {
labels["certificateProviderSigned"] = pt.Localizer.Format(
"certificateProviderHasDeclared",
map[string]interface{}{"CertificateProviderFullName": lpa.CertificateProvider.FullName()},
)
} else {
labels["certificateProviderSigned"] = pt.Localizer.T("yourCertificateProviderHasDeclared")
}
}
progress := Progress{
isOrganisation: lpa.IsOrganisationDonor,
Paid: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["paid"],
},
ConfirmedID: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["confirmedID"],
},
DonorSigned: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["donorSigned"],
},
CertificateProviderSigned: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["certificateProviderSigned"],
},
AttorneysSigned: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["attorneysSigned"],
},
LpaSubmitted: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["lpaSubmitted"],
},
NoticesOfIntentSent: ProgressTask{
State: actor.TaskNotStarted,
},
StatutoryWaitingPeriod: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["statutoryWaitingPeriod"],
},
LpaRegistered: ProgressTask{
State: actor.TaskNotStarted,
Label: labels["lpaRegistered"],
},
}
if lpa.IsOrganisationDonor {
progress.Paid.State = actor.TaskInProgress
if !lpa.Paid {
return progress
}
progress.Paid.State = actor.TaskCompleted
progress.ConfirmedID.State = actor.TaskInProgress
if lpa.Donor.IdentityCheck.CheckedAt.IsZero() {
return progress
}
progress.ConfirmedID.State = actor.TaskCompleted
progress.DonorSigned.State = actor.TaskInProgress
if lpa.SignedAt.IsZero() {
return progress
}
} else {
progress.DonorSigned.State = actor.TaskInProgress
if lpa.SignedAt.IsZero() {
return progress
}
}
progress.DonorSigned.State = actor.TaskCompleted
progress.CertificateProviderSigned.State = actor.TaskInProgress
if lpa.CertificateProvider.SignedAt.IsZero() {
return progress
}
progress.CertificateProviderSigned.State = actor.TaskCompleted
progress.AttorneysSigned.State = actor.TaskInProgress
if !lpa.AllAttorneysSigned() {
return progress
}
progress.AttorneysSigned.State = actor.TaskCompleted
progress.LpaSubmitted.State = actor.TaskInProgress
if !lpa.Submitted {
return progress
}
progress.LpaSubmitted.State = actor.TaskCompleted
if lpa.PerfectAt.IsZero() {
return progress
}
progress.NoticesOfIntentSent.Label = pt.Localizer.Format(labels["noticesOfIntentSent"], map[string]any{
"SentOn": pt.Localizer.FormatDate(lpa.PerfectAt),
})
progress.NoticesOfIntentSent.State = actor.TaskCompleted
progress.StatutoryWaitingPeriod.State = actor.TaskInProgress
if lpa.RegisteredAt.IsZero() {
return progress
}
progress.StatutoryWaitingPeriod.State = actor.TaskCompleted
progress.LpaRegistered.State = actor.TaskCompleted
return progress
}