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 ProfitLossMR extends Component { constructor(props) { super(props) this.state = { dataTable: [], loading: true, visiblePLMR: true, minValue: 0, maxValue: 0, updateBy: '-', notesUpdate: '-', bebas: false, judulColumn: null } this.fileHandler = this.fileHandler.bind(this); } componentDidMount() { // this.getItemHierarki() this.getLatestUpdate() this.getSettingControl() } 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")) { 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, "monthly_report_id": this.props.monthlyReportId, "months": this.props.month.month_id } api.create().getLastestUpdateMR(payload).then(response => { console.log(response) if (response.data) { if (response.data.status === "success") { this.setState({ updateBy: response.data.data.latest_update === null ? '-' : response.data.data.latest_update, notesUpdate: 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")) { setTimeout(() => { localStorage.removeItem(Constant.TOKEN) window.location.reload(); }, 1000); } }) } } else { this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false }) } }) } getItemHierarki() { let payload = { "report_id": this.props.report_id, "revision": Number(this.props.revision), "periode": this.props.periode, "company_id": this.props.company.company_id, "monthly_report_id": this.props.monthlyReportId, "months": this.props.month.month_id } console.log(payload); api.create().getHierarkiMontlyReportPL(payload).then(response => { console.log(response); let dataTable = [] if (response.data) { 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 === "" ? null : item.profit_loss.notes, item.profit_loss.rolling_outlook === null ? "0.0" : item.profit_loss.rolling_outlook === "" ? "0.0" : item.profit_loss.rolling_outlook === "0" ? "0.0" : item.profit_loss.rolling_outlook, item.profit_loss.master_budget === null ? "0.0" : item.profit_loss.master_budget === "" ? "0.0" : item.profit_loss.master_budget, item.profit_loss.rolling_budget === null ? "0.0" : item.profit_loss.rolling_budget === "" ? "0.0" : item.profit_loss.rolling_budget, item.profit_loss.actual === null ? "0.0" : item.profit_loss.actual === "" ? "0.0" : item.profit_loss.actual, 0, item.profit_loss.actual_previous_month === null ? "0.0" : item.profit_loss.actual_previous_month === "" ? "0.0" : item.profit_loss.actual_previous_month, item.profit_loss.amount_act_vs_previous_month === null ? "0.0" : item.profit_loss.amount_act_vs_previous_month === "" ? "0.0" : item.profit_loss.amount_act_vs_previous_month, item.profit_loss.percent_act_vs_previous_month === null ? "0.0" : item.profit_loss.percent_act_vs_previous_month === "" ? "0.0" : item.profit_loss.percent_act_vs_previous_month, item.profit_loss.amount_act_vs_mb === null ? "0.0" : item.profit_loss.amount_act_vs_mb === "" ? "0.0" : item.profit_loss.amount_act_vs_mb, item.profit_loss.percent_act_vs_mb === null ? "0.0" : item.profit_loss.percent_act_vs_mb === "" ? "0.0" : item.profit_loss.percent_act_vs_mb, item.profit_loss.amount_act_vs_rb === null ? "0.0" : item.profit_loss.amount_act_vs_rb === "" ? "0.0" : item.profit_loss.amount_act_vs_rb, item.profit_loss.percent_act_vs_rb === null ? "0.0" : item.profit_loss.percent_act_vs_rb === "" ? "0.0" : item.profit_loss.percent_act_vs_rb, item.profit_loss.mtd_vs_previous_month === null ? "" : item.profit_loss.mtd_vs_previous_month, item.profit_loss.mtd_vs_mb === null ? "" : item.profit_loss.mtd_vs_mb, item.profit_loss.mtd_vs_rb === null ? "" : item.profit_loss.mtd_vs_rb, item.order, item.profit_loss.ytd_actual === null ? "0.0" : item.profit_loss.ytd_actual === "" ? "0.0" : item.profit_loss.ytd_actual, ]) } 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 === "" ? null : item.profit_loss.notes, item.profit_loss.rolling_outlook === null ? "0.0" : item.profit_loss.rolling_outlook === "" ? "0.0" : item.profit_loss.rolling_outlook, item.profit_loss.master_budget === null ? "0.0" : item.profit_loss.master_budget === "" ? "0.0" : item.profit_loss.master_budget, item.profit_loss.rolling_budget === null ? "0.0" : item.profit_loss.rolling_budget === "" ? "0.0" : item.profit_loss.rolling_budget, item.profit_loss.actual === null ? "0.0" : item.profit_loss.actual === "" ? "0.0" : item.profit_loss.actual, 0, item.profit_loss.actual_previous_month === null ? "0.0" : item.profit_loss.actual_previous_month === "" ? "0.0" : item.profit_loss.actual_previous_month, item.profit_loss.amount_act_vs_previous_month === null ? "0.0" : item.profit_loss.amount_act_vs_previous_month === "" ? "0.0" : item.profit_loss.amount_act_vs_previous_month, item.profit_loss.percent_act_vs_previous_month === null ? "0.0" : item.profit_loss.percent_act_vs_previous_month === "" ? "0.0" : item.profit_loss.percent_act_vs_previous_month, item.profit_loss.amount_act_vs_mb === null ? "0.0" : item.profit_loss.amount_act_vs_mb === "" ? "0.0" : item.profit_loss.amount_act_vs_mb, item.profit_loss.percent_act_vs_mb === null ? "0.0" : item.profit_loss.percent_act_vs_mb === "" ? "0.0" : item.profit_loss.percent_act_vs_mb, item.profit_loss.amount_act_vs_rb === null ? "0.0" : item.profit_loss.amount_act_vs_rb === "" ? "0.0" : item.profit_loss.amount_act_vs_rb, item.profit_loss.percent_act_vs_rb === null ? "0.0" : item.profit_loss.percent_act_vs_rb === "" ? "0.0" : item.profit_loss.percent_act_vs_rb, item.profit_loss.mtd_vs_previous_month === null ? "" : item.profit_loss.mtd_vs_previous_month, item.profit_loss.mtd_vs_mb === null ? "" : item.profit_loss.mtd_vs_mb, item.profit_loss.mtd_vs_rb === null ? "" : item.profit_loss.mtd_vs_rb, item.order, item.profit_loss.ytd_actual === null ? "0.0" : item.profit_loss.ytd_actual === "" ? "0.0" : item.profit_loss.ytd_actual, ]) if (item.children !== null) { if (item.children.length > 0) { item.children.map((items, indexs) => { handlePushChild(items) }) } } }) this.setState({ dataTable, loading: false, buttonError: true, saveDraft: true }) } console.log(dataTable); }) } downloadTemplate = async () => { let res = await fetch( `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/monthly_report_pl/download_template?report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}` ) 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 Monthly Report Profit Loss.xlsx'; a.click(); } } async downloadAllData() { let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/monthly_report_pl/export_monthly_report?monthly_report_id=${this.props.monthlyReportId}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&months=${this.props.month.month_id}` console.log(url); let res = await fetch( `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/monthly_report_pl/export_monthly_report?monthly_report_id=${this.props.monthlyReportId === null ? "" : this.props.monthlyReportId}&&report_id=${this.props.report_id}&&company_id=${this.props.company.company_id}&&year=${this.props.periode}&&revision=${this.props.revision}&&months=${this.props.month.month_id}` ) 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 = 'Monthly Report Profit Loss.xlsx'; a.click(); } } backToMonthlyReport(type) { // this.setState({ loading: true }) let data = [] this.state.dataTable.map(i => { 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_previous_month": i[19], "mtd_vs_mb": i[20], "mtd_vs_rb": i[21] }) }) 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": type, "months": this.props.month.month_id, "profit_loss": data } // console.log(JSON.stringify(payload)); api.create('UPLOAD').createMonthlyReportPL(payload).then(response => { console.log(response); if (response.data) { if (response.data.status === "success") { this.props.saveToMonthlyReport() } else { this.setState({ loading: false }, () => { this.props.saveToMonthlyReport() }) } } else { this.setState({ loading: false }) } }) } 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 ? "" : String(i[1]).trim(), item_report: i[2] === undefined ? "" : String(i[2]).trim(), notes: i[3] === undefined ? "" : String(i[3]).trim(), actual: i[4] === undefined ? "0" : reg.test(String(i[4])) === false ? "0" : String(i[4]).trim(), mtd_vs_previous_month: i[5] === undefined ? "" : String(i[5]).trim(), mtd_vs_mb: i[6] === undefined ? "" : String(i[6]).trim(), mtd_vs_rb: i[7] === undefined ? "" : String(i[7]).trim(), }) } }) let body = { company_id: this.props.company.company_id, periode: this.props.periode, report_id: this.props.report_id, months: this.props.month.month_id, profit_loss: payload } console.log(body) this.setState({ payload: body, judul: resp.rows[1][0], judulColumn: resp.rows[0][0] }) } }); } checkUpload() { api.create().checkUploadMonthlyReportPL(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, visiblePLMR: 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.rolling_outlook === null ? "" : item.rolling_outlook === "" ? "" : item.rolling_outlook, item.master_budget === "" ? "" : item.master_budget, item.rolling_budget === "" ? "" : item.rolling_budget, item.actual === "" ? "" : item.actual, 0, item.actual_previous_month === null ? "" : item.actual_previous_month === "" ? "" : item.actual_previous_month, 0, 0, 0, 0, 0, 0, // item.amount_act_vs_previous_month, // item.percent_act_vs_previous_month, // item.amount_act_vs_mb, // item.percent_act_vs_mb, // item.amount_act_vs_rb, // item.percent_act_vs_rb, item.mtd_vs_previous_month , item.mtd_vs_mb , item.mtd_vs_rb , item.orders, item.ytd_actual === null ? "" : item.ytd_actual === "" ? "" : item.ytd_actual, item.error ] }) 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); } } }) } uploadProfitLossMR(type) { let data = [] this.state.dataTable.map(i => { data.push({ item_report_id: i[1], notes: String(i[6]), rolling_outlook: String(Number(i[7]).toFixed(1)), master_budget: String(Number(i[8]).toFixed(1)), rolling_budget: String(Number(i[9]).toFixed(1)), actual: String(Number(i[10]).toFixed(1)), ytd_actual: String(Number(i[11]).toFixed(1)), actual_previous_month: String(Number(i[12]).toFixed(1)), amount_act_vs_previous_month: String(Number(i[13]).toFixed(1)), percent_act_vs_previous_month: String(Number(i[14]).toFixed(1)), amount_act_vs_mb: String(Number(i[15]).toFixed(1)), percent_act_vs_mb: String(Number(i[16]).toFixed(1)), amount_act_vs_rb: String(Number(i[17]).toFixed(1)), percent_act_vs_rb: String(Number(i[18]).toFixed(1)), mtd_vs_previous_month: String(i[19]), mtd_vs_mb: String(i[20]), mtd_vs_rb: String(i[21]), }) }) 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, "months": this.props.month.month_id, "status": type, "profit_loss": data } console.log(data); api.create('UPLOAD').uploadMonthlyReportPL(body).then(response => { console.log(response); if (response.data) { if (response.ok) { if (response.data.status === "success") { this.props.saveToMonthlyReport() // this.props.onClickClose() // this.props.getReport() } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => { if (response.data.message.includes("Someone Logged In")) { setTimeout(() => { localStorage.removeItem(Constant.TOKEN) window.location.reload(); }, 1000); } }) // alert(response.data.status) } } else { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false }) } } else { this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false }) } }) } 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_previous_month": i[19], "mtd_vs_mb": i[20], "mtd_vs_rb": i[21] }) }) // console.log(JSON.stringify(data)); data.map(i => { if (i.mtd_vs_previous_month === "" && (Number(i.percent_act_vs_previous_month) < this.state.minValue || Number(i.percent_act_vs_previous_month) > this.state.maxValue)) { console.log('msk 1'); console.log(i); err = true } else if (i.mtd_vs_mb === "" && (Number(i.percent_act_vs_mb) < this.state.minValue || Number(i.percent_act_vs_mb) > this.state.maxValue)) { console.log('msk 2'); err = true } else if (i.mtd_vs_rb === "" && (Number(i.percent_act_vs_rb) < this.state.minValue || Number(i.percent_act_vs_rb) > this.state.maxValue)) { console.log('msk 3'); err = true } }) // 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) 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")) { 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 handleCalculate = () => { // let error = false // let messageError = "" // dataTable2.map((item, index) => { // if (item[19] == "" && Number(item[14]) <= this.state.minValue || Number(item[14]) >= this.state.maxValue) { // error = true // messageError = "MTD Explanation vs Prev. Month is Reqiured" // } // if (item[20] == "" && Number(item[16]) <= this.state.minValue || Number(item[16]) >= this.state.maxValue) { // error = true // messageError = "MTD Explanation vs MB is Reqiured" // } // if (item[21] == "" && Number(item[18]) <= this.state.minValue || Number(item[18]) >= this.state.maxValue) { // error = true // messageError = "MTD Explanation vs RB is Reqiured" // } // }) // if (error === true) { // this.setState({ alert: true, messageAlert: messageError, tipeAlert: 'error', loading: false, bebas: true }) // } // } const handleText = (value, tableMeta, type) => { // dataTable2[tableMeta.rowIndex][type] = value let a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = value console.log(dataTable2); // console.log(dataTable2[tableMeta.rowIndex]); } const handleChange = (value, tableMeta, type) => { let val = String(value).split(",").join("") if (type === "actual") { // console.log(val); dataTable2[tableMeta.rowIndex][10] = Number(val).toFixed(1) } else { let indexParent = dataTable2.findIndex((val) => val[1] === dataTable2[tableMeta.rowIndex][2]) if (indexParent > 0) { dataTable2[tableMeta.rowIndex][10] = Number(val).toFixed(1) let jagain = Number(dataTable2[indexParent][10]).toFixed(1) dataTable2[indexParent][10] = jagain === undefined ? (0 + Number(val)).toFixed(1) : Number(Number(jagain) + Number(val)).toFixed(1) } else { dataTable2[tableMeta.rowIndex][10] = Number(val).toFixed(1) } } } const handleValue = (data, type) => { let total = 0 dataTable2.map((item, index) => { if (data.rowData[1] == item[2]) { total = item[data.columnIndex + type] == undefined ? (Number(total) + 0) : (Number(total) + Number(String(item[data.columnIndex + type]).includes('-')? Number(String(item[data.columnIndex + type]).substr(1, String(item[data.columnIndex + type]).length)) * -1 : Number(item[data.columnIndex + type]))) } }) let indexParent = dataTable2.findIndex((val) => val[1] == dataTable2[data.rowIndex][2]) let a = dataTable2[data.rowIndex][data.columnIndex + type] = Number(total) // console.log(indexParent); return a } const handleFormula = (data, tableMeta, type) => { 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) { arrayJumlah.push(dataTable2[index][tableMeta.columnIndex + type]) } } } }) 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) // if (tableMeta.rowData[22] === 3) { // console.log(dataTable2[tableMeta.rowIndex]); // console.log(total); // console.log(item); // console.log(arrayJumlah); // } } 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' : Number(total) / Number(item)) } else { total += Number(item) } } }) let a = dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total) return a } const handleVariance = (tableMeta, dex, type) => { let total = 0 if (dex === 1) { total = Number(tableMeta.rowData[10]) - Number(tableMeta.rowData[12]) dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1) } else if (dex === 2) { total = Number(tableMeta.rowData[10]) - Number(tableMeta.rowData[8]) dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1) } else if (dex === 3) { total = Number(tableMeta.rowData[10]) - Number(tableMeta.rowData[9]) dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1) } return total } const handleVariancePercent = (tableMeta, dex, type) => { let total = 0 if (dex === 1) { // total = Number(dataTable2[tableMeta.rowIndex][13]) / Number(dataTable2[tableMeta.rowIndex][12]) total = R.equals((Number(dataTable2[tableMeta.rowIndex][13]) / Number(dataTable2[tableMeta.rowIndex][12])), NaN) ? '0' : R.equals((Number(dataTable2[tableMeta.rowIndex][13]) / Number(dataTable2[tableMeta.rowIndex][12])), Infinity) ? '0' : (Number(dataTable2[tableMeta.rowIndex][13]) / Number(dataTable2[tableMeta.rowIndex][12]) == "-Infinity" ? '0' : Number(dataTable2[tableMeta.rowIndex][13]) / Number(dataTable2[tableMeta.rowIndex][12])) dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1) } else if (dex === 2) { // total = Number(dataTable2[tableMeta.rowIndex][15]) / Number(dataTable2[tableMeta.rowIndex][8]) total = R.equals((Number(dataTable2[tableMeta.rowIndex][15]) / Number(dataTable2[tableMeta.rowIndex][8])), NaN) ? '0' : R.equals((Number(dataTable2[tableMeta.rowIndex][15]) / Number(dataTable2[tableMeta.rowIndex][8])), Infinity) ? '0' : (Number(dataTable2[tableMeta.rowIndex][15]) / Number(dataTable2[tableMeta.rowIndex][8]) == "-Infinity" ? '0' : Number(dataTable2[tableMeta.rowIndex][15]) / Number(dataTable2[tableMeta.rowIndex][8])) dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1) } else if (dex === 3) { // total = Number(dataTable2[tableMeta.rowIndex][17]) / Number(dataTable2[tableMeta.rowIndex][9]) total = R.equals((Number(dataTable2[tableMeta.rowIndex][17]) / Number(dataTable2[tableMeta.rowIndex][9])), NaN) ? '0' : R.equals((Number(dataTable2[tableMeta.rowIndex][17]) / Number(dataTable2[tableMeta.rowIndex][9])), Infinity) ? '0' : (Number(dataTable2[tableMeta.rowIndex][17]) / Number(dataTable2[tableMeta.rowIndex][9]) == "-Infinity" ? '0' : Number(dataTable2[tableMeta.rowIndex][17]) / Number(dataTable2[tableMeta.rowIndex][9])) dataTable2[tableMeta.rowIndex][tableMeta.columnIndex + type] = Number(total).toFixed(1) } return total } const handleTotal = (value, tableMeta) => { // console.log(tableMeta) let total = 0 dataTable2[tableMeta.rowIndex].map((item, index) => { if (index == 10) { let itemActual = item == undefined || item == "" || item == "undefined" ? 0.0 : item total = Number(tableMeta.rowData[23]) + Number(itemActual) } }) dataTable2[tableMeta.rowIndex][11] = Number(total).toFixed(1) 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 : { // updateValue(event.target.value) handleText(event.target.value, tableMeta, 0) // console.log(dataTable2) }} /> } />}
) } } }, { name: `Rolling Outlook (FY ${this.props.periode})`, options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1? null : tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Month To Date (MTD)`, options: { customHeadRender: (columnMeta) => ( {/* {columnMeta.name} */}
{columnMeta.name}
{"Master Budget (MB)"}
{"Rolling Budget (RB)"}
{"Actual"}
), setCellProps: () => ({ style: { paddingLeft: 0, paddingRight: 0 } }), customBodyRender: (value, tableMeta, updateValue) => { // console.log(tableMeta); return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 6 ?
} />
:
} />
}
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 6 ?
} />
:
} />
}
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[0] === 3 ?
{ handleChange(event.target.value, tableMeta, "actual") }} /> } />
: tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 6 || tableMeta.rowData[0] === 5 ?
} />
:
} />
}
) } } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "YTD Actual", options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: "Actual Previous Month", options: { customHeadRender: (columnMeta) => ( {columnMeta.name} ), setCellProps: () => ({ style2 }), customBodyRender: (val, tableMeta, updateValuvale) => { return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[0] === 2 ? : tableMeta.rowData[0] === 6 ?
} />
:
} />
}
) } } }, { name: `Variance`, options: { customHeadRender: (columnMeta) => (
{columnMeta.name}
{"Act vs Previous Month"}
{"Amount"}
{"%"}
{"Act vs MB"}
{"Amount"}
{"%"}
{"Act vs RB"}
{"Amount"}
{"%"}
), setCellProps: () => ({ style: { paddingLeft: 0, paddingRight: 10 } }), customBodyRender: (val, tableMeta, updateValue) => { // console.log(tableMeta); return (
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null :
} />
}
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null :
this.state.maxValue ? 'red' : '#000000b0', fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }} type="text" placeholder="" suffix={'%'} disabled={true} value={Number(handleVariancePercent(tableMeta, 1, 1)).toFixed(1)} // value={11} /> } />
}
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null :
} />
}
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null :
this.state.maxValue ? 'red' : '#000000b0', fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }} suffix={'%'} type="text" placeholder="" disabled={true} value={Number(handleVariancePercent(tableMeta, 2, 3)).toFixed(1)} /> } />
}
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null :
} />
}
{tableMeta.rowData[0] === 4 || tableMeta.rowData[0] === 1 ? null :
this.state.maxValue ? 'red' : '#000000b0', fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }} suffix={'%'} disabled={true} value={Number(handleVariancePercent(tableMeta, 3, 5)).toFixed(1)} /> } />
}
) } } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: `MTD Explanation`, options: { customHeadRender: (columnMeta) => ( {/* {columnMeta.name} */}
{columnMeta.name}
{"vs Prev Month"}
{"vs MB"}
{"vs RB"}
), setCellProps: () => ({ style: { paddingLeft: 0, paddingRight: 0 } }), customBodyRender: (val, tableMeta, updateValue) => { return (
{tableMeta.rowData[0] === 4 ? null : tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[4] === 0 ? null : tableMeta.rowData[4] === 1 ? null : this.state.maxValue) ? { handleText(event.target.value, tableMeta, 0) }} /> : this.state.maxValue ? false : true} // value={tableMeta.rowData[19]} defaultValue={tableMeta.rowData[19]} inputProps={{ style: { color: Number(tableMeta.rowData[14]) < this.state.minValue || Number(tableMeta.rowData[14]) > this.state.maxValue ? "#5198ea" : '#5198ea', textAlign: 'right' } }} onBlur={(event) => { handleText(event.target.value, tableMeta, 0) }} /> } /> }
{tableMeta.rowData[0] === 4 ? null : tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[4] === 0 ? null : tableMeta.rowData[4] === 1 ? null : this.state.maxValue) ? { handleText(event.target.value, tableMeta, 1) }} /> : this.state.maxValue ? false : true} // value={tableMeta.rowData[20]} defaultValue={tableMeta.rowData[20]} inputProps={{ style: { color: Number(tableMeta.rowData[14]) < this.state.minValue || Number(tableMeta.rowData[14]) > this.state.maxValue ? "#5198ea" : '#5198ea', textAlign: 'right' } }} onBlur={(event) => { handleText(event.target.value, tableMeta, 1) }} /> } />}
{tableMeta.rowData[0] === 4 ? null : tableMeta.rowData[0] === 1 ? null : tableMeta.rowData[4] === 0 ? null : tableMeta.rowData[4] === 1 ? null : this.state.maxValue) ? { handleText(event.target.value, tableMeta, 2) }} /> : this.state.maxValue ? false : true} // value={tableMeta.rowData[21]} defaultValue={tableMeta.rowData[21]} inputProps={{ style: { color: Number(tableMeta.rowData[16]) < this.state.minValue || Number(tableMeta.rowData[16]) > this.state.maxValue ? "#5198ea" : '#5198ea', textAlign: 'right' } }} onBlur={(event) => { handleText(event.target.value, tableMeta, 2) }} /> } />}
) } } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }, { name: "", options: { display: false } } ] const loadingComponent = (
); return (
{this.state.loading && loadingComponent}
Monthly Report Submission
this.closeAlert()}> this.closeAlert()} severity={this.state.tipeAlert}> {this.state.messageAlert}
{this.state.visiblePLMR ?
Monthly Report - Profit Loss
{this.props.company.company_name} Period : {this.props.periode} (rev.{this.props.revision}) in IDR mn
{/* {!this.state.loading && ( */} {/* )} */}
Last Updated by : {this.state.updateBy} 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 ?
:
}
{/* : null } */}
:
Monthly Report - Profit Loss
{this.props.company.company_name} Period : {this.props.periode} (rev.{this.props.revision}) in IDR mn
{this.state.dataLoaded && ( )}
}
{this.state.visibleUpload && (
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("MONTHLY") && String(this.state.judul).includes("REPORT") && String(this.state.judul).includes("PROFIT") && String(this.state.judul).includes("LOSS") ? this.checkUpload() : this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' }) }} />
)}
) } }