Commit 6bfa93af authored by Riri Novita's avatar Riri Novita

Merge branch 'riri' into 'master'

ilangin month

See merge request !1119
parents 616d4e34 3a1fad0d
...@@ -42,81 +42,12 @@ export default class SummaryOfTriputra extends Component { ...@@ -42,81 +42,12 @@ export default class SummaryOfTriputra extends Component {
componentDidMount() { componentDidMount() {
// this.getDetailUser() // this.getDetailUser()
this.setState({ report: this.state.reportType[0], loading: true }) this.setState({ report: this.state.reportType[0], loading: true }, () => {
console.log(this.state.report);
this.getPeriode() this.getPeriode()
// this.getMonth()
}
getDetailUser() {
let userId = localStorage.getItem(Constant.USER)
api.create().getDetailUser(userId).then((response) => {
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
this.setState({ userCompany: response.data.data.company }, () => {
this.getCompanyActive()
})
}
}
}
})
}
getCompanyActive() {
api.create().getPerusahaanActive().then((response) => {
// console.log(response);
if (response.data) {
if (response.data.status === 'success') {
let data = response.data.data
let comID = this.state.rawData ? this.state.rawData.company_id : 0
let companyData = data.map((item) => {
return {
company_id: item.company_id,
company_name: item.company_name,
}
}) })
let arrayBaru = [] // this.getMonth()
this.state.userCompany.map((item, index) => {
let indexID = companyData.findIndex((val) => val.company_id == item)
if (indexID !== -1) {
arrayBaru.push(companyData[indexID])
}
})
let defaultProps = {
options: arrayBaru,
getOptionLabel: (option) => titleCase(option.company_name),
};
let index = arrayBaru.findIndex((val) => val.company_id == comID)
this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1 ? companyData[0] : (index == -1 ? arrayBaru[0] : arrayBaru[index]) }, () => {
this.getLastPeriod()
})
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', listCompany: null, company: null })
}
})
}
getLastPeriod() {
api.create().getLastPeriod(this.state.company.company_id).then(response => {
// console.log(response);
if (response.data.status === "success") {
this.setState({ lastPeriod: response.data.data.last_periode, latestPeriode: response.data.data.latest_periode }, () => {
this.getPeriode()
})
}
})
} }
getPeriode() { getPeriode() {
...@@ -129,7 +60,7 @@ export default class SummaryOfTriputra extends Component { ...@@ -129,7 +60,7 @@ export default class SummaryOfTriputra extends Component {
let data = [] let data = []
response.data.data.map((item) => { response.data.data.map((item) => {
// if (this.state.isApprover) { // if (this.state.isApprover) {
if (item >= 2000 && item <= (Number(currentYear))) { if (item >= 2000 && item <= (Number(currentYear) + 1)) {
data.push(item) data.push(item)
} }
// } else { // } else {
...@@ -203,65 +134,65 @@ export default class SummaryOfTriputra extends Component { ...@@ -203,65 +134,65 @@ export default class SummaryOfTriputra extends Component {
}) })
} }
getReportType() { // getReportType() {
let payload = { // let payload = {
"company_id": this.state.company.company_id, // "company_id": this.state.company.company_id,
"periode": this.state.periode.periode, // "periode": this.state.periode.periode,
"report_type": "Master Budget", // "report_type": "Master Budget",
} // }
api.create().getReportTypeBody(payload).then(response => { // api.create().getReportTypeBody(payload).then(response => {
console.log(response); // console.log(response);
if (response.data) { // if (response.data) {
if (response.data.status === "success") { // if (response.data.status === "success") {
if (this.state.report.value === 1) { // if (this.state.report.value === 1) {
response.data.data.map((item, index) => { // response.data.data.map((item, index) => {
if (item.report_name === 'MTD Report') { // if (item.report_name === 'MTD Report') {
this.setState({ revisionType: item.revision }, ()=> { // this.setState({ revisionType: item.revision }, ()=> {
this.getSubmission() // this.getSubmission()
}) // })
} // }
}) // })
} else if (this.state.report.value === 1) { // } else if (this.state.report.value === 1) {
response.data.data.map((item, index) => { // response.data.data.map((item, index) => {
if (item.report_name === 'YTD Report') { // if (item.report_name === 'YTD Report') {
this.setState({ revisionType: item.revision }, ()=> { // this.setState({ revisionType: item.revision }, ()=> {
this.getSubmission() // this.getSubmission()
}) // })
} // }
}) // })
} else { // } else {
this.setState({ revisionType: 0 }, ()=> { // this.setState({ revisionType: 0 }, ()=> {
this.getSubmission() // this.getSubmission()
}) // })
} // }
} // }
} // }
}) // })
} // }
getSubmission() { // getSubmission() {
this.setState({ loading: true }) // this.setState({ loading: true })
let payload = { // let payload = {
"company_id": this.state.company.company_id, // "company_id": this.state.company.company_id,
"periode": this.state.periode.periode, // "periode": this.state.periode.periode,
"is_approver": true // "is_approver": true
} // }
api.create().getSubmission(payload).then(response => { // api.create().getSubmission(payload).then(response => {
// console.log(response) // // console.log(response)
if (response.data) { // if (response.data) {
if (response.data.status === "success") { // if (response.data.status === "success") {
this.setState({ // this.setState({
submissionID: response.data.data.submission_id, // submissionID: response.data.data.submission_id,
lastRevision: response.data.data.last_revision, // lastRevision: response.data.data.last_revision,
}, () => { // }, () => {
this.getDataTable() // this.getDataTable()
}) // })
} else { // } else {
this.setState({ submissionID: null, loading: false }) // this.setState({ submissionID: null, loading: false })
} // }
} // }
}) // })
} // }
getDataTable() { getDataTable() {
let payload = { let payload = {
...@@ -1470,8 +1401,23 @@ export default class SummaryOfTriputra extends Component { ...@@ -1470,8 +1401,23 @@ export default class SummaryOfTriputra extends Component {
getOptionLabel={(option) => titleCase(option.label)} getOptionLabel={(option) => titleCase(option.label)}
id="typereport" id="typereport"
onChange={(event, newInputValue) => this.setState({ report: newInputValue, loading: true, previewTable: false }, () => { onChange={(event, newInputValue) => this.setState({ report: newInputValue, loading: true, previewTable: false }, () => {
let data = this.state.listPeriode.options
let currentYear = new Date().getFullYear()
let periode = (this.state.lastPeriod == "" ? String(Number(currentYear) + 1) : this.state.lastPeriod)
let dateNow = new Date()
dateNow.setMonth(dateNow.getMonth() - 1);
let yearNow = dateNow.getFullYear()
// this.getSubmission() // this.getSubmission()
if (!String(this.state.report.label).toLocaleLowerCase().includes('historical')) {
let index = data.sort((a, b) => a - b).findIndex((val) => val.periode == yearNow)
// console.log(index)
this.setState({periode: data[index]}, () => {
this.getDataTable() this.getDataTable()
})
} else {
this.getDataTable()
}
})} })}
disableClearable disableClearable
style={{ width: 250 }} style={{ width: 250 }}
...@@ -1496,7 +1442,8 @@ export default class SummaryOfTriputra extends Component { ...@@ -1496,7 +1442,8 @@ export default class SummaryOfTriputra extends Component {
value={this.state.periode} value={this.state.periode}
/> />
</div> </div>
<div style={{ marginTop: 15 }}>
{(this.state.report != null && !String(this.state.report.label).toLocaleLowerCase().includes('historical')) && <div style={{ marginTop: 15 }}>
<Autocomplete <Autocomplete
{...this.state.listMonths} {...this.state.listMonths}
// getOptionLabel={(option) => titleCase(option.label)} // getOptionLabel={(option) => titleCase(option.label)}
...@@ -1509,7 +1456,7 @@ export default class SummaryOfTriputra extends Component { ...@@ -1509,7 +1456,7 @@ export default class SummaryOfTriputra extends Component {
renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />} renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
value={this.state.month} value={this.state.month}
/> />
</div> </div>}
</div> </div>
<div> <div>
<div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}> <div style={{ display: 'flex', justifyContent: 'space-between', padding: '0px 20px 10px 20px' }}>
......
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