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

validasi ReportItem

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