import { createMuiTheme, FormControlLabel, Input, MuiThemeProvider, Paper, 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 { fixNumber } from '../../library/Utils'; const LightTooltip = withStyles((theme) => ({ tooltip: { backgroundColor: theme.palette.common.white, color: 'rgba(0, 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 }; export default class CashFlowMR extends Component { constructor(props) { super(props) this.state = { dataTable: [], loading: false, visibleCFMR: true, // valueThreshold: 0, minValue: 0, maxValue: 0, viewOnly: true, defaultCurrencyUpload: this.props.defaultCurrency, visibleAlertSave: false } } 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 } // console.log(this.props.status) // console.log(this.props.lastStatus) // console.log(checkStatus) // console.log(checkLastStatus) // console.log(checkApprover) // console.log(checkPrevRev) this.setState({ viewOnly: !checkApprover && checkLastStatus && checkStatus && checkPrevRev }) // this.setState({viewOnly: true}) } componentDidMount() { // this.getItemHierarki() console.log(this.props.PLBSFAMSubmitted) this.handleViewOnly() this.getSettingControl() } getSettingControl() { let body = { group: 'THRESHOLD_CONTROL', company_id: this.props.company.company_id, type: 'CASH_FLOW' } api.create().getAllSettingByType(body).then(response => { console.log(response) if (response.data) { if (response.data.status === 'success') { this.setState({ minValue: response.data.data[0] ? response.data.data[0].min_value : null, maxValue: response.data.data[0] ? response.data.data[0].max_value : null, }, () => { 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 }) } }) } 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, "currency_id": this.props.defaultCurrency.id, "get_for": "edit" } api.create().getHierarkiMontlyReportCF(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, { value: item.cash_flow.actual, formula: item.cash_flow.actual_formula }, 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, { value: item.cash_flow.actual, formula: item.cash_flow.actual_formula }, item.order, ]) if (item.children !== null) { if (item.children.length > 0) { item.children.map((items, indexs) => { handlePushChild(items) }) } } }) console.log(dataTable) this.setState({ dataTable, loading: false }) } }) } async downloadAllData() { let url = `${process.env.REACT_APP_URL_MAIN_BE}/public/transaction/cash_flow/monthly_report/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/cash_flow/monthly_report/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 Cash Flow.xlsx'; a.click(); } } payloadCF(dataTable2) { let listCF = [] console.log(dataTable2) dataTable2.map((item, index) => { // if (item[6].value == "" || item[6].value == 0 || item[6].value == "0.0") { // item[6].value = this.handleValueFormula(item, index) listCF.push({ "item_report_id": item[1], "actual": item[0] == 1 ? "" : this.props.defaultCurrency.id == 1 ? fixNumber(Number(item[6].value), 1) : Number(item[6].value) }) // } else { // listCF.push({ // "item_report_id": item[1], // "actual": item[0] == 1 ? "" : Number(item[6].value).toFixed(1) // }) // } }) this.createCashFlow(listCF) } createCashFlow(listCF) { let payload = { "monthly_report_id": this.props.monthlyReportId, "company_id": this.props.company.company_id, "periode": this.props.periode, "report_id": 13, "status": "submitted", "months": this.props.month.month_id, "currency_id": this.props.defaultCurrency.id, "cash_flow": listCF } this.props.createCashFlow(payload) } render() { let dataTable2 = this.state.dataTable const handleValueFormula = (tableMeta, colIdx) => { // loading = true // console.log(tableMeta); // "@44[M-1]#BS" let splitFormula = String(tableMeta.rowData[3]).split(/([()@])/) let baru = [] let anjay = [] // console.log(splitFormula); splitFormula.map((item, index) => { let items = String(item).substr(Number(String(item).length) - 1, 1) let subForm = String(item).substr(0, Number(String(item).length) - 1) // console.log(item); // console.log(items); // console.log(subForm); let re = /^[a-zA-Z0-9_]+$/; if (item !== "") { if (items == ']') { baru.push(String(item)) } else if (!re.test(items)) { baru.push(subForm) baru.push(items) } else { baru.push(String(item)) } } }) // console.log(baru); let tambahan = false let opet = "" baru.map((item, index) => { if (item == 'X') { tambahan = true } else if (item == '-' || item == '+' || item == '/' || item == '*' || item == '(' || item == ')') { anjay.push(item) } else { if (String(item).includes('#')) { if (String(item).includes('[M-1]')) { let tst = '@' + String(item).replace('[M-1]', '[M1]') // console.log(dataTable2[tableMeta.rowIndex]); // console.log(tableMeta); // console.log(tst); let indexID = dataTable2[tableMeta.rowIndex][6].formula.findIndex((val) => val.item_formula == tst) // console.log(indexID); if (indexID !== -1) { let valuezz = dataTable2[tableMeta.rowIndex][6].formula[indexID].value anjay.push(valuezz == "" ? 0 : valuezz) // console.log(valuezz); } } else { let data = tableMeta.rowData[6].formula == null ? [] : tableMeta.rowData[6].formula // console.log(data) let indexID = data.findIndex((val) => val.item_formula == String(`@${item}`)) if (indexID !== -1) { let valuezz = data[indexID].value anjay.push(valuezz == "" ? 0 : valuezz) } } } else { if (String(item).includes('[M-1]')) { let tst = String(item).replace('[M-1]', '') let indexID = dataTable2.findIndex((val) => val[7] == tst) if (indexID !== -1) { let valuezz = dataTable2[indexID][8] anjay.push(valuezz == "" ? 0 : valuezz) } } else { let indexID = dataTable2.findIndex((val) => val[7] == item) if (item == 'X-1') { anjay.push(-1) } else if (tambahan) { if (item == '-' || item == '+' || item == '/' || item == '*') { opet = item } else { anjay.push(opet == '' ? Number(item) : Number(String(opet + String(item)))) tambahan = false opet = "" } } else { if (indexID !== -1) { let valuezz = dataTable2[indexID][colIdx].value if (item == dataTable2[tableMeta.rowIndex][7]) { anjay.push(0) } else { anjay.push(valuezz == "" ? 0 : valuezz) } } else { if (item === '(-1)') { anjay.push(-1) } } } } } } }) let anjay2 = [] let kurung = false let item1 = [] anjay.map((item, index) => { if (item == "(") { kurung = true } else if (item == ")") { kurung = false anjay2.push(item1) item1 = [] } else { if (kurung) { item1.push(item) } else { anjay2.push(item) } } }) let total = 0 let opt = "" let totalPrio = 0 let optPrio = "" let prio = false anjay2.map((item, index) => { if (Array.isArray(item)) { prio = true item.map((items, indexs) => { if (items == "+") { optPrio = "tambah" } else if (items == "-") { optPrio = "kurang" } else if (items == "*") { optPrio = "kali" } else if (items == "/") { optPrio = "bagi" } else { if (optPrio == "tambah") { totalPrio = Number(totalPrio) + Number(items) } else if (optPrio == "kurang") { totalPrio = Number(totalPrio) - Number(items) } else if (optPrio == "kali") { totalPrio = Number(totalPrio) * Number(items) } else if (optPrio == "bagi") { totalPrio = Number(totalPrio) / Number(items) == NaN ? 0 : Number(totalPrio) / Number(items) } else { totalPrio += Number(items) } } }) // if (index == anjay2.length - 1) { // if (opt == "tambah") { // total = Number(total) + Number(totalPrio) // } else if (opt == "kurang") { // total = Number(total) - Number(totalPrio) // } else if (opt == "kali") { // total = Number(total) * Number(totalPrio) // } else if (opt == "bagi") { // total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio) // } else { // total += Number(totalPrio) // } // } // if (opt == "") { // total = Number(Number(total) + Number(totalPrio)) // } else { if (opt == "tambah") { total = Number(total) + Number(totalPrio) totalPrio = 0 } else if (opt == "kurang") { total = Number(total) - Number(totalPrio) totalPrio = 0 } else if (opt == "kali") { total = Number(total) * Number(totalPrio) totalPrio = 0 } else if (opt == "bagi") { total = Number(total) / Number(totalPrio) == NaN ? 0 : Number(total) / Number(totalPrio) totalPrio = 0 } // } // if (tableMeta.rowData[5] == '3.2 Movement of SHL and intercompany loan (nett)') { // console.log(totalPrio) // console.log(opt) // console.log(total) // } } else { // const handleReturn = (x,y) => { // return Number(totalXYZ) // } if (item == "+") { opt = "tambah" if (prio) { total = Number(Number(totalPrio) + Number(total)) // total = handleReturn() prio = false totalPrio = 0 optPrio = "" } } else if (item == "-") { opt = "kurang" if (prio) { total = Number(Number(totalPrio) + Number(total)) // total = handleReturn() prio = false totalPrio = 0 optPrio = "" } } else if (item == "*") { opt = "kali" if (prio) { total = Number(Number(totalPrio) + Number(total)) // total = handleReturn() prio = false totalPrio = 0 optPrio = "" } } else if (item == "/") { opt = "bagi" if (prio) { total = Number(Number(totalPrio) + Number(total)) // total = handleReturn() prio = false totalPrio = 0 optPrio = "" } } 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 = Number(total) / Number(item) == NaN ? 0 : Number(total) / Number(item) } else { total += Number(item) } } } }) // if (tableMeta.rowData[5] == '3.2 Movement of SHL and intercompany loan (nett)' || tableMeta.rowData[5] == '3.6 Other') { // console.log(tableMeta.rowData[5]) // console.log(splitFormula) // console.log(baru) // console.log(anjay) // console.log(anjay2) // console.log(total) // } dataTable2[tableMeta.rowIndex][6].value = 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: "Actual", options: { customHeadRender: (columnMeta) => ( // dataTable2.length > 0 ? // // {columnMeta.name} // : {columnMeta.name} ), setCellProps: () => ({ style: { position: "sticky", background: "white", zIndex: 101, left: 350 } }), customBodyRender: (value, tableMeta, updateValue) => { // console.log(tableMeta); return (
{tableMeta.rowData[0] === 5 || tableMeta.rowData[0] === 6 ? : tableMeta.rowData[0] === 7 ? // // Number(this.state.minValue) || Number(handleValueFormula(tableMeta, 6)).toFixed(1) < Number(this.state.maxValue) ? 'red' : 'black' , fontSize: 12, textAlign: 'right', borderColor: 'transparent', margin: 0, width: 96, backgroundColor: 'transparent' }} // type="text" // placeholder="" // disabled={true} // value={Number(handleValueFormula(tableMeta, 6)).toFixed(1)} // /> // this.props.defaultCurrency.id == 1 ? (fixNumber(Number(handleValueFormula(tableMeta, 6)), 1) > Number(this.state.minValue) && fixNumber(Number(handleValueFormula(tableMeta, 6)), 1) < Number(this.state.maxValue)) ? : : (Number(handleValueFormula(tableMeta, 6)) > Number(this.state.minValue) && Number(handleValueFormula(tableMeta, 6)) < Number(this.state.maxValue)) ? : : null}
) } } }, { name: "", options: { display: false } }, ] const loadingComponent = (
); return (
{this.state.loading && loadingComponent}
Monthly Report
Monthly Report - Cash Flow
{this.props.company.company_name} Period : {String(this.props.month.month_value).toLocaleUpperCase()} {this.props.periode} (rev.{this.props.revision}) {this.props.defaultCurrency.id === 1 ? in IDR mn : in USD thousand }
{/* */}
{!this.state.loading && ( )}
{/* {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.state.viewOnly && }
); } }