Commit 3da9297e authored by Rifka Kurnia Irfiana's avatar Rifka Kurnia Irfiana

update monthly report

parent cbe9be65
import React, { Component } from 'react';
import { Typography, Paper, TextField, MenuItem } from '@material-ui/core';
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';
......@@ -10,49 +10,75 @@ 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 = {
periode: '2020',
perusahaan: 'TAP Group',
revisi: '0',
visibleBudgetTahunan: true,
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
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": this.state.periode.periode,
"report_type": "Monthly Report",
}
api.create().getReportTypeBody(payload).then(response => {
console.log(response.data)
// console.log(response);
if (response.data) {
if (response.data.status === "success") {
let dataTable = response.data.data.map((item, index) => {
return [
index + 1,
item.number,
item.report_name,
"",
item.report_id
item.revision,
item.current_status,
item.report_id,
item.is_can_upload,
item.revision
]
})
// console.log(dataTable);
this.setState({ dataTable })
}
}
......@@ -73,18 +99,73 @@ export default class MonthlyReport extends Component {
options: companyData,
getOptionLabel: (option) => titleCase(option.company_name),
};
this.setState({ listCompany: defaultProps, company: companyData[0] }, ()=> this.getReport())
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({
visibleBudgetTahunan: false,
visibleMonthlyReport: false,
visibleBS: true,
visiblePL: false,
visibleCAT: false,
......@@ -93,7 +174,7 @@ export default class MonthlyReport extends Component {
})
} else if (item === 'Profit & Loss') {
this.setState({
visibleBudgetTahunan: false,
visibleMonthlyReport: false,
visibleBS: false,
visiblePL: true,
visibleCAT: false,
......@@ -102,7 +183,7 @@ export default class MonthlyReport extends Component {
})
} else if (item === 'Tax Planning') {
this.setState({
visibleBudgetTahunan: false,
visibleMonthlyReport: false,
visibleBS: false,
visiblePL: false,
visibleCAT: false,
......@@ -110,8 +191,8 @@ export default class MonthlyReport extends Component {
visibleTP: true
})
} else if (item === 'Fixed Assets Movement') {
this.setState({
visibleBudgetTahunan: false,
this.setState({
visibleMonthlyReport: false,
visibleBS: false,
visiblePL: false,
visibleCAT: false,
......@@ -119,8 +200,8 @@ export default class MonthlyReport extends Component {
visibleTP: false
})
} else if (item === 'CAT') {
this.setState({
visibleBudgetTahunan: false,
this.setState({
visibleMonthlyReport: false,
visibleBS: false,
visiblePL: false,
visibleCAT: true,
......@@ -130,17 +211,88 @@ export default class MonthlyReport extends Component {
}
}
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 (
<div style={{ display: 'flex' }}>
<FormControlLabel
style={{ margin: 0 }}
value={val}
control={
<Select
value={val}
onChange={event => {
// console.log(event.target)
updateValue(event.target.value)
this.handleChange(event.target.value, tableMeta)
}}
autoWidth
>
{list.map((item, index) =>
<MenuItem key={index} value={item}>{item}</MenuItem>
)}
</Select>
}
/>
</div >
);
}
}
}, {
name: "Status",
options: {
customBodyRender: (val, tableMeta) => {
return (
<div style={{ display: 'flex' }}>
{val === "acc" ?
{val === "submitted" || val === "approved" ?
<img src={Images.ceklis} style={{ width: 31, height: 24 }} /> :
val === "revision" ?
<span>Revisi</span> :
null
}
</div >
......@@ -157,17 +309,25 @@ export default class MonthlyReport extends Component {
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
cursor: tableMeta.rowData[5] ? 'pointer' : null,
borderColor: 'transparent'
}}
// onClick={() => this.clickDetail(tableMeta.rowData[1], tableMeta.rowData[3])}
// onClick={() =>
// tableMeta.rowData[5] ? this.clickDetail(tableMeta.rowData[1], tableMeta.rowData[4]) : null
// }
>
<Typography style={{ color: '#5198ea', fontSize: 12, }}>Detail</Typography>
<Typography style={{ color: tableMeta.rowData[5] ? '#5198ea' : 'GrayText', fontSize: 12, }}>Detail</Typography>
</button>
</div >
);
}
}
}, {
name: "",
options: { display: false }
}, {
name: "",
options: { display: false }
}]
// const dataTable = [
// ["1", "Balance Sheet", "done"],
......@@ -199,6 +359,7 @@ export default class MonthlyReport extends Component {
search: false
}
const periode = [
{ value: '2021', label: '2021' },
{ value: '2020', label: '2020' },
{ value: '2019', label: '2019' },
{ value: '2018', label: '2018' },
......@@ -218,7 +379,7 @@ export default class MonthlyReport extends Component {
]
return (
<div style={{ flex: 1, backgroundColor: '#f8f8f8' }}>
{this.state.visibleBudgetTahunan && (
{this.state.visibleMonthlyReport && (
<div>
<div className={"main-color"} style={{ height: 78, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
<Typography style={{ fontSize: '16px', color: 'white' }}>Monthly Report</Typography>
......@@ -226,30 +387,32 @@ export default class MonthlyReport extends Component {
<div style={{ padding: 20, width: '100%' }}>
<Paper style={{ paddingTop: 10 }}>
<div style={{ borderBottom: 'solid 1px #c4c4c4' }} >
<Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>Monthly Report</Typography>
<Typography style={{ fontSize: '12px', color: '#4b4b4b', margin: 10 }}>MonthlyReport</Typography>
</div>
<div style={{ padding: 20 }}>
<div>
<TextField
style={{ width: 250, }}
<Autocomplete
{...this.state.listPeriode}
id="periode"
select
label="Periode"
onChange={(event, newInputValue) => this.setState({ periode: newInputValue }, () => {
this.getReport()
this.getReportAttachment()
})}
debug
disableClearable
style={{ width: 250 }}
renderInput={(params) => <TextField {...params} label="Periode" margin="normal" style={{ marginTop: 7 }} />}
value={this.state.periode}
onChange={(e) => this.setState({ periode: e.target.value })}
>
{periode.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))}
</TextField>
/>
</div>
<div style={{ marginTop: 20 }}>
<Autocomplete
{...this.state.listCompany}
id="company"
onChange={(event, newInputValue) => this.setState({ company: newInputValue })}
onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => {
this.getReport()
this.getReportAttachment()
})}
debug
disableClearable
style={{ width: 250 }}
......@@ -258,20 +421,19 @@ export default class MonthlyReport extends Component {
/>
</div>
<div style={{ marginTop: 20 }}>
<TextField
style={{ width: 250, }}
id="reivisi"
select
label="Revisi"
value={this.state.revisi}
onChange={(e) => this.setState({ revisi: e.target.value })}
>
{revisi.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))}
</TextField>
<Autocomplete
{...this.state.listRevision}
id="revision"
onChange={(event, newInputValue) => this.setState({ revision: newInputValue }, () => {
this.getReport()
this.getReportAttachment()
})}
debug
disableClearable
style={{ width: 250 }}
renderInput={(params) => <TextField {...params} label="Revision" margin="normal" style={{ marginTop: 7 }} />}
value={this.state.revision}
/>
</div>
<div style={{ marginTop: 20 }}>
......@@ -286,17 +448,39 @@ export default class MonthlyReport extends Component {
<Typography style={{ fontSize: '16px', color: '#4b4b4b', fontWeight: 'bold' }}>Attachment: </Typography>
</div>
<div style={{ width: '50%' }}>
<Typography style={{ fontSize: '16px', color: '#5198ea' }}>Upload File</Typography>
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
outline: 'none'
}}
onClick={() => this.setState({ visibleUpload: true })}
>
<Typography style={{ fontSize: '16px', color: '#5198ea' }}>Upload File</Typography>
</button>
</div>
</div>
<div style={{ display: 'flex', marginTop: 10 }}>
<div style={{ width: '50%', paddingLeft: 20 }}>
<Typography style={{ fontSize: '16px', color: '#4b4b4b' }}>File 1.xls </Typography>
<Typography style={{ fontSize: '16px', color: '#4b4b4b' }}>File 2.xls </Typography>
{this.state.listAttachment.length > 0 ?
this.state.listAttachment.map((item) => {
return (
<Typography style={{ fontSize: '16px', color: '#4b4b4b' }}>{item.attachment_name}</Typography>
)
})
: null
}
</div>
<div style={{ width: '50%' }}>
<Typography style={{ fontSize: '16px', color: '#ff3939' }}>Delete</Typography>
<Typography style={{ fontSize: '16px', color: '#ff3939' }}>Delete</Typography>
{this.state.listAttachment.length > 0 ?
this.state.listAttachment.map((item) => {
return (
<Typography style={{ fontSize: '16px', color: '#ff3939' }}>Delete</Typography>
)
})
: null
}
</div>
</div>
</div>
......@@ -311,36 +495,70 @@ export default class MonthlyReport extends Component {
</div>
)}
{this.state.visibleUpload && (
<div className="test app-popup-show">
<div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
<div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
<div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
<div className="popup-title">
<span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File</span>
</div>
</div>
<div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
<button
type="button"
className="btn btn-circle btn-white"
onClick={() => this.setState({ visibleUpload: false })}
>
<img src={Images.close} />
</button>
</div>
</div>
<UploadFile
type={this.state.uploadStatus}
percentage={this.state.percentage}
result={this.state.result}
acceptedFiles={["xlsx"]}
onHandle={(dt) => {
this.fileHandler(dt)
this.setState({ uploadStatus: 'idle', percentage: '0' })
}}
onUpload={() => this.uploadAttachment(this.state.formData)}
/>
</div>
</div>
)}
{this.state.visibleBS && (
<BalanceSheet
report_id={this.state.report_id}
company={this.state.company}
onClickClose={()=> this.setState({ visibleBS: false, visibleBudgetTahunan: true})}
onClickClose={() => this.setState({ visibleBS: false, visibleMonthlyReport: true })}
/>
)}
{this.state.visiblePL && (
<ProfitLoss
<ProfitLoss
report_id={this.state.report_id}
company={this.state.company}
onClickClose={()=> this.setState({ visiblePL: false, visibleBudgetTahunan: true})}
onClickClose={() => this.setState({ visiblePL: false, visibleMonthlyReport: true })}
/>
)}
{this.state.visibleTP && (
<TaxPlanning
<TaxPlanning
report_id={this.state.report_id}
company={this.state.company}
onClickClose={() => this.setState({ visibleTP: false, visibleBudgetTahunan: true })}
onClickClose={() => this.setState({ visibleTP: false, visibleMonthlyReport: true })}
/>
)}
{this.state.visibleFAM && (
<FixedAssetsMovement
onClickClose={() => this.setState({ visibleFAM: false, visibleBudgetTahunan: true })}
<FixedAssetsMovement
onClickClose={() => this.setState({ visibleFAM: false, visibleMonthlyReport: true })}
/>
)}
{this.state.visibleCAT && (
<CorporateAnnualTarget
onClickClose={() => this.setState({ visibleCAT: false, visibleBudgetTahunan: true })}
<CorporateAnnualTarget
onClickClose={() => this.setState({ visibleCAT: false, visibleMonthlyReport: true })}
/>
)}
</div >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment