import React, { Component } from 'react';
import { Typography, Paper, TextField, Snackbar, withStyles} from '@material-ui/core';
import Images from '../../assets/Images';
import Constant from '../../library/Constant';
import api from '../../api';
import { PropagateLoader } from 'react-spinners';
import { format } from 'date-fns';
import Autocomplete from '@material-ui/lab/Autocomplete';
import TableProgressReport from './TableProgressReport'
import ReactTooltip from "react-tooltip";
import MuiAlert from '@material-ui/lab/Alert';
const Alert = withStyles({
})((props) => );
class ReportProgress extends Component {
constructor(props) {
super(props)
this.state = {
listApproval: null,
listCategory: {
options: [{ name: 'Report Status', value: 'report-status' }, { name: 'Approval Progress', value: 'approval-progress' }],
getOptionLabel: (option) => option.name,
},
listReportType: null,
listQuarter: {
options: [{ name: 'Q1', value: 'q1' }, { name: 'Q2', value: 'q2' }, { name: 'Q3', value: 'q3' }],
getOptionLabel: (option) => option.name,
},
listMonth: null,
listPeriodeMB: null,
quarter: {
name: 'Q1', value: 'q1'
},
category: {
name: 'Report Status', value: 'report-status'
},
month: null,
periodeMB: null,
reportType: null,
dataTable: [],
alert: false,
tipeAlert: '',
messageAlert: '',
company: null
}
}
componentDidMount() {
this.getMonth()
// console.log(this.state.listCategory);
// console.log(this.state.category);
}
getMonth() {
this.setState({ loading: true })
api.create().getMonthTransaction().then(response => {
let dateNow = new Date()
dateNow.setMonth(dateNow.getMonth() - 1);
let month = format(dateNow, 'MMMM')
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
let monthData = data.map((item) => {
return {
month_id: item.id,
month_value: String(item.month_name).substr(0, 3)
}
})
let defaultProps = {
options: monthData,
getOptionLabel: (option) => option.month_value,
};
let index = data.findIndex((val) => val.month_name == month)
this.setState({ listMonth: defaultProps, month: index == -1 ? monthData[0] : monthData[index] }, () => {
this.getPeriode()
})
} else {
this.setState({ 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({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
})
}
getPeriode() {
let currentYear = new Date().getFullYear()
let MB = []
for (var i = 2000; i <= currentYear; i++) {
MB.push({ name: String(i), value: i })
if (i == currentYear) {
MB.push({ name: String(i + 1), value: i + 1})
}
}
let defaultPropsMB = {
options: MB,
getOptionLabel: (option) => option.name,
};
this.setState({
listPeriodeMB: defaultPropsMB,
periodeMB: MB[MB.length - 1],
}, () => {
this.getReportType()
// console.log(this.state.listMonth)
// console.log(this.state.listPeriodeMB)
})
}
getReportType() {
let arrayReportType = [
{
name: 'Master Budget',
value: 0
}, {
name: 'Monthly Report',
value: 1
}, {
name: 'Rolling Outlook',
value: 2
}, {
name: 'Outlook PA',
value: 3
},
]
let defaultProps = {
options: arrayReportType,
getOptionLabel: (option) => option.name,
};
this.setState({ listReportType: defaultProps, reportType: arrayReportType[0] }, () => {
// console.log(this.state.periodeMB)
this.getDataMonitoring()
// console.log(this.state.listReportType)
// console.log(this.state.reportType)
})
}
getDataMonitoring() {
let payload = {
"year": this.state.periodeMB.name,
"month": this.state.month.month_id,
"quarter": this.state.quarter.value
}
console.log(payload)
if (String(this.state.reportType.name).toLocaleUpperCase().includes('MASTER')) {
this.getMonitoringMB(payload)
} else if (String(this.state.reportType.name).toLocaleUpperCase().includes('MONTHLY')) {
this.getMonitoringMR(payload)
} else if (String(this.state.reportType.name).toLocaleUpperCase().includes('ROLLING')) {
this.getMonitoringRO(payload)
} else {
this.getMonitoringOLPA(payload)
}
}
getMonitoringMB(payload) {
let dataTable = []
api.create().getMonitoringMB(payload).then((response) => {
console.log(response)
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
data.map((item,index) => {
let report = []
let statusSubmission = String(item.submission_status).toLocaleUpperCase()
let statusOI = String(item.operating_indicator).toLocaleUpperCase()
item.report.map((items,index) => {
let statusReport = String(items.status_report).toLocaleUpperCase()
report.push({report_name: items.report_name, status_report: (statusReport == 'APPROVED' || statusReport == 'REVISION' || statusReport == 'COMPLETED') ? (statusReport + ' - ' + items.report_date) : statusReport })
})
report.push(
{report_name: 'Operating Indicator', status_report: statusOI},
{report_name: 'Submission Status', status_report: (statusSubmission == 'APPROVED' || statusSubmission == 'REVISION' || statusSubmission == 'COMPLETED') ? (statusSubmission + ' - ' + item.submissionStatusDate) : statusSubmission})
dataTable.push([
item.company_name,
report,
item.automatic_reminder_report_date,
item.manual_reminder_report_status,
item.manual_reminder_report_date,
item.submission_status,
item.manual_reminder_report_button,
item.company_id,
])
})
// data.map((item,index) => {
// let report = []
// item.report.map((items,indexs) => {
// if (!String(items.report_name).includes('Indicator') && !String(items.report_name).includes('OLPA')) {
// if (String(items.report_name).includes('Fixed')) {
// report.push({...items, status_report: (items.report_date == null? items.status_report : items.status_report + ' - ' + items.report_date), report_name: 'Fixed Assets Movement'})
// } else {
// report.push({...items, status_report: (items.report_date == null? items.status_report : items.status_report + ' - ' + items.report_date)})
// }
// }
// })
// report.push({report_name: 'Operating Indicator', status_report: item.operatingIndicator}, {report_name: 'Submission Status', status_report: (item.submissionStatusDate == null? item.submissionStatus : item.submissionStatus + ' - ' + item.submissionStatusDate)})
// dataTable.push([
// item.companyName,
// report
// ])
// })
// console.log(dataTable)
this.setState({dataTable, loading: 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.data.message, tipeAlert: 'error', loading: false })
}
})
}
getMonitoringMR(payload) {
let dataTable = []
api.create().getMonitoringMR(payload).then((response) => {
console.log(response)
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
data.map((item,index) => {
let report = item.report
report.push({report_name: 'Operating Indicator', status_report: item.operating_indicator}, {report_name: 'Monthly Status', status_report: item.monthly_status})
dataTable.push([
item.company_name,
report,
item.automatic_reminder_report_date,
item.manual_reminder_report_status,
item.manual_reminder_report_date,
item.monthly_status,
item.manual_reminder_report_button,
item.company_id,
])
})
this.setState({dataTable, loading: 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.data.message, tipeAlert: 'error', loading: false })
}
})
}
getMonitoringRO(payload) {
let dataTable = []
api.create().getMonitoringRO(payload).then((response) => {
console.log(response)
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
data.map((item,index) => {
let report = item.report
report.push({report_name: 'Operating Indicator', status_report: item.operating_indicator}, {report_name: 'Rolling Status', status_report: item.rolling_status})
dataTable.push([
item.company_name,
report,
item.automatic_reminder_report_date,
item.manual_reminder_report_status,
item.manual_reminder_report_date,
item.rolling_status,
item.manual_reminder_report_button,
item.company_id,
])
})
this.setState({dataTable, loading: 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.data.message, tipeAlert: 'error', loading: false })
}
})
}
getMonitoringOLPA(payload) {
let dataTable = []
api.create().getMonitoringOLPA(payload).then((response) => {
console.log(response)
if (response.data) {
if (response.data.status === "success") {
let data = response.data.data
data.map((item,index) => {
let report = []
let statusSubmission = String(item.outlook_status).toLocaleUpperCase()
let statusOI = String(item.operating_indicator).toLocaleUpperCase()
item.report.map((items,index) => {
let statusReport = String(items.status_report).toLocaleUpperCase()
report.push({report_name: items.report_name, status_report: (statusReport == 'APPROVED' || statusReport == 'REVISION' || statusReport == 'COMPLETED') ? (statusReport + ' - ' + items.report_date) : statusReport })
})
report.push(
{report_name: 'Operating Indicator', status_report: statusOI},
{report_name: 'OLPA Status', status_report: (statusSubmission == 'APPROVED' || statusSubmission == 'REVISION' || statusSubmission == 'COMPLETED') ? (statusSubmission + ' - ' + item.submissionStatusDate) : statusSubmission})
dataTable.push([
item.company_name,
report,
item.automatic_reminder_report_date,
item.manual_reminder_report_status,
item.manual_reminder_report_date,
item.outlook_status,
item.manual_reminder_report_button,
item.company_id,
])
})
// data.map((item,index) => {
// let report = []
// item.report.map((items,indexs) => {
// if (!String(items.report_name).includes('Indicator') && !String(items.report_name).includes('OLPA')) {
// if (String(items.report_name).includes('Fixed')) {
// report.push({...items, status_report: (items.report_date == null? items.status_report : items.status_report + ' - ' + items.report_date), report_name: 'Fixed Assets Movement'})
// } else {
// report.push({...items, status_report: (items.report_date == null? items.status_report : items.status_report + ' - ' + items.report_date)})
// }
// }
// })
// report.push({report_name: 'Operating Indicator', status_report: item.operatingIndicator}, {report_name: 'OLPA Status', status_report: (item.submissionStatusDate == null? item.submissionStatus : item.submissionStatus + ' - ' + item.submissionStatusDate)})
// dataTable.push([
// item.companyName,
// report
// ])
// let report = item.report
// report.push({report_name: 'Operating Indicator', status_report: item.operating_indicator}, {report_name: 'OLPA Status', status_report: item.olpa_status})
// dataTable.push([
// item.company_name,
// report
// ])
// })
this.setState({dataTable, loading: 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.data.message, tipeAlert: 'error', loading: false })
}
})
}
closeAlert() {
this.setState({ alert: false })
}
downloadData() {
let path = ''
let type = ''
if (String(this.state.reportType.name).toLocaleUpperCase().includes('MASTER')) {
path = `public/transaction/monitoring/master_budget?periode=${this.state.periodeMB.name}`
type = 'Master Budget'
} else if (String(this.state.reportType.name).toLocaleUpperCase().includes('MONTHLY')) {
path = `public/transaction/monitoring/monthly_report?months=${this.state.month.month_id}&&periode=${this.state.periodeMB.name}`
type = `Monthly Report (${this.state.month.month_value})`
} else if (String(this.state.reportType.name).toLocaleUpperCase().includes('ROLLING')) {
path = `public/transaction/monitoring/rolling_outlook?quartals=${this.state.quarter.value}&&periode=${this.state.periodeMB.name}`
type = `Rolling Outlook ${this.state.quarter.name}`
} else {
path = `public/transaction/monitoring/outlook_pa?periode=${this.state.periodeMB.name}`
type = 'Outlook PA'
}
this.downloadAllData(path, type)
}
async downloadAllData(path, type) {
let url = `${process.env.REACT_APP_URL_MAIN_BE}/${path}`
console.log(url);
let res = await fetch(
`${process.env.REACT_APP_URL_MAIN_BE}/${path}`
)
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 = `Progress Report - ${type}.xlsx`;
a.click();
}
}
render() {
const dataTableMB = [
['Tax Planning', '2', 'ABA: Anugerah Buminusantara Abadi', '2021-05-03'],
['CAT', '1', 'ABA: Anugerah Buminusantara Abadi', '2021-05-03'],
['Profit Loss', '0', 'ABA: Anugerah Buminusantara Abadi', '2021-05-03']
]
const dataTableMBStatus = [
['ABA: Anugerah Buminusantara Abadi', '2021', 'approved', '2', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved'],
['ABA: Anugerah Buminusantara Abadi', '2021', 'approved', '1', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved'],
['ABA: Anugerah Buminusantara Abadi', '2021', 'approved', '0', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved', 'Sudah Approved']
]
const loadingComponent = (
);
return (
this.closeAlert()}>
this.closeAlert()} severity={this.state.tipeAlert}>
{this.state.messageAlert}
Report Status & Approval Progress Monitoring
Report Status & Approval Progress
{/*
this.setState({ category: newInputValue, loading: true }, () => {
// this.getListUserSubcoRO()
this.getReportType()
this.setState({ loading: false })
})}
disableClearable
style={{ minWidth: 210, marginRight: 20 }}
renderInput={(params) => }
value={this.state.category}
/>
this.setState({ reportType: newInputValue, loading: true }, () => {
// this.getListUserSubcoRO()
this.setState({ loading: false })
})}
disableClearable
style={{ minWidth: 210, marginRight: 20 }}
renderInput={(params) => }
value={this.state.reportType}
/>
*/}
{/* {this.state.previewDownload && ( */}
{/* )} */}
{this.state.loading && loadingComponent}
{this.state.reportType != null && !this.state.loading && (
)}
);
}
}
export default ReportProgress;