@@ -84,6 +84,21 @@ const ChallengeStatus = {
84
84
COMPLETED : 'Completed'
85
85
}
86
86
87
+ /**
88
+ * Aggregate payment status for Work Period which is determined
89
+ * based on the payments the Work Period has using `PaymentStatusRules`
90
+ */
91
+ const AggregatePaymentStatus = {
92
+ PENDING : 'pending' ,
93
+ IN_PROGRESS : 'in-progress' ,
94
+ PARTIALLY_COMPLETED : 'partially-completed' ,
95
+ COMPLETED : 'completed' ,
96
+ NO_DAYS : 'no-days'
97
+ }
98
+
99
+ /**
100
+ * `WorkPeriodPayment.status` - possible values
101
+ */
87
102
const WorkPeriodPaymentStatus = {
88
103
COMPLETED : 'completed' ,
89
104
SCHEDULED : 'scheduled' ,
@@ -92,6 +107,37 @@ const WorkPeriodPaymentStatus = {
92
107
CANCELLED : 'cancelled'
93
108
}
94
109
110
+ /**
111
+ * The rules how to determine WorkPeriod.paymentStatus based on the payments
112
+ *
113
+ * The top rule has priority over the bottom rules.
114
+ */
115
+ const PaymentStatusRules = [
116
+ { paymentStatus : AggregatePaymentStatus . NO_DAYS , condition : { daysWorked : 0 } } ,
117
+ { paymentStatus : AggregatePaymentStatus . IN_PROGRESS , condition : { hasWorkPeriodPaymentStatus : [ WorkPeriodPaymentStatus . SCHEDULED , WorkPeriodPaymentStatus . IN_PROGRESS ] } } ,
118
+ { paymentStatus : AggregatePaymentStatus . COMPLETED , condition : { hasWorkPeriodPaymentStatus : [ WorkPeriodPaymentStatus . COMPLETED ] , hasDueDays : false } } ,
119
+ { paymentStatus : AggregatePaymentStatus . PARTIALLY_COMPLETED , condition : { hasWorkPeriodPaymentStatus : [ WorkPeriodPaymentStatus . COMPLETED ] , hasDueDays : true } } ,
120
+ { paymentStatus : AggregatePaymentStatus . PENDING , condition : { hasDueDays : true } }
121
+ ]
122
+
123
+ /**
124
+ * The WorkPeriodPayment.status values which we take into account when calculate
125
+ * aggregate values inside WorkPeriod:
126
+ * - daysPaid
127
+ * - paymentTotal
128
+ * - paymentStatus
129
+ */
130
+ const ActiveWorkPeriodPaymentStatuses = [
131
+ WorkPeriodPaymentStatus . SCHEDULED ,
132
+ WorkPeriodPaymentStatus . IN_PROGRESS ,
133
+ WorkPeriodPaymentStatus . COMPLETED
134
+ ]
135
+
136
+ const WorkPeriodPaymentUpdateStatus = {
137
+ SCHEDULED : 'scheduled' ,
138
+ CANCELLED : 'cancelled'
139
+ }
140
+
95
141
const PaymentProcessingSwitch = {
96
142
ON : 'ON' ,
97
143
OFF : 'OFF'
@@ -112,7 +158,11 @@ module.exports = {
112
158
Scopes,
113
159
Interviews,
114
160
ChallengeStatus,
161
+ AggregatePaymentStatus,
115
162
WorkPeriodPaymentStatus,
163
+ WorkPeriodPaymentUpdateStatus,
116
164
PaymentSchedulerStatus,
117
- PaymentProcessingSwitch
165
+ PaymentProcessingSwitch,
166
+ PaymentStatusRules,
167
+ ActiveWorkPeriodPaymentStatuses
118
168
}
0 commit comments