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 {
componentDidMount() {
// this.getDetailUser()
this.setState({ report: this.state.reportType[0], loading: true })
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.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()
})
}
this.setState({ report: this.state.reportType[0], loading: true }, () => {
console.log(this.state.report);
this.getPeriode()
})
// this.getMonth()
}
getPeriode() {
......@@ -129,7 +60,7 @@ export default class SummaryOfTriputra extends Component {
let data = []
response.data.data.map((item) => {
// if (this.state.isApprover) {
if (item >= 2000 && item <= (Number(currentYear))) {
if (item >= 2000 && item <= (Number(currentYear) + 1)) {
data.push(item)
}
// } else {
......@@ -203,65 +134,65 @@ export default class SummaryOfTriputra extends Component {
})
}
getReportType() {
let payload = {
"company_id": this.state.company.company_id,
"periode": this.state.periode.periode,
"report_type": "Master Budget",
}
api.create().getReportTypeBody(payload).then(response => {
console.log(response);
if (response.data) {
if (response.data.status === "success") {
if (this.state.report.value === 1) {
response.data.data.map((item, index) => {
if (item.report_name === 'MTD Report') {
this.setState({ revisionType: item.revision }, ()=> {
this.getSubmission()
})
}
})
} else if (this.state.report.value === 1) {
response.data.data.map((item, index) => {
if (item.report_name === 'YTD Report') {
this.setState({ revisionType: item.revision }, ()=> {
this.getSubmission()
})
}
})
} else {
this.setState({ revisionType: 0 }, ()=> {
this.getSubmission()
})
}
}
}
})
}
// getReportType() {
// let payload = {
// "company_id": this.state.company.company_id,
// "periode": this.state.periode.periode,
// "report_type": "Master Budget",
// }
// api.create().getReportTypeBody(payload).then(response => {
// console.log(response);
// if (response.data) {
// if (response.data.status === "success") {
// if (this.state.report.value === 1) {
// response.data.data.map((item, index) => {
// if (item.report_name === 'MTD Report') {
// this.setState({ revisionType: item.revision }, ()=> {
// this.getSubmission()
// })
// }
// })
// } else if (this.state.report.value === 1) {
// response.data.data.map((item, index) => {
// if (item.report_name === 'YTD Report') {
// this.setState({ revisionType: item.revision }, ()=> {
// this.getSubmission()
// })
// }
// })
// } else {
// this.setState({ revisionType: 0 }, ()=> {
// this.getSubmission()
// })
// }
// }
// }
// })
// }
getSubmission() {
this.setState({ loading: true })
let payload = {
"company_id": this.state.company.company_id,
"periode": this.state.periode.periode,
"is_approver": true
}
api.create().getSubmission(payload).then(response => {
// console.log(response)
if (response.data) {
if (response.data.status === "success") {
this.setState({
submissionID: response.data.data.submission_id,
lastRevision: response.data.data.last_revision,
}, () => {
this.getDataTable()
})
} else {
this.setState({ submissionID: null, loading: false })
}
}
})
}
// getSubmission() {
// this.setState({ loading: true })
// let payload = {
// "company_id": this.state.company.company_id,
// "periode": this.state.periode.periode,
// "is_approver": true
// }
// api.create().getSubmission(payload).then(response => {
// // console.log(response)
// if (response.data) {
// if (response.data.status === "success") {
// this.setState({
// submissionID: response.data.data.submission_id,
// lastRevision: response.data.data.last_revision,
// }, () => {
// this.getDataTable()
// })
// } else {
// this.setState({ submissionID: null, loading: false })
// }
// }
// })
// }
getDataTable() {
let payload = {
......@@ -1470,8 +1401,23 @@ export default class SummaryOfTriputra extends Component {
getOptionLabel={(option) => titleCase(option.label)}
id="typereport"
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.getDataTable()
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()
})
} else {
this.getDataTable()
}
})}
disableClearable
style={{ width: 250 }}
......@@ -1496,7 +1442,8 @@ export default class SummaryOfTriputra extends Component {
value={this.state.periode}
/>
</div>
<div style={{ marginTop: 15 }}>
{(this.state.report != null && !String(this.state.report.label).toLocaleLowerCase().includes('historical')) && <div style={{ marginTop: 15 }}>
<Autocomplete
{...this.state.listMonths}
// getOptionLabel={(option) => titleCase(option.label)}
......@@ -1509,7 +1456,7 @@ export default class SummaryOfTriputra extends Component {
renderInput={(params) => <TextField {...params} label="Months" margin="normal" style={{ marginTop: 7 }} />}
value={this.state.month}
/>
</div>
</div>}
</div>
<div>
<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