Skip to content

Work period automation #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 16, 2021
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