Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion app-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ const ChallengeStatus = {
COMPLETED: 'Completed'
}

/**
* Aggregate payment status for Work Period which is determined
* based on the payments the Work Period has using `PaymentStatusRules`
*/
const AggregatePaymentStatus = {
PENDING: 'pending',
IN_PROGRESS: 'in-progress',
PARTIALLY_COMPLETED: 'partially-completed',
COMPLETED: 'completed',
NO_DAYS: 'no-days'
}

/**
* `WorkPeriodPayment.status` - possible values
*/
const WorkPeriodPaymentStatus = {
COMPLETED: 'completed',
SCHEDULED: 'scheduled',
Expand All @@ -92,6 +107,37 @@ const WorkPeriodPaymentStatus = {
CANCELLED: 'cancelled'
}

/**
* The rules how to determine WorkPeriod.paymentStatus based on the payments
*
* The top rule has priority over the bottom rules.
*/
const PaymentStatusRules = [
{ paymentStatus: AggregatePaymentStatus.NO_DAYS, condition: { daysWorked: 0 } },
{ paymentStatus: AggregatePaymentStatus.IN_PROGRESS, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.SCHEDULED, WorkPeriodPaymentStatus.IN_PROGRESS] } },
{ paymentStatus: AggregatePaymentStatus.COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: false } },
{ paymentStatus: AggregatePaymentStatus.PARTIALLY_COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: true } },
{ paymentStatus: AggregatePaymentStatus.PENDING, condition: { hasDueDays: true } }
]

/**
* The WorkPeriodPayment.status values which we take into account when calculate
* aggregate values inside WorkPeriod:
* - daysPaid
* - paymentTotal
* - paymentStatus
*/
const ActiveWorkPeriodPaymentStatuses = [
WorkPeriodPaymentStatus.SCHEDULED,
WorkPeriodPaymentStatus.IN_PROGRESS,
WorkPeriodPaymentStatus.COMPLETED
]

const WorkPeriodPaymentUpdateStatus = {
SCHEDULED: 'scheduled',
CANCELLED: 'cancelled'
}

const PaymentProcessingSwitch = {
ON: 'ON',
OFF: 'OFF'
Expand All @@ -112,7 +158,11 @@ module.exports = {
Scopes,
Interviews,
ChallengeStatus,
AggregatePaymentStatus,
WorkPeriodPaymentStatus,
WorkPeriodPaymentUpdateStatus,
PaymentSchedulerStatus,
PaymentProcessingSwitch
PaymentProcessingSwitch,
PaymentStatusRules,
ActiveWorkPeriodPaymentStatuses
}
Loading