import { createMuiTheme, FormControlLabel, Input, MuiThemeProvider, Paper, Snackbar, TableCell, Tooltip, Typography, withStyles } from '@material-ui/core' import MUIDataTable from 'mui-datatables'; import React, { Component } from 'react' import ReactTooltip from 'react-tooltip'; import Images from '../../assets/Images'; import api from '../../api'; import NumberFormat from 'react-number-format'; import * as R from 'ramda'; import { PropagateLoader } from 'react-spinners'; import { ExcelRenderer } from 'react-excel-renderer'; import Constant from '../../library/Constant'; import UploadFile from "../../library/Upload"; import { Alert } from '@material-ui/lab'; const LightTooltip = withStyles((theme) => ({ tooltip: { backgroundColor: theme.palette.common.white, color: 'rgba(0, 0, 0, 0.87)', boxShadow: theme.shadows[1], fontSize: 11, }, }))(Tooltip); const LightTooltipError = withStyles((theme) => ({ tooltip: { backgroundColor: theme.palette.common.white, color: 'rgba(255, 0, 0, 0.87)', boxShadow: theme.shadows[1], fontSize: 11, }, }))(Tooltip); var ct = require("../../library/CustomTable"); const getMuiTheme = () => createMuiTheme(ct.customTable3()); const options = ct.customOptionsFixedColumn(); const style = { position: "sticky", left: 0, zIndex: 101, background: "white", }; const style2 = { position: "sticky", background: "white", zIndex: 100, top: 0 }; const stylenotes = { position: "sticky", background: "white", zIndex: 101, left: 350 }; const styleNotesEmpty = { position: "sticky", background: "white", zIndex: 99, left: 0 } // const StyledButton = withStyles({ // root: { // background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)', // borderRadius: 3, // border: 0, // color: 'white', // height: 48, // padding: '0 30px', // boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)', // }, // label: { // textTransform: 'capitalize', // }, // })(Input); export default class ProfitLossROO extends Component { constructor(props) { super(props) this.state = { dataTable: [], loading: true, visiblePLRO: true, minValue: 0, maxValue: 0, updateBy: [], notesUpdate: '-', bebas: false, judulColumn: null, handleTekTekTek: 0, saveDraft: true, buttonError: true, viewOnly: true, get_for: 'view' } this.fileHandler = this.fileHandler.bind(this); } componentDidMount() { this.getItemHierarki() this.getLatestUpdate() // this.getSettingControl() this.handleViewOnly() } handleViewOnly() { let checkApprover = false let checkLastStatus = false let checkStatus = false let checkPrevRev = false if (this.props.isApprover) { checkApprover = true } else { checkApprover = false } if (this.props.lastStatus == 'SUBMIT' || this.props.lastStatus == 'REVISION') { checkLastStatus = true } else { checkLastStatus = false } if (this.props.prevRevision) { checkPrevRev = true } else { checkPrevRev = false } if (this.props.status === 'revision' || this.props.status === 'not-yet' || this.props.status === 'draft' || this.props.status === 'submitted') { checkStatus = true } else { checkStatus = false } this.setState({ viewOnly: !checkApprover && checkLastStatus && checkStatus && checkPrevRev }) } handleGetFor(type) { this.setState({ get_for: type }, () => { // this.getLatestUpdate() // this.getSettingControl() this.getItemHierarki() }) } // getSettingControl() { // let body = { // group: 'THRESHOLD_VARIANCE', // company_id: this.props.company.company_id, // type: 'PNL' // } // api.create().getAllSettingByType(body).then(response => { // console.log(response); // if (response.data) { // if (response.data.status === 'success') { // this.setState({ // // valueThreshold: response.data.data[0] ? response.data.data[0].value : null, // minValue: response.data.data[0] ? Number(response.data.data[0].min_value) : -10, // maxValue: response.data.data[0] ? Number(response.data.data[0].max_value) : 10, // }, () => { // this.getItemHierarki() // }) // } else { // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => { // if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) { // setTimeout(() => { // localStorage.removeItem(Constant.TOKEN) // window.location.reload(); // }, 1000); // } // }) // } // } else { // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false }) // } // }) // } getLatestUpdate() { let payload = { "report_id": this.props.report_id, "revision": Number(this.props.revision), "periode": this.props.periode, "company_id": this.props.company.company_id, "rolling_outlook_id": this.props.rollingOutlookID, "quartal": this.props.quarter } api.create().getRollingOutlookLastUpdate(payload).then(response => { console.log(response); if (response.data) { if (response.data.status === "success") { this.setState({ updateBy: response.data.data.detail === null ? '-' : response.data.data.detail, notes: response.data.data.notes_update === null ? "" : response.data.data.notes_update }) } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => { if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) { setTimeout(() => { localStorage.removeItem(Constant.TOKEN) window.location.reload(); }, 1000); } }) } } else { this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false }) } }) } getItemHierarki() { let payload = { "company_id": this.props.company.company_id, "get_for": this.state.get_for, "quartal": this.props.quarter, "periode": this.props.periode, "report_id": this.props.report_id, "revision": Number(this.props.revision), "rolling_outlook_id": this.props.rollingOutlookID } console.log(payload); api.create().getRollingOutlookPL(payload).then(response => { console.log(response); let dataTable = [] let err = false if (response.data) { if (response.data.status === 'success') { let res = response.data.data const handlePushChild = (item) => { let indexIDzz = dataTable.findIndex((val) => val[1] === item.id) if (indexIDzz === -1) { dataTable.push([ item.type_report_id, item.id, item.parent, item.formula, item.level, item.description, item.profit_loss.notes, item.profit_loss.last_year_total === "" ? "0" : item.profit_loss.last_year_total, item.profit_loss.january === "" ? "0" : item.profit_loss.january, item.profit_loss.february === "" ? "0" : item.profit_loss.february, item.profit_loss.march === "" ? "0" : item.profit_loss.march, item.profit_loss.april === "" ? "0" : item.profit_loss.april, item.profit_loss.may === "" ? "0" : item.profit_loss.may, item.profit_loss.june === "" ? "0" : item.profit_loss.june, item.profit_loss.july === "" ? "0" : item.profit_loss.july, item.profit_loss.august === "" ? "0" : item.profit_loss.august, item.profit_loss.september === "" ? "0" : item.profit_loss.september, item.profit_loss.october === "" ? "0" : item.profit_loss.october, item.profit_loss.november === "" ? "0" : item.profit_loss.november, item.profit_loss.december === "" ? "0" : item.profit_loss.december, item.profit_loss.current_year_total === "" ? "0" : item.profit_loss.current_year_total, "", item.order, ]) } if (item.children !== null) { if (item.children.length > 0) { item.children.map((items, indexs) => { handlePushChild(items) }) } } } res.map((item, index) => { dataTable.push([ item.type_report_id, item.id, item.parent, item.formula, item.level, item.description, item.profit_loss.notes, item.profit_loss.last_year_total === "" ? "0" : item.profit_loss.last_year_total, item.profit_loss.january === "" ? "0" : item.profit_loss.january, item.profit_loss.february === "" ? "0" : item.profit_loss.february, item.profit_loss.march === "" ? "0" : item.profit_loss.march, item.profit_loss.april === "" ? "0" : item.profit_loss.april, item.profit_loss.may === "" ? "0" : item.profit_loss.may, item.profit_loss.june === "" ? "0" : item.profit_loss.june, item.profit_loss.july === "" ? "0" : item.profit_loss.july, item.profit_loss.august === "" ? "0" : item.profit_loss.august, item.profit_loss.september === "" ? "0" : item.profit_loss.september, item.profit_loss.october === "" ? "0" : item.profit_loss.october, item.profit_loss.november === "" ? "0" : item.profit_loss.november, item.profit_loss.december === "" ? "0" : item.profit_loss.december, item.profit_loss.current_year_total === "" ? "0" : item.profit_loss.current_year_total, "", item.order, ]) if (item.children !== null) { if (item.children.length > 0) { item.children.map((items, indexs) => { handlePushChild(items) }) } } }) // if (err === true) { // this.setState({ bebas: true }) // } this.setState({ dataTable, loading: false, buttonError: true, saveDraft: true, refresh: false }) } else { this.setState({ loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => { if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) { setTimeout(() => { localStorage.removeItem(Constant.TOKEN) window.location.reload(); }, 1000); } }) } } else { this.setState({ dataTable, loading: false, buttonError: true, saveDraft: true, refresh: false }) } console.log(dataTable); }) } downloadTemplate = async () => { // alert('Coming Soon ...') let res = await fetch( `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/profit_loss/rolling_outlook/download_template?report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&quartal=${this.props.quarter}` ) res = await res.blob() // console.log(res) if (res.size > 0) { let url = window.URL.createObjectURL(res); let a = document.createElement('a'); a.href = url; a.download = 'Template Rolling Outlook Profit Loss.xlsx'; a.click(); } setTimeout(() => { this.setState({loading: false}) }, 500); } async downloadAllData() { // alert('Coming Soon ...') let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/profit_loss/rolling_outlook/export_rolling_outlook?rolling_outlook_id=${this.props.rollingOutlookID}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&quartal=${this.props.quarter}` console.log(url); let res = await fetch( `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/profit_loss/rolling_outlook/export_rolling_outlook?rolling_outlook_id=${this.props.rollingOutlookID === null ? "" : this.props.rollingOutlookID}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&quartal=${this.props.quarter}` ) res = await res.blob() this.setState({ loading: false }) if (res.size > 0) { let url = window.URL.createObjectURL(res); let a = document.createElement('a'); a.href = url; a.download = 'Rolling Outlook Profit Loss.xlsx'; a.click(); } setTimeout(() => { this.setState({loading: false}) }, 500); } backToRollingOutlook(type) { console.log('test'); // this.setState({ loading: true }) let data = [] this.state.dataTable.map(i => { data.push({ "item_report_id": i[1], "notes": String(i[6]), "last_year_total": String(Number(i[7]).toFixed(1)), "january": String(Number(i[8]).toFixed(1)), "february": String(Number(i[9]).toFixed(1)), "march": String(Number(i[10]).toFixed(1)), "april": String(Number(i[11]).toFixed(1)), "may": String(Number(i[12]).toFixed(1)), "june": String(Number(i[13]).toFixed(1)), "july": String(Number(i[14]).toFixed(1)), "august": String(Number(i[15]).toFixed(1)), "september": String(Number(i[16]).toFixed(1)), "october": String(Number(i[17]).toFixed(1)), "november": String(Number(i[18]).toFixed(1)), "december": String(Number(i[19]).toFixed(1)), "current_year_total": String(Number(i[20]).toFixed(1)), }) }) let payload = { "rolling_outlook_id": this.props.rollingOutlookID, "company_id": this.props.company.company_id, "periode": this.props.periode, "report_id": this.props.report_id, "quartal": this.props.quarter, "status": type, "profit_loss": data } console.log(payload); // console.log(JSON.stringify(payload)); api.create('UPLOAD').createRollingOutlookPL(payload).then(response => { console.log(response); if (response.data) { if (response.data.status === "success") { if (type == 'submitted') { this.props.refresh('PL') } else { this.props.refresh() } this.props.onClickClose() } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false, handleTekTekTek: 0 }, () => { document.body.style.overflow = 'unset'; if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) { setTimeout(() => { localStorage.removeItem(Constant.TOKEN) window.location.reload(); }, 1000); } // this.props.saveToMonthlyReport() this.props.onClickClose() }) } } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false, handleTekTekTek: 0 }) } }) } fileHandler = (event) => { let fileObj = event ExcelRenderer(fileObj, (err, resp) => { console.log(resp) if (err) { console.log(err); } else { let isi = resp.rows.slice(3) // console.log(resp.rows[2]); let payload = [] let reg = /^[-+]?(?:[0-9]+,)*[0-9]+(?:\.[0-9]+)?$/; isi.map((i, index) => { if (i.length > 0) { payload.push({ orders: i[0] === undefined ? "" : String(i[0]).trim(), "item_report_id": i[1] === undefined ? 0 : i[1], "item_report": i[2] === undefined ? "" : String(i[2]).trim(), "notes": i[3] === undefined ? "" : reg.test(String(i[3])) === false ? "" : String(i[3]).trim(), "january": i[5] === undefined ? "0" : reg.test(String(i[5])) === false ? "0" : String(i[5]).trim(), "february": i[6] === undefined ? "0" : reg.test(String(i[6])) === false ? "0" : String(i[6]).trim(), "march": i[7] === undefined ? "0" : reg.test(String(i[7])) === false ? "0" : String(i[7]).trim(), "april": i[8] === undefined ? "0" : reg.test(String(i[8])) === false ? "0" : String(i[8]).trim(), "may": i[9] === undefined ? "0" : reg.test(String(i[9])) === false ? "0" : String(i[9]).trim(), "june": i[10] === undefined ? "0" : reg.test(String(i[10])) === false ? "0" : String(i[10]).trim(), "july": i[11] === undefined ? "0" : reg.test(String(i[11])) === false ? "0" : String(i[11]).trim(), "august": i[12] === undefined ? "0" : reg.test(String(i[12])) === false ? "0" : String(i[12]).trim(), "september": i[13] === undefined ? "0" : reg.test(String(i[13])) === false ? "0" : String(i[13]).trim(), "october": i[14] === undefined ? "0" : reg.test(String(i[14])) === false ? "0" : String(i[14]).trim(), "november": i[15] === undefined ? "0" : reg.test(String(i[15])) === false ? "0" : String(i[15]).trim(), "december": i[16] === undefined ? "0" : reg.test(String(i[16])) === false ? "0" : String(i[16]).trim(), }) } }) let body = { company_id: this.props.company.company_id, periode: this.props.periode, report_id: this.props.report_id, quartal: this.props.quarter, rolling_outlook_id: this.props.rollingOutlookID, status: 'submitted', profit_loss: payload } console.log(body) this.setState({ payload: body, judul: resp.rows[1][0], judulColumn: resp.rows[0][0] }) } }); } checkUpload() { api.create().checkImportRollingOutlookPL(this.state.payload).then(response => { // console.log(JSON.stringify(this.state.payload)); console.log(response) if (response.data) { if (response.data.status === 'success') { this.setState({ visibleUpload: false, visiblePLRO: false, loading: true }) let dataTable = response.data.data.map((item, index) => { return [ item.type_report_id, item.item_report_id, item.parent, item.formula, item.level, item.item_report, item.notes, item.last_year_total === "" ? "0" : item.last_year_total, item.january === "" ? "0" : item.january, item.february === "" ? "0" : item.february, item.march === "" ? "0" : item.march, item.april === "" ? "0" : item.april, item.may === "" ? "0" : item.may, item.june === "" ? "0" : item.june, item.july === "" ? "0" : item.july, item.august === "" ? "0" : item.august, item.september === "" ? "0" : item.september, item.october === "" ? "0" : item.october, item.november === "" ? "0" : item.november, item.december === "" ? "0" : item.december, item.current_year_total === "" ? "0" : item.current_year_total, "", item.order, ] }) this.setState({ dataTable, dataLoaded: true, loading: false, buttonError: false }, () => { this.state.dataTable.map(item => { // if (item[24].length > 0) { // // console.log('masuk') // this.setState({ buttonError: true, errorPreview: true }) // } }) // console.log(this.state.buttonError) }) console.log(dataTable); } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => { if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) { setTimeout(() => { localStorage.removeItem(Constant.TOKEN) window.location.reload(); }, 1000); } }) } } }) } uploadProfitLossRO(type) { let data = [] this.state.dataTable.map(i => { data.push({ "item_report_id": i[1], "item_report": i[5], "notes": String(i[6]), "last_year_total": String(Number(i[7]).toFixed(1)), "january": String(Number(i[8]).toFixed(1)), "february": String(Number(i[9]).toFixed(1)), "march": String(Number(i[10]).toFixed(1)), "april": String(Number(i[11]).toFixed(1)), "may": String(Number(i[12]).toFixed(1)), "june": String(Number(i[13]).toFixed(1)), "july": String(Number(i[14]).toFixed(1)), "august": String(Number(i[15]).toFixed(1)), "september": String(Number(i[16]).toFixed(1)), "october": String(Number(i[17]).toFixed(1)), "november": String(Number(i[18]).toFixed(1)), "december": String(Number(i[19]).toFixed(1)), "current_year_total": String(Number(i[20]).toFixed(1)), }) }) let body = { "monthly_report_id": this.props.monthlyReportId, "company_id": this.props.company.company_id, "periode": this.props.periode, "report_id": this.props.report_id, "quartal": this.props.quarter, "rolling_outlook_id": this.props.rollingOutlookID, "status": type, "profit_loss": data } console.log(data); api.create('UPLOAD').importRollingOutlookPL(body).then(response => { console.log(response); if (response.data) { if (response.ok) { if (response.data.status === "success") { this.props.onClickClose() if (type == 'submitted') { this.props.refresh('PL') } else { this.props.refresh() } // this.props.onClickClose() // this.props.getReport() } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false, handleTekTekTek: 0 }, () => { if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) { setTimeout(() => { localStorage.removeItem(Constant.TOKEN) window.location.reload(); }, 1000); } this.props.onClickClose() this.props.refresh() }) // alert(response.data.status) } } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false, handleTekTekTek: 0 }) } } else { this.setState({ alert: true, messageAlert: 'Error saving data. Please try again', tipeAlert: 'error', loading: false, handleTekTekTek: 0 }) } }) } handleValidate() { // let data = [] // let err = false // this.state.dataTable.map((i, index) => { // data.push({ // "item_report_id": i[1], // "notes": i[6], // "rolling_outlook": i[7], // "master_budget": i[8], // "rolling_budget": i[9], // "actual": i[10], // "ytd_actual": i[11], // "actual_previous_month": i[12], // "amount_act_vs_previous_month": i[13], // "percent_act_vs_previous_month": i[14], // "amount_act_vs_mb": i[15], // "percent_act_vs_mb": i[16], // "amount_act_vs_rb": i[17], // "percent_act_vs_rb": i[18], // "mtd_vs_mb": i[19], // "mtd_vs_rb": i[20], // "mtd_vs_previous_month": i[21], // }) // }) // console.log(this.state.dataTable); // console.log(JSON.stringify(data)) // let payload = { // "monthly_report_id": this.props.monthlyReportId, // "company_id": this.props.company.company_id, // "periode": this.props.periode, // "report_id": this.props.report_id, // "status": "submitted", // "months": this.props.month.month_id, // "profit_loss": data // } // console.log(JSON.stringify(payload)); // api.create().validateSubmitReportPL(payload).then((response) => { // console.log(response.data.data.result) // console.log(err); // if (response.data) { // if (response.data.status === "success") { // if (response.data.data.result && err === false) { this.setState({ loading: false, buttonError: false, editable: false, saveDraft: false }) // } else { // this.setState({ loading: false, buttonError: true, editable: true, saveDraft: false }) // } // } else { // this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => { // if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) { // setTimeout(() => { // localStorage.removeItem(Constant.TOKEN) // window.location.reload(); // }, 1000); // } // }) // } // } else { // this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false }) // } // }) } closeAlert() { this.setState({ alert: false }) } render() { let dataTable2 = this.state.dataTable const handleNotes = (value, tableMeta) => { // console.log(value) let a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = value // console.log(dataTable2[tableMeta.rowIndex]); } const handleChange = (value, tableMeta, type) => { console.log(dataTable2); let val = String(value).split(",").join("") dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(val) } const handleValue = (value, data) => { let total = 0 // console.log(data); // console.log(dataTable2); dataTable2.map((item, index) => { if (data.rowData[1] == item[2]) { total = item[data.columnIndex] == undefined ? (Number(total) + 0) : (Number(total) + Number(String(item[data.columnIndex]).includes('-') ? Number(String(item[data.columnIndex]).substr(1, String(item[data.columnIndex]).length)) * -1 : Number(item[data.columnIndex]))) // if (data.rowData[5] == "Revenue") { // console.log(total); // // console.log(a); // } } }) // console.log(total); let indexParent = dataTable2.findIndex((val) => val[1] == dataTable2[data.rowIndex][2]) let a = dataTable2[data.rowIndex][data.columnIndex] = Number(total) return a } const handleFormula = (data, tableMeta, month) => { let arrayFormula = tableMeta.rowData[3].match(/[a-zA-Z]+|[0-9]+|[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]+(?:\.[0-9]+@|)/g) let arrayJumlah = [] let tambahan = false let opet = "" arrayFormula.map((item, indexs) => { if (item == 'X') { tambahan = true } else if (item == '-' || item == '+' || item == '/' || item == '*') { arrayJumlah.push(item) } else { let index = dataTable2.findIndex((val) => val[22] == item) if (tambahan) { if (item == '-' || item == '+' || item == '/' || item == '*') { opet = item } else { arrayJumlah.push(opet == '' ? Number(item) : Number(String(opet + String(item)))) tambahan = false opet = "" } } else { if (index != -1) { if (item === String(tableMeta.rowData[23])) { arrayJumlah.push(0) } else { arrayJumlah.push(dataTable2[index][tableMeta.columnIndex]) } } } } // if (indexs % 2 !== 0) { // operator.push(item) // } }) // if (String(tableMeta.rowData[5]) == "Net Trading Profit (TPAT)") { // console.log(tableMeta.rowData[3]) // console.log(arrayFormula) // console.log(arrayJumlah) // } let array = arrayJumlah let total = 0 let opt = "" array.map((item, index) => { if (item == "+") { opt = "tambah" } else if (item == "-") { opt = "kurang" } else if (item == "*") { opt = "kali" } else if (item == "/") { opt = "bagi" } else { if (opt == "tambah") { total = Number(total) + Number(item) } else if (opt == "kurang") { total = Number(total) - Number(item) } else if (opt == "kali") { total = Number(total) * Number(item) } else if (opt == "bagi") { total = R.equals((Number(total) / Number(item)), NaN) ? '0' : (R.equals((Number(total) / Number(item)), Infinity) ? '0' : (Number(total) / Number(item) == "-Infinity") ? "0.0" : Number(total) / Number(item)) } else { total += Number(item) } } }) total = R.equals(total, NaN) ? "0.0" : (R.equals(total, Infinity) ? "0.0" : (total == "-Infinity" ? "0.0" : total)) // if (tableMeta.rowData[1] === 20092) { // console.log(total); // console.log(arrayJumlah); // } // if (dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] === "" || dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] === undefined || dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] === null) { dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = Number(total).toFixed(1) // } return Number(total) } const handleTotal = (val, tableMeta) => { let total = 0 tableMeta.rowData.map((item,index) => { if (index >= 8 && index <= 19) { total += Number(item) } }) if (String(tableMeta.rowData[5]).toLocaleLowerCase() == "sales price") { let value = Number(dataTable2[tableMeta.rowIndex - 2][20]) / Number(dataTable2[tableMeta.rowIndex - 1][20]) dataTable2[tableMeta.rowIndex][20] = R.equals(value, NaN) ? "0.0" : (R.equals(value, Infinity) ? "0.0" : (value == "-Infinity" ? "0.0" : value)) return R.equals(value, NaN) ? "0.0" : (R.equals(value, Infinity) ? "0.0" : (value == "-Infinity" ? "0.0" : value)) } // else if (String(tableMeta.rowData[5]).toLocaleLowerCase() == "total man power") { // let totalTMP = dataTable2[tableMeta.rowIndex][20] = dataTable2[tableMeta.rowIndex][19] // return totalTMP // } else if (indexParent !== -1 && String(dataTable2[indexParent][5]).toLocaleUpperCase() == "GROSS PROFIT MARGIN (% OF REVENUE)") { // return handleFormula(0, tableMeta, 0) // } else { dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = total return total } // dataTable2[tableMeta.rowIndex][tableMeta.columnIndex] = total // if (String(tableMeta.rowData[5]).toLocaleLowerCase === "sales volume") { // console.log(total); // } // return total } let columns = [ { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "Account", options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style }), customBodyRender: (val, tableMeta) => { return (
{tableMeta.rowData[0] === null ? tableMeta.rowData[4] == 0 ? {String(val).toUpperCase()} :
{tableMeta.rowData[0] === 4 ? "" : val}
: tableMeta.rowData[4] == 0 ? {String(tableMeta.rowData[0] === 4 ? "" : val).toUpperCase()} :
{tableMeta.rowData[0] === 4 ? "" : val}
}
) } } }, { name: "Notes", options: { customHeadRender: (columnMeta) => ( dataTable2.length > 0 ? {columnMeta.name} : {columnMeta.name} ), setCellProps: () => ({ style: { position: "sticky", background: "white", zIndex: 101, left: 350 } }), customBodyRender: (value, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 ? null : tableMeta.rowData[4] === 0 ? null : tableMeta.rowData[4] === 1 ? null : this.state.get_for == 'view' ? : { // updateValue(event.target.value) handleNotes(event.target.value, tableMeta) // console.log(dataTable2) }} /> } />}
) } } }, { name: `${Number(this.props.periode) - 1} Total Actual`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : // tableMeta.rowData[0] === 2 ? // // // // : // tableMeta.rowData[0] === 3 ? //
// { // handleChange(event.target.value, tableMeta) // }} // /> // } // /> //
// : // tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ? //
// // } // /> //
// :
} />
}
) } } }, { name: `Jan ${this.props.periode} Actual`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : // tableMeta.rowData[0] === 2 ? // // // // : // tableMeta.rowData[0] === 3 ? //
// { // handleChange(event.target.value, tableMeta) // }} // /> // } // /> //
// : // tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ? //
// // } // /> //
// :
} />
}
) } } }, { name: `Feb ${this.props.periode} Actual`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : // tableMeta.rowData[0] === 2 ? // // // // : // tableMeta.rowData[0] === 3 ? //
// { // handleChange(event.target.value, tableMeta) // }} // /> // } // /> //
// : // tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ? //
// // } // /> //
// :
} />
}
) } } }, { name: `Mar ${this.props.periode} Actual`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : // tableMeta.rowData[0] === 2 ? // // // // : // tableMeta.rowData[0] === 3 ? //
// { // handleChange(event.target.value, tableMeta) // }} // /> // } // /> //
// : // tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ? //
// // } // /> //
// :
} />
}
) } } }, { name: `Apr ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `May ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Jun ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Jul ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Aug ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Sep ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Oct ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Nov ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Dec ${this.props.periode}`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta) }} /> } />
: tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `${this.props.periode} Total Outlook`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : this.state.get_for == 'view' ? :
} />
}
) } } }, ] const loadingComponent = (
); return (
{this.state.loading && loadingComponent}
Rolling Outlook & Revision CAT
this.closeAlert()}> this.closeAlert()} severity={this.state.tipeAlert}> {this.state.messageAlert}
{this.state.visiblePLRO ?
Rolling Outlook - Profit Loss
{this.props.company.company_name} Period : {this.props.periode} {String(this.props.quarter).toLocaleUpperCase()} (rev.{this.props.revision}) in IDR mn
{!this.state.refresh && ( )}
Last Updated by :
{ this.state.updateBy.length > 0 ? this.state.updateBy.reverse().map((item, index) => { return ( {item.latest_update} ) }) : - }
Notes : {this.state.notesUpdate}
{/* {this.props.isApprover === true || this.state.dataTable.length == 0 ? null : (this.props.lastStatus === 'SUBMIT' || this.props.lastStatus === 'REVISION') && this.props.prevRevision === false && (this.props.status === 'revision' || this.props.status === 'not-yet' || this.props.status === 'draft' || this.props.status === 'submitted') ? */}
{this.props.isApprover === true ?
:
{this.state.get_for == 'view' && this.state.viewOnly && } {this.state.get_for == 'edit' && } {this.state.get_for == 'edit' && } {this.state.get_for == 'edit' && }
}
{/* : null } */}
:
Rolling Outlook - Profit Loss
{this.props.company.company_name} Period : {this.props.periode} {String(this.props.quarter).toLocaleUpperCase()} (rev.{this.props.revision}) in IDR mn
{this.state.dataLoaded && ( )}
}
{this.state.visibleUpload && ( // alert("Coming Soon...")
Upload File
{ this.fileHandler(dt) this.setState({ uploadStatus: 'idle', percentage: '0' }) }} onUpload={() => { String(this.state.judulColumn).includes("TEMPLATE") && String(this.state.judulColumn).includes("UPLOAD") && String(this.state.judul).includes("ROLLING") && String(this.state.judul).includes("OUTLOOK") && String(this.state.judul).includes("PROFIT") && String(this.state.judul).includes("LOSS") ? this.checkUpload() : this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' }) }} />
)}
) } }