Commit 3d15a31e authored by Deni Rinaldi's avatar Deni Rinaldi

validasi ReportItem

parent 0eb344cf
......@@ -727,11 +727,11 @@ export default class CreateReportItems extends Component {
<div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
<div style={{display: 'flex'}}>
<Typography style={{ fontSize: 11, width: '20%' }}>Dibuat</Typography>
<Typography style={{ fontSize: 11 }}>: Admin - 21 Jul 2020, 18:45</Typography>
<Typography style={{ fontSize: 11 }}>:</Typography>
</div>
<div style={{display: 'flex'}}>
<Typography style={{ fontSize: 11, width: '20%' }}>Diubah</Typography>
<Typography style={{ fontSize: 11 }}>: Admin - 21 Jul 2020, 18:45</Typography>
<Typography style={{ fontSize: 11 }}>:</Typography>
</div>
</div>
</div>
......
......@@ -41,6 +41,10 @@ export default class EditReportItems extends Component {
msgErrorOrder: '',
msgErrorDesc: '',
msgErrorFormula: '',
errorTipeData: false,
msgErrorTipeData: '',
errorCondition: false,
msgErrorCondition: '',
msgErrorRV: '',
msgErrorSD: '',
msgErrorED: '',
......@@ -116,18 +120,18 @@ export default class EditReportItems extends Component {
if (R.isNil(this.state.reportType)) return alert("Jenis Laporan is Required.");
if (R.isNil(this.state.company)) return alert("Perusahaan is Required.");
else if (R.isEmpty(this.state.tempData.order)) {
this.setState({errorOrder: true, msgErrorOrder: 'Order Harus Diisi'})
this.setState({ errorOrder: true, msgErrorOrder: 'Order Harus Diisi' })
} else if (R.isEmpty(this.state.tempData.description)) {
this.setState({errorDesc: true, msgErrorDesc: 'Deskripsi Harus Diisi'})
} else if (R.isNil(this.state.InputType)) return alert("Tipe Data harus dipilih.")
else if (this.state.InputType.type_report_name === 'Formula' || this.state.InputType.type_report_name === 'Validation' && R.isEmpty(this.state.tempData.formula)) {
this.setState({errorFormula: true, msgErrorFormula: 'Formula Harus Diisi'})
}
else if (this.state.InputType.type_report_name === 'Validation' && R.isEmpty(this.state.tempData.condition_it_should_be)) {
this.setState({errorRV: true, msgErrorRV: 'Nilai Seharusnya Harus Diisi'})
}
else if (this.state.InputType.type_report_name === 'Validation' && R.isNil(this.state.condition)) return alert("Kondisi Jika Salah is Required.");
else if (R.isNil(this.state.tempData.start_date)) {
this.setState({ errorDesc: true, msgErrorDesc: 'Deskripsi Harus Diisi' })
} else if (R.isNil(this.state.InputType)) {
this.setState({ errorTipeData: true, msgErrorTipeData: 'Tipe Data Harus Diisi' })
} else if ((this.state.InputType.type_report_name === 'Formula' && R.isEmpty(this.state.tempData.formula)) || (this.state.InputType.type_report_name === 'Validation' && R.isEmpty(this.state.tempData.formula))) {
this.setState({ errorFormula: true, msgErrorFormula: 'Formula Harus Diisi' })
} else if (this.state.InputType.type_report_name === 'Validation' && R.isEmpty(this.state.tempData.condition_it_should_be)) {
this.setState({ errorRV: true, msgErrorRV: 'Nilai Seharusnya Harus Diisi' })
} else if (this.state.InputType.type_report_name === 'Validation' && R.isNil(this.state.tempData.condition_if_wrong)) {
this.setState({ errorCondition: true, msgErrorCondition: 'Kondisi Jika Salah Harus Diisi' })
} else if (R.isNil(this.state.tempData.start_date)) {
this.setState({ errorStartDate: true, msgErrorSD: 'Start Date Harus Diisi' })
} else if (R.isNil(this.state.tempData.end_date)) {
this.setState({ errorEndDate: true, msgErrorED: 'End Date Harus Diisi' })
......@@ -141,12 +145,12 @@ export default class EditReportItems extends Component {
// alert('test')
let payload = {
"item_report_id": this.state.tempData.item_report_id,
"report_id": this.state.reportType == null? this.state.tempData.report_id : this.state.reportType.report_id,
"company_id": this.state.company == null? this.state.tempData.company_id : this.state.company.company_id,
"report_id": this.state.reportType == null ? this.state.tempData.report_id : this.state.reportType.report_id,
"company_id": this.state.company == null ? this.state.tempData.company_id : this.state.company.company_id,
"description": this.state.tempData.description,
"orders": this.state.tempData.order,
"parent": this.state.parent == null? this.state.tempData.parent : this.state.parent.item_report_id,
"type_report_id": this.state.InputType == null? this.state.tempData.type_report_id : this.state.InputType.type_report_id,
"parent": this.state.parent == null ? this.state.tempData.parent : this.state.parent.item_report_id,
"type_report_id": this.state.InputType == null ? this.state.tempData.type_report_id : this.state.InputType.type_report_id,
"formula": this.state.tempData.formula,
"uom": this.state.tempData.uom,
"weight": this.state.tempData.weight,
......@@ -156,22 +160,23 @@ export default class EditReportItems extends Component {
"end_date": this.state.tempData.end_date
}
console.log(payload)
// api.create().updateReportItems(payload).then((response) => {
// if (response.data) {
// if (response.data.status === 'success') {
// this.props.onClickClose()
// this.props.refresh()
// } else {
// alert(response.data.message)
// }
// }
// })
api.create().updateReportItems(payload).then((response) => {
console.log(response);
if (response.data) {
if (response.data.status === 'success') {
this.props.onClickClose()
this.props.refresh()
} else {
alert(response.data.message)
}
}
})
}
getDetailReportItems() {
api.create().getDetailReportItems(this.props.data[1]).then((response) => {
if (response.data.status === 'success') {
this.setState({ tempData: response.data.data}, () => this.getInputType(), this.getPerusahaan(), this.getReportType(),)
this.setState({ tempData: response.data.data }, () => this.getInputType(), this.getPerusahaan(), this.getReportType(),)
console.log(response.data.data)
} else {
alert(response.data.message)
......@@ -182,7 +187,7 @@ export default class EditReportItems extends Component {
getInputType() {
api.create().getInputType().then((response) => {
// console.log(response)
if(response.data.status === 'success') {
if (response.data.status === 'success') {
let data = response.data.data
let inputData = data.map((item) => {
return {
......@@ -196,7 +201,7 @@ export default class EditReportItems extends Component {
};
let index = inputData.findIndex((val) => val.type_report_id === this.state.tempData.type_report_id)
this.setState({listInputType: defaultProps, InputType: index === -1 ? null : inputData[index]})
this.setState({ listInputType: defaultProps, InputType: index === -1 ? null : inputData[index] })
} else {
alert(response.data.message)
}
......@@ -206,7 +211,7 @@ export default class EditReportItems extends Component {
getPerusahaan() {
api.create().getPerusahaanActive().then((response) => {
console.log(response)
if(response.data.status === 'success') {
if (response.data.status === 'success') {
let data = response.data.data
let companyData = data.map((item) => {
return {
......@@ -220,7 +225,7 @@ export default class EditReportItems extends Component {
};
let index = companyData.findIndex((val) => val.company_id === this.state.tempData.company_id)
this.setState({listCompany: defaultProps, company: index === -1 ? null : companyData[index]}, () => this.getParent())
this.setState({ listCompany: defaultProps, company: index === -1 ? null : companyData[index] }, () => this.getParent())
} else {
alert(response.data.message)
}
......@@ -230,7 +235,7 @@ export default class EditReportItems extends Component {
getReportType() {
api.create().getReportType().then((response) => {
console.log(response)
if(response.data.status === 'success') {
if (response.data.status === 'success') {
let data = response.data.data
let reportTypeData = data.map((item) => {
return {
......@@ -244,7 +249,7 @@ export default class EditReportItems extends Component {
};
let index = reportTypeData.findIndex((val) => val.report_id === this.state.tempData.report_id)
this.setState({listReportType: defaultProps, reportType: index === -1 ? null: reportTypeData[index]}, () => this.getParent())
this.setState({ listReportType: defaultProps, reportType: index === -1 ? null : reportTypeData[index] }, () => this.getParent())
} else {
alert(response.data.message)
}
......@@ -259,7 +264,7 @@ export default class EditReportItems extends Component {
}
api.create().getReportParent(payload).then((response) => {
console.log(response)
if(response.data.status === 'success') {
if (response.data.status === 'success') {
let data = response.data.data
let parentData = data.map((item) => {
return {
......@@ -272,7 +277,7 @@ export default class EditReportItems extends Component {
getOptionLabel: (option) => titleCase(option.description),
};
let index = parentData.findIndex((val) => val.item_report_id === this.state.tempData.parent)
this.setState({listParent: defaultProps, parent: index == -1? null : parentData[index]})
this.setState({ listParent: defaultProps, parent: index == -1 ? null : parentData[index] })
} else {
alert(response.data.message)
}
......@@ -280,6 +285,15 @@ export default class EditReportItems extends Component {
}
}
clearMessage() {
this.setState({
errorFormula: false, msgErrorFormula: '',
errorTipeData: false, msgErrorTipeData: '',
errorCondition: false, msgErrorCondition: '',
errorRV: false, msgErrorRV: ''
})
}
render() {
return (
......@@ -297,7 +311,7 @@ export default class EditReportItems extends Component {
className="btn btn-circle btn-white"
onClick={() => this.props.onClickClose()}
>
<img src={Images.close}/>
<img src={Images.close} />
</button>
</div>
</div>
......@@ -330,11 +344,11 @@ export default class EditReportItems extends Component {
</div>
</div>
<div className="column-2">
<div className="margin-top-10px" style={{padding: 10}}>
<div className="margin-top-10px" style={{ padding: 10 }}>
<Autocomplete
{...this.state.listReportType}
id="reportType"
onChange={(event, newInputValue) => this.setState({reportType: newInputValue}, () => this.getParent())}
onChange={(event, newInputValue) => this.setState({ reportType: newInputValue }, () => this.getParent())}
debug
renderInput={(params) =>
<TextField {...params}
......@@ -355,11 +369,11 @@ export default class EditReportItems extends Component {
</div>
<div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1">
<div className="margin-top-10px" style={{padding: 10}} >
<div className="margin-top-10px" style={{ padding: 10 }} >
<Autocomplete
{...this.state.listCompany}
id="company"
onChange={(event, newInputValue) => this.setState({company: newInputValue}, () => this.getParent())}
onChange={(event, newInputValue) => this.setState({ company: newInputValue }, () => this.getParent())}
debug
renderInput={(params) =>
<TextField {...params}
......@@ -436,11 +450,11 @@ export default class EditReportItems extends Component {
</div>
</div>
<div className="column-2">
<div className="margin-top-10px" style={{padding: 10}} >
<div className="margin-top-10px" style={{ padding: 10 }} >
<Autocomplete
{...this.state.listParent}
id="parentId"
onChange={(event, newInputValue) => this.setState({parent: newInputValue})}
onChange={(event, newInputValue) => this.setState({ parent: newInputValue })}
disabled={this.state.reportType == null || this.state.company == null}
debug
renderInput={(params) =>
......@@ -516,16 +530,16 @@ export default class EditReportItems extends Component {
</div>
<div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1">
<div className="margin-top-10px" style={{padding: 10}}>
<div className="margin-top-10px" style={{ padding: 10 }}>
<Autocomplete
{...this.state.listInputType}
id="inputType"
onChange={(event, newInputValue) =>
this.setState({InputType: newInputValue,
tempData: {...this.state.tempData, formula: '', condition_it_should_be: '', condition_if_wrong: ''},
errorFormula: false, msgErrorFormula: '',
errorRV: false, msgErrorRV: ''},
() => console.log(this.state.InputType))}
this.setState({
InputType: newInputValue,
tempData: { ...this.state.tempData, formula: '', condition_it_should_be: '', condition_if_wrong: '' },
},
() => console.log(this.state.InputType), this.clearMessage())}
debug
renderInput={(params) =>
<TextField {...params}
......@@ -537,6 +551,8 @@ export default class EditReportItems extends Component {
color: '#7e8085'
}
}}
error={this.state.errorTipeData}
helperText={this.state.msgErrorTipeData}
InputProps={{ ...params.InputProps, style: { fontSize: 11, fontFamily: 'Nunito Sans, sans-serif' } }}
/>}
value={this.state.InputType}
......@@ -549,7 +565,7 @@ export default class EditReportItems extends Component {
style={{ width: '100%' }}
id="formula"
label="Formula"
disabled={this.state.InputType == null? true : (this.state.InputType.type_report_name === 'Formula' || this.state.InputType.type_report_name === 'Validation'? false : true)}
disabled={this.state.InputType == null ? true : (this.state.InputType.type_report_name === 'Formula' || this.state.InputType.type_report_name === 'Validation' ? false : true)}
name="formula"
error={this.state.errorFormula}
helperText={this.state.msgErrorFormula}
......@@ -582,7 +598,7 @@ export default class EditReportItems extends Component {
label="Nilai Seharusnya"
error={this.state.errorRV}
helperText={this.state.msgErrorRV}
disabled={this.state.InputType == null? true : (this.state.InputType.type_report_name === 'Validation'? false : true)}
disabled={this.state.InputType == null ? true : (this.state.InputType.type_report_name === 'Validation' ? false : true)}
name="condition_it_should_be"
onChange={(e) => this.handleChange(e, '')}
value={this.state.tempData === null ? '' : this.state.tempData.condition_it_should_be}
......@@ -603,13 +619,13 @@ export default class EditReportItems extends Component {
</div>
</div>
<div className="column-2">
<div className="margin-top-10px" style={{padding: 10}}>
<div className="margin-top-10px" style={{ padding: 10 }}>
<Autocomplete
value={this.state.tempData === null ? '' : this.state.tempData.condition}
value={this.state.tempData === null ? "" : this.state.tempData.condition_if_wrong}
id="isWrongCondition"
disabled={this.state.InputType == null? true : (this.state.InputType.type_report_name === 'Validation'? false : true)}
disabled={this.state.InputType == null ? true : (this.state.InputType.type_report_name === 'Validation' ? false : true)}
onChange={(event, newValue) => {
this.setState({condition: newValue});
this.setState({ tempData: { ...this.state.tempData, condition_if_wrong: newValue } }, () => this.clearMessage());
}}
options={this.state.options}
renderInput={(params) =>
......@@ -622,6 +638,8 @@ export default class EditReportItems extends Component {
color: '#7e8085'
}
}}
error={this.state.errorCondition}
helperText={this.state.msgErrorCondition}
InputProps={{ ...params.InputProps, style: { fontSize: 11, fontFamily: 'Nunito Sans, sans-serif' } }}
/>}
/>
......@@ -697,13 +715,13 @@ export default class EditReportItems extends Component {
<div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1">
<div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
<div style={{display: 'flex'}}>
<div style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '20%' }}>Dibuat</Typography>
<Typography style={{ fontSize: 11 }}>: Admin - 21 Jul 2020, 18:45</Typography>
<Typography style={{ fontSize: 11 }}>: {this.state.tempData === null ? "" : this.state.tempData.created}</Typography>
</div>
<div style={{display: 'flex'}}>
<div style={{ display: 'flex' }}>
<Typography style={{ fontSize: 11, width: '20%' }}>Diubah</Typography>
<Typography style={{ fontSize: 11 }}>: Admin - 21 Jul 2020, 18:45</Typography>
<Typography style={{ fontSize: 11 }}>: {this.state.tempData === null ? "" : this.state.tempData.updated}</Typography>
</div>
</div>
</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