From 6a6b946c42c530f07be848bb61be149f169db664 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 27 Feb 2023 15:05:19 +0700 Subject: [PATCH] Adding manpower data for project dashboard --- src/views/Dashboard/Components/index.js | 4 +- src/views/Dashboard/DashboardProject.js | 131 ++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 9 deletions(-) diff --git a/src/views/Dashboard/Components/index.js b/src/views/Dashboard/Components/index.js index 1cd88c0..3310481 100644 --- a/src/views/Dashboard/Components/index.js +++ b/src/views/Dashboard/Components/index.js @@ -100,7 +100,7 @@ export const HealthByBudget = ({status}) => { } return (
-
{status.toUpperCase()}
+
Health By Budget
) } @@ -114,7 +114,7 @@ export const HealthBySchedule = ({status}) => { } return (
-
{status.toUpperCase()}
+
Health By Schedule
) } diff --git a/src/views/Dashboard/DashboardProject.js b/src/views/Dashboard/DashboardProject.js index 42cb383..fde62f7 100644 --- a/src/views/Dashboard/DashboardProject.js +++ b/src/views/Dashboard/DashboardProject.js @@ -80,6 +80,10 @@ const DashboardProject = () => { const [healthBySchedule, setHealthBySchedule] = useState('-') const [healthByBudget, setHealthByBudget] = useState('-') const [reportDistribution, setReportDistribution] = useState([]); + const [manPower, setManPower] = useState(0); + const [assignedHr, setAssignedHr] = useState([]); + const [assignedHrCount, setAssignedHrCount] = useState(0); + const [actualHrCount, setActualHrCount] = useState(0); let history = useHistory(); @@ -100,6 +104,17 @@ const DashboardProject = () => { } }, [activeTabIdx]); + useEffect(() => { + async function fetchData() { + await Promise.all([ + getManpower(), + getAssignedHR(), + ...(assignedHr.length > 0 ? [getActualHR()] : []) + ]) + } + fetchData() + }, [manPower, assignedHr]) + useEffect(() => { let deviation = 0; if (plannedCost && totalCost) { @@ -113,6 +128,57 @@ const DashboardProject = () => { history.push("/projects/" + GANTT_ID + "/" + PROJECT_ID + "/gantt"); } + const getManpower = async () => { + const url = `${BASE_OSPRO}/api/project/manpower/${PROJECT_ID}` + try { + const response = await axios.get(url, HEADER) + setManPower(response.data.totalRecord) + } catch (error) { + console.error('Failed to get manpower:', error) + } + } + + const getAssignedHR = async () => { + const url = `${BASE_OSPRO}/api/project/manpower/assigned/${GANTT_ID}` + try { + const response = await axios.get(url, HEADER) + const today = moment() + const assignedList = response.data.data + .filter(item => today.isBetween(moment(item.start_date), moment(item.end_date))) + .map(item => item.user_id) + setAssignedHrCount(assignedList.length) + setAssignedHr(assignedList) + } catch (error) { + console.error('Failed to get assigned HR:', error) + } + } + + const getActualHR = async () => { + const dateStart = moment().startOf('day').toDate() + const dateEnd = moment().endOf('day').toDate() + try { + const payload = { + paging: { start: 0, length: -1 }, + columns: [ + { name: 'name', logic_operator: 'ilike', value: '', table_name: 'm_users' }, + { name: 'clock_in', logic_operator: 'range', value: dateStart, value1: dateEnd }, + ], + joins: [{ + name: 'm_users', + column_join: 'user_id', + column_results: ['name', 'ktp_number'], + }], + orders: { columns: ['id'], ascending: false }, + } + const url = `${BASE_OSPRO}/api/presence/search` + const response = await axios.post(url, payload, HEADER) + const actualHrCount = response.data.data.filter(item => assignedHr.includes(item.user_id)).length + setActualHrCount(actualHrCount) + } catch (error) { + console.error('Failed to get actual HR:', error) + } + } + const getProjectDetail = async () => { setIsReadyProjectDetail(false); const URL = `${BASE_OSPRO}/api/project/detail/${PROJECT_ID}`; @@ -631,6 +697,7 @@ const DashboardProject = () => { : } + Committed Cost @@ -680,16 +747,66 @@ const DashboardProject = () => { -
-
Health By Budget
- {isReadyOverdueActivities ? : } +
+ {isReadyOverdueActivities && } + {isReadySCurve && }
-
-
Health By Schedule
- {isReadySCurve ? : } -
+ + +
+ Manpower : {manPower} +
+ +
+ + +
+ Assigned : {assignedHrCount} +
+ + +
+ Actual : {actualHrCount} +
+ +