Commit a29d37ef authored by Dida Adams Arizona's avatar Dida Adams Arizona

Merge branch 'didam' into 'master'

handleCAT

See merge request !755
parents d47c96df e1685815
......@@ -81,7 +81,10 @@ export default class CorporateAnnualTarget extends Component {
handleTekTekTek: 0,
editable: false,
dataCustomerPrs: [],
dataInternalBsn: []
dataInternalBsn: [],
dataFin: [],
dataLearn: [],
handleDataSalah: false,
}
this.fileHandler = this.fileHandler.bind(this);
......@@ -110,6 +113,8 @@ export default class CorporateAnnualTarget extends Component {
let dataTable = []
let dataCustomerPrs = []
let dataInternalBsn = []
let dataFin = []
let dataLearn = []
// console.log(response)
if (response.data) {
if (response.ok) {
......@@ -140,6 +145,26 @@ export default class CorporateAnnualTarget extends Component {
}
}
if (item.parent_name == 'FINANCIAL PERSPECTIVE') {
if (item.type_report_id !== 4) {
dataFin.push({
id: item.id,
name: item.description,
check: false
})
}
}
if (item.parent_name == 'LEARNING & GROWTH PERSPECTIVE') {
if (item.type_report_id !== 4) {
dataLearn.push({
id: item.id,
name: item.description,
check: false
})
}
}
dataTable.push([
item.type_report_id,
item.id,
......@@ -227,7 +252,7 @@ export default class CorporateAnnualTarget extends Component {
}
})
// console.log(dataTable)
this.setState({ dataTable, loading: false, dataReal: res, editable: true, dataCustomerPrs, dataInternalBsn }, () => {
this.setState({ dataTable, loading: false, dataReal: res, editable: true, dataCustomerPrs, dataInternalBsn, dataFin, dataLearn}, () => {
// // console.log(dataCustomerPrs)
})
} else {
......@@ -299,6 +324,7 @@ export default class CorporateAnnualTarget extends Component {
// console.log(isi);
let payload = []
let reg = /^[-+]?(?:[0-9]+,)*[0-9]+(?:\.[0-9]+)?$/;
let newValidate = false
isi.map((i, index) => {
if (i.length > 0) {
let total = 0
......@@ -318,9 +344,46 @@ export default class CorporateAnnualTarget extends Component {
}
nilaiTotal = i[6] == 'SUM' ? total : i[6] == 'AVG' ? total / 12 : lastValz
}
// console.log(i[2])
// // console.log(Number(i[2] * 100))
// // // // console.log(i[2] === undefined ? "" : String(Number(i[2]*100)).length > 3? String(Number(i[2]*100).toFixed(0) + '%') : String(Number(i[2]*100)) + '%')
if (String(i[1]).trim().toLocaleUpperCase() == "CUSTOMER PERSPECTIVE") {
newValidate = true
}
if (String(i[1]).trim().toLocaleUpperCase() == "LEARNING & GROWTH PERSPECTIVE") {
newValidate = false
}
if (i[0] === undefined || i[0] === null) {
if (newValidate) {
payload.push({
item_report_id: i[0] === undefined ? 0 : reg.test(String(i[0])) === false ? 0 : String(i[0]).trim(),
item_report: i[1] === undefined ? "" : String(i[1]).trim(),
weight: i[2] === undefined ? "" : (String(i[2]).includes('%')? String(i[2].trim()) : (String(Number(i[2] * 100)).length > 3 ? String(Number(i[2] * 100).toFixed(0) + '%') : String(Number(i[2] * 100)) + '%')),
uom: i[3] === undefined ? "" : String(i[3]).trim(),
kpi_type: i[4] === undefined ? "" : String(i[4]).trim(),
max_ach: i[5] === undefined ? "" : String(i[5]).toLocaleLowerCase() !== 'unlimited' ? (String(i[5]).includes('%')? String(i[5].trim()) : String(Number(i[5] * 100) + '%')) : String(i[5]).trim(),
formula: i[6] === undefined ? "" : String(i[6]).trim(),
total_actual_before: i[7] === undefined ? "0.0" : reg.test(String(i[7])) === false ? "0.0" : String(Number(i[7]).toFixed(1)).trim(),
january: i[8] === undefined ? "0.0" : reg.test(String(i[8])) === false ? "0.0" : String(Number(i[8]).toFixed(1)).trim(),
february: i[9] === undefined ? "0.0" : reg.test(String(i[9])) === false ? "0.0" : String(Number(i[9]).toFixed(1)).trim(),
march: i[10] === undefined ? "0.0" : reg.test(String(i[10])) === false ? "0.0" : String(Number(i[10].toFixed(1))).trim(),
april: i[11] === undefined ? "0.0" : reg.test(String(i[11])) === false ? "0.0" : String(Number(i[11]).toFixed(1)).trim(),
may: i[12] === undefined ? "0.0" : reg.test(String(i[12])) === false ? "0.0" : String(Number(i[12].toFixed(1))).trim(),
june: i[13] === undefined ? "0.0" : reg.test(String(i[13])) === false ? "0.0" : String(Number(i[13].toFixed(1))).trim(),
july: i[14] === undefined ? "0.0" : reg.test(String(i[14])) === false ? "0.0" : String(Number(i[14].toFixed(1))).trim(),
august: i[15] === undefined ? "0.0" : reg.test(String(i[15])) === false ? "0.0" : String(Number(i[15]).toFixed(1)).trim(),
september: i[16] === undefined ? "0.0" : reg.test(String(i[16])) === false ? "0.0" : String(Number(i[16]).toFixed(1)).trim(),
october: i[17] === undefined ? "0.0" : reg.test(String(i[17])) === false ? "0.0" : String(Number(i[17]).toFixed(1)).trim(),
november: i[18] === undefined ? "0.0" : reg.test(String(i[18])) === false ? "0.0" : String(Number(i[18]).toFixed(1)).trim(),
december: i[19] === undefined ? "0.0" : reg.test(String(i[19])) === false ? "0.0" : String(Number(i[19]).toFixed(1)).trim(),
total_current_year: i[20] == 0 ? "0.0" : String(Number(nilaiTotal).toFixed(1)).trim(),
total_next_year: i[21] === undefined ? "0.0" : reg.test(String(i[21])) === false ? "0.0" : String(Number(i[21]).toFixed(1)).trim(),
total_more_year: i[22] === undefined ? "0.0" : reg.test(String(i[22])) === false ? "0.0" : String(Number(i[22]).toFixed(1)).trim(),
strategic: i[23] === undefined ? "" : String(i[23]).trim(),
pic: i[24] === undefined ? "" : String(i[24]).trim()
})
}
} else {
payload.push({
item_report_id: i[0] === undefined ? 0 : reg.test(String(i[0])) === false ? 0 : String(i[0]).trim(),
item_report: i[1] === undefined ? "" : String(i[1]).trim(),
......@@ -349,6 +412,11 @@ export default class CorporateAnnualTarget extends Component {
pic: i[24] === undefined ? "" : String(i[24]).trim()
})
}
// console.log(i[2])
// // console.log(Number(i[2] * 100))
// // // // console.log(i[2] === undefined ? "" : String(Number(i[2]*100)).length > 3? String(Number(i[2]*100).toFixed(0) + '%') : String(Number(i[2]*100)) + '%')
}
})
// console.log(payload)
......@@ -382,8 +450,8 @@ export default class CorporateAnnualTarget extends Component {
})
// console.log(this.state.payload)
api.create().checkUploadMB(this.state.payload).then(response => {
// // console.log(JSON.stringify(this.state.payload));
// // console.log(response)
// console.log(JSON.stringify(this.state.payload));
// console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
......@@ -393,6 +461,9 @@ export default class CorporateAnnualTarget extends Component {
let custoId = 0
let bisnsId = 0
let dataDelete = this.state.dataDelete
let dataFin = this.state.dataFin
let dataLearn = this.state.dataLearn
let newValidate = false
response.data.data.map((item, index) => {
if (item.item_report == 'CUSTOMER PERSPECTIVE') {
custoId = item.item_report_id
......@@ -402,6 +473,14 @@ export default class CorporateAnnualTarget extends Component {
bisnsId = item.item_report_id
}
if (String(item.item_report).trim().toLocaleUpperCase() == "CUSTOMER PERSPECTIVE") {
newValidate = true
}
if (String(item.item_report).trim().toLocaleUpperCase() == "LEARNING & GROWTH PERSPECTIVE") {
newValidate = false
}
if (item.type_report_id !== 4 && item.parent !== null && (item.parent == custoId || item.parent == bisnsId)) {
let indexCust = this.state.dataCustomerPrs.findIndex((val) => val.name == item.item_report)
let indexBisn = this.state.dataInternalBsn.findIndex((val) => val.name == item.item_report)
......@@ -414,6 +493,17 @@ export default class CorporateAnnualTarget extends Component {
}
}
if (newValidate == false) {
let indexIDx = dataFin.findIndex((val) => String(val.name).toLocaleLowerCase() == String(item.item_report).toLocaleLowerCase())
let indexIDz = dataLearn.findIndex((val) => String(val.name).toLocaleLowerCase() == String(item.item_report).toLocaleLowerCase())
if (indexIDx != -1) {
dataFin[indexIDx].check = true
}
if (indexIDz != -1) {
dataLearn[indexIDz].check = true
}
}
dataTable.push([
item.type_report_id,
item.item_report_id,
......@@ -428,18 +518,18 @@ export default class CorporateAnnualTarget extends Component {
item.max_ach == "" || item.max_ach == null ? null : { value: titleCase(item.max_ach) },
item.formula_ytd == "" || item.formula_ytd == null ? null : { value: item.formula_ytd },
item.total_actual_before == "" ? item.total_actual_before : String(item.total_actual_before).indexOf(".") == -1 ? Number(item.total_actual_before) : Number(item.total_actual_before).toFixed(1),
item.item_report === 'ROIC' ? Number(item.january).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.january, formula: item.january_formula } : item.january == "" ? item.january : String(item.january).indexOf(".") == -1 ? Number(item.january) : Number(item.january).toFixed(1),
item.item_report === 'ROIC' ? Number(item.february).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.february, formula: item.february_formula } : item.february == "" ? item.february : String(item.february).indexOf(".") == -1 ? Number(item.february) : Number(item.february).toFixed(1),
item.item_report === 'ROIC' ? Number(item.march).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.march_formula, formula: item.march_formula } : item.march == "" ? item.march : String(item.march).indexOf(".") == -1 ? Number(item.march) : Number(item.march).toFixed(1),
item.item_report === 'ROIC' ? Number(item.april).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.april, formula: item.april_formula } : item.april == "" ? item.april : String(item.april).indexOf(".") == -1 ? Number(item.april) : Number(item.april).toFixed(1),
item.item_report === 'ROIC' ? Number(item.may).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.may, formula: item.may_formula } : item.may == "" ? item.may : String(item.may).indexOf(".") == -1 ? Number(item.may) : Number(item.may).toFixed(1),
item.item_report === 'ROIC' ? Number(item.june).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.june, formula: item.june_formula } : item.june == "" ? item.june : String(item.june).indexOf(".") == -1 ? Number(item.june) : Number(item.june).toFixed(1),
item.item_report === 'ROIC' ? Number(item.july).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.july, formula: item.july_formula } : item.july == "" ? item.july : String(item.july).indexOf(".") == -1 ? Number(item.july) : Number(item.july).toFixed(1),
item.item_report === 'ROIC' ? Number(item.august).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.august, formula: item.august_formula } : item.august == "" ? item.august : String(item.august).indexOf(".") == -1 ? Number(item.august) : Number(item.august).toFixed(1),
item.item_report === 'ROIC' ? Number(item.september).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.september, formula: item.september_formula } : item.september == "" ? item.september : String(item.september).indexOf(".") == -1 ? Number(item.september) : Number(item.september).toFixed(1),
item.item_report === 'ROIC' ? Number(item.october).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.october, formula: item.october_formula } : item.october == "" ? item.october : String(item.october).indexOf(".") == -1 ? Number(item.october) : Number(item.october).toFixed(1),
item.item_report === 'ROIC' ? Number(item.november).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.november, formula: item.november_formula } : item.november == "" ? item.november : String(item.november).indexOf(".") == -1 ? Number(item.november) : Number(item.november).toFixed(1),
item.item_report === 'ROIC' ? Number(item.december).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? { value: item.december, formula: item.december_formula } : item.december == "" ? item.december : String(item.december).indexOf(".") == -1 ? Number(item.december) : Number(item.december).toFixed(1),
item.item_report === 'ROIC' ? Number(item.january).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.january).toFixed(1) : { value: item.january, formula: item.january_formula } : item.january == "" ? item.january : String(item.january).indexOf(".") == -1 ? Number(item.january) : Number(item.january).toFixed(1),
item.item_report === 'ROIC' ? Number(item.february).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.february).toFixed(1) : { value: item.february, formula: item.february_formula } : item.february == "" ? item.february : String(item.february).indexOf(".") == -1 ? Number(item.february) : Number(item.february).toFixed(1),
item.item_report === 'ROIC' ? Number(item.march).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.march).toFixed(1) : { value: item.march, formula: item.march_formula } : item.march == "" ? item.march : String(item.march).indexOf(".") == -1 ? Number(item.march) : Number(item.march).toFixed(1),
item.item_report === 'ROIC' ? Number(item.april).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.april).toFixed(1) : { value: item.april, formula: item.april_formula } : item.april == "" ? item.april : String(item.april).indexOf(".") == -1 ? Number(item.april) : Number(item.april).toFixed(1),
item.item_report === 'ROIC' ? Number(item.may).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.may).toFixed(1) : { value: item.may, formula: item.may_formula } : item.may == "" ? item.may : String(item.may).indexOf(".") == -1 ? Number(item.may) : Number(item.may).toFixed(1),
item.item_report === 'ROIC' ? Number(item.june).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.june).toFixed(1) : { value: item.june, formula: item.june_formula } : item.june == "" ? item.june : String(item.june).indexOf(".") == -1 ? Number(item.june) : Number(item.june).toFixed(1),
item.item_report === 'ROIC' ? Number(item.july).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.july).toFixed(1) : { value: item.july, formula: item.july_formula } : item.july == "" ? item.july : String(item.july).indexOf(".") == -1 ? Number(item.july) : Number(item.july).toFixed(1),
item.item_report === 'ROIC' ? Number(item.august).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.august).toFixed(1) : { value: item.august, formula: item.august_formula } : item.august == "" ? item.august : String(item.august).indexOf(".") == -1 ? Number(item.august) : Number(item.august).toFixed(1),
item.item_report === 'ROIC' ? Number(item.september).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.september).toFixed(1) : { value: item.september, formula: item.september_formula } : item.september == "" ? item.september : String(item.september).indexOf(".") == -1 ? Number(item.september) : Number(item.september).toFixed(1),
item.item_report === 'ROIC' ? Number(item.october).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.october).toFixed(1) : { value: item.october, formula: item.october_formula } : item.october == "" ? item.october : String(item.october).indexOf(".") == -1 ? Number(item.october) : Number(item.october).toFixed(1),
item.item_report === 'ROIC' ? Number(item.november).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.november).toFixed(1) : { value: item.november, formula: item.november_formula } : item.november == "" ? item.november : String(item.november).indexOf(".") == -1 ? Number(item.november) : Number(item.november).toFixed(1),
item.item_report === 'ROIC' ? Number(item.december).toFixed(1) : item.parent_name == "FINANCIAL PERSPECTIVE" ? item.type_report_id == 3 ? Number(item.december).toFixed(1) : { value: item.december, formula: item.december_formula } : item.december == "" ? item.december : String(item.december).indexOf(".") == -1 ? Number(item.december) : Number(item.december).toFixed(1),
item.total_current_year == "" ? item.total_current_year : String(item.total_current_year).indexOf(".") == -1 ? Number(item.total_current_year) : Number(item.total_current_year).toFixed(1),
item.item_report === 'ROIC' ? Number(item.total_next_year).toFixed(1) : item.total_next_year == "" ? item.total_next_year : String(item.total_next_year).indexOf(".") == -1 ? Number(item.total_next_year) : Number(item.total_next_year).toFixed(1),
item.item_report === 'ROIC' ? Number(item.total_more_year).toFixed(1) : item.total_more_year == "" ? item.total_more_year : String(item.total_more_year).indexOf(".") == -1 ? Number(item.total_more_year) : Number(item.total_more_year).toFixed(1),
......@@ -450,9 +540,16 @@ export default class CorporateAnnualTarget extends Component {
item.error
])
})
// // console.log(dataTable)
let checkDataFin = dataFin.filter((val) => val.check == false)
let checkDataLearn = dataLearn.filter((val) => val.check == false)
let handleDataSalah = this.state.handleDataSalah
if (checkDataFin.length > 0 || checkDataLearn.length > 0) {
handleDataSalah = true
}
// console.log(indexCheck)
// // // console.log(this.state.buttonError)
this.setState({ dataTable, dataLoaded: true, loading: false, buttonError: false, editable: true, dataDelete }, () => {
this.setState({ dataTable, dataLoaded: true, loading: false, buttonError: false, editable: true, dataDelete, handleDataSalah }, () => {
this.state.dataTable.map(item => {
if (item[30].length > 0) {
// // // console.log('masuk')
......@@ -3446,23 +3543,23 @@ export default class CorporateAnnualTarget extends Component {
{(this.props.lastStatus === 'SUBMIT' || this.props.lastStatus === 'REVISION') && <button
className="button"
type="button"
disabled={this.state.buttonDraft}
disabled={this.state.buttonDraft? true : this.state.handleDataSalah? true : false}
style={{
backgroundColor: 'transparent',
cursor: this.state.editable === true ? 'default' : 'pointer',
cursor: this.state.editable === true ? 'default' : this.state.handleDataSalah? 'default' : 'pointer',
borderColor: 'transparent',
outline: 'none',
marginRight: 20
}}
onClick={() => this.state.editable ?
this.setState({ alert: true }) : this.setState({ loading: true }, () =>
this.setState({ alert: true }) : (this.state.handleDataSalah? null : this.setState({ loading: true }, () =>
this.state.handleTekTekTek == 1 ? null :
this.setState({ handleTekTekTek: 1 }, () => {
setTimeout(() => {
this.uploadCAT("draft")
}, 100);
})
)
))
}
>
<div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
......@@ -3473,22 +3570,22 @@ export default class CorporateAnnualTarget extends Component {
type="button"
style={{
backgroundColor: 'transparent',
cursor: this.state.editable !== true ? 'pointer' : 'default',
cursor: this.state.editable === true ? 'default' : this.state.handleDataSalah? 'default' : 'pointer',
borderColor: 'transparent',
outline: 'none'
}}
disabled={this.state.buttonDraft}
disabled={this.state.buttonDraft? true : this.state.handleDataSalah? true : false}
onClick={() =>
this.state.editable ? this.setState({ alert: true }) :
this.state.buttonError === true ?
this.setState({ alert: true, messageAlert: 'Data is not complete !', tipeAlert: 'warning' }) : this.setState({ loading: true }, () =>
this.setState({ alert: true, messageAlert: 'Data is not complete !', tipeAlert: 'warning' }) : (this.state.handleDataSalah? null : this.setState({ loading: true }, () =>
this.state.handleTekTekTek == 1 ? null :
this.setState({ handleTekTekTek: 1 }, () => {
setTimeout(() => {
this.uploadCAT("submitted")
}, 100);
})
)
))
}
>
<div style={{ backgroundColor: '#354960', width: 105, height: 25, borderRadius: 3, justifyContent: 'center', display: 'flex', alignItems: 'center' }}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment