Commit 1bd6874e authored by Dida Adams Arizona's avatar Dida Adams Arizona

Merge branch 'didam' into 'master'

apdet

See merge request !490
parents be132695 bcc10220
...@@ -37,13 +37,49 @@ export default class OperatingIndicator extends Component { ...@@ -37,13 +37,49 @@ export default class OperatingIndicator extends Component {
operatingIndID: null, operatingIndID: null,
alert: false, alert: false,
tipeAlert: '', tipeAlert: '',
messageAlert: '' messageAlert: '',
buttonCreate: true,
buttonEdit: true,
buttonDelete: true
} }
this.fileHandler = this.fileHandler.bind(this); this.fileHandler = this.fileHandler.bind(this);
} }
componentDidMount() { componentDidMount() {
this.getDetailUser() this.getDetailUser()
this.getPermission()
}
getPermission() {
let payload = {
menu: "operating indicator"
}
api.create().getPermission(payload).then(response => {
console.log(response)
if (response.data) {
if (response.data.status === "success") {
this.setState({
buttonCreate: response.data.data.create,
buttonEdit: response.data.data.edit,
buttonDelete: response.data.data.delete,
load: true
})
} else {
this.setState({ load: true })
}
}
})
}
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()
})
}
})
} }
getReportAttachment() { getReportAttachment() {
...@@ -150,7 +186,7 @@ export default class OperatingIndicator extends Component { ...@@ -150,7 +186,7 @@ export default class OperatingIndicator extends Component {
}; };
this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1? companyData[0] : arrayBaru[0] }, () => { this.setState({ listCompany: defaultProps, company: arrayBaru.length < 1? companyData[0] : arrayBaru[0] }, () => {
this.getPeriode() this.getLastPeriod()
}) })
} else { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
...@@ -172,9 +208,21 @@ export default class OperatingIndicator extends Component { ...@@ -172,9 +208,21 @@ export default class OperatingIndicator extends Component {
api.create().getPeriodeTransaction().then(response => { api.create().getPeriodeTransaction().then(response => {
let dateNow = new Date let dateNow = new Date
let year = format(dateNow, 'yyyy') let year = format(dateNow, 'yyyy')
let currentYear = new Date().getFullYear()
if (response.data) { if (response.data) {
if (response.data.status === "success") { if (response.data.status === "success") {
let data = response.data.data let data = []
response.data.data.map((item) => {
if (this.state.isApprover) {
if (item >= 2000 && item <= (Number(currentYear) + 1)) {
data.push(item)
}
} else {
if ((item >= 2000) && (item == this.state.lastPeriod || item < this.state.lastPeriod)) {
data.push(item)
}
}
})
let periodeData = data.map((item) => { let periodeData = data.map((item) => {
return { return {
periode: item, periode: item,
...@@ -184,7 +232,8 @@ export default class OperatingIndicator extends Component { ...@@ -184,7 +232,8 @@ export default class OperatingIndicator extends Component {
options: periodeData, options: periodeData,
getOptionLabel: (option) => option.periode, getOptionLabel: (option) => option.periode,
}; };
let index = data.sort((a, b) => a - b).findIndex((val) => val == year) let periode = (this.state.latestPeriode == "" ? String(Number(currentYear) + 1) : this.state.latestPeriode)
let index = data.sort((a, b) => a - b).findIndex((val) => val === periode)
this.setState({ listPeriode: defaultProps, periode: index == -1 ? periodeData[0] : periodeData[index] }, () => { this.setState({ listPeriode: defaultProps, periode: index == -1 ? periodeData[0] : periodeData[index] }, () => {
this.getReport() this.getReport()
this.getOperatingID() this.getOperatingID()
...@@ -522,7 +571,8 @@ export default class OperatingIndicator extends Component { ...@@ -522,7 +571,8 @@ export default class OperatingIndicator extends Component {
})} })}
getReport={() => this.getReport()} getReport={() => this.getReport()}
saveOperatingInd={this.saveOperatingInd.bind(this)} saveOperatingInd={this.saveOperatingInd.bind(this)}
superUser={this.state.superUser} // superUser={this.state.superUser}
permission={{create: this.state.buttonCreate, edit: this.state.buttonEdit, delete: this.state.buttonDelete}}
/> />
} }
......
...@@ -1244,7 +1244,7 @@ export default class BalanceSheet extends Component { ...@@ -1244,7 +1244,7 @@ export default class BalanceSheet extends Component {
</div> </div>
<div style={{ width: '50%' }}> <div style={{ width: '50%' }}>
<div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}> <div style={{ justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
{this.props.superUser && <a data-tip={'Download Template'} data-for="template"> {(this.props.permission.create && this.props.permission.edit) && <a data-tip={'Download Template'} data-for="template">
<button <button
style={{ style={{
backgroundColor: 'transparent', backgroundColor: 'transparent',
...@@ -1258,7 +1258,7 @@ export default class BalanceSheet extends Component { ...@@ -1258,7 +1258,7 @@ export default class BalanceSheet extends Component {
</button> </button>
</a>} </a>}
<ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
{this.props.superUser && <a data-tip={'Upload'} data-for="upload"> {(this.props.permission.create && this.props.permission.edit) && <a data-tip={'Upload'} data-for="upload">
<button <button
style={{ style={{
backgroundColor: 'transparent', backgroundColor: 'transparent',
...@@ -1323,7 +1323,7 @@ export default class BalanceSheet extends Component { ...@@ -1323,7 +1323,7 @@ export default class BalanceSheet extends Component {
</div> </div>
</button> </button>
</div> </div>
{!this.state.emptyData && this.props.superUser && <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}> {!this.state.emptyData && (this.props.permission.create && this.props.permission.edit) && <div className="col-2" style={{ display: 'flex', justifyContent: 'flex-end', maxWidth: '100%' }}>
<button <button
type="button" type="button"
onClick={() => onClick={() =>
......
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