-
Notifications
You must be signed in to change notification settings - Fork 1
feat(TargetUnit): Add DepTech hours calculation and Redmine custom field IDs #71
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
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f28e847
Enhance weekly financial report queries with custom field IDs
anatolyshipitz c7181f0
Refactor SQL query in TargetUnit service for clarity
anatolyshipitz 5101599
Fix SQL query in TargetUnit service to handle single quotes correctly
anatolyshipitz be71add
Fix formatting issue in TargetUnit service SQL query
anatolyshipitz 6960293
Enhance TARGET_UNITS_QUERY to include filter_name field
anatolyshipitz 0f557e5
Merge branch 'main' into feature/add_deptech_hours
anatolyshipitz 1c842ad
Merge branch 'main' into feature/add_deptech_hours
anatolyshipitz 814e1ea
Merge branch 'main' into feature/add_deptech_hours
killev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,98 @@ | ||
| export const TARGET_UNITS_QUERY = `SELECT | ||
| group_id, | ||
| group_name, | ||
| project_id, | ||
| project_name, | ||
| user_id, | ||
| username, | ||
| DATE_FORMAT(spent_on, '%Y-%m-%d') AS spent_on, | ||
| SUM(total_hours) AS total_hours | ||
| FROM ( | ||
| SELECT | ||
| g.id AS group_id, | ||
| g.lastname AS group_name, | ||
| p.id AS project_id, | ||
| p.name AS project_name, | ||
| te.user_id AS user_id, | ||
| CONCAT(u.firstname, ' ', u.lastname) AS username, | ||
| te.spent_on AS spent_on, | ||
| te.hours AS total_hours | ||
| import { | ||
| GroupNameEnum, | ||
| RELATED_PROJECT_FIELD_ID, | ||
| REPORT_FILTER_FIELD_ID, | ||
| } from '../../configs/weeklyFinancialReport'; | ||
|
|
||
| const groupNamesList = Object.values(GroupNameEnum) | ||
| .map((name) => `'${name.replace(/'/g, "''")}'`) | ||
| .join(', '); | ||
|
|
||
| const COMMON_SELECT = ` | ||
| SELECT | ||
| g.id AS group_id, | ||
| g.lastname AS group_name, | ||
| p.id AS project_id, | ||
| p.name AS project_name, | ||
| te.user_id AS user_id, | ||
| CONCAT(u.firstname, ' ', u.lastname) AS username, | ||
| te.spent_on AS spent_on, | ||
| cv.value AS filter_name, | ||
| `; | ||
|
|
||
| const COMMON_FROM = ` | ||
| FROM users AS g | ||
| JOIN custom_values as cv ON cv.customized_id = g.id | ||
| JOIN members AS m ON m.user_id = g.id | ||
| JOIN projects AS p ON p.id = m.project_id | ||
| JOIN time_entries te ON te.project_id = p.id | ||
| JOIN users AS u ON u.id = te.user_id | ||
| JOIN custom_values as cv ON cv.customized_id = g.id | ||
| JOIN members AS m ON m.user_id = g.id | ||
| JOIN projects AS p ON p.id = m.project_id | ||
| `; | ||
|
|
||
| const COMMON_WHERE = ` | ||
| WHERE g.type = 'Group' | ||
| AND cv.customized_type = 'Principal' and cv.value = ? | ||
| AND cv.customized_type = 'Principal' | ||
| AND cv.custom_field_id = ${REPORT_FILTER_FIELD_ID} | ||
| AND cv.value IN (${groupNamesList}) | ||
| AND te.spent_on BETWEEN DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) + 7 DAY) | ||
| AND DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) + 1 DAY) | ||
| ) t | ||
| GROUP BY | ||
| `; | ||
|
|
||
| function buildDirectGroupTimeEntries() { | ||
| return ` | ||
| ${COMMON_SELECT} | ||
| te.hours AS project_hours, | ||
| 0 as deptech_hours | ||
| ${COMMON_FROM} | ||
| JOIN time_entries te ON te.project_id = p.id | ||
| JOIN users AS u ON u.id = te.user_id | ||
| ${COMMON_WHERE} | ||
| `; | ||
| } | ||
|
|
||
| function buildRelatedProjectTimeEntries() { | ||
| return ` | ||
| ${COMMON_SELECT} | ||
| 0 as project_hours, | ||
| te.hours AS deptech_hours | ||
| ${COMMON_FROM} | ||
| JOIN custom_values icv ON icv.value = CAST(p.id AS CHAR) | ||
| AND icv.customized_type = 'Issue' | ||
| AND icv.custom_field_id = ${RELATED_PROJECT_FIELD_ID} | ||
| AND icv.value <> "" | ||
| JOIN time_entries te ON te.issue_id = icv.customized_id | ||
| JOIN users AS u ON u.id = te.user_id | ||
| ${COMMON_WHERE} | ||
| `; | ||
| } | ||
|
|
||
| export const TARGET_UNITS_QUERY = ` | ||
| SELECT | ||
| group_id, | ||
| group_name, | ||
| project_id, | ||
| project_name, | ||
| user_id, | ||
| username, | ||
| spent_on | ||
| DATE_FORMAT(spent_on, '%Y-%m-%d') AS spent_on, | ||
| SUM(project_hours) AS project_hours, | ||
| SUM(deptech_hours) AS deptech_hours, | ||
| SUM(project_hours) + SUM(deptech_hours) AS total_hours, | ||
| filter_name | ||
| FROM ( | ||
| ${buildDirectGroupTimeEntries()} | ||
| UNION ALL | ||
| ${buildRelatedProjectTimeEntries()} | ||
| ) t | ||
| GROUP BY | ||
| t.group_id, | ||
| t.group_name, | ||
| t.project_id, | ||
| t.project_name, | ||
| t.user_id, | ||
| t.username, | ||
| t.spent_on | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| ORDER BY | ||
| group_name ASC, | ||
| project_name ASC, | ||
| username ASC, | ||
| spent_on ASC`; | ||
| t.group_name ASC, | ||
| t.project_name ASC, | ||
| t.username ASC, | ||
| t.spent_on ASC | ||
| `; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.