import React, { Component } from "react";
import { createMuiTheme, FormControlLabel, Input, MuiThemeProvider, Snackbar, TableCell, Typography, withStyles } from "@material-ui/core";
import MUIDataTable from "mui-datatables";
import api from '../../api';
import Constant from '../../library/Constant';
import { PropagateLoader } from "react-spinners";
import Images from "../../assets/Images";
import MuiAlert from '@material-ui/lab/Alert';
const Alert = withStyles({
})((props) => );
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
};
export default class TableProgressReport extends Component {
constructor(props) {
super(props)
this.state = {
visiblePopup: false,
idCompany: null,
companyName: "",
month: "",
alert: false,
tipeAlert: '',
messageAlert: '',
}
}
handleShowPopup(id, data) {
console.log(this.props);
let item = this.props
let bulan = item.month == 1 ? "Jan" : item.month == 2 ? "Feb" : item.month == 3 ? "Mar" : item.month == 4 ? "Apr" : item.month == 5 ? "May" : item.month == 6 ? "Jun" : item.month == 7 ? "Jul" : item.month == 8 ? "Aug" : item.month == 9 ? "Sep" : item.month == 10 ? "Oct" : item.month == 11 ? "Nov" : item.month == 12 ? "Dec" : null
this.setState({ visiblePopup: true, idCompany: id, companyName: data[0], month: bulan })
}
handleSendEmail() {
this.setState({ loading: true, visiblePopup: false, })
let data = this.props
let q1 = data.reportType === 2 && data.quarter === "Q1"
let q2 = data.reportType === 2 && data.quarter === "Q2"
let q3 = data.reportType === 2 && data.quarter === "Q3"
let payload = {
"company_id": this.state.idCompany,
"setting_type_name": data.reportType === 0 ? "master_budget" : data.reportType === 1 ? "monthly_report" : q1 ? "outlook_q1" : q2 ? "outlook_q2" : q3 ? "outlook_q3" : data.reportType === 3 ? "outlook_pa" : null,
"year": data.year,
"month": data.reportType === 1 ? data.month : null
}
let payloadGetData = {
"year": data.year,
"month": data.month,
"quarter": data.quarter === "Q1" ? "q1" : data.quarter === "Q2" ? "q2" : data.quarter === "Q3" ? "q3" : null
}
api.create().sendEmail(payload).then(response => {
console.log(response);
if (response.data) {
if (response.ok) {
this.setState({ loading: false })
if (response.data.status == 'success') {
if (data.reportType === 0) {
this.props.getMonitoringMB(payloadGetData)
} else if (data.reportType === 1) {
this.props.getMonitoringMR(payloadGetData)
} else if (data.reportType === 2) {
this.props.getMonitoringRO(payloadGetData)
} else if (data.reportType === 3) {
this.props.getMonitoringOLPA(payloadGetData)
}
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', loading: false })
// this.setState({ visiblePopup: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success' }, () => {
// setTimeout(() => {
// if (data.reportType === 0 ) {
// this.props.getMonitoringMB(payloadGetData)
// } else if (data.reportType === 1 ) {
// this.props.getMonitoringMR(payloadGetData)
// } else if (data.reportType === 2 ) {
// this.props.getMonitoringRO(payloadGetData)
// } else if (data.reportType === 3 ) {
// this.props.getMonitoringOLPA(payloadGetData)
// }
// this.setState({ loading: false })
// }, 1000)
// })
// this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
} else {
this.setState({ alert: true, messageAlert: response.problem, 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 })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
}
})
}
closeAlert() {
this.setState({ alert: false })
}
render() {
let dataTable2 = this.props.dataTable;
// console.log(dataTable2);
const handleValue = (tableMeta, itemName) => {
let value = tableMeta.rowData[1].filter((val) => val.report_name == itemName)
// console.log(itemName)
// console.log(tableMeta.rowData)
// console.log(value)
return value[0].status_report == null || value[0].status_report == '' ? 'N/A' : value[0].status_report
}
const columnMB = [
{
name: "Company",
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
),
setCellProps: () => ({ style }),
customBodyRender: (val, tableMeta) => {
return (
{val}
)
}
}
},
{
name: `INPUT MASTER BUDGET`,
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
{"Profit Loss"}
{"Tax Planning"}
{"Balance Sheet"}
{"Fixed Assets Movement"}
{"Cash Flow"}
{"CAT"}
{"Submission Status"}
{"Operating Indicator"}
{"Automatic Reminder"}
{"Manual Reminder"}
{"Last Manual Reminder"}
),
setCellProps: () => ({ style2 }),
customBodyRender: (value, tableMeta, updateValue) => {
return (
{handleValue(tableMeta, 'Profit Loss')}
{handleValue(tableMeta, 'Tax Planning')}
{handleValue(tableMeta, 'Balance Sheet')}
{handleValue(tableMeta, 'Fixed Assets Movement')}
{handleValue(tableMeta, 'Cash Flow')}
{handleValue(tableMeta, 'CAT')}
{handleValue(tableMeta, 'Submission Status')}
{handleValue(tableMeta, 'Operating Indicator')}
{tableMeta.rowData[5] === "OPEN" ?
this.handleShowPopup(tableMeta.rowData[7], tableMeta.rowData)}
>
{tableMeta.rowData[3] === null || tableMeta.rowData[3] === 0 ? "Send Email" : "Sent"}
:
"-"
}
)
},
},
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
}
];
const columnMR = [
{
name: "Company",
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
),
setCellProps: () => ({ style }),
customBodyRender: (val, tableMeta) => {
return (
{val}
)
}
}
},
{
name: `INPUT MONTHLY REPORT`,
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
{"Profit Loss"}
{"Tax Planning"}
{"Balance Sheet"}
{"Fixed Assets Movement"}
{"LOCF"}
{"Cash Flow"}
{"CAT"}
{"Monthly Status"}
{"Operating Indicator"}
{"Automatic Reminder"}
{"Manual Reminder"}
{"Last Manual Reminder"}
),
setCellProps: () => ({ style2 }),
customBodyRender: (value, tableMeta, updateValue) => {
return (
{handleValue(tableMeta, 'Profit Loss')}
{handleValue(tableMeta, 'Profit Loss')}
{handleValue(tableMeta, 'Balance Sheet')}
{handleValue(tableMeta, 'Fixed Assets Movement')}
{handleValue(tableMeta, 'List of Credit Facilities')}
{handleValue(tableMeta, 'Cash Flow')}
{handleValue(tableMeta, 'CAT')}
{handleValue(tableMeta, 'Monthly Status')}
{handleValue(tableMeta, 'Operating Indicator')}
{tableMeta.rowData[5] === "OPEN" ?
this.handleShowPopup(tableMeta.rowData[7], tableMeta.rowData)}
>
{tableMeta.rowData[3] === null || tableMeta.rowData[3] === 0 ? "Send Email" : "Sent"}
:
"-"
}
)
},
},
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
}
];
const columnRO = [
{
name: "Company",
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
),
setCellProps: () => ({ style }),
customBodyRender: (val, tableMeta) => {
return (
{val}
)
}
},
},
{
name: `INPUT ROLLING OUTLOOK`,
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
{"Profit Loss"}
{"Tax Planning"}
{"Balance Sheet"}
{"Cash Flow"}
{"CAT"}
{"Rolling Status"}
{"Operating Indicator"}
{"Automatic Reminder"}
{"Manual Reminder"}
{"Last Manual Reminder"}
),
setCellProps: () => ({ style2 }),
customBodyRender: (value, tableMeta, updateValue) => {
return (
{handleValue(tableMeta, 'Profit Loss')}
{handleValue(tableMeta, 'Profit Loss')}
{handleValue(tableMeta, 'Balance Sheet')}
{handleValue(tableMeta, 'Cash Flow')}
{handleValue(tableMeta, 'CAT')}
{handleValue(tableMeta, 'Rolling Status')}
{handleValue(tableMeta, 'Operating Indicator')}
{tableMeta.rowData[5] === "OPEN" ?
this.handleShowPopup(tableMeta.rowData[7], tableMeta.rowData)}
>
{tableMeta.rowData[3] === null || tableMeta.rowData[3] === 0 ? "Send Email" : "Sent"}
:
"-"
}
)
},
},
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
}
];
const columnOLPA = [
{
name: "Company",
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
),
setCellProps: () => ({ style }),
customBodyRender: (val, tableMeta) => {
return (
{val}
)
}
},
},
{
name: `INPUT OUTLOOK PA`,
options: {
customHeadRender: (columnMeta) => (
{columnMeta.name}
{"Profit Loss"}
{"Tax Planning"}
{"Balance Sheet"}
{"Cash Flow"}
{"CAT"}
{"OLPA Status"}
{/*
{"Operating Indicator"}
*/}
{"Automatic Reminder"}
{"Manual Reminder"}
{"Last Manual Reminder"}
),
setCellProps: () => ({ style2 }),
customBodyRender: (value, tableMeta, updateValue) => {
return (
{handleValue(tableMeta, 'Profit Loss')}
{handleValue(tableMeta, 'Tax Planning')}
{handleValue(tableMeta, 'Balance Sheet')}
{handleValue(tableMeta, 'Cash Flow')}
{handleValue(tableMeta, 'CAT')}
{handleValue(tableMeta, 'OLPA Status')}
{/*
{handleValue(tableMeta, 'Operating Indicator')}
*/}
{tableMeta.rowData[5] === "OPEN" ?
this.handleShowPopup(tableMeta.rowData[7], tableMeta.rowData)}
>
{tableMeta.rowData[3] === null || tableMeta.rowData[3] === 0 ? "Send Email" : "Sent"}
:
"-"
}
)
},
},
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
},
{
name: "",
options: {
display: false
}
}
];
const loadingComponent = (
);
return (
this.closeAlert()}>
this.closeAlert()} severity={this.state.tipeAlert}>
{this.state.messageAlert}
{this.state.loading && loadingComponent}
{this.state.visiblePopup && (
{this.props.reportType === 1 ?
Apakah anda yakin ingin mengirimkan email Reminder Submission {this.props.typeReport} {this.state.month} {this.props.year} ke perusahaan {this.state.companyName} ?
:
this.props.reportType === 2 ?
Apakah anda yakin ingin mengirimkan email Reminder Submission {this.props.typeReport} {this.props.quarter} {this.props.year} ke perusahaan {this.state.companyName} ?
:
Apakah anda yakin ingin mengirimkan email Reminder Submission {this.props.typeReport} {this.props.year} ke perusahaan {this.state.companyName} ?
}
this.setState({ visiblePopup: false })}
>
Cancel
this.handleSendEmail()}
>
Send
)}
);
}
}