Browse Source

add sum

pull/1/head
wahyu 1 year ago
parent
commit
11fff21f3e
  1. 21
      src/views/SimproV2/CreatedProyek/ReportAnalysis.js

21
src/views/SimproV2/CreatedProyek/ReportAnalysis.js

@ -16,6 +16,7 @@ const ReportAnalysis = ({ openDialog, closeDialog, toggleDialog }) => {
const token = localStorage.getItem("token"); const token = localStorage.getItem("token");
const [activeTab, setActiveTab] = useState('1'); const [activeTab, setActiveTab] = useState('1');
const [search, setSearch] = useState(''); const [search, setSearch] = useState('');
const [avgActivity, setAvgActivity] = useState(0);
const [dataTable, setDatatable] = useState([]); const [dataTable, setDatatable] = useState([]);
const [dataTableActivityToHr, setDataTableActivityToHr] = useState([]); const [dataTableActivityToHr, setDataTableActivityToHr] = useState([]);
const [hrList, setHrList] = useState([]); const [hrList, setHrList] = useState([]);
@ -77,6 +78,8 @@ const ReportAnalysis = ({ openDialog, closeDialog, toggleDialog }) => {
} }
} }
const getDataActivityToHr = async () => { const getDataActivityToHr = async () => {
setAvgActivity(0);
let sum = 0;
const payload = { const payload = {
columns: [ columns: [
{ {
@ -104,6 +107,10 @@ const ReportAnalysis = ({ openDialog, closeDialog, toggleDialog }) => {
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data || []; let dataRes = result.data.data || [];
dataRes.forEach(element => {
element.persentase_progress ? sum += parseInt(element.persentase_progress) : sum += 0;
});
setAvgActivity(sum / dataRes.length);
setDataTableActivityToHr(dataRes); setDataTableActivityToHr(dataRes);
} else { } else {
NotificationManager.error("Gagal Mengambil Data!!", "Failed"); NotificationManager.error("Gagal Mengambil Data!!", "Failed");
@ -111,6 +118,8 @@ const ReportAnalysis = ({ openDialog, closeDialog, toggleDialog }) => {
}; };
const getDataActivity = async () => { const getDataActivity = async () => {
setAvgActivity(0);
let sum = 0;
const payload = { const payload = {
columns: [ columns: [
{ {
@ -132,6 +141,10 @@ const ReportAnalysis = ({ openDialog, closeDialog, toggleDialog }) => {
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
let dataRes = result.data.data || []; let dataRes = result.data.data || [];
dataRes.forEach(element => {
element.persentase_progress ? sum += parseInt(element.persentase_progress) : sum += 0;
});
setAvgActivity(sum / dataRes.length);
setDatatable(dataRes); setDatatable(dataRes);
} else { } else {
NotificationManager.error("Gagal Mengambil Data!!", "Failed"); NotificationManager.error("Gagal Mengambil Data!!", "Failed");
@ -186,7 +199,9 @@ const ReportAnalysis = ({ openDialog, closeDialog, toggleDialog }) => {
<CardBody> <CardBody>
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
<h1> <h1>
Hello World {
search && avgActivity ? `Activity ${search} adalah ${avgActivity.toFixed(2)} %` : null
}
</h1> </h1>
</div> </div>
<Table <Table
@ -217,7 +232,9 @@ const ReportAnalysis = ({ openDialog, closeDialog, toggleDialog }) => {
<CardBody> <CardBody>
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
<h1> <h1>
Hello World {
selectedHr && avgActivity ? `Activity user ini adalah ${avgActivity.toFixed(2)} %` : null
}
</h1> </h1>
</div> </div>
<Table <Table

Loading…
Cancel
Save