-
Notifications
You must be signed in to change notification settings - Fork 32
Work period automation #345
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
Work period automation #345
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eisbilir here are some issues I found so far:
-
If we have fisrt/last WP with daysWorked < 5, and we extend RB time so it adds one more week, we have to recalculate daysWorked for the first/last WP which is not last anymore to 5.
Example: We have RB:
"startDate": "2021-02-03", "endDate": "2021-02-17"
The last WP is:
"startDate": "2021-02-14", "endDate": "2021-02-20", "daysWorked": 3,
Now we extend end of RB to "2021-02-23"
Now the the WP which was last before "startDate": "2021-02-14", "endDate": "2021-02-20", hast to have "daysWorked": 5
-
You've added new WP.paymentStatus
noDays. It's good, but let's name it asno-daysbecause we use dash in all other statuses for consistency. -
You've implemented logic to recalculate fields in WP when we update WPP in file
src/eventHandlers/WorkPeriodPaymentEventHandler.js. But this logic also depends onWP.daysWorked. So we have to execute the same logic ifWP.daysWorkedis changed.
⏳ I'm still reviewing the PR, and would update this review if find something else...
I tried several times and it works fine for me. Could you please retry. The first week of the example you show has also 3
Yes. There are 3 areas that causes WP changes:
|
233ae68 to
9db3798
Compare
Sorry, looks like I overlooked something. It works good for me to now, below my verification steps. I keep them just for history, not need to go through them. Create RB: "startDate": "2021-02-09",
"endDate": "2021-02-23",Work Periods: "workPeriods": [
{
"endDate": "2021-02-13",
"daysWorked": 4,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 5,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
},
{
"endDate": "2021-02-27",
"daysWorked": 2,
"id": "921099bf-78a3-4b59-9fe0-9a106f355cc4",
"startDate": "2021-02-21"
}
],Update WP "workPeriods": [
{
"endDate": "2021-02-13",
"daysWorked": 4,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 3,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
},
{
"endDate": "2021-02-27",
"daysWorked": 2,
"id": "921099bf-78a3-4b59-9fe0-9a106f355cc4",
"startDate": "2021-02-21"
}
],Update RB endDate to "workPeriods": [
{
"endDate": "2021-02-13",
"daysWorked": 4,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 3,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
},
{
"endDate": "2021-02-27",
"daysWorked": 5,
"id": "921099bf-78a3-4b59-9fe0-9a106f355cc4",
"startDate": "2021-02-21"
},
{
"endDate": "2021-03-06",
"daysWorked": 1,
"id": "2c151d25-097b-42c2-a26a-11dbe1f23c69",
"startDate": "2021-02-28"
}
],Update RB startDate to "workPeriods": [
{
"endDate": "2021-01-30",
"daysWorked": 5,
"id": "f9a180f9-1a6c-412d-bd2c-c737eceb64d1",
"startDate": "2021-01-24"
},
{
"endDate": "2021-02-06",
"daysWorked": 5,
"id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8",
"startDate": "2021-01-31"
},
{
"endDate": "2021-02-13",
"daysWorked": 5,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 3,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
},
{
"endDate": "2021-02-27",
"daysWorked": 5,
"id": "921099bf-78a3-4b59-9fe0-9a106f355cc4",
"startDate": "2021-02-21"
},
{
"endDate": "2021-03-06",
"daysWorked": 1,
"id": "2c151d25-097b-42c2-a26a-11dbe1f23c69",
"startDate": "2021-02-28"
}
]Update RB endDate to "workPeriods": [
{
"endDate": "2021-01-30",
"daysWorked": 5,
"id": "f9a180f9-1a6c-412d-bd2c-c737eceb64d1",
"startDate": "2021-01-24"
},
{
"endDate": "2021-02-06",
"daysWorked": 5,
"id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8",
"startDate": "2021-01-31"
},
{
"endDate": "2021-02-13",
"daysWorked": 5,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 3,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
},
{
"endDate": "2021-02-27",
"daysWorked": 5,
"id": "921099bf-78a3-4b59-9fe0-9a106f355cc4",
"startDate": "2021-02-21"
},
{
"endDate": "2021-03-06",
"daysWorked": 4,
"id": "2c151d25-097b-42c2-a26a-11dbe1f23c69",
"startDate": "2021-02-28"
}
]Update RB endDate to "workPeriods": [
{
"endDate": "2021-01-30",
"daysWorked": 5,
"id": "f9a180f9-1a6c-412d-bd2c-c737eceb64d1",
"startDate": "2021-01-24"
},
{
"endDate": "2021-02-06",
"daysWorked": 5,
"id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8",
"startDate": "2021-01-31"
},
{
"endDate": "2021-02-13",
"daysWorked": 5,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 3,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
},
{
"endDate": "2021-02-27",
"daysWorked": 5,
"id": "921099bf-78a3-4b59-9fe0-9a106f355cc4",
"startDate": "2021-02-21"
},
{
"endDate": "2021-03-06",
"daysWorked": 2,
"id": "2c151d25-097b-42c2-a26a-11dbe1f23c69",
"startDate": "2021-02-28"
}
]Update RB endDate to "workPeriods": [
{
"endDate": "2021-01-30",
"daysWorked": 5,
"id": "f9a180f9-1a6c-412d-bd2c-c737eceb64d1",
"startDate": "2021-01-24"
},
{
"endDate": "2021-02-06",
"daysWorked": 5,
"id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8",
"startDate": "2021-01-31"
},
{
"endDate": "2021-02-13",
"daysWorked": 5,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 3,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
}
]Update WP days Worked to 3 for "WP.id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8": "workPeriods": [
{
"endDate": "2021-01-30",
"daysWorked": 5,
"id": "f9a180f9-1a6c-412d-bd2c-c737eceb64d1",
"startDate": "2021-01-24"
},
{
"endDate": "2021-02-06",
"daysWorked": 3,
"id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8",
"startDate": "2021-01-31"
},
{
"endDate": "2021-02-13",
"daysWorked": 5,
"id": "62849337-ac4e-42be-9dcf-4e317b1059ec",
"startDate": "2021-02-07"
},
{
"endDate": "2021-02-20",
"daysWorked": 3,
"id": "0d560869-c8ac-49bc-88f6-fe7e2cc329fa",
"startDate": "2021-02-14"
}
] Update RB endDate to "workPeriods": [
{
"endDate": "2021-01-30",
"daysWorked": 5,
"id": "f9a180f9-1a6c-412d-bd2c-c737eceb64d1",
"startDate": "2021-01-24"
},
{
"endDate": "2021-02-06",
"daysWorked": 2,
"id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8",
"startDate": "2021-01-31"
}
]Update RB "startDate": "2021-02-01": "workPeriods": [
{
"endDate": "2021-02-06",
"daysWorked": 2,
"id": "02c40bc8-6ce7-4277-9664-d99ad2161ed8",
"startDate": "2021-01-31"
}
], |
|
in general there is one thing which I'd really like to improve - the logic to calculate paymentStatus
What would be great to have is some kind of method:
and the second thing, logic with if is not super clear too, it's hard to understand it when reading: if (workPeriod.daysWorked === 0) {
data.paymentStatus = PaymentStatus.NO_DAYS
} else if (paymentStatuses[WorkPeriodPaymentStatus.SCHEDULED] || paymentStatuses[WorkPeriodPaymentStatus.IN_PROGRESS]) {
data.paymentStatus = PaymentStatus.IN_PROGRESS
} else if (workPeriod.daysWorked === data.daysPaid) {
data.paymentStatus = PaymentStatus.COMPLETED
} else if (paymentStatuses[WorkPeriodPaymentStatus.FAILED]) {
data.paymentStatus = PaymentStatus.FAILED
} else if (paymentStatuses[WorkPeriodPaymentStatus.COMPLETED]) {
data.paymentStatus = PaymentStatus.PARTIALLY_COMPLETED
} else {
data.paymentStatus = PaymentStatus.PENDING
}I'm thinking about some kind of declarative way, something like this: // define rules for the payment status as constant
const PAYMENT_STATUS_RULES = [
{ paymentStatus: PaymentStatus.NO_DAYS, condition: { daysWorked: 0 } },
{ paymentStatus: PaymentStatus.IN_PROGRESS, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.SCHEDULED, WorkPeriodPaymentStatus.IN_PROGRESS] } },
{ paymentStatus: PaymentStatus.COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: false } },
{ paymentStatus: PaymentStatus.PARTIALLY_COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: true } },
{ paymentStatus: PaymentStatus.FAILED, condition: { hasWorkPeriodPaymentStatus: [PaymentStatus.FAILED], hasDueDays: true } },
{ paymentStatus: PaymentStatus.PENDING, condition: { hasDueDays: true } }
]
// find the first rule which is matched by the Work Period
for (let rule of PAYMENT_STATUS_RULES) {
if (matchRule(workPeriod, rule)) {
data.paymentStatus = rule.paymentStatus
}
}
// so have to implement method `matchRule` which would check if rule is matched or no
// possible conditions:
// - daysWorked - how many days worked
// - hasWorkPeriodPaymentStatus - check if any of the payments has any of these statuses
// - hasDueDays - true if daysWorked > daysPaidAlso, I see in |
|
@eisbilir I think everything good. Just would like to make code improvements mentioned above #345 (comment). |
src/services/WorkPeriodService.js
Outdated
| data.paymentStatus = helper.calculateWorkPeriodPaymentStatus(_.assign({}, oldValue, data)) | ||
| if (oldValue.paymentStatus === data.paymentStatus) { | ||
| return oldValue | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eisbilir if paymentStatus is not changed this logic would not update WP at all. But we can also update other values, like daysWorked, daysPaid and so on. Would not this cause issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eisbilir can we avoid all such places?
It feels like it would be better just update the records even though data is not changed. Would it break anything if I just remove such places?



No description provided.