import React, { Component } from 'react'; import { Typography, Paper, TextField, MenuItem, Select, FormControlLabel } from '@material-ui/core'; import MUIDataTable from 'mui-datatables'; import Images from '../assets/Images'; import BalanceSheet from './BudgetTahunan/BalanceSheet'; import api from '../api'; import Autocomplete from '@material-ui/lab/Autocomplete'; import { titleCase } from '../library/Utils'; import ProfitLoss from './BudgetTahunan/ProfitLoss'; import TaxPlanning from './BudgetTahunan/TaxPlanning'; import FixedAssetsMovement from './BudgetTahunan/FixedAssetsMovement'; import CorporateAnnualTarget from './BudgetTahunan/CorporateAnnualTarget'; import { ExcelRenderer } from 'react-excel-renderer'; import UploadFile from "../library/Upload"; import { format } from 'date-fns'; export default class MonthlyReport extends Component { constructor(props) { super(props) this.state = { perusahaan: 'TAP Group', listRevision: null, revision: null, visibleMonthlyReport: true, visibleBS: false, listPeriode: null, periode: null, listCompany: null, company: null, report_id: null, visiblePL: false, visibleFAM: false, visibleCAT: false, listAttachment: [], visibleUpload: false } this.fileHandler = this.fileHandler.bind(this); } componentDidMount() { this.getCompanyActive() } getReportAttachment() { let payload = { "company_id": this.state.company.company_id, "periode": this.state.periode.periode, "revision": this.state.revision.revision, } api.create().getMasterBudgetAtt(payload).then(response => { if (response.data) { if (response.data.status === "success") { this.setState({ listAttachment: response.data.data }) } } // console.log(response); }) } getReport() { let payload = { "company_id": this.state.company.company_id, "periode": this.state.periode.periode, "report_type": "Monthly Report", } api.create().getReportTypeBody(payload).then(response => { // console.log(response); if (response.data) { if (response.data.status === "success") { let dataTable = response.data.data.map((item, index) => { return [ item.number, item.report_name, item.revision, item.current_status, item.report_id, item.is_can_upload, item.revision ] }) // console.log(dataTable); this.setState({ dataTable }) } } }) } getCompanyActive() { api.create().getPerusahaanActive().then((response) => { if (response.data.status === 'success') { let data = response.data.data let companyData = data.map((item) => { return { company_id: item.company_id, company_name: item.company_name, } }) let defaultProps = { options: companyData, getOptionLabel: (option) => titleCase(option.company_name), }; this.setState({ listCompany: defaultProps, company: companyData[0] }, () => { this.getPeriode() }) } else { alert(response.data.message) } }) } getPeriode() { api.create().getPeriodeTransaction().then(response => { let dateNow = new Date let year = format(dateNow, 'yyyy') if (response.data) { if (response.data.status === "success") { let data = response.data.data let periodeData = data.map((item) => { return { periode: item, } }) let defaultProps = { options: periodeData, getOptionLabel: (option) => option.periode, }; let index = data.sort((a, b) => a - b).findIndex((val) => val == year) this.setState({ listPeriode: defaultProps, periode: index == -1 ? periodeData[0] : periodeData[index] }, () => { this.getRevision() }) } } }) } getRevision() { let payload = { "company_id": this.state.company.company_id, "periode": this.state.periode.periode } api.create().getRevision(payload).then(response => { console.log(response); if (response.data) { if (response.data.status === "success") { let data = response.data.data let revisionData = data.map((item) => { return { revision: item, } }) let defaultProps = { options: revisionData, getOptionLabel: (option) => option.revision, }; this.setState({ listRevision: defaultProps, revision: revisionData[0] }, () => { this.getReport() this.getReportAttachment() }) } } }) } clickDetail(item, id) { this.setState({ report_id: id }) if (item === 'Balance Sheet') { this.setState({ visibleMonthlyReport: false, visibleBS: true, visiblePL: false, visibleCAT: false, visibleFAM: false, visibleTP: false, }) } else if (item === 'Profit & Loss') { this.setState({ visibleMonthlyReport: false, visibleBS: false, visiblePL: true, visibleCAT: false, visibleFAM: false, visibleTP: false }) } else if (item === 'Tax Planning') { this.setState({ visibleMonthlyReport: false, visibleBS: false, visiblePL: false, visibleCAT: false, visibleFAM: false, visibleTP: true }) } else if (item === 'Fixed Assets Movement') { this.setState({ visibleMonthlyReport: false, visibleBS: false, visiblePL: false, visibleCAT: false, visibleFAM: true, visibleTP: false }) } else if (item === 'CAT') { this.setState({ visibleMonthlyReport: false, visibleBS: false, visiblePL: false, visibleCAT: true, visibleFAM: false, visibleTP: false }) } } handleChange(value, tableMeta) { let data = this.state.dataTable data[tableMeta.rowIndex][tableMeta.columnIndex] = value } fileHandler = (event) => { let fileObj = event ExcelRenderer(fileObj, (err, resp) => { // console.log(resp) if (err) { console.log(err); } else { const formData = new FormData(); formData.append("revision", Number(this.state.revisi)); formData.append("companyId", this.state.company.company_id); formData.append("periode", Number(this.state.periode.periode)); formData.append("file", event); this.setState({ formData }) } }) } uploadAttachment(formData) { api.create().uploadAttachment(formData).then(response => { if (response.data) { if (response.data.status === "success") { this.setState({ visibleUpload: false }, () => { this.getReport() this.getReportAttachment() }) } } // console.log(response) }) } render() { const columns = ["#", "Jenis Laporan", { name: "Revision", options: { customBodyRender: (val, tableMeta, updateValue) => { var list = []; for (var i = 0; i <= tableMeta.rowData[6]; i++) { list.push(i); } return (
{ // console.log(event.target) updateValue(event.target.value) this.handleChange(event.target.value, tableMeta) }} autoWidth > {list.map((item, index) => {item} )} } />
); } } }, { name: "Status", options: { customBodyRender: (val, tableMeta) => { return (
{val === "submitted" || val === "approved" ? : val === "revision" ? Revisi : null }
); } } }, { name: "Action", options: { customBodyRender: (val, tableMeta) => { return (
); } } }, { name: "", options: { display: false } }, { name: "", options: { display: false } }] // const dataTable = [ // ["1", "Balance Sheet", "done"], // ["2", "Profit & Loss", ""], // ["3", "CAT", "done"], // ["4", "Fixed Assets Movement", ""], // ["5", "Tax Planning", "done"], // ["6", "Balance Sheet", "done"], // ["7", "Profit & Loss", ""], // ["8", "CAT", "done"], // ["9", "Fixed Assets Movement", ""], // ["10", "Tax Planning", "done"], // ["11", "Balance Sheet", "done"], // ["12", "Profit & Loss", "done"], // ["13", "CAT", "done"], // ["14", "Fixed Assets Movement", "done"], // ["15", "Tax Planning", "done"], // ] const options = { filter: false, sort: false, responsive: "scroll", print: false, download: false, selectableRows: false, viewColumns: false, rowsPerPage: 5, rowsPerPageOptions: [5, 25, 100], search: false } const periode = [ { value: '2021', label: '2021' }, { value: '2020', label: '2020' }, { value: '2019', label: '2019' }, { value: '2018', label: '2018' }, { value: '2017', label: '2017' }, { value: '2016', label: '2016' }, ] const perusahaan = [ { value: 'TAP Group', label: 'TAP Group' }, { value: '2019', label: '2019' }, { value: '2018', label: '2018' }, { value: '2017', label: '2017' }, { value: '2016', label: '2016' }, ] const revisi = [ { value: '0', label: '0' }, { value: '1', label: '1' }, ] return (
{this.state.visibleMonthlyReport && (
Monthly Report
MonthlyReport
this.setState({ periode: newInputValue }, () => { this.getReport() this.getReportAttachment() })} debug disableClearable style={{ width: 250 }} renderInput={(params) => } value={this.state.periode} />
this.setState({ company: newInputValue }, () => { this.getReport() this.getReportAttachment() })} debug disableClearable style={{ width: 250 }} renderInput={(params) => } value={this.state.company} />
this.setState({ revision: newInputValue }, () => { this.getReport() this.getReportAttachment() })} debug disableClearable style={{ width: 250 }} renderInput={(params) => } value={this.state.revision} />
Attachment:
{this.state.listAttachment.length > 0 ? this.state.listAttachment.map((item) => { return ( {item.attachment_name} ) }) : null }
{this.state.listAttachment.length > 0 ? this.state.listAttachment.map((item) => { return ( Delete ) }) : null }
Submit
)} {this.state.visibleUpload && (
Upload File
{ this.fileHandler(dt) this.setState({ uploadStatus: 'idle', percentage: '0' }) }} onUpload={() => this.uploadAttachment(this.state.formData)} />
)} {this.state.visibleBS && ( this.setState({ visibleBS: false, visibleMonthlyReport: true })} /> )} {this.state.visiblePL && ( this.setState({ visiblePL: false, visibleMonthlyReport: true })} /> )} {this.state.visibleTP && ( this.setState({ visibleTP: false, visibleMonthlyReport: true })} /> )} {this.state.visibleFAM && ( this.setState({ visibleFAM: false, visibleMonthlyReport: true })} /> )} {this.state.visibleCAT && ( this.setState({ visibleCAT: false, visibleMonthlyReport: true })} /> )}
); } }